@deck.gl/mapbox 8.8.0-beta.2 → 8.8.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dist.dev.js CHANGED
@@ -183,25 +183,27 @@ function getDeckInstance({
183
183
  map.on('move', () => onMapMove(deck, map));
184
184
  }
185
185
 
186
+ let deckInstance;
187
+
186
188
  if (deck) {
189
+ deckInstance = deck;
187
190
  deck.setProps(deckProps);
188
191
  deck.userData.isExternal = true;
189
192
  } else {
190
- deck = new _deck_gl_core__WEBPACK_IMPORTED_MODULE_0__["Deck"](deckProps);
193
+ deckInstance = new _deck_gl_core__WEBPACK_IMPORTED_MODULE_0__["Deck"](deckProps);
191
194
  map.on('remove', () => {
192
- deck.finalize();
195
+ deckInstance.finalize();
193
196
  map.__deck = null;
194
197
  });
195
198
  }
196
199
 
197
- deck.userData.mapboxLayers = new Set();
198
- deck.userData.mapboxVersion = getMapboxVersion(map);
199
- map.__deck = deck;
200
+ deckInstance.userData.mapboxLayers = new Set();
201
+ deckInstance.userData.mapboxVersion = getMapboxVersion(map);
202
+ map.__deck = deckInstance;
200
203
  map.on('render', () => {
201
- // @ts-expect-error (2445) protected property
202
- if (deck.layerManager) afterRender(deck, map);
204
+ if (deckInstance.isInitialized) afterRender(deckInstance, map);
203
205
  });
204
- return deck;
206
+ return deckInstance;
205
207
  }
206
208
  function addLayer(deck, layer) {
207
209
  deck.userData.mapboxLayers.add(layer);
@@ -224,10 +226,9 @@ function drawLayer(deck, map, layer) {
224
226
  // Generate viewport from the current map state.
225
227
  currentViewport = getViewport(deck, map, true);
226
228
  deck.userData.currentViewport = currentViewport;
227
- } // @ts-expect-error (2445) protected property
228
-
229
+ }
229
230
 
