1- import React , { useEffect , useState , useMemo } from "react"
1+ import React , { useEffect , useState } from "react"
22import { centroid } from "@turf/centroid"
3- import DeckGL from "@deck.gl/react"
3+ import { Map , useControl , useMap } from "react-map-gl/mapbox"
4+ import { MapboxOverlay } from "@deck.gl/mapbox"
45import {
56 COORDINATE_SYSTEM ,
67 _GlobeView as GlobeView ,
@@ -22,6 +23,7 @@ import {
2223import "./deck-gl.css"
2324import { colors } from "../../theme"
2425import { MOVING_PLATFORMS } from "../../utils/constants"
26+ import "maplibre-gl/dist/maplibre-gl.css"
2527
2628const INITIAL_VIEW_STATE = {
2729 longitude : - 98 ,
@@ -30,6 +32,20 @@ const INITIAL_VIEW_STATE = {
3032}
3133const MAPBOX_TOKEN = process . env . GATSBY_MAPBOX_TOKEN
3234
35+ function DeckGLOverlay ( props ) {
36+ const overlay = useControl ( ( ) => new MapboxOverlay ( props ) )
37+ const { current : map } = useMap ( )
38+
39+ useEffect ( ( ) => {
40+ if ( map ) {
41+ map . flyTo ( { center : [ - 90 , 20 ] , curve : 0.1 , speed : 0.002 } )
42+ }
43+ } , [ map ] )
44+
45+ overlay . setProps ( props )
46+ return null
47+ }
48+
3349export function GlobeMap ( {
3450 geojson,
3551 deployments,
@@ -77,54 +93,13 @@ export function GlobeMap({
7793 longitude : lon ,
7894 latitude : lat ,
7995 zoom : 1 ,
80- transitionInterpolator : new FlyToInterpolator ( { speed : 1.5 } ) ,
8196 transitionDuration : "auto" ,
8297 } )
8398 } , [ geojson ] )
8499
85- const backgroundLayers = useMemo (
86- ( ) => [
87- new SimpleMeshLayer ( {
88- id : "earth-sphere" ,
89- data : [ 0 ] ,
90- mesh : new SphereGeometry ( {
91- radius : 6.3e6 ,
92- nlat : 18 ,
93- nlong : 36 ,
94- } ) ,
95- coordinateSystem : COORDINATE_SYSTEM . CARTESIAN ,
96- getPosition : [ 0 , 0 , 0 ] ,
97- getColor : [ 42 , 98 , 163 , 125 ] ,
98- } ) ,
99- new TileLayer ( {
100- id : "TileLayer" ,
101- data : `https://api.mapbox.com/styles/v1/${ mapStyleID } /tiles/256/{z}/{x}/{y}@2x?access_token=${ MAPBOX_TOKEN } ` ,
102- maxZoom : 22 ,
103- minZoom : 3 ,
104- extent : [ - 180 , - 90 , 180 , 90 ] ,
105- tileSize : 256 ,
106- renderSubLayers : props => {
107- // eslint-disable-next-line react/prop-types
108- const { boundingBox } = props . tile
109- return new BitmapLayer ( props , {
110- data : null ,
111- // eslint-disable-next-line react/prop-types
112- image : props . data ,
113- bounds : [
114- boundingBox [ 0 ] [ 0 ] ,
115- boundingBox [ 0 ] [ 1 ] ,
116- boundingBox [ 1 ] [ 0 ] ,
117- boundingBox [ 1 ] [ 1 ] ,
118- ] ,
119- } )
120- } ,
121- } ) ,
122- ] ,
123- [ ]
124- )
125-
126100 const flights = new GeoJsonLayer ( {
127101 id : "flights" ,
102+ pickable : true ,
128103 data : {
129104 ...geojson ,
130105 features : geojson . features
@@ -138,7 +113,7 @@ export function GlobeMap({
138113 ) ,
139114 } ,
140115 lineWidthMinPixels : 0.5 ,
141- getLineWidth : 1 ,
116+ getLineWidth : 1.5 ,
142117 getLineColor : f =>
143118 getLineColorAsRGB (
144119 movingPlatforms
@@ -168,37 +143,18 @@ export function GlobeMap({
168143 if ( iconMapping && geojson ) {
169144 return (
170145 < MapContainer >
171- < DeckGL
172- views = {
173- new GlobeView ( {
174- controller : { keyboard : false , inertia : true } ,
175- } )
176- }
177- controller = { true }
146+ < Map
147+ reuseMaps
148+ projection = "globe"
149+ id = "map"
150+ // mapStyle="https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json"
151+ mapStyle = { `mapbox://styles/ ${ mapStyleID } ` }
152+ mapboxAccessToken = { MAPBOX_TOKEN }
178153 initialViewState = { initialViewState }
179- layers = { [ backgroundLayers , flights , staticLocations ] }
180- widgets = { [
181- new ZoomWidget ( { placement : "bottom-right" } ) ,
182- new FullscreenWidget ( { placement : "bottom-right" } ) ,
183- ] }
184- > </ DeckGL >
154+ >
155+ < DeckGLOverlay layers = { [ flights , staticLocations ] } />
156+ </ Map >
185157 { children }
186- < Attribution >
187- < a
188- href = "https://www.mapbox.com/about/maps/"
189- target = "_blank"
190- rel = "noreferrer"
191- >
192- © Mapbox
193- </ a >
194- < a
195- href = "https://www.openstreetmap.org/about/"
196- target = "_blank"
197- rel = "noreferrer"
198- >
199- © OpenStreetMap
200- </ a >
201- </ Attribution >
202158 </ MapContainer >
203159 )
204160 }
0 commit comments