首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Deck.gl globe建议

Deck.gl globe建议
EN

Stack Overflow用户
提问于 2020-08-21 19:58:04
回答 1查看 197关注 0票数 0

我想知道是否有人能提供一个在Deck.gl中使用的地球的例子,它是一个真实的地球还是仅仅是一个视图。因为我希望能够看到一个地球,我做了一个小小的尝试来使用它,但这给我留下了一个静态的背景地图和一个放在上面的全局视图,这并不是我想要的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-22 01:02:15

我在deck.gl网站上找到了全球视图的示例,我已经更改了代码以利用React,这似乎工作得很好。

代码语言:javascript
复制
import React from 'react'
import {Deck, _GlobeView as GlobeView} from '@deck.gl/core';
import {SolidPolygonLayer, GeoJsonLayer, ArcLayer} from '@deck.gl/layers';
import { DeckGL } from 'deck.gl';

// source: Natural Earth http://www.naturalearthdata.com/ via geojson.xyz
const COUNTRIES =
  'https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_50m_admin_0_scale_rank.geojson'; //eslint-disable-line
const AIR_PORTS =
  'https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_10m_airports.geojson';

const INITIAL_VIEW_STATE = {
  latitude: 50,
  longitude: 50,
  zoom: 0
};

export function Globe() {

    return (
        <DeckGL 
            views={ new GlobeView()}
            initialViewState={INITIAL_VIEW_STATE}
            controller={true}
            layers= {[
                // A GeoJSON polygon that covers the entire earth
                // See /docs/api-reference/globe-view.md#remarks
                new SolidPolygonLayer({
                    id: 'background',
                    data: [
                        // prettier-ignore
                        [[-180, 90], [0, 90], [180, 90], [180, -90], [0, -90], [-180, -90]]
                    ],
                    opacity: 0.5,
                    getPolygon: d => d,
                    stroked: false,
                    filled: true,
                    getFillColor: [32, 201, 218]
                }),
                new GeoJsonLayer({
                    id: 'base-map',
                    data: COUNTRIES,
                    // Styles
                    stroked: true,
                    filled: true,
                    lineWidthMinPixels: 2,
                    getLineColor: [35, 107, 19],
                    getFillColor: [41, 156, 22]
                }),
                new GeoJsonLayer({
                    id: 'airports',
                    data: AIR_PORTS,
                    // Styles
                    filled: true,
                    pointRadiusMinPixels: 2,
                    pointRadiusScale: 2000,
                    getRadius: f => 11 - f.properties.scalerank,
                    getFillColor: [200, 0, 80, 180],
                    // Interactive props
                    pickable: true,
                    autoHighlight: true,
                    onClick: info =>
                        // eslint-disable-next-line
                        info.object && alert(`${info.object.properties.name} (${info.object.properties.abbrev})`)
                }),
                new ArcLayer({
                    id: 'arcs',
                    data: AIR_PORTS,
                    dataTransform: d => d.features.filter(f => f.properties.scalerank < 4),
                    // Styles
                    getSourcePosition: f => [-0.4531566, 51.4709959], // London
                    getTargetPosition: f => f.geometry.coordinates,
                    getSourceColor: [0, 128, 200],
                    getTargetColor: [200, 0, 80],
                    getWidth: 1
                })
            ]}
        />   
    )
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63522514

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档