230
- if (!deck.layerManager) {
231
+ if (!deck.isInitialized) {
231
232
  return;
232
233
  }
233
234
 
@@ -17,8 +17,6 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
17
17
  var _core = require("@deck.gl/core");
18
18
 
19
19
  function getDeckInstance(_ref) {
20
- var _deck;
21
-
22
20
  var map = _ref.map,
23
21
  gl = _ref.gl,
24
22
  deck = _ref.deck;
@@ -27,7 +25,7 @@ function getDeckInstance(_ref) {
27
25
  return map.__deck;
28
26
  }
29
27
 
30
- var customRender = (_deck = deck) === null || _deck === void 0 ? void 0 : _deck.props._customRender;
28
+ var customRender = deck === null || deck === void 0 ? void 0 : deck.props._customRender;
31
29
  var deckProps = {
32
30
  useDevicePixels: true,
33
31
  _customRender: function _customRender(reason) {
@@ -61,24 +59,27 @@ function getDeckInstance(_ref) {
61
59
  });
62
60
  }
63
61
 
62
+ var deckInstance;
63
+
64
64
  if (deck) {
65
+ deckInstance = deck;
65
66
  deck.setProps(deckProps);
66
67
  deck.userData.isExternal = true;
67
68
  } else {
68
- deck = new _core.Deck(deckProps);
69
+ deckInstance = new _core.Deck(deckProps);
69
70
  map.on('remove', function () {
70
- deck.finalize();
71
+ deckInstance.finalize();
71
72
  map.__deck = null;
72
73
  });
73
74
  }
74
75
 
75
- deck.userData.mapboxLayers = new Set();
76
- deck.userData.mapboxVersion = getMapboxVersion(map);
77
- map.__deck = deck;
76
+ deckInstance.userData.mapboxLayers = new Set();
77
+ deckInstance.userData.mapboxVersion = getMapboxVersion(map);
78
+ map.__deck = deckInstance;
78
79
  map.on('render', function () {
79
- if (deck.layerManager) afterRender(deck, map);
80
+ if (deckInstance.isInitialized) afterRender(deckInstance, map);
80
81
  });
81
- return deck;
82
+ return deckInstance;
82
83
  }
83
84
 
84
85
  function addLayer(deck, layer) {
@@ -104,7 +105,7 @@ function drawLayer(deck, map, layer) {
104
105
  deck.userData.currentViewport = currentViewport;
105
106
  }
106
107
 
107
- if (!deck.layerManager) {
108
+ if (!deck.isInitialized) {
108
109
  return;
109
110
  }
110
111
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/deck-utils.ts"],"names":["getDeckInstance","map","gl","deck","__deck","customRender","props","_customRender","deckProps","useDevicePixels","reason","triggerRepaint","parameters","depthMask","depthTest","blend","blendFunc","polygonOffsetFill","depthFunc","blendEquation","views","MapView","id","Object","assign","width","height","touchAction","viewState","getViewState","on","onMapMove","setProps","userData","isExternal","Deck","finalize","mapboxLayers","Set","mapboxVersion","getMapboxVersion","layerManager","afterRender","addLayer","layer","add","updateLayers","removeLayer","delete","updateLayer","drawLayer","currentViewport","getViewport","_drawLayers","viewports","layerFilter","deckLayer","clearCanvas","getCenter","lng","lat","longitude","latitude","zoom","getZoom","bearing","getBearing","pitch","getPitch","padding","getPadding","repeat","getRenderWorldCopies","major","minor","version","split","slice","Number","useMapboxProjection","WebMercatorViewport","x","y","nearZMultiplier","mapboxLayerIds","Array","from","deckLayers","layers","Boolean","hasNonMapboxLayers","some","includes","getViewports","mapboxViewportIdx","findIndex","vp","hasNonMapboxViews","length","params","viewport","needsRedraw","clearRedrawFlags","layerIndex","forEach","LayerType","type","_offset","push"],"mappings":";;;;;;;;;;;;;;;;AAAA;;AAYO,SAASA,eAAT,OAQE;AAAA;;AAAA,MAPPC,GAOO,QAPPA,GAOO;AAAA,MANPC,EAMO,QANPA,EAMO;AAAA,MALPC,IAKO,QALPA,IAKO;;AAEP,MAAIF,GAAG,CAACG,MAAR,EAAgB;AACd,WAAOH,GAAG,CAACG,MAAX;AACD;;AAED,MAAMC,YAAY,YAAGF,IAAH,0CAAG,MAAMG,KAAN,CAAYC,aAAjC;AAEA,MAAMC,SAAoB,GAAG;AAC3BC,IAAAA,eAAe,EAAE,IADU;AAE3BF,IAAAA,aAAa,EAAE,uBAACG,MAAD,EAAoB;AACjCT,MAAAA,GAAG,CAACU,cAAJ;AAGAN,MAAAA,YAAY,SAAZ,IAAAA,YAAY,WAAZ,YAAAA,YAAY,CAAGK,MAAH,CAAZ;AACD,KAP0B;AAS3BE,IAAAA,UAAU,EAAE;AACVC,MAAAA,SAAS,EAAE,IADD;AAEVC,MAAAA,SAAS,EAAE,IAFD;AAGVC,MAAAA,KAAK,EAAE,IAHG;AA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CAAmB5B,IAAnB,EAA+BF,GAA/B,EAA+C;AAC7CE,EAAAA,IAAI,CAAC6B,QAAL,CAAc;AACZJ,IAAAA,SAAS,EAAEC,YAAY,CAAC5B,GAAD;AADX,GAAd;AAMAE,EAAAA,IAAI,CAACkG,WAAL,CAAiB;AAACC,IAAAA,gBAAgB,EAAE;AAAnB,GAAjB;AACD;;AAED,SAASxD,YAAT,CAAsB3C,IAAtB,EAAwC;AACtC,MAAKA,IAAI,CAAC8B,QAAN,CAA4BC,UAAhC,EAA4C;AAC1C;AACD;;AAED,MAAMsD,MAAe,GAAG,EAAxB;AACA,MAAIe,UAAU,GAAG,CAAjB;AACCpG,EAAAA,IAAI,CAAC8B,QAAN,CAA4BI,YAA5B,CAAyCmE,OAAzC,CAAiD,UAAAhD,SAAS,EAAI;AAC5D,QAAMiD,SAAS,GAAGjD,SAAS,CAAClD,KAAV,CAAgBoG,IAAlC;AACA,QAAM9D,KAAK,GAAG,IAAI6D,SAAJ,CAAcjD,SAAS,CAAClD,KAAxB,EAA+B;AAACqG,MAAAA,OAAO,EAAEJ,UAAU;AAApB,KAA/B,CAAd;AACAf,IAAAA,MAAM,CAACoB,IAAP,CAAYhE,KAAZ;AACD,GAJD;AAKAzC,EAAAA,IAAI,CAAC6B,QAAL,CAAc;AAACwD,IAAAA,MAAM,EAANA;AAAD,GAAd;AACD","sourcesContent":["import {Deck, WebMercatorViewport, MapView, _flatten as flatten} from '@deck.gl/core';\nimport type {DeckProps, MapViewState, Layer} from '@deck.gl/core';\nimport type MapboxLayer from './mapbox-layer';\nimport type {Map} from 'mapbox-gl';\n\ntype UserData = {\n isExternal: boolean;\n currentViewport?: WebMercatorViewport | null;\n mapboxLayers: Set<MapboxLayer<any>>;\n mapboxVersion: {minor: number; major: number};\n};\n\nexport function getDeckInstance({\n map,\n gl,\n deck\n}: {\n map: Map & {__deck?: Deck | null};\n gl: WebGLRenderingContext;\n deck?: Deck;\n}): Deck {\n // Only create one deck instance per context\n if (map.__deck) {\n return map.__deck;\n }\n\n const customRender = deck?.props._customRender;\n\n const deckProps: DeckProps = {\n useDevicePixels: true,\n _customRender: (reason: string) => {\n map.triggerRepaint();\n // customRender may be subscribed by DeckGL React component to update child props\n // make sure it is still called\n customRender?.(reason);\n },\n // TODO: import these defaults from a single source of truth\n parameters: {\n depthMask: true,\n depthTest: true,\n blend: true,\n blendFunc: [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA],\n polygonOffsetFill: true,\n depthFunc: gl.LEQUAL,\n blendEquation: gl.FUNC_ADD\n },\n views: (deck && deck.props.views) || [new MapView({id: 'mapbox'})]\n };\n\n if (!deck || deck.props.gl === gl) {\n // deck is using the WebGLContext created by mapbox\n // block deck from setting the canvas size\n Object.assign(deckProps, {\n gl,\n width: null,\n height: null,\n touchAction: 'unset',\n viewState: getViewState(map)\n });\n // If using the WebGLContext created by deck (React use case), we use deck's viewState to drive the map.\n // Otherwise (pure JS use case), we use the map's viewState to drive deck.\n map.on('move', () => onMapMove(deck!, map));\n }\n\n if (deck) {\n deck.setProps(deckProps);\n (deck.userData as UserData).isExternal = true;\n } else {\n deck = new Deck(deckProps);\n map.on('remove', () => {\n deck!.finalize();\n map.__deck = null;\n });\n }\n\n (deck.userData as UserData).mapboxLayers = new Set();\n (deck.userData as UserData).mapboxVersion = getMapboxVersion(map);\n map.__deck = deck;\n map.on('render', () => {\n // @ts-expect-error (2445) protected property\n if (deck.layerManager) afterRender(deck, map);\n });\n\n return deck;\n}\n\nexport function addLayer(deck: Deck, layer: MapboxLayer<any>): void {\n (deck.userData as UserData).mapboxLayers.add(layer);\n updateLayers(deck);\n}\n\nexport function removeLayer(deck: Deck, layer: MapboxLayer<any>): void {\n (deck.userData as UserData).mapboxLayers.delete(layer);\n updateLayers(deck);\n}\n\nexport function updateLayer(deck: Deck, layer: MapboxLayer<any>): void {\n updateLayers(deck);\n}\n\nexport function drawLayer(deck: Deck, map: Map, layer: MapboxLayer<any>): void {\n let {currentViewport} = deck.userData as UserData;\n if (!currentViewport) {\n // This is the first layer drawn in this render cycle.\n // Generate viewport from the current map state.\n currentViewport = getViewport(deck, map, true);\n (deck.userData as UserData).currentViewport = currentViewport;\n }\n\n // @ts-expect-error (2445) protected property\n if (!deck.layerManager) {\n return;\n }\n\n deck._drawLayers('mapbox-repaint', {\n viewports: [currentViewport],\n layerFilter: ({layer: deckLayer}) => layer.id === deckLayer.id,\n clearCanvas: false\n });\n}\n\nexport function getViewState(map: Map): MapViewState & {\n repeat: boolean;\n padding: {\n left: number;\n right: number;\n top: number;\n bottom: number;\n };\n} {\n const {lng, lat} = map.getCenter();\n return {\n // Longitude returned by getCenter can be outside of [-180, 180] when zooming near the anti meridian\n // https://github.com/visgl/deck.gl/issues/6894\n longitude: ((lng + 540) % 360) - 180,\n latitude: lat,\n zoom: map.getZoom(),\n bearing: map.getBearing(),\n pitch: map.getPitch(),\n padding: map.getPadding(),\n repeat: map.getRenderWorldCopies()\n };\n}\n\nfunction getMapboxVersion(map: Map): {minor: number; major: number} {\n // parse mapbox version string\n let major = 0;\n let minor = 0;\n // @ts-ignore (2339) undefined property\n const version: string = map.version;\n if (version) {\n [major, minor] = version.split('.').slice(0, 2).map(Number);\n }\n return {major, minor};\n}\n\nfunction getViewport(deck: Deck, map: Map, useMapboxProjection = true): WebMercatorViewport {\n const {mapboxVersion} = deck.userData as UserData;\n\n return new WebMercatorViewport(\n Object.assign(\n {\n id: 'mapbox',\n x: 0,\n y: 0,\n width: deck.width,\n height: deck.height\n },\n getViewState(map),\n useMapboxProjection\n ? {\n // match mapbox's projection matrix\n // A change of near plane was made in 1.3.0\n // https://github.com/mapbox/mapbox-gl-js/pull/8502\n nearZMultiplier:\n (mapboxVersion.major === 1 && mapboxVersion.minor >= 3) || mapboxVersion.major >= 2\n ? 0.02\n : 1 / (deck.height || 1)\n }\n : {\n // use deck.gl's own default\n nearZMultiplier: 0.1\n }\n )\n );\n}\n\nfunction afterRender(deck: Deck, map: Map): void {\n const {mapboxLayers, isExternal} = deck.userData as UserData;\n\n if (isExternal) {\n // Draw non-Mapbox layers\n const mapboxLayerIds = Array.from(mapboxLayers, layer => layer.id);\n const deckLayers = flatten(deck.props.layers, Boolean) as Layer[];\n const hasNonMapboxLayers = deckLayers.some(\n layer => layer && !mapboxLayerIds.includes(layer.id)\n );\n let viewports = deck.getViewports();\n const mapboxViewportIdx = viewports.findIndex(vp => vp.id === 'mapbox');\n const hasNonMapboxViews = viewports.length > 1 || mapboxViewportIdx < 0;\n\n if (hasNonMapboxLayers || hasNonMapboxViews) {\n if (mapboxViewportIdx >= 0) {\n viewports = viewports.slice();\n viewports[mapboxViewportIdx] = getViewport(deck, map, false);\n }\n\n deck._drawLayers('mapbox-repaint', {\n viewports,\n layerFilter: params =>\n (!deck.props.layerFilter || deck.props.layerFilter(params)) &&\n (params.viewport.id !== 'mapbox' || !mapboxLayerIds.includes(params.layer.id)),\n clearCanvas: false\n });\n }\n }\n\n // End of render cycle, clear generated viewport\n (deck.userData as UserData).currentViewport = null;\n}\n\nfunction onMapMove(deck: Deck, map: Map): void {\n deck.setProps({\n viewState: getViewState(map)\n });\n // Camera changed, will trigger a map repaint right after this\n // Clear any change flag triggered by setting viewState so that deck does not request\n // a second repaint\n deck.needsRedraw({clearRedrawFlags: true});\n}\n\nfunction updateLayers(deck: Deck): void {\n if ((deck.userData as UserData).isExternal) {\n return;\n }\n\n const layers: Layer[] = [];\n let layerIndex = 0;\n (deck.userData as UserData).mapboxLayers.forEach(deckLayer => {\n const LayerType = deckLayer.props.type;\n const layer = new LayerType(deckLayer.props, {_offset: layerIndex++});\n layers.push(layer);\n });\n deck.setProps({layers});\n}\n"],"file":"deck-utils.js"}
1
+ {"version":3,"sources":["../../src/deck-utils.ts"],"names":["getDeckInstance","map","gl","deck","__deck","customRender","props","_customRender","deckProps","useDevicePixels","reason","triggerRepaint","parameters","depthMask","depthTest","blend","blendFunc","polygonOffsetFill","depthFunc","blendEquation","views","MapView","id","Object","assign","width","height","touchAction","viewState","getViewState","on","onMapMove","deckInstance","setProps","userData","isExternal","Deck","finalize","mapboxLayers","Set","mapboxVersion","getMapboxVersion","isInitialized","afterRender","addLayer","layer","add","updateLayers","removeLayer","delete","updateLayer","drawLayer","currentViewport","getViewport","_drawLayers","viewports","layerFilter","deckLayer","clearCanvas","getCenter","lng","lat","longitude","latitude","zoom","getZoom","bearing","getBearing","pitch","getPitch","padding","getPadding","repeat","getRenderWorldCopies","major","minor","version","split","slice","Number","useMapboxProjection","WebMercatorViewport","x","y","nearZMultiplier","mapboxLayerIds","Array","from","deckLayers","layers","Boolean","hasNonMapboxLayers","some","includes","getViewports","mapboxViewportIdx","findIndex","vp","hasNonMapboxViews","length","params","viewport","needsRedraw","clearRedrawFlags","layerIndex","forEach","LayerType","type","_offset","push"],"mappings":";;;;;;;;;;;;;;;;AAAA;;AAYO,SAASA,eAAT,OAQE;AAAA,MAPPC,GAOO,QAPPA,GAOO;AAAA,MANPC,EAMO,QANPA,EAMO;AAAA,MALPC,IAKO,QALPA,IAKO;;AAEP,MAAIF,GAAG,CAACG,MAAR,EAAgB;AACd,WAAOH,GAAG,CAACG,MAAX;AACD;;AAED,MAAMC,YAAY,GAAGF,IAAH,aAAGA,IAAH,uBAAGA,IAAI,CAAEG,KAAN,CAAYC,aAAjC;AAEA,MAAMC,SAAoB,GAAG;AAC3BC,IAAAA,eAAe,EAAE,IADU;AAE3BF,IAAAA,aAAa,EAAE,uBAACG,MAAD,EAAoB;AACjCT,MAAAA,GAAG,CAACU,cAAJ;AAGAN,MAAAA,YAAY,SAAZ,IAAAA,YAAY,WAAZ,YAAAA,YAAY,CAAGK,MAAH,CAAZ;AACD,KAP0B;AAS3BE,IAAAA,UAAU,EAAE;AACVC,MAAAA,SAAS,EAAE,IADD;AAEVC,MAAAA,SAAS,EAAE,IAFD;AAGVC,MAAAA,KAAK,EAAE,IAHG;AAIVC,MAAAA,SAAS,EAAE,kBAJD;AAKVC,MAAAA,iB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IAAnB,EAA+BF,GAA/B,EAA+C;AAC7CE,EAAAA,IAAI,CAAC8B,QAAL,CAAc;AACZL,IAAAA,SAAS,EAAEC,YAAY,CAAC5B,GAAD;AADX,GAAd;AAMAE,EAAAA,IAAI,CAACmG,WAAL,CAAiB;AAACC,IAAAA,gBAAgB,EAAE;AAAnB,GAAjB;AACD;;AAED,SAASxD,YAAT,CAAsB5C,IAAtB,EAAwC;AACtC,MAAKA,IAAI,CAAC+B,QAAN,CAA4BC,UAAhC,EAA4C;AAC1C;AACD;;AAED,MAAMsD,MAAe,GAAG,EAAxB;AACA,MAAIe,UAAU,GAAG,CAAjB;AACCrG,EAAAA,IAAI,CAAC+B,QAAN,CAA4BI,YAA5B,CAAyCmE,OAAzC,CAAiD,UAAAhD,SAAS,EAAI;AAC5D,QAAMiD,SAAS,GAAGjD,SAAS,CAACnD,KAAV,CAAgBqG,IAAlC;AACA,QAAM9D,KAAK,GAAG,IAAI6D,SAAJ,CAAcjD,SAAS,CAACnD,KAAxB,EAA+B;AAACsG,MAAAA,OAAO,EAAEJ,UAAU;AAApB,KAA/B,CAAd;AACAf,IAAAA,MAAM,CAACoB,IAAP,CAAYhE,KAAZ;AACD,GAJD;AAKA1C,EAAAA,IAAI,CAAC8B,QAAL,CAAc;AAACwD,IAAAA,MAAM,EAANA;AAAD,GAAd;AACD","sourcesContent":["import {Deck, WebMercatorViewport, MapView, _flatten as flatten} from '@deck.gl/core';\nimport type {DeckProps, MapViewState, Layer} from '@deck.gl/core';\nimport type MapboxLayer from './mapbox-layer';\nimport type {Map} from 'mapbox-gl';\n\ntype UserData = {\n isExternal: boolean;\n currentViewport?: WebMercatorViewport | null;\n mapboxLayers: Set<MapboxLayer<any>>;\n mapboxVersion: {minor: number; major: number};\n};\n\nexport function getDeckInstance({\n map,\n gl,\n deck\n}: {\n map: Map & {__deck?: Deck | null};\n gl: WebGLRenderingContext;\n deck?: Deck;\n}): Deck {\n // Only create one deck instance per context\n if (map.__deck) {\n return map.__deck;\n }\n\n const customRender = deck?.props._customRender;\n\n const deckProps: DeckProps = {\n useDevicePixels: true,\n _customRender: (reason: string) => {\n map.triggerRepaint();\n // customRender may be subscribed by DeckGL React component to update child props\n // make sure it is still called\n customRender?.(reason);\n },\n // TODO: import these defaults from a single source of truth\n parameters: {\n depthMask: true,\n depthTest: true,\n blend: true,\n blendFunc: [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA],\n polygonOffsetFill: true,\n depthFunc: gl.LEQUAL,\n blendEquation: gl.FUNC_ADD\n },\n views: (deck && deck.props.views) || [new MapView({id: 'mapbox'})]\n };\n\n if (!deck || deck.props.gl === gl) {\n // deck is using the WebGLContext created by mapbox\n // block deck from setting the canvas size\n Object.assign(deckProps, {\n gl,\n width: null,\n height: null,\n touchAction: 'unset',\n viewState: getViewState(map)\n });\n // If using the WebGLContext created by deck (React use case), we use deck's viewState to drive the map.\n // Otherwise (pure JS use case), we use the map's viewState to drive deck.\n map.on('move', () => onMapMove(deck!, map));\n }\n\n let deckInstance: Deck;\n if (deck) {\n deckInstance = deck;\n deck.setProps(deckProps);\n (deck.userData as UserData).isExternal = true;\n } else {\n deckInstance = new Deck(deckProps);\n map.on('remove', () => {\n deckInstance.finalize();\n map.__deck = null;\n });\n }\n\n (deckInstance.userData as UserData).mapboxLayers = new Set();\n (deckInstance.userData as UserData).mapboxVersion = getMapboxVersion(map);\n map.__deck = deckInstance;\n map.on('render', () => {\n if (deckInstance.isInitialized) afterRender(deckInstance, map);\n });\n\n return deckInstance;\n}\n\nexport function addLayer(deck: Deck, layer: MapboxLayer<any>): void {\n (deck.userData as UserData).mapboxLayers.add(layer);\n updateLayers(deck);\n}\n\nexport function removeLayer(deck: Deck, layer: MapboxLayer<any>): void {\n (deck.userData as UserData).mapboxLayers.delete(layer);\n updateLayers(deck);\n}\n\nexport function updateLayer(deck: Deck, layer: MapboxLayer<any>): void {\n updateLayers(deck);\n}\n\nexport function drawLayer(deck: Deck, map: Map, layer: MapboxLayer<any>): void {\n let {currentViewport} = deck.userData as UserData;\n if (!currentViewport) {\n // This is the first layer drawn in this render cycle.\n // Generate viewport from the current map state.\n currentViewport = getViewport(deck, map, true);\n (deck.userData as UserData).currentViewport = currentViewport;\n }\n\n if (!deck.isInitialized) {\n return;\n }\n\n deck._drawLayers('mapbox-repaint', {\n viewports: [currentViewport],\n layerFilter: ({layer: deckLayer}) => layer.id === deckLayer.id,\n clearCanvas: false\n });\n}\n\nexport function getViewState(map: Map): MapViewState & {\n repeat: boolean;\n padding: {\n left: number;\n right: number;\n top: number;\n bottom: number;\n };\n} {\n const {lng, lat} = map.getCenter();\n return {\n // Longitude returned by getCenter can be outside of [-180, 180] when zooming near the anti meridian\n // https://github.com/visgl/deck.gl/issues/6894\n longitude: ((lng + 540) % 360) - 180,\n latitude: lat,\n zoom: map.getZoom(),\n bearing: map.getBearing(),\n pitch: map.getPitch(),\n padding: map.getPadding(),\n repeat: map.getRenderWorldCopies()\n };\n}\n\nfunction getMapboxVersion(map: Map): {minor: number; major: number} {\n // parse mapbox version string\n let major = 0;\n let minor = 0;\n // @ts-ignore (2339) undefined property\n const version: string = map.version;\n if (version) {\n [major, minor] = version.split('.').slice(0, 2).map(Number);\n }\n return {major, minor};\n}\n\nfunction getViewport(deck: Deck, map: Map, useMapboxProjection = true): WebMercatorViewport {\n const {mapboxVersion} = deck.userData as UserData;\n\n return new WebMercatorViewport(\n Object.assign(\n {\n id: 'mapbox',\n x: 0,\n y: 0,\n width: deck.width,\n height: deck.height\n },\n getViewState(map),\n useMapboxProjection\n ? {\n // match mapbox's projection matrix\n // A change of near plane was made in 1.3.0\n // https://github.com/mapbox/mapbox-gl-js/pull/8502\n nearZMultiplier:\n (mapboxVersion.major === 1 && mapboxVersion.minor >= 3) || mapboxVersion.major >= 2\n ? 0.02\n : 1 / (deck.height || 1)\n }\n : {\n // use deck.gl's own default\n nearZMultiplier: 0.1\n }\n )\n );\n}\n\nfunction afterRender(deck: Deck, map: Map): void {\n const {mapboxLayers, isExternal} = deck.userData as UserData;\n\n if (isExternal) {\n // Draw non-Mapbox layers\n const mapboxLayerIds = Array.from(mapboxLayers, layer => layer.id);\n const deckLayers = flatten(deck.props.layers, Boolean) as Layer[];\n const hasNonMapboxLayers = deckLayers.some(\n layer => layer && !mapboxLayerIds.includes(layer.id)\n );\n let viewports = deck.getViewports();\n const mapboxViewportIdx = viewports.findIndex(vp => vp.id === 'mapbox');\n const hasNonMapboxViews = viewports.length > 1 || mapboxViewportIdx < 0;\n\n if (hasNonMapboxLayers || hasNonMapboxViews) {\n if (mapboxViewportIdx >= 0) {\n viewports = viewports.slice();\n viewports[mapboxViewportIdx] = getViewport(deck, map, false);\n }\n\n deck._drawLayers('mapbox-repaint', {\n viewports,\n layerFilter: params =>\n (!deck.props.layerFilter || deck.props.layerFilter(params)) &&\n (params.viewport.id !== 'mapbox' || !mapboxLayerIds.includes(params.layer.id)),\n clearCanvas: false\n });\n }\n }\n\n // End of render cycle, clear generated viewport\n (deck.userData as UserData).currentViewport = null;\n}\n\nfunction onMapMove(deck: Deck, map: Map): void {\n deck.setProps({\n viewState: getViewState(map)\n });\n // Camera changed, will trigger a map repaint right after this\n // Clear any change flag triggered by setting viewState so that deck does not request\n // a second repaint\n deck.needsRedraw({clearRedrawFlags: true});\n}\n\nfunction updateLayers(deck: Deck): void {\n if ((deck.userData as UserData).isExternal) {\n return;\n }\n\n const layers: Layer[] = [];\n let layerIndex = 0;\n (deck.userData as UserData).mapboxLayers.forEach(deckLayer => {\n const LayerType = deckLayer.props.type;\n const layer = new LayerType(deckLayer.props, {_offset: layerIndex++});\n layers.push(layer);\n });\n deck.setProps({layers});\n}\n"],"file":"deck-utils.js"}
@@ -4,13 +4,11 @@ export function getDeckInstance({
4
4
  gl,
5
5
  deck
6
6
  }) {
7
- var _deck;
8
-
9
7
  if (map.__deck) {
10
8
  return map.__deck;
11
9
  }
12
10
 
13
- const customRender = (_deck = deck) === null || _deck === void 0 ? void 0 : _deck.props._customRender;
11
+ const customRender = deck === null || deck === void 0 ? void 0 : deck.props._customRender;
14
12
  const deckProps = {
15
13
  useDevicePixels: true,
16
14
  _customRender: reason => {
@@ -42,24 +40,27 @@ export function getDeckInstance({
42
40
  map.on('move', () => onMapMove(deck, map));
43
41
  }
44
42
 
43
+ let deckInstance;
44
+
45
45
  if (deck) {
46
+ deckInstance = deck;
46
47
  deck.setProps(deckProps);
47
48
  deck.userData.isExternal = true;
48
49
  } else {
49
- deck = new Deck(deckProps);
50
+ deckInstance = new Deck(deckProps);
50
51
  map.on('remove', () => {
51
- deck.finalize();
52
+ deckInstance.finalize();
52
53
  map.__deck = null;
53
54
  });
54
55
  }
55
56
 
56
- deck.userData.mapboxLayers = new Set();
57
- deck.userData.mapboxVersion = getMapboxVersion(map);
58
- map.__deck = deck;
57
+ deckInstance.userData.mapboxLayers = new Set();
58
+ deckInstance.userData.mapboxVersion = getMapboxVersion(map);
59
+ map.__deck = deckInstance;
59
60
  map.on('render', () => {
60
- if (deck.layerManager) afterRender(deck, map);
61
+ if (deckInstance.isInitialized) afterRender(deckInstance, map);
61
62
  });
62
- return deck;
63
+ return deckInstance;
63
64
  }
64
65
  export function addLayer(deck, layer) {
65
66
  deck.userData.mapboxLayers.add(layer);
@@ -82,7 +83,7 @@ export function drawLayer(deck, map, layer) {
82
83
  deck.userData.currentViewport = currentViewport;
83
84
  }
84
85
 
85
- if (!deck.layerManager) {
86
+ if (!deck.isInitialized) {
86
87
  return;
87
88
  }
88
89
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/deck-utils.ts"],"names":["Deck","WebMercatorViewport","MapView","_flatten","flatten","getDeckInstance","map","gl","deck","__deck","customRender","props","_customRender","deckProps","useDevicePixels","reason","triggerRepaint","parameters","depthMask","depthTest","blend","blendFunc","polygonOffsetFill","depthFunc","blendEquation","views","id","Object","assign","width","height","touchAction","viewState","getViewState","on","onMapMove","setProps","userData","isExternal","finalize","mapboxLayers","Set","mapboxVersion","getMapboxVersion","layerManager","afterRender","addLayer","layer","add","updateLayers","removeLayer","delete","updateLayer","drawLayer","currentViewport","getViewport","_drawLayers","viewports","layerFilter","deckLayer","clearCanvas","lng","lat","getCenter","longitude","latitude","zoom","getZoom","bearing","getBearing","pitch","getPitch","padding","getPadding","repeat","getRenderWorldCopies","major","minor","version","split","slice","Number","useMapboxProjection","x","y","nearZMultiplier","mapboxLayerIds","Array","from","deckLayers","layers","Boolean","hasNonMapboxLayers","some","includes","getViewports","mapboxViewportIdx","findIndex","vp","hasNonMapboxViews","length","params","viewport","needsRedraw","clearRedrawFlags","layerIndex","forEach","LayerType","type","_offset","push"],"mappings":"AAAA,SAAQA,IAAR,EAAcC,mBAAd,EAAmCC,OAAnC,EAA4CC,QAAQ,IAAIC,OAAxD,QAAsE,eAAtE;AAYA,OAAO,SAASC,eAAT,CAAyB;AAC9BC,EAAAA,GAD8B;AAE9BC,EAAAA,EAF8B;AAG9BC,EAAAA;AAH8B,CAAzB,EAQE;AAAA;;AAEP,MAAIF,GAAG,CAACG,MAAR,EAAgB;AACd,WAAOH,GAAG,CAACG,MAAX;AACD;;AAED,QAAMC,YAAY,YAAGF,IAAH,0CAAG,MAAMG,KAAN,CAAYC,aAAjC;AAEA,QAAMC,SAAoB,GAAG;AAC3BC,IAAAA,eAAe,EAAE,IADU;AAE3BF,IAAAA,aAAa,EAAGG,MAAD,IAAoB;AACjCT,MAAAA,GAAG,CAACU,cAAJ;AAGAN,MAAAA,YAAY,SAAZ,IAAAA,YAAY,WAAZ,YAAAA,YAAY,CAAGK,MAAH,CAAZ;AACD,KAP0B;AAS3BE,IAAAA,UAAU,EAAE;AACVC,MAAAA,SAAS,EAAE,IADD;AAEVC,MAAAA,SAAS,EAAE,IAFD;AAGVC,MAAAA,KAAK,EAAE,IAHG;AAIVC,MAAAA,SAAS,EAAE,kBAJD;AAKVC,MAAAA,iBAAiB,EAAE,IALT;AAMVC,MAAAA,SAAS,KANC;AAOVC,MAAAA,aAAa;A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MoD,MAAe,GAAG,EAAxB;AACA,MAAIe,UAAU,GAAG,CAAjB;AACCjG,EAAAA,IAAI,CAAC6B,QAAN,CAA4BG,YAA5B,CAAyCkE,OAAzC,CAAiD/C,SAAS,IAAI;AAC5D,UAAMgD,SAAS,GAAGhD,SAAS,CAAChD,KAAV,CAAgBiG,IAAlC;AACA,UAAM7D,KAAK,GAAG,IAAI4D,SAAJ,CAAchD,SAAS,CAAChD,KAAxB,EAA+B;AAACkG,MAAAA,OAAO,EAAEJ,UAAU;AAApB,KAA/B,CAAd;AACAf,IAAAA,MAAM,CAACoB,IAAP,CAAY/D,KAAZ;AACD,GAJD;AAKAvC,EAAAA,IAAI,CAAC4B,QAAL,CAAc;AAACsD,IAAAA;AAAD,GAAd;AACD","sourcesContent":["import {Deck, WebMercatorViewport, MapView, _flatten as flatten} from '@deck.gl/core';\nimport type {DeckProps, MapViewState, Layer} from '@deck.gl/core';\nimport type MapboxLayer from './mapbox-layer';\nimport type {Map} from 'mapbox-gl';\n\ntype UserData = {\n isExternal: boolean;\n currentViewport?: WebMercatorViewport | null;\n mapboxLayers: Set<MapboxLayer<any>>;\n mapboxVersion: {minor: number; major: number};\n};\n\nexport function getDeckInstance({\n map,\n gl,\n deck\n}: {\n map: Map & {__deck?: Deck | null};\n gl: WebGLRenderingContext;\n deck?: Deck;\n}): Deck {\n // Only create one deck instance per context\n if (map.__deck) {\n return map.__deck;\n }\n\n const customRender = deck?.props._customRender;\n\n const deckProps: DeckProps = {\n useDevicePixels: true,\n _customRender: (reason: string) => {\n map.triggerRepaint();\n // customRender may be subscribed by DeckGL React component to update child props\n // make sure it is still called\n customRender?.(reason);\n },\n // TODO: import these defaults from a single source of truth\n parameters: {\n depthMask: true,\n depthTest: true,\n blend: true,\n blendFunc: [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA],\n polygonOffsetFill: true,\n depthFunc: gl.LEQUAL,\n blendEquation: gl.FUNC_ADD\n },\n views: (deck && deck.props.views) || [new MapView({id: 'mapbox'})]\n };\n\n if (!deck || deck.props.gl === gl) {\n // deck is using the WebGLContext created by mapbox\n // block deck from setting the canvas size\n Object.assign(deckProps, {\n gl,\n width: null,\n height: null,\n touchAction: 'unset',\n viewState: getViewState(map)\n });\n // If using the WebGLContext created by deck (React use case), we use deck's viewState to drive the map.\n // Otherwise (pure JS use case), we use the map's viewState to drive deck.\n map.on('move', () => onMapMove(deck!, map));\n }\n\n if (deck) {\n deck.setProps(deckProps);\n (deck.userData as UserData).isExternal = true;\n } else {\n deck = new Deck(deckProps);\n map.on('remove', () => {\n deck!.finalize();\n map.__deck = null;\n });\n }\n\n (deck.userData as UserData).mapboxLayers = new Set();\n (deck.userData as UserData).mapboxVersion = getMapboxVersion(map);\n map.__deck = deck;\n map.on('render', () => {\n // @ts-expect-error (2445) protected property\n if (deck.layerManager) afterRender(deck, map);\n });\n\n return deck;\n}\n\nexport function addLayer(deck: Deck, layer: MapboxLayer<any>): void {\n (deck.userData as UserData).mapboxLayers.add(layer);\n updateLayers(deck);\n}\n\nexport function removeLayer(deck: Deck, layer: MapboxLayer<any>): void {\n (deck.userData as UserData).mapboxLayers.delete(layer);\n updateLayers(deck);\n}\n\nexport function updateLayer(deck: Deck, layer: MapboxLayer<any>): void {\n updateLayers(deck);\n}\n\nexport function drawLayer(deck: Deck, map: Map, layer: MapboxLayer<any>): void {\n let {currentViewport} = deck.userData as UserData;\n if (!currentViewport) {\n // This is the first layer drawn in this render cycle.\n // Generate viewport from the current map state.\n currentViewport = getViewport(deck, map, true);\n (deck.userData as UserData).currentViewport = currentViewport;\n }\n\n // @ts-expect-error (2445) protected property\n if (!deck.layerManager) {\n return;\n }\n\n deck._drawLayers('mapbox-repaint', {\n viewports: [currentViewport],\n layerFilter: ({layer: deckLayer}) => layer.id === deckLayer.id,\n clearCanvas: false\n });\n}\n\nexport function getViewState(map: Map): MapViewState & {\n repeat: boolean;\n padding: {\n left: number;\n right: number;\n top: number;\n bottom: number;\n };\n} {\n const {lng, lat} = map.getCenter();\n return {\n // Longitude returned by getCenter can be outside of [-180, 180] when zooming near the anti meridian\n // https://github.com/visgl/deck.gl/issues/6894\n longitude: ((lng + 540) % 360) - 180,\n latitude: lat,\n zoom: map.getZoom(),\n bearing: map.getBearing(),\n pitch: map.getPitch(),\n padding: map.getPadding(),\n repeat: map.getRenderWorldCopies()\n };\n}\n\nfunction getMapboxVersion(map: Map): {minor: number; major: number} {\n // parse mapbox version string\n let major = 0;\n let minor = 0;\n // @ts-ignore (2339) undefined property\n const version: string = map.version;\n if (version) {\n [major, minor] = version.split('.').slice(0, 2).map(Number);\n }\n return {major, minor};\n}\n\nfunction getViewport(deck: Deck, map: Map, useMapboxProjection = true): WebMercatorViewport {\n const {mapboxVersion} = deck.userData as UserData;\n\n return new WebMercatorViewport(\n Object.assign(\n {\n id: 'mapbox',\n x: 0,\n y: 0,\n width: deck.width,\n height: deck.height\n },\n getViewState(map),\n useMapboxProjection\n ? {\n // match mapbox's projection matrix\n // A change of near plane was made in 1.3.0\n // https://github.com/mapbox/mapbox-gl-js/pull/8502\n nearZMultiplier:\n (mapboxVersion.major === 1 && mapboxVersion.minor >= 3) || mapboxVersion.major >= 2\n ? 0.02\n : 1 / (deck.height || 1)\n }\n : {\n // use deck.gl's own default\n nearZMultiplier: 0.1\n }\n )\n );\n}\n\nfunction afterRender(deck: Deck, map: Map): void {\n const {mapboxLayers, isExternal} = deck.userData as UserData;\n\n if (isExternal) {\n // Draw non-Mapbox layers\n const mapboxLayerIds = Array.from(mapboxLayers, layer => layer.id);\n const deckLayers = flatten(deck.props.layers, Boolean) as Layer[];\n const hasNonMapboxLayers = deckLayers.some(\n layer => layer && !mapboxLayerIds.includes(layer.id)\n );\n let viewports = deck.getViewports();\n const mapboxViewportIdx = viewports.findIndex(vp => vp.id === 'mapbox');\n const hasNonMapboxViews = viewports.length > 1 || mapboxViewportIdx < 0;\n\n if (hasNonMapboxLayers || hasNonMapboxViews) {\n if (mapboxViewportIdx >= 0) {\n viewports = viewports.slice();\n viewports[mapboxViewportIdx] = getViewport(deck, map, false);\n }\n\n deck._drawLayers('mapbox-repaint', {\n viewports,\n layerFilter: params =>\n (!deck.props.layerFilter || deck.props.layerFilter(params)) &&\n (params.viewport.id !== 'mapbox' || !mapboxLayerIds.includes(params.layer.id)),\n clearCanvas: false\n });\n }\n }\n\n // End of render cycle, clear generated viewport\n (deck.userData as UserData).currentViewport = null;\n}\n\nfunction onMapMove(deck: Deck, map: Map): void {\n deck.setProps({\n viewState: getViewState(map)\n });\n // Camera changed, will trigger a map repaint right after this\n // Clear any change flag triggered by setting viewState so that deck does not request\n // a second repaint\n deck.needsRedraw({clearRedrawFlags: true});\n}\n\nfunction updateLayers(deck: Deck): void {\n if ((deck.userData as UserData).isExternal) {\n return;\n }\n\n const layers: Layer[] = [];\n let layerIndex = 0;\n (deck.userData as UserData).mapboxLayers.forEach(deckLayer => {\n const LayerType = deckLayer.props.type;\n const layer = new LayerType(deckLayer.props, {_offset: layerIndex++});\n layers.push(layer);\n });\n deck.setProps({layers});\n}\n"],"file":"deck-utils.js"}
1
+ {"version":3,"sources":["../../src/deck-utils.ts"],"names":["Deck","WebMercatorViewport","MapView","_flatten","flatten","getDeckInstance","map","gl","deck","__deck","customRender","props","_customRender","deckProps","useDevicePixels","reason","triggerRepaint","parameters","depthMask","depthTest","blend","blendFunc","polygonOffsetFill","depthFunc","blendEquation","views","id","Object","assign","width","height","touchAction","viewState","getViewState","on","onMapMove","deckInstance","setProps","userData","isExternal","finalize","mapboxLayers","Set","mapboxVersion","getMapboxVersion","isInitialized","afterRender","addLayer","layer","add","updateLayers","removeLayer","delete","updateLayer","drawLayer","currentViewport","getViewport","_drawLayers","viewports","layerFilter","deckLayer","clearCanvas","lng","lat","getCenter","longitude","latitude","zoom","getZoom","bearing","getBearing","pitch","getPitch","padding","getPadding","repeat","getRenderWorldCopies","major","minor","version","split","slice","Number","useMapboxProjection","x","y","nearZMultiplier","mapboxLayerIds","Array","from","deckLayers","layers","Boolean","hasNonMapboxLayers","some","includes","getViewports","mapboxViewportIdx","findIndex","vp","hasNonMapboxViews","length","params","viewport","needsRedraw","clearRedrawFlags","layerIndex","forEach","LayerType","type","_offset","push"],"mappings":"AAAA,SAAQA,IAAR,EAAcC,mBAAd,EAAmCC,OAAnC,EAA4CC,QAAQ,IAAIC,OAAxD,QAAsE,eAAtE;AAYA,OAAO,SAASC,eAAT,CAAyB;AAC9BC,EAAAA,GAD8B;AAE9BC,EAAAA,EAF8B;AAG9BC,EAAAA;AAH8B,CAAzB,EAQE;AAEP,MAAIF,GAAG,CAACG,MAAR,EAAgB;AACd,WAAOH,GAAG,CAACG,MAAX;AACD;;AAED,QAAMC,YAAY,GAAGF,IAAH,aAAGA,IAAH,uBAAGA,IAAI,CAAEG,KAAN,CAAYC,aAAjC;AAEA,QAAMC,SAAoB,GAAG;AAC3BC,IAAAA,eAAe,EAAE,IADU;AAE3BF,IAAAA,aAAa,EAAGG,MAAD,IAAoB;AACjCT,MAAAA,GAAG,CAACU,cAAJ;AAGAN,MAAAA,YAAY,SAAZ,IAAAA,YAAY,WAAZ,YAAAA,YAAY,CAAGK,MAAH,CAAZ;AACD,KAP0B;AAS3BE,IAAAA,UAAU,EAAE;AACVC,MAAAA,SAAS,EAAE,IADD;AAEVC,MAAAA,SAAS,EAAE,IAFD;AAGVC,MAAAA,KAAK,EAAE,IAHG;AAIVC,MAAAA,SAAS,EAAE,kBAJD;AAKVC,MAAAA,iBAAiB,EAAE,IALT;AAMVC,MAAAA,SAAS,KANC;AAOVC,MAAAA,aAAa;AAPH,KATe;AAkB3BC,IAAAA,KAAK,EAAGjB,IAAI,IAAIA,IAAI,CAACG,KAAL,CAAWc,KAApB,IAA8B,CAAC,IAAIvB,OAAJ,CAAY;AAACwB,MAAAA,EAAE,EAAE;AAAL,KAAZ,CAAD;AAlBV,GAA7B;;AAqBA,MAAI,CAAClB,IAAD,IAASA,IAAI,CAACG,KAAL,CAAW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kG,IAAlC;AACA,UAAM7D,KAAK,GAAG,IAAI4D,SAAJ,CAAchD,SAAS,CAACjD,KAAxB,EAA+B;AAACmG,MAAAA,OAAO,EAAEJ,UAAU;AAApB,KAA/B,CAAd;AACAf,IAAAA,MAAM,CAACoB,IAAP,CAAY/D,KAAZ;AACD,GAJD;AAKAxC,EAAAA,IAAI,CAAC6B,QAAL,CAAc;AAACsD,IAAAA;AAAD,GAAd;AACD","sourcesContent":["import {Deck, WebMercatorViewport, MapView, _flatten as flatten} from '@deck.gl/core';\nimport type {DeckProps, MapViewState, Layer} from '@deck.gl/core';\nimport type MapboxLayer from './mapbox-layer';\nimport type {Map} from 'mapbox-gl';\n\ntype UserData = {\n isExternal: boolean;\n currentViewport?: WebMercatorViewport | null;\n mapboxLayers: Set<MapboxLayer<any>>;\n mapboxVersion: {minor: number; major: number};\n};\n\nexport function getDeckInstance({\n map,\n gl,\n deck\n}: {\n map: Map & {__deck?: Deck | null};\n gl: WebGLRenderingContext;\n deck?: Deck;\n}): Deck {\n // Only create one deck instance per context\n if (map.__deck) {\n return map.__deck;\n }\n\n const customRender = deck?.props._customRender;\n\n const deckProps: DeckProps = {\n useDevicePixels: true,\n _customRender: (reason: string) => {\n map.triggerRepaint();\n // customRender may be subscribed by DeckGL React component to update child props\n // make sure it is still called\n customRender?.(reason);\n },\n // TODO: import these defaults from a single source of truth\n parameters: {\n depthMask: true,\n depthTest: true,\n blend: true,\n blendFunc: [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA],\n polygonOffsetFill: true,\n depthFunc: gl.LEQUAL,\n blendEquation: gl.FUNC_ADD\n },\n views: (deck && deck.props.views) || [new MapView({id: 'mapbox'})]\n };\n\n if (!deck || deck.props.gl === gl) {\n // deck is using the WebGLContext created by mapbox\n // block deck from setting the canvas size\n Object.assign(deckProps, {\n gl,\n width: null,\n height: null,\n touchAction: 'unset',\n viewState: getViewState(map)\n });\n // If using the WebGLContext created by deck (React use case), we use deck's viewState to drive the map.\n // Otherwise (pure JS use case), we use the map's viewState to drive deck.\n map.on('move', () => onMapMove(deck!, map));\n }\n\n let deckInstance: Deck;\n if (deck) {\n deckInstance = deck;\n deck.setProps(deckProps);\n (deck.userData as UserData).isExternal = true;\n } else {\n deckInstance = new Deck(deckProps);\n map.on('remove', () => {\n deckInstance.finalize();\n map.__deck = null;\n });\n }\n\n (deckInstance.userData as UserData).mapboxLayers = new Set();\n (deckInstance.userData as UserData).mapboxVersion = getMapboxVersion(map);\n map.__deck = deckInstance;\n map.on('render', () => {\n if (deckInstance.isInitialized) afterRender(deckInstance, map);\n });\n\n return deckInstance;\n}\n\nexport function addLayer(deck: Deck, layer: MapboxLayer<any>): void {\n (deck.userData as UserData).mapboxLayers.add(layer);\n updateLayers(deck);\n}\n\nexport function removeLayer(deck: Deck, layer: MapboxLayer<any>): void {\n (deck.userData as UserData).mapboxLayers.delete(layer);\n updateLayers(deck);\n}\n\nexport function updateLayer(deck: Deck, layer: MapboxLayer<any>): void {\n updateLayers(deck);\n}\n\nexport function drawLayer(deck: Deck, map: Map, layer: MapboxLayer<any>): void {\n let {currentViewport} = deck.userData as UserData;\n if (!currentViewport) {\n // This is the first layer drawn in this render cycle.\n // Generate viewport from the current map state.\n currentViewport = getViewport(deck, map, true);\n (deck.userData as UserData).currentViewport = currentViewport;\n }\n\n if (!deck.isInitialized) {\n return;\n }\n\n deck._drawLayers('mapbox-repaint', {\n viewports: [currentViewport],\n layerFilter: ({layer: deckLayer}) => layer.id === deckLayer.id,\n clearCanvas: false\n });\n}\n\nexport function getViewState(map: Map): MapViewState & {\n repeat: boolean;\n padding: {\n left: number;\n right: number;\n top: number;\n bottom: number;\n };\n} {\n const {lng, lat} = map.getCenter();\n return {\n // Longitude returned by getCenter can be outside of [-180, 180] when zooming near the anti meridian\n // https://github.com/visgl/deck.gl/issues/6894\n longitude: ((lng + 540) % 360) - 180,\n latitude: lat,\n zoom: map.getZoom(),\n bearing: map.getBearing(),\n pitch: map.getPitch(),\n padding: map.getPadding(),\n repeat: map.getRenderWorldCopies()\n };\n}\n\nfunction getMapboxVersion(map: Map): {minor: number; major: number} {\n // parse mapbox version string\n let major = 0;\n let minor = 0;\n // @ts-ignore (2339) undefined property\n const version: string = map.version;\n if (version) {\n [major, minor] = version.split('.').slice(0, 2).map(Number);\n }\n return {major, minor};\n}\n\nfunction getViewport(deck: Deck, map: Map, useMapboxProjection = true): WebMercatorViewport {\n const {mapboxVersion} = deck.userData as UserData;\n\n return new WebMercatorViewport(\n Object.assign(\n {\n id: 'mapbox',\n x: 0,\n y: 0,\n width: deck.width,\n height: deck.height\n },\n getViewState(map),\n useMapboxProjection\n ? {\n // match mapbox's projection matrix\n // A change of near plane was made in 1.3.0\n // https://github.com/mapbox/mapbox-gl-js/pull/8502\n nearZMultiplier:\n (mapboxVersion.major === 1 && mapboxVersion.minor >= 3) || mapboxVersion.major >= 2\n ? 0.02\n : 1 / (deck.height || 1)\n }\n : {\n // use deck.gl's own default\n nearZMultiplier: 0.1\n }\n )\n );\n}\n\nfunction afterRender(deck: Deck, map: Map): void {\n const {mapboxLayers, isExternal} = deck.userData as UserData;\n\n if (isExternal) {\n // Draw non-Mapbox layers\n const mapboxLayerIds = Array.from(mapboxLayers, layer => layer.id);\n const deckLayers = flatten(deck.props.layers, Boolean) as Layer[];\n const hasNonMapboxLayers = deckLayers.some(\n layer => layer && !mapboxLayerIds.includes(layer.id)\n );\n let viewports = deck.getViewports();\n const mapboxViewportIdx = viewports.findIndex(vp => vp.id === 'mapbox');\n const hasNonMapboxViews = viewports.length > 1 || mapboxViewportIdx < 0;\n\n if (hasNonMapboxLayers || hasNonMapboxViews) {\n if (mapboxViewportIdx >= 0) {\n viewports = viewports.slice();\n viewports[mapboxViewportIdx] = getViewport(deck, map, false);\n }\n\n deck._drawLayers('mapbox-repaint', {\n viewports,\n layerFilter: params =>\n (!deck.props.layerFilter || deck.props.layerFilter(params)) &&\n (params.viewport.id !== 'mapbox' || !mapboxLayerIds.includes(params.layer.id)),\n clearCanvas: false\n });\n }\n }\n\n // End of render cycle, clear generated viewport\n (deck.userData as UserData).currentViewport = null;\n}\n\nfunction onMapMove(deck: Deck, map: Map): void {\n deck.setProps({\n viewState: getViewState(map)\n });\n // Camera changed, will trigger a map repaint right after this\n // Clear any change flag triggered by setting viewState so that deck does not request\n // a second repaint\n deck.needsRedraw({clearRedrawFlags: true});\n}\n\nfunction updateLayers(deck: Deck): void {\n if ((deck.userData as UserData).isExternal) {\n return;\n }\n\n const layers: Layer[] = [];\n let layerIndex = 0;\n (deck.userData as UserData).mapboxLayers.forEach(deckLayer => {\n const LayerType = deckLayer.props.type;\n const layer = new LayerType(deckLayer.props, {_offset: layerIndex++});\n layers.push(layer);\n });\n deck.setProps({layers});\n}\n"],"file":"deck-utils.js"}
package/dist.min.js CHANGED
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("deck")):"function"==typeof define&&define.amd?define(["deck"],t):"object"==typeof exports?exports.deck=t(require("deck")):e.deck=t(e.deck)}(window,(function(e){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=6)}([function(e,t){e.exports=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}},function(t,n){t.exports=e},function(e,t){e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}},function(e,t){function n(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}e.exports=function(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),e}},function(e,t,n){var r=n(7),i=n(8),o=n(9);e.exports=function(e,t){return r(e)||i(e,t)||o()}},function(e,t,n){var r=n(10);e.exports=function(e,t){if(null==e)return{};var n,i,o=r(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(i=0;i<a.length;i++)n=a[i],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}},function(e,t,n){var r=n(11),i=globalThis.deck||{};if(!i.Layer)throw new Error("@deck.gl/core is not found");e.exports=Object.assign(i,r)},function(e,t){e.exports=function(e){if(Array.isArray(e))return e}},function(e,t){e.exports=function(e,t){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)){var n=[],r=!0,i=!1,o=void 0;try{for(var a,s=e[Symbol.iterator]();!(r=(a=s.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){i=!0,o=e}finally{try{r||null==s.return||s.return()}finally{if(i)throw o}}return n}}},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}},function(e,t){e.exports=function(e,t){if(null==e)return{};var n,r,i={},o=Object.keys(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||(i[n]=e[n]);return i}},function(e,t,n){"use strict";n.r(t);var r=n(2),i=n.n(r),o=n(3),a=n.n(o),s=n(0),u=n.n(s),c=n(4),l=n.n(c),d=n(1);function p(e){var t,n=e.map,r=e.gl,i=e.deck;if(n.__deck)return n.__deck;var o=null===(t=i)||void 0===t?void 0:t.props._customRender,a={useDevicePixels:!0,_customRender:function(e){n.triggerRepaint(),null==o||o(e)},parameters:{depthMask:!0,depthTest:!0,blend:!0,blendFunc:[770,771,1,771],polygonOffsetFill:!0,depthFunc:515,blendEquation:32774},views:i&&i.props.views||[new d.MapView({id:"mapbox"})]};return i&&i.props.gl!==r||(Object.assign(a,{gl:r,width:null,height:null,touchAction:"unset",viewState:f(n)}),n.on("move",(function(){return function(e,t){e.setProps({viewState:f(t)}),e.needsRedraw({clearRedrawFlags:!0})}(i,n)}))),i?(i.setProps(a),i.userData.isExternal=!0):(i=new d.Deck(a),n.on("remove",(function(){i.finalize(),n.__deck=null}))),i.userData.mapboxLayers=new Set,i.userData.mapboxVersion=function(e){var t=0,n=0,r=e.version;if(r){var i=r.split(".").slice(0,2).map(Number),o=l()(i,2);t=o[0],n=o[1]}return{major:t,minor:n}}(n),n.__deck=i,n.on("render",(function(){i.layerManager&&function(e,t){var n=e.userData,r=n.mapboxLayers;if(n.isExternal){var i=Array.from(r,(function(e){return e.id})),o=Object(d._flatten)(e.props.layers,Boolean).some((function(e){return e&&!i.includes(e.id)})),a=e.getViewports(),s=a.findIndex((function(e){return"mapbox"===e.id})),u=a.length>1||s<0;(o||u)&&(s>=0&&((a=a.slice())[s]=v(e,t,!1)),e._drawLayers("mapbox-repaint",{viewports:a,layerFilter:function(t){return(!e.props.layerFilter||e.props.layerFilter(t))&&("mapbox"!==t.viewport.id||!i.includes(t.layer.id))},clearCanvas:!1}))}e.userData.currentViewport=null}(i,n)})),i}function f(e){var t=e.getCenter();return{longitude:(t.lng+540)%360-180,latitude:t.lat,zoom:e.getZoom(),bearing:e.getBearing(),pitch:e.getPitch(),padding:e.getPadding(),repeat:e.getRenderWorldCopies()}}function v(e,t){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],r=e.userData,i=r.mapboxVersion;return new d.WebMercatorViewport(Object.assign({id:"mapbox",x:0,y:0,width:e.width,height:e.height},f(t),n?{nearZMultiplier:1===i.major&&i.minor>=3||i.major>=2?.02:1/(e.height||1)}:{nearZMultiplier:.1}))}function h(e){if(!e.userData.isExternal){var t=[],n=0;e.userData.mapboxLayers.forEach((function(e){var r=new(0,e.props.type)(e.props,{_offset:n++});t.push(r)})),e.setProps({layers:t})}}var y=function(){function e(t){if(i()(this,e),u()(this,"id",void 0),u()(this,"type",void 0),u()(this,"renderingMode",void 0),u()(this,"map",void 0),u()(this,"deck",void 0),u()(this,"props",void 0),!t.id)throw new Error("Layer must have an unique id");this.id=t.id,this.type="custom",this.renderingMode=t.renderingMode||"3d",this.map=null,this.deck=null,this.props=t}return a()(e,[{key:"onAdd",value:function(e,t){var n,r;this.map=e,this.deck=p({map:e,gl:t,deck:this.props.deck}),n=this.deck,r=this,n.userData.mapboxLayers.add(r),h(n)}},{key:"onRemove",value:function(){var e,t;this.deck&&(e=this.deck,t=this,e.userData.mapboxLayers.delete(t),h(e))}},{key:"setProps",value:function(e){Object.assign(this.props,e,{id:this.id}),this.deck&&h(this.deck)}},{key:"render",value:function(){var e,t,n,r;e=this.deck,t=this.map,n=this,(r=e.userData.currentViewport)||(r=v(e,t,!0),e.userData.currentViewport=r),e.layerManager&&e._drawLayers("mapbox-repaint",{viewports:[r],layerFilter:function(e){var t=e.layer;return n.id===t.id},clearCanvas:!1})}}]),e}(),_=n(5),b=n.n(_);function m(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return g(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return g(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function g(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function k(e,t,n,r){if(e&&t&&e.style&&e.style._loaded){var i=Object(d._flatten)(r,Boolean);if(n!==r){var o,a=Object(d._flatten)(n,Boolean),s=new Set(a.map((function(e){return e.id}))),u=m(i);try{for(u.s();!(o=u.n()).done;){var c=o.value;s.delete(c.id)}}catch(e){u.e(e)}finally{u.f()}var l,p=m(s);try{for(p.s();!(l=p.n()).done;){var f=l.value;e.getLayer(f)&&e.removeLayer(f)}}catch(e){p.e(e)}finally{p.f()}}var v,h=m(i);try{for(h.s();!(v=h.n()).done;){var _=v.value;e.getLayer(_.id)||e.addLayer(new y({id:_.id,deck:t}),_.props.beforeId)}}catch(e){h.e(e)}finally{h.f()}var b,g=e.style._order,k={},w=m(i);try{for(w.s();!(b=w.n()).done;){var O=b.value,j=O.props.beforeId;j&&g.includes(j)||(j="__UNDEFINED__"),k[j]=k[j]||[],k[j].push(O.id)}}catch(e){w.e(e)}finally{w.f()}for(var x in k)for(var E=k[x],S="__UNDEFINED__"===x?g.length:g.indexOf(x),P="__UNDEFINED__"===x?void 0:x,M=E.length-1;M>=0;M--){var D=E[M],C=g.indexOf(D);C!==S-1&&(e.moveLayer(D,P),C>S&&S++),S--,P=D}}}var w=["interleaved"];function O(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function j(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?O(Object(n),!0).forEach((function(t){u()(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):O(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var x=function(){function e(t){var n=this;i()(this,e),u()(this,"_props",void 0),u()(this,"_deck",void 0),u()(this,"_map",void 0),u()(this,"_container",void 0),u()(this,"_interleaved",void 0),u()(this,"_handleStyleChange",(function(){k(n._map,n._deck,n._props.layers,n._props.layers)})),u()(this,"_updateContainerSize",(function(){if(n._map&&n._container){var e=n._map.getContainer(),t=e.clientWidth,r=e.clientHeight;Object.assign(n._container.style,{width:"".concat(t,"px"),height:"".concat(r,"px")})}})),u()(this,"_updateViewState",(function(){var e=n._deck;e&&(e.setProps({viewState:f(n._map)}),e.redraw())})),u()(this,"_handleMouseEvent",(function(e){var t=n._deck;if(t){var r={type:e.type,offsetCenter:e.point,srcEvent:e};switch(e.type){case"click":r.tapCount=1,t._onPointerDown(r),t._onEvent(r);break;case"dblclick":r.type="click",r.tapCount=2,t._onEvent(r);break;case"mousemove":r.type="pointermove",t._onPointerMove(r);break;case"mouseout":r.type="pointerleave",t._onPointerMove(r);break;default:return}}}));var r=t.interleaved,o=void 0!==r&&r,a=b()(t,w);this._interleaved=o,this._props=a}return a()(e,[{key:"setProps",value:function(e){this._interleaved&&e.layers&&k(this._map,this._deck,this._props.layers,e.layers),Object.assign(this._props,e),this._deck&&this._deck.setProps(this._props)}},{key:"onAdd",value:function(e){return this._map=e,this._interleaved?this._onAddInterleaved(e):this._onAddOverlaid(e)}},{key:"_onAddOverlaid",value:function(e){var t=document.createElement("div");return Object.assign(t.style,{position:"absolute",left:0,top:0,pointerEvents:"none"}),this._container=t,this._deck=new d.Deck(j(j({},this._props),{},{parent:t,viewState:f(e)})),e.on("resize",this._updateContainerSize),e.on("render",this._updateViewState),e.on("mousemove",this._handleMouseEvent),e.on("mouseout",this._handleMouseEvent),e.on("click",this._handleMouseEvent),e.on("dblclick",this._handleMouseEvent),this._updateContainerSize(),t}},{key:"_onAddInterleaved",value:function(e){return this._deck=new d.Deck(j(j({},this._props),{},{gl:e.painter.context.gl})),e.on("styledata",this._handleStyleChange),k(e,this._deck,[],this._props.layers),document.createElement("div")}},{key:"onRemove",value:function(){var e,t=this._map;t&&(this._interleaved?this._onRemoveInterleaved(t):this._onRemoveOverlaid(t)),null===(e=this._deck)||void 0===e||e.finalize(),this._deck=void 0,this._map=void 0,this._container=void 0}},{key:"_onRemoveOverlaid",value:function(e){e.off("resize",this._updateContainerSize),e.off("render",this._updateViewState),e.off("mousemove",this._handleMouseEvent),e.off("mouseout",this._handleMouseEvent),e.off("click",this._handleMouseEvent),e.off("dblclick",this._handleMouseEvent)}},{key:"_onRemoveInterleaved",value:function(e){e.off("styledata",this._handleStyleChange),k(e,this._deck,this._props.layers,[])}},{key:"getDefaultPosition",value:function(){return"top-left"}},{key:"pickObject",value:function(e){return Object(d.assert)(this._deck),this._deck.pickObject(e)}},{key:"pickMultipleObjects",value:function(e){return Object(d.assert)(this._deck),this._deck.pickMultipleObjects(e)}},{key:"pickObjects",value:function(e){return Object(d.assert)(this._deck),this._deck.pickObjects(e)}},{key:"finalize",value:function(){this._map&&this._map.removeControl(this)}}]),e}();n.d(t,"MapboxLayer",(function(){return y})),n.d(t,"MapboxOverlay",(function(){return x}))}])}));
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("deck")):"function"==typeof define&&define.amd?define(["deck"],t):"object"==typeof exports?exports.deck=t(require("deck")):e.deck=t(e.deck)}(window,(function(e){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=6)}([function(e,t){e.exports=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}},function(t,n){t.exports=e},function(e,t){e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}},function(e,t){function n(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}e.exports=function(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),e}},function(e,t,n){var r=n(7),i=n(8),o=n(9);e.exports=function(e,t){return r(e)||i(e,t)||o()}},function(e,t,n){var r=n(10);e.exports=function(e,t){if(null==e)return{};var n,i,o=r(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(i=0;i<a.length;i++)n=a[i],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}},function(e,t,n){var r=n(11),i=globalThis.deck||{};if(!i.Layer)throw new Error("@deck.gl/core is not found");e.exports=Object.assign(i,r)},function(e,t){e.exports=function(e){if(Array.isArray(e))return e}},function(e,t){e.exports=function(e,t){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)){var n=[],r=!0,i=!1,o=void 0;try{for(var a,s=e[Symbol.iterator]();!(r=(a=s.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){i=!0,o=e}finally{try{r||null==s.return||s.return()}finally{if(i)throw o}}return n}}},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}},function(e,t){e.exports=function(e,t){if(null==e)return{};var n,r,i={},o=Object.keys(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||(i[n]=e[n]);return i}},function(e,t,n){"use strict";n.r(t);var r=n(2),i=n.n(r),o=n(3),a=n.n(o),s=n(0),u=n.n(s),c=n(4),l=n.n(c),d=n(1);function p(e){var t=e.map,n=e.gl,r=e.deck;if(t.__deck)return t.__deck;var i,o=null==r?void 0:r.props._customRender,a={useDevicePixels:!0,_customRender:function(e){t.triggerRepaint(),null==o||o(e)},parameters:{depthMask:!0,depthTest:!0,blend:!0,blendFunc:[770,771,1,771],polygonOffsetFill:!0,depthFunc:515,blendEquation:32774},views:r&&r.props.views||[new d.MapView({id:"mapbox"})]};return r&&r.props.gl!==n||(Object.assign(a,{gl:n,width:null,height:null,touchAction:"unset",viewState:f(t)}),t.on("move",(function(){return function(e,t){e.setProps({viewState:f(t)}),e.needsRedraw({clearRedrawFlags:!0})}(r,t)}))),r?(i=r,r.setProps(a),r.userData.isExternal=!0):(i=new d.Deck(a),t.on("remove",(function(){i.finalize(),t.__deck=null}))),i.userData.mapboxLayers=new Set,i.userData.mapboxVersion=function(e){var t=0,n=0,r=e.version;if(r){var i=r.split(".").slice(0,2).map(Number),o=l()(i,2);t=o[0],n=o[1]}return{major:t,minor:n}}(t),t.__deck=i,t.on("render",(function(){i.isInitialized&&function(e,t){var n=e.userData,r=n.mapboxLayers;if(n.isExternal){var i=Array.from(r,(function(e){return e.id})),o=Object(d._flatten)(e.props.layers,Boolean).some((function(e){return e&&!i.includes(e.id)})),a=e.getViewports(),s=a.findIndex((function(e){return"mapbox"===e.id})),u=a.length>1||s<0;(o||u)&&(s>=0&&((a=a.slice())[s]=v(e,t,!1)),e._drawLayers("mapbox-repaint",{viewports:a,layerFilter:function(t){return(!e.props.layerFilter||e.props.layerFilter(t))&&("mapbox"!==t.viewport.id||!i.includes(t.layer.id))},clearCanvas:!1}))}e.userData.currentViewport=null}(i,t)})),i}function f(e){var t=e.getCenter();return{longitude:(t.lng+540)%360-180,latitude:t.lat,zoom:e.getZoom(),bearing:e.getBearing(),pitch:e.getPitch(),padding:e.getPadding(),repeat:e.getRenderWorldCopies()}}function v(e,t){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],r=e.userData,i=r.mapboxVersion;return new d.WebMercatorViewport(Object.assign({id:"mapbox",x:0,y:0,width:e.width,height:e.height},f(t),n?{nearZMultiplier:1===i.major&&i.minor>=3||i.major>=2?.02:1/(e.height||1)}:{nearZMultiplier:.1}))}function h(e){if(!e.userData.isExternal){var t=[],n=0;e.userData.mapboxLayers.forEach((function(e){var r=new(0,e.props.type)(e.props,{_offset:n++});t.push(r)})),e.setProps({layers:t})}}var y=function(){function e(t){if(i()(this,e),u()(this,"id",void 0),u()(this,"type",void 0),u()(this,"renderingMode",void 0),u()(this,"map",void 0),u()(this,"deck",void 0),u()(this,"props",void 0),!t.id)throw new Error("Layer must have an unique id");this.id=t.id,this.type="custom",this.renderingMode=t.renderingMode||"3d",this.map=null,this.deck=null,this.props=t}return a()(e,[{key:"onAdd",value:function(e,t){var n,r;this.map=e,this.deck=p({map:e,gl:t,deck:this.props.deck}),n=this.deck,r=this,n.userData.mapboxLayers.add(r),h(n)}},{key:"onRemove",value:function(){var e,t;this.deck&&(e=this.deck,t=this,e.userData.mapboxLayers.delete(t),h(e))}},{key:"setProps",value:function(e){Object.assign(this.props,e,{id:this.id}),this.deck&&h(this.deck)}},{key:"render",value:function(){var e,t,n,r;e=this.deck,t=this.map,n=this,(r=e.userData.currentViewport)||(r=v(e,t,!0),e.userData.currentViewport=r),e.isInitialized&&e._drawLayers("mapbox-repaint",{viewports:[r],layerFilter:function(e){var t=e.layer;return n.id===t.id},clearCanvas:!1})}}]),e}(),_=n(5),b=n.n(_);function m(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return k(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return k(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function k(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function g(e,t,n,r){if(e&&t&&e.style&&e.style._loaded){var i=Object(d._flatten)(r,Boolean);if(n!==r){var o,a=Object(d._flatten)(n,Boolean),s=new Set(a.map((function(e){return e.id}))),u=m(i);try{for(u.s();!(o=u.n()).done;){var c=o.value;s.delete(c.id)}}catch(e){u.e(e)}finally{u.f()}var l,p=m(s);try{for(p.s();!(l=p.n()).done;){var f=l.value;e.getLayer(f)&&e.removeLayer(f)}}catch(e){p.e(e)}finally{p.f()}}var v,h=m(i);try{for(h.s();!(v=h.n()).done;){var _=v.value;e.getLayer(_.id)||e.addLayer(new y({id:_.id,deck:t}),_.props.beforeId)}}catch(e){h.e(e)}finally{h.f()}var b,k=e.style._order,g={},w=m(i);try{for(w.s();!(b=w.n()).done;){var O=b.value,j=O.props.beforeId;j&&k.includes(j)||(j="__UNDEFINED__"),g[j]=g[j]||[],g[j].push(O.id)}}catch(e){w.e(e)}finally{w.f()}for(var x in g)for(var E=g[x],S="__UNDEFINED__"===x?k.length:k.indexOf(x),P="__UNDEFINED__"===x?void 0:x,D=E.length-1;D>=0;D--){var M=E[D],C=k.indexOf(M);C!==S-1&&(e.moveLayer(M,P),C>S&&S++),S--,P=M}}}var w=["interleaved"];function O(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function j(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?O(Object(n),!0).forEach((function(t){u()(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):O(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var x=function(){function e(t){var n=this;i()(this,e),u()(this,"_props",void 0),u()(this,"_deck",void 0),u()(this,"_map",void 0),u()(this,"_container",void 0),u()(this,"_interleaved",void 0),u()(this,"_handleStyleChange",(function(){g(n._map,n._deck,n._props.layers,n._props.layers)})),u()(this,"_updateContainerSize",(function(){if(n._map&&n._container){var e=n._map.getContainer(),t=e.clientWidth,r=e.clientHeight;Object.assign(n._container.style,{width:"".concat(t,"px"),height:"".concat(r,"px")})}})),u()(this,"_updateViewState",(function(){var e=n._deck;e&&(e.setProps({viewState:f(n._map)}),e.redraw())})),u()(this,"_handleMouseEvent",(function(e){var t=n._deck;if(t){var r={type:e.type,offsetCenter:e.point,srcEvent:e};switch(e.type){case"click":r.tapCount=1,t._onPointerDown(r),t._onEvent(r);break;case"dblclick":r.type="click",r.tapCount=2,t._onEvent(r);break;case"mousemove":r.type="pointermove",t._onPointerMove(r);break;case"mouseout":r.type="pointerleave",t._onPointerMove(r);break;default:return}}}));var r=t.interleaved,o=void 0!==r&&r,a=b()(t,w);this._interleaved=o,this._props=a}return a()(e,[{key:"setProps",value:function(e){this._interleaved&&e.layers&&g(this._map,this._deck,this._props.layers,e.layers),Object.assign(this._props,e),this._deck&&this._deck.setProps(this._props)}},{key:"onAdd",value:function(e){return this._map=e,this._interleaved?this._onAddInterleaved(e):this._onAddOverlaid(e)}},{key:"_onAddOverlaid",value:function(e){var t=document.createElement("div");return Object.assign(t.style,{position:"absolute",left:0,top:0,pointerEvents:"none"}),this._container=t,this._deck=new d.Deck(j(j({},this._props),{},{parent:t,viewState:f(e)})),e.on("resize",this._updateContainerSize),e.on("render",this._updateViewState),e.on("mousemove",this._handleMouseEvent),e.on("mouseout",this._handleMouseEvent),e.on("click",this._handleMouseEvent),e.on("dblclick",this._handleMouseEvent),this._updateContainerSize(),t}},{key:"_onAddInterleaved",value:function(e){return this._deck=new d.Deck(j(j({},this._props),{},{gl:e.painter.context.gl})),e.on("styledata",this._handleStyleChange),g(e,this._deck,[],this._props.layers),document.createElement("div")}},{key:"onRemove",value:function(){var e,t=this._map;t&&(this._interleaved?this._onRemoveInterleaved(t):this._onRemoveOverlaid(t)),null===(e=this._deck)||void 0===e||e.finalize(),this._deck=void 0,this._map=void 0,this._container=void 0}},{key:"_onRemoveOverlaid",value:function(e){e.off("resize",this._updateContainerSize),e.off("render",this._updateViewState),e.off("mousemove",this._handleMouseEvent),e.off("mouseout",this._handleMouseEvent),e.off("click",this._handleMouseEvent),e.off("dblclick",this._handleMouseEvent)}},{key:"_onRemoveInterleaved",value:function(e){e.off("styledata",this._handleStyleChange),g(e,this._deck,this._props.layers,[])}},{key:"getDefaultPosition",value:function(){return"top-left"}},{key:"pickObject",value:function(e){return Object(d.assert)(this._deck),this._deck.pickObject(e)}},{key:"pickMultipleObjects",value:function(e){return Object(d.assert)(this._deck),this._deck.pickMultipleObjects(e)}},{key:"pickObjects",value:function(e){return Object(d.assert)(this._deck),this._deck.pickObjects(e)}},{key:"finalize",value:function(){this._map&&this._map.removeControl(this)}}]),e}();n.d(t,"MapboxLayer",(function(){return y})),n.d(t,"MapboxOverlay",(function(){return x}))}])}));
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@deck.gl/mapbox",
3
3
  "description": "Use deck.gl layers as custom mapbox-gl-js layers",
4
4
  "license": "MIT",
5
- "version": "8.8.0-beta.2",
5
+ "version": "8.8.0-beta.5",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
@@ -35,5 +35,5 @@
35
35
  "peerDependencies": {
36
36
  "@deck.gl/core": "^8.0.0"
37
37
  },
38
- "gitHead": "d9bae59d015387c547366465d75d80950c60a34e"
38
+ "gitHead": "20b7becdb467aa917c17c9517461bf62ecc48b12"
39
39
  }
package/src/deck-utils.ts CHANGED
@@ -62,26 +62,27 @@ export function getDeckInstance({
62
62
  map.on('move', () => onMapMove(deck!, map));
63
63
  }
64
64
 
65
+ let deckInstance: Deck;
65
66
  if (deck) {
67
+ deckInstance = deck;
66
68
  deck.setProps(deckProps);
67
69
  (deck.userData as UserData).isExternal = true;
68
70
  } else {
69
- deck = new Deck(deckProps);
71
+ deckInstance = new Deck(deckProps);
70
72
  map.on('remove', () => {
71
- deck!.finalize();
73
+ deckInstance.finalize();
72
74
  map.__deck = null;
73
75
  });
74
76
  }
75
77
 
76
- (deck.userData as UserData).mapboxLayers = new Set();
77
- (deck.userData as UserData).mapboxVersion = getMapboxVersion(map);
78
- map.__deck = deck;
78
+ (deckInstance.userData as UserData).mapboxLayers = new Set();
79
+ (deckInstance.userData as UserData).mapboxVersion = getMapboxVersion(map);
80
+ map.__deck = deckInstance;
79
81
  map.on('render', () => {
80
- // @ts-expect-error (2445) protected property
81
- if (deck.layerManager) afterRender(deck, map);
82
+ if (deckInstance.isInitialized) afterRender(deckInstance, map);
82
83
  });
83
84
 
84
- return deck;
85
+ return deckInstance;
85
86
  }
86
87
 
87
88
  export function addLayer(deck: Deck, layer: MapboxLayer<any>): void {
@@ -107,8 +108,7 @@ export function drawLayer(deck: Deck, map: Map, layer: MapboxLayer<any>): void {
107
108
  (deck.userData as UserData).currentViewport = currentViewport;
108
109
  }
109
110
 
110
- // @ts-expect-error (2445) protected property
111
- if (!deck.layerManager) {
111
+ if (!deck.isInitialized) {
112
112
  return;
113
113
  }
114
114
 
@@ -1 +1 @@
1
- {"version":3,"file":"deck-utils.d.ts","sourceRoot":"","sources":["../src/deck-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAoD,MAAM,eAAe,CAAC;AACtF,OAAO,KAAK,EAAY,YAAY,EAAQ,MAAM,eAAe,CAAC;AAClE,OAAO,KAAK,WAAW,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,WAAW,CAAC;AASnC,wBAAgB,eAAe,CAAC,EAC9B,GAAG,EACH,EAAE,EACF,IAAI,EACL,EAAE;IACD,GAAG,EAAE,GAAG,GAAG;QAAC,MAAM,CAAC,EAAE,IAAI,GAAG,IAAI,CAAA;KAAC,CAAC;IAClC,EAAE,EAAE,qBAAqB,CAAC;IAC1B,IAAI,CAAC,EAAE,IAAI,CAAC;CACb,GAAG,IAAI,CAgEP;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,GAAG,IAAI,CAGlE;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,GAAG,IAAI,CAGrE;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,GAAG,IAAI,CAErE;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,GAAG,IAAI,CAmB7E;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,YAAY,GAAG;IACrD,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE;QACP,IAAI,EA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,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,GAAG,EAAE,MAAM,CAAC;QACZ,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH,CAaA"}
@@ -1,185 +0,0 @@
1
- import { Deck, WebMercatorViewport, MapView, _flatten as flatten } from '@deck.gl/core';
2
- export function getDeckInstance({ map, gl, deck }) {
3
- // Only create one deck instance per context
4
- if (map.__deck) {
5
- return map.__deck;
6
- }
7
- const customRender = deck?.props._customRender;
8
- const deckProps = {
9
- useDevicePixels: true,
10
- _customRender: (reason) => {
11
- map.triggerRepaint();
12
- // customRender may be subscribed by DeckGL React component to update child props
13
- // make sure it is still called
14
- customRender?.(reason);
15
- },
16
- // TODO: import these defaults from a single source of truth
17
- parameters: {
18
- depthMask: true,
19
- depthTest: true,
20
- blend: true,
21
- blendFunc: [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA],
22
- polygonOffsetFill: true,
23
- depthFunc: gl.LEQUAL,
24
- blendEquation: gl.FUNC_ADD
25
- },
26
- views: (deck && deck.props.views) || [new MapView({ id: 'mapbox' })]
27
- };
28
- if (!deck || deck.props.gl === gl) {
29
- // deck is using the WebGLContext created by mapbox
30
- // block deck from setting the canvas size
31
- Object.assign(deckProps, {
32
- gl,
33
- width: null,
34
- height: null,
35
- touchAction: 'unset',
36
- viewState: getViewState(map)
37
- });
38
- // If using the WebGLContext created by deck (React use case), we use deck's viewState to drive the map.
39
- // Otherwise (pure JS use case), we use the map's viewState to drive deck.
40
- map.on('move', () => onMapMove(deck, map));
41
- }
42
- if (deck) {
43
- deck.setProps(deckProps);
44
- deck.userData.isExternal = true;
45
- }
46
- else {
47
- deck = new Deck(deckProps);
48
- map.on('remove', () => {
49
- deck.finalize();
50
- map.__deck = null;
51
- });
52
- }
53
- deck.userData.mapboxLayers = new Set();
54
- deck.userData.mapboxVersion = getMapboxVersion(map);
55
- map.__deck = deck;
56
- map.on('render', () => {
57
- // @ts-expect-error (2445) protected property
58
- if (deck.layerManager)
59
- afterRender(deck, map);
60
- });
61
- return deck;
62
- }
63
- export function addLayer(deck, layer) {
64
- deck.userData.mapboxLayers.add(layer);
65
- updateLayers(deck);
66
- }
67
- export function removeLayer(deck, layer) {
68
- deck.userData.mapboxLayers.delete(layer);
69
- updateLayers(deck);
70
- }
71
- export function updateLayer(deck, layer) {
72
- updateLayers(deck);
73
- }
74
- export function drawLayer(deck, map, layer) {
75
- let { currentViewport } = deck.userData;
76
- if (!currentViewport) {
77
- // This is the first layer drawn in this render cycle.
78
- // Generate viewport from the current map state.
79
- currentViewport = getViewport(deck, map, true);
80
- deck.userData.currentViewport = currentViewport;
81
- }
82
- // @ts-expect-error (2445) protected property
83
- if (!deck.layerManager) {
84
- return;
85
- }
86
- deck._drawLayers('mapbox-repaint', {
87
- viewports: [currentViewport],
88
- layerFilter: ({ layer: deckLayer }) => layer.id === deckLayer.id,
89
- clearCanvas: false
90
- });
91
- }
92
- export function getViewState(map) {
93
- const { lng, lat } = map.getCenter();
94
- return {
95
- // Longitude returned by getCenter can be outside of [-180, 180] when zooming near the anti meridian
96
- // https://github.com/visgl/deck.gl/issues/6894
97
- longitude: ((lng + 540) % 360) - 180,
98
- latitude: lat,
99
- zoom: map.getZoom(),
100
- bearing: map.getBearing(),
101
- pitch: map.getPitch(),
102
- repeat: map.getRenderWorldCopies()
103
- };
104
- }
105
- function getMapboxVersion(map) {
106
- // parse mapbox version string
107
- let major = 0;
108
- let minor = 0;
109
- // @ts-ignore (2339) undefined property
110
- const version = map.version;
111
- if (version) {
112
- [major, minor] = version.split('.').slice(0, 2).map(Number);
113
- }
114
- return { major, minor };
115
- }
116
- function getViewport(deck, map, useMapboxProjection = true) {
117
- const { mapboxVersion } = deck.userData;
118
- return new WebMercatorViewport(Object.assign({
119
- id: 'mapbox',
120
- x: 0,
121
- y: 0,
122
- width: deck.width,
123
- height: deck.height
124
- }, getViewState(map), useMapboxProjection
125
- ? {
126
- // match mapbox's projection matrix
127
- // A change of near plane was made in 1.3.0
128
- // https://github.com/mapbox/mapbox-gl-js/pull/8502
129
- nearZMultiplier: (mapboxVersion.major === 1 && mapboxVersion.minor >= 3) || mapboxVersion.major >= 2
130
- ? 0.02
131
- : 1 / (deck.height || 1)
132
- }
133
- : {
134
- // use deck.gl's own default
135
- nearZMultiplier: 0.1
136
- }));
137
- }
138
- function afterRender(deck, map) {
139
- const { mapboxLayers, isExternal } = deck.userData;
140
- if (isExternal) {
141
- // Draw non-Mapbox layers
142
- const mapboxLayerIds = Array.from(mapboxLayers, layer => layer.id);
143
- const deckLayers = flatten(deck.props.layers, Boolean);
144
- const hasNonMapboxLayers = deckLayers.some(layer => layer && !mapboxLayerIds.includes(layer.id));
145
- let viewports = deck.getViewports();
146
- const mapboxViewportIdx = viewports.findIndex(vp => vp.id === 'mapbox');
147
- const hasNonMapboxViews = viewports.length > 1 || mapboxViewportIdx < 0;
148
- if (hasNonMapboxLayers || hasNonMapboxViews) {
149
- if (mapboxViewportIdx >= 0) {
150
- viewports = viewports.slice();
151
- viewports[mapboxViewportIdx] = getViewport(deck, map, false);
152
- }
153
- deck._drawLayers('mapbox-repaint', {
154
- viewports,
155
- layerFilter: params => (!deck.props.layerFilter || deck.props.layerFilter(params)) &&
156
- (params.viewport.id !== 'mapbox' || !mapboxLayerIds.includes(params.layer.id)),
157
- clearCanvas: false
158
- });
159
- }
160
- }
161
- // End of render cycle, clear generated viewport
162
- deck.userData.currentViewport = null;
163
- }
164
- function onMapMove(deck, map) {
165
- deck.setProps({
166
- viewState: getViewState(map)
167
- });
168
- // Camera changed, will trigger a map repaint right after this
169
- // Clear any change flag triggered by setting viewState so that deck does not request
170
- // a second repaint
171
- deck.needsRedraw({ clearRedrawFlags: true });
172
- }
173
- function updateLayers(deck) {
174
- if (deck.userData.isExternal) {
175
- return;
176
- }
177
- const layers = [];
178
- let layerIndex = 0;
179
- deck.userData.mapboxLayers.forEach(deckLayer => {
180
- const LayerType = deckLayer.props.type;
181
- const layer = new LayerType(deckLayer.props, { _offset: layerIndex++ });
182
- layers.push(layer);
183
- });
184
- deck.setProps({ layers });
185
- }
package/typed/index.js DELETED
@@ -1,2 +0,0 @@
1
- export { default as MapboxLayer } from './mapbox-layer';
2
- export { default as MapboxOverlay } from './mapbox-overlay';
@@ -1,37 +0,0 @@
1
- import { getDeckInstance, addLayer, removeLayer, updateLayer, drawLayer } from './deck-utils';
2
- export default class MapboxLayer {
3
- /* eslint-disable no-this-before-super */
4
- constructor(props) {
5
- if (!props.id) {
6
- throw new Error('Layer must have an unique id');
7
- }
8
- this.id = props.id;
9
- this.type = 'custom';
10
- this.renderingMode = props.renderingMode || '3d';
11
- this.map = null;
12
- this.deck = null;
13
- this.props = props;
14
- }
15
- /* Mapbox custom layer methods */
16
- onAdd(map, gl) {
17
- this.map = map;
18
- this.deck = getDeckInstance({ map, gl, deck: this.props.deck });
19
- addLayer(this.deck, this);
20
- }
21
- onRemove() {
22
- if (this.deck) {
23
- removeLayer(this.deck, this);
24
- }
25
- }
26
- setProps(props) {
27
- // id cannot be changed
28
- Object.assign(this.props, props, { id: this.id });
29
- // safe guard in case setProps is called before onAdd
30
- if (this.deck) {
31
- updateLayer(this.deck, this);
32
- }
33
- }
34
- render() {
35
- drawLayer(this.deck, this.map, this);
36
- }
37
- }
@@ -1,139 +0,0 @@
1
- import { Deck, assert } from '@deck.gl/core';
2
- import { getViewState } from './deck-utils';
3
- /**
4
- * Implements Mapbox [IControl](https://docs.mapbox.com/mapbox-gl-js/api/markers/#icontrol) interface
5
- * Renders deck.gl layers over the base map and automatically synchronizes with the map's camera
6
- */
7
- export default class MapboxOverlay {
8
- constructor(props) {
9
- this._updateContainerSize = () => {
10
- if (this._map && this._container) {
11
- const { clientWidth, clientHeight } = this._map.getContainer();
12
- Object.assign(this._container.style, {
13
- width: `${clientWidth}px`,
14
- height: `${clientHeight}px`
15
- });
16
- }
17
- };
18
- this._updateViewState = () => {
19
- const deck = this._deck;
20
- if (deck) {
21
- // @ts-ignore (2345) map is always defined if deck is
22
- deck.setProps({ viewState: getViewState(this._map) });
23
- // Redraw immediately if view state has changed
24
- deck.redraw();
25
- }
26
- };
27
- this._handleMouseEvent = (event) => {
28
- const deck = this._deck;
29
- if (!deck) {
30
- return;
31
- }
32
- const mockEvent = {
33
- type: event.type,
34
- offsetCenter: event.point,
35
- srcEvent: event
36
- };
37
- switch (event.type) {
38
- case 'click':
39
- mockEvent.tapCount = 1;
40
- // Hack: because we do not listen to pointer down, perform picking now
41
- deck._onPointerDown(mockEvent);
42
- deck._onEvent(mockEvent);
43
- break;
44
- case 'dblclick':
45
- mockEvent.type = 'click';
46
- mockEvent.tapCount = 2;
47
- deck._onEvent(mockEvent);
48
- break;
49
- case 'mousemove':
50
- mockEvent.type = 'pointermove';
51
- deck._onPointerMove(mockEvent);
52
- break;
53
- case 'mouseout':
54
- mockEvent.type = 'pointerleave';
55
- deck._onPointerMove(mockEvent);
56
- break;
57
- default:
58
- return;
59
- }
60
- };
61
- this._props = { ...props };
62
- }
63
- /** Update (partial) props of the underlying Deck instance. */
64
- setProps(props) {
65
- Object.assign(this._props, props);
66
- if ('viewState' in this._props) {
67
- delete this._props.viewState;
68
- }
69
- if (this._deck) {
70
- this._deck.setProps(this._props);
71
- }
72
- }
73
- /** Called when the control is added to a map */
74
- onAdd(map) {
75
- this._map = map;
76
- /* global document */
77
- const container = document.createElement('div');
78
- Object.assign(container.style, {
79
- position: 'absolute',
80
- left: 0,
81
- top: 0,
82
- pointerEvents: 'none'
83
- });
84
- this._container = container;
85
- this._deck = new Deck({
86
- ...this._props,
87
- parent: container,
88
- viewState: getViewState(map)
89
- });
90
- map.on('resize', this._updateContainerSize);
91
- map.on('render', this._updateViewState);
92
- map.on('mousemove', this._handleMouseEvent);
93
- map.on('mouseout', this._handleMouseEvent);
94
- map.on('click', this._handleMouseEvent);
95
- map.on('dblclick', this._handleMouseEvent);
96
- this._updateContainerSize();
97
- return container;
98
- }
99
- /** Called when the control is removed from a map */
100
- onRemove() {
101
- const map = this._map;
102
- if (map) {
103
- map.off('resize', this._updateContainerSize);
104
- map.off('render', this._updateViewState);
105
- map.off('mousemove', this._handleMouseEvent);
106
- map.off('mouseout', this._handleMouseEvent);
107
- map.off('click', this._handleMouseEvent);
108
- map.off('dblclick', this._handleMouseEvent);
109
- }
110
- this._deck?.finalize();
111
- this._deck = undefined;
112
- this._map = undefined;
113
- this._container = undefined;
114
- }
115
- getDefaultPosition() {
116
- return 'top-left';
117
- }
118
- /** Forwards the Deck.pickObject method */
119
- pickObject(params) {
120
- assert(this._deck);
121
- return this._deck.pickObject(params);
122
- }
123
- /** Forwards the Deck.pickMultipleObjects method */
124
- pickMultipleObjects(params) {
125
- assert(this._deck);
126
- return this._deck.pickMultipleObjects(params);
127
- }
128
- /** Forwards the Deck.pickObjects method */
129
- pickObjects(params) {
130
- assert(this._deck);
131
- return this._deck.pickObjects(params);
132
- }
133
- /** Remove from map and releases all resources */
134
- finalize() {
135
- if (this._map) {
136
- this._map.removeControl(this);
137
- }
138
- }
139
- }