@deck.gl/mapbox 8.7.0-beta.4 → 8.7.0-beta.7
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 +30 -14
- package/dist/es5/deck-utils.js +30 -11
- package/dist/es5/deck-utils.js.map +1 -1
- package/dist/esm/deck-utils.js +28 -12
- package/dist/esm/deck-utils.js.map +1 -1
- package/dist.min.js +1 -1
- package/package.json +2 -2
- package/src/deck-utils.js +34 -14
package/dist/dist.dev.js
CHANGED
|
@@ -158,32 +158,41 @@ function getDeckInstance({
|
|
|
158
158
|
parameters: {
|
|
159
159
|
depthMask: true,
|
|
160
160
|
depthTest: true,
|
|
161
|
+
blend: true,
|
|
161
162
|
blendFunc: [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA],
|
|
163
|
+
polygonOffsetFill: true,
|
|
164
|
+
depthFunc: gl.LEQUAL,
|
|
162
165
|
blendEquation: gl.FUNC_ADD
|
|
163
166
|
},
|
|
164
167
|
userData: {
|
|
165
168
|
isExternal: false,
|
|
166
169
|
mapboxLayers: new Set()
|
|
167
|
-
}
|
|
170
|
+
},
|
|
171
|
+
views: deck && deck.props.views || [new _deck_gl_core__WEBPACK_IMPORTED_MODULE_0__["MapView"]({
|
|
172
|
+
id: 'mapbox'
|
|
173
|
+
})]
|
|
168
174
|
};
|
|
169
175
|
|
|
170
|
-
if (deck) {
|
|
171
|
-
deck
|
|
172
|
-
deck
|
|
173
|
-
} else {
|
|
174
|
-
// Using external gl context - do not set css size
|
|
176
|
+
if (!deck || deck.props.gl === gl) {
|
|
177
|
+
// deck is using the WebGLContext created by mapbox
|
|
178
|
+
// block deck from setting the canvas size
|
|
175
179
|
Object.assign(deckProps, {
|
|
176
180
|
gl,
|
|
177
181
|
width: false,
|
|
178
182
|
height: false,
|
|
179
183
|
touchAction: 'unset',
|
|
180
184
|
viewState: getViewState(map)
|
|
181
|
-
});
|
|
182
|
-
deck = new _deck_gl_core__WEBPACK_IMPORTED_MODULE_0__["Deck"](deckProps); // If deck is externally provided (React use case), we use deck's viewState to
|
|
183
|
-
// drive the map.
|
|
185
|
+
}); // If using the WebGLContext created by deck (React use case), we use deck's viewState to drive the map.
|
|
184
186
|
// Otherwise (pure JS use case), we use the map's viewState to drive deck.
|
|
185
187
|
|
|
186
188
|
map.on('move', () => onMapMove(deck, map));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (deck) {
|
|
192
|
+
deck.setProps(deckProps);
|
|
193
|
+
deck.props.userData.isExternal = true;
|
|
194
|
+
} else {
|
|
195
|
+
deck = new _deck_gl_core__WEBPACK_IMPORTED_MODULE_0__["Deck"](deckProps);
|
|
187
196
|
map.on('remove', () => {
|
|
188
197
|
deck.finalize();
|
|
189
198
|
map.__deck = null;
|
|
@@ -267,6 +276,7 @@ function getViewport(deck, map, useMapboxProjection = true) {
|
|
|
267
276
|
mapboxVersion
|
|
268
277
|
} = deck.props.userData;
|
|
269
278
|
return new _deck_gl_core__WEBPACK_IMPORTED_MODULE_0__["WebMercatorViewport"](Object.assign({
|
|
279
|
+
id: 'mapbox',
|
|
270
280
|
x: 0,
|
|
271
281
|
y: 0,
|
|
272
282
|
width: deck.width,
|
|
@@ -293,13 +303,19 @@ function afterRender(deck, map) {
|
|
|
293
303
|
// Draw non-Mapbox layers
|
|
294
304
|
const mapboxLayerIds = Array.from(mapboxLayers, layer => layer.id);
|
|
295
305
|
const hasNonMapboxLayers = deck.props.layers.some(layer => !mapboxLayerIds.includes(layer.id));
|
|
306
|
+
let viewports = deck.getViewports();
|
|
307
|
+
const mapboxViewportIdx = viewports.findIndex(vp => vp.id === 'mapbox');
|
|
308
|
+
const hasNonMapboxViews = viewports.length > 1 || mapboxViewportIdx < 0;
|
|
309
|
+
|
|
310
|
+
if (hasNonMapboxLayers || hasNonMapboxViews) {
|
|
311
|
+
if (mapboxViewportIdx >= 0) {
|
|
312
|
+
viewports = viewports.slice();
|
|
313
|
+
viewports[mapboxViewportIdx] = getViewport(deck, map, false);
|
|
314
|
+
}
|
|
296
315
|
|
|
297
|
-
if (hasNonMapboxLayers) {
|
|
298
316
|
deck._drawLayers('mapbox-repaint', {
|
|
299
|
-
viewports
|
|
300
|
-
layerFilter: (
|
|
301
|
-
layer
|
|
302
|
-
}) => !mapboxLayerIds.includes(layer.id),
|
|
317
|
+
viewports,
|
|
318
|
+
layerFilter: params => (!deck.props.layerFilter || deck.props.layerFilter(params)) && (params.viewport.id !== 'mapbox' || !mapboxLayerIds.includes(params.layer.id)),
|
|
303
319
|
clearCanvas: false
|
|
304
320
|
});
|
|
305
321
|
}
|
package/dist/es5/deck-utils.js
CHANGED
|
@@ -37,19 +37,22 @@ function getDeckInstance(_ref) {
|
|
|
37
37
|
parameters: {
|
|
38
38
|
depthMask: true,
|
|
39
39
|
depthTest: true,
|
|
40
|
+
blend: true,
|
|
40
41
|
blendFunc: [770, 771, 1, 771],
|
|
42
|
+
polygonOffsetFill: true,
|
|
43
|
+
depthFunc: 515,
|
|
41
44
|
blendEquation: 32774
|
|
42
45
|
},
|
|
43
46
|
userData: {
|
|
44
47
|
isExternal: false,
|
|
45
48
|
mapboxLayers: new Set()
|
|
46
|
-
}
|
|
49
|
+
},
|
|
50
|
+
views: deck && deck.props.views || [new _core.MapView({
|
|
51
|
+
id: 'mapbox'
|
|
52
|
+
})]
|
|
47
53
|
};
|
|
48
54
|
|
|
49
|
-
if (deck) {
|
|
50
|
-
deck.setProps(deckProps);
|
|
51
|
-
deck.props.userData.isExternal = true;
|
|
52
|
-
} else {
|
|
55
|
+
if (!deck || deck.props.gl === gl) {
|
|
53
56
|
Object.assign(deckProps, {
|
|
54
57
|
gl: gl,
|
|
55
58
|
width: false,
|
|
@@ -57,10 +60,16 @@ function getDeckInstance(_ref) {
|
|
|
57
60
|
touchAction: 'unset',
|
|
58
61
|
viewState: getViewState(map)
|
|
59
62
|
});
|
|
60
|
-
deck = new _core.Deck(deckProps);
|
|
61
63
|
map.on('move', function () {
|
|
62
64
|
return onMapMove(deck, map);
|
|
63
65
|
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (deck) {
|
|
69
|
+
deck.setProps(deckProps);
|
|
70
|
+
deck.props.userData.isExternal = true;
|
|
71
|
+
} else {
|
|
72
|
+
deck = new _core.Deck(deckProps);
|
|
64
73
|
map.on('remove', function () {
|
|
65
74
|
deck.finalize();
|
|
66
75
|
map.__deck = null;
|
|
@@ -148,6 +157,7 @@ function getViewport(deck, map) {
|
|
|
148
157
|
var useMapboxProjection = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
149
158
|
var mapboxVersion = deck.props.userData.mapboxVersion;
|
|
150
159
|
return new _core.WebMercatorViewport(Object.assign({
|
|
160
|
+
id: 'mapbox',
|
|
151
161
|
x: 0,
|
|
152
162
|
y: 0,
|
|
153
163
|
width: deck.width,
|
|
@@ -172,13 +182,22 @@ function afterRender(deck, map) {
|
|
|
172
182
|
var hasNonMapboxLayers = deck.props.layers.some(function (layer) {
|
|
173
183
|
return !mapboxLayerIds.includes(layer.id);
|
|
174
184
|
});
|
|
185
|
+
var viewports = deck.getViewports();
|
|
186
|
+
var mapboxViewportIdx = viewports.findIndex(function (vp) {
|
|
187
|
+
return vp.id === 'mapbox';
|
|
188
|
+
});
|
|
189
|
+
var hasNonMapboxViews = viewports.length > 1 || mapboxViewportIdx < 0;
|
|
190
|
+
|
|
191
|
+
if (hasNonMapboxLayers || hasNonMapboxViews) {
|
|
192
|
+
if (mapboxViewportIdx >= 0) {
|
|
193
|
+
viewports = viewports.slice();
|
|
194
|
+
viewports[mapboxViewportIdx] = getViewport(deck, map, false);
|
|
195
|
+
}
|
|
175
196
|
|
|
176
|
-
if (hasNonMapboxLayers) {
|
|
177
197
|
deck._drawLayers('mapbox-repaint', {
|
|
178
|
-
viewports:
|
|
179
|
-
layerFilter: function layerFilter(
|
|
180
|
-
|
|
181
|
-
return !mapboxLayerIds.includes(layer.id);
|
|
198
|
+
viewports: viewports,
|
|
199
|
+
layerFilter: function layerFilter(params) {
|
|
200
|
+
return (!deck.props.layerFilter || deck.props.layerFilter(params)) && (params.viewport.id !== 'mapbox' || !mapboxLayerIds.includes(params.layer.id));
|
|
182
201
|
},
|
|
183
202
|
clearCanvas: false
|
|
184
203
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/deck-utils.js"],"names":["getDeckInstance","map","gl","deck","__deck","customRender","props","_customRender","deckProps","useDevicePixels","triggerRepaint","parameters","depthMask","depthTest","blendFunc","blendEquation","userData","isExternal","mapboxLayers","Set","setProps","Object","assign","width","height","touchAction","viewState","getViewState","Deck","on","onMapMove","finalize","mapboxVersion","getMapboxVersion","layerManager","afterRender","addLayer","layer","add","updateLayers","removeLayer","delete","updateLayer","drawLayer","currentViewport","getViewport","_drawLayers","viewports","layerFilter","deckLayer","id","clearCanvas","getCenter","lng","lat","longitude","latitude","zoom","getZoom","bearing","getBearing","pitch","getPitch","major","minor","version","split","slice","Number","useMapboxProjection","WebMercatorViewport","x","y","repeat","getRenderWorldCopies","nearZMultiplier","mapboxLayerIds","Array","from","hasNonMapboxLayers","layers","some","includes","needsRedraw","clearRedrawFlags","layerIndex","forEach","LayerType","type","_offset","push"],"mappings":";;;;;;;;;;;;;;;AAAA;;AAEO,SAASA,eAAT,OAA0C;AAAA,MAAhBC,GAAgB,QAAhBA,GAAgB;AAAA,MAAXC,EAAW,QAAXA,EAAW;AAAA,MAAPC,IAAO,QAAPA,IAAO;;AAE/C,MAAIF,GAAG,CAACG,MAAR,EAAgB;AACd,WAAOH,GAAG,CAACG,MAAX;AACD;;AAED,MAAMC,YAAY,GAAGF,IAAI,IAAIA,IAAI,CAACG,KAAL,CAAWC,aAAxC;AAEA,MAAMC,SAAS,GAAG;AAChBC,IAAAA,eAAe,EAAE,IADD;AAEhBF,IAAAA,aAAa,EAAE,yBAAM;AACnBN,MAAAA,GAAG,CAACS,cAAJ;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/core';\n\nexport function getDeckInstance({map, gl, deck}) {\n // Only create one deck instance per context\n if (map.__deck) {\n return map.__deck;\n }\n\n const customRender = deck && deck.props._customRender;\n\n const deckProps = {\n useDevicePixels: true,\n _customRender: () => {\n map.triggerRepaint();\n if (customRender) {\n // customRender may be subscribed by DeckGL React component to update child props\n // make sure it is still called\n customRender();\n }\n },\n // TODO: import these defaults from a single source of truth\n parameters: {\n depthMask: true,\n depthTest: true,\n blendFunc: [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA],\n blendEquation: gl.FUNC_ADD\n },\n userData: {\n isExternal: false,\n mapboxLayers: new Set()\n }\n };\n\n if (deck) {\n deck.setProps(deckProps);\n deck.props.userData.isExternal = true;\n } else {\n // Using external gl context - do not set css size\n Object.assign(deckProps, {\n gl,\n width: false,\n height: false,\n touchAction: 'unset',\n viewState: getViewState(map)\n });\n deck = new Deck(deckProps);\n\n // If deck is externally provided (React use case), we use deck's viewState to\n // 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 map.on('remove', () => {\n deck.finalize();\n map.__deck = null;\n });\n }\n deck.props.userData.mapboxVersion = getMapboxVersion(map);\n map.__deck = deck;\n map.on('render', () => {\n if (deck.layerManager) afterRender(deck, map);\n });\n\n return deck;\n}\n\nexport function addLayer(deck, layer) {\n deck.props.userData.mapboxLayers.add(layer);\n updateLayers(deck);\n}\n\nexport function removeLayer(deck, layer) {\n deck.props.userData.mapboxLayers.delete(layer);\n updateLayers(deck);\n}\n\nexport function updateLayer(deck, layer) {\n updateLayers(deck);\n}\n\nexport function drawLayer(deck, map, layer) {\n let {currentViewport} = deck.props.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.props.userData.currentViewport = currentViewport;\n }\n if (!deck.layerManager) {\n return;\n }\n deck._drawLayers('mapbox-repaint', {\n viewports: [currentViewport],\n layerFilter: ({layer: deckLayer}) => layer.id === deckLayer.id,\n clearCanvas: false\n });\n}\n\nfunction getViewState(map) {\n const {lng, lat} = map.getCenter();\n return {\n longitude: lng,\n latitude: lat,\n zoom: map.getZoom(),\n bearing: map.getBearing(),\n pitch: map.getPitch()\n };\n}\n\nfunction getMapboxVersion(map) {\n // parse mapbox version string\n let major = 0;\n let minor = 0;\n if (map.version) {\n [major, minor] = map.version.split('.').slice(0, 2).map(Number);\n }\n return {major, minor};\n}\n\nfunction getViewport(deck, map, useMapboxProjection = true) {\n const {mapboxVersion} = deck.props.userData;\n\n return new WebMercatorViewport(\n Object.assign(\n {\n x: 0,\n y: 0,\n width: deck.width,\n height: deck.height,\n repeat: map.getRenderWorldCopies()\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, map) {\n const {mapboxLayers, isExternal} = deck.props.userData;\n\n if (isExternal) {\n // Draw non-Mapbox layers\n const mapboxLayerIds = Array.from(mapboxLayers, layer => layer.id);\n const hasNonMapboxLayers = deck.props.layers.some(layer => !mapboxLayerIds.includes(layer.id));\n if (hasNonMapboxLayers) {\n deck._drawLayers('mapbox-repaint', {\n viewports: [getViewport(deck, map, false)],\n layerFilter: ({layer}) => !mapboxLayerIds.includes(layer.id),\n clearCanvas: false\n });\n }\n }\n\n // End of render cycle, clear generated viewport\n deck.props.userData.currentViewport = null;\n}\n\nfunction onMapMove(deck, map) {\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) {\n if (deck.props.userData.isExternal) {\n return;\n }\n\n const layers = [];\n let layerIndex = 0;\n deck.props.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.js"],"names":["getDeckInstance","map","gl","deck","__deck","customRender","props","_customRender","deckProps","useDevicePixels","triggerRepaint","parameters","depthMask","depthTest","blend","blendFunc","polygonOffsetFill","depthFunc","blendEquation","userData","isExternal","mapboxLayers","Set","views","MapView","id","Object","assign","width","height","touchAction","viewState","getViewState","on","onMapMove","setProps","Deck","finalize","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","major","minor","version","split","slice","Number","useMapboxProjection","WebMercatorViewport","x","y","repeat","getRenderWorldCopies","nearZMultiplier","mapboxLayerIds","Array","from","hasNonMapboxLayers","layers","some","includes","getViewports","mapboxViewportIdx","findIndex","vp","hasNonMapboxViews","length","params","viewport","needsRedraw","clearRedrawFlags","layerIndex","forEach","LayerType","type","_offset","push"],"mappings":";;;;;;;;;;;;;;;AAAA;;AAEO,SAASA,eAAT,OAA0C;AAAA,MAAhBC,GAAgB,QAAhBA,GAAgB;AAAA,MAAXC,EAAW,QAAXA,EAAW;AAAA,MAAPC,IAAO,QAAPA,IAAO;;AAE/C,MAAIF,GAAG,CAACG,MAAR,EAAgB;AACd,WAAOH,GAAG,CAACG,MAAX;AACD;;AAED,MAAMC,YAAY,GAAGF,IAAI,IAAIA,IAAI,CAACG,KAAL,CAAWC,aAAxC;AAEA,MAAMC,SAAS,GAAG;AAChBC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AwBO,MAAM,CAACnD,KAAP,CAAalB,EAArC,CADrC,CADiB;AAAA,SAFc;AAKjC+B,QAAAA,WAAW,EAAE;AALoB,OAAnC;AAOD;AACF;;AAGDrD,EAAAA,IAAI,CAACG,KAAL,CAAWa,QAAX,CAAoB+B,eAApB,GAAsC,IAAtC;AACD;;AAED,SAAShB,SAAT,CAAmB/B,IAAnB,EAAyBF,GAAzB,EAA8B;AAC5BE,EAAAA,IAAI,CAACgC,QAAL,CAAc;AACZJ,IAAAA,SAAS,EAAEC,YAAY,CAAC/B,GAAD;AADX,GAAd;AAMAE,EAAAA,IAAI,CAAC6F,WAAL,CAAiB;AAACC,IAAAA,gBAAgB,EAAE;AAAnB,GAAjB;AACD;;AAED,SAASpD,YAAT,CAAsB1C,IAAtB,EAA4B;AAC1B,MAAIA,IAAI,CAACG,KAAL,CAAWa,QAAX,CAAoBC,UAAxB,EAAoC;AAClC;AACD;;AAED,MAAMiE,MAAM,GAAG,EAAf;AACA,MAAIa,UAAU,GAAG,CAAjB;AACA/F,EAAAA,IAAI,CAACG,KAAL,CAAWa,QAAX,CAAoBE,YAApB,CAAiC8E,OAAjC,CAAyC,UAAA5C,SAAS,EAAI;AACpD,QAAM6C,SAAS,GAAG7C,SAAS,CAACjD,KAAV,CAAgB+F,IAAlC;AACA,QAAM1D,KAAK,GAAG,IAAIyD,SAAJ,CAAc7C,SAAS,CAACjD,KAAxB,EAA+B;AAACgG,MAAAA,OAAO,EAAEJ,UAAU;AAApB,KAA/B,CAAd;AACAb,IAAAA,MAAM,CAACkB,IAAP,CAAY5D,KAAZ;AACD,GAJD;AAKAxC,EAAAA,IAAI,CAACgC,QAAL,CAAc;AAACkD,IAAAA,MAAM,EAANA;AAAD,GAAd;AACD","sourcesContent":["import {Deck, WebMercatorViewport, MapView} from '@deck.gl/core';\n\nexport function getDeckInstance({map, gl, deck}) {\n // Only create one deck instance per context\n if (map.__deck) {\n return map.__deck;\n }\n\n const customRender = deck && deck.props._customRender;\n\n const deckProps = {\n useDevicePixels: true,\n _customRender: () => {\n map.triggerRepaint();\n if (customRender) {\n // customRender may be subscribed by DeckGL React component to update child props\n // make sure it is still called\n customRender();\n }\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 userData: {\n isExternal: false,\n mapboxLayers: new Set()\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: false,\n height: false,\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.props.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.props.userData.mapboxVersion = getMapboxVersion(map);\n map.__deck = deck;\n map.on('render', () => {\n if (deck.layerManager) afterRender(deck, map);\n });\n\n return deck;\n}\n\nexport function addLayer(deck, layer) {\n deck.props.userData.mapboxLayers.add(layer);\n updateLayers(deck);\n}\n\nexport function removeLayer(deck, layer) {\n deck.props.userData.mapboxLayers.delete(layer);\n updateLayers(deck);\n}\n\nexport function updateLayer(deck, layer) {\n updateLayers(deck);\n}\n\nexport function drawLayer(deck, map, layer) {\n let {currentViewport} = deck.props.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.props.userData.currentViewport = currentViewport;\n }\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\nfunction getViewState(map) {\n const {lng, lat} = map.getCenter();\n return {\n longitude: lng,\n latitude: lat,\n zoom: map.getZoom(),\n bearing: map.getBearing(),\n pitch: map.getPitch()\n };\n}\n\nfunction getMapboxVersion(map) {\n // parse mapbox version string\n let major = 0;\n let minor = 0;\n if (map.version) {\n [major, minor] = map.version.split('.').slice(0, 2).map(Number);\n }\n return {major, minor};\n}\n\nfunction getViewport(deck, map, useMapboxProjection = true) {\n const {mapboxVersion} = deck.props.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 repeat: map.getRenderWorldCopies()\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, map) {\n const {mapboxLayers, isExternal} = deck.props.userData;\n\n if (isExternal) {\n // Draw non-Mapbox layers\n const mapboxLayerIds = Array.from(mapboxLayers, layer => layer.id);\n const hasNonMapboxLayers = deck.props.layers.some(layer => !mapboxLayerIds.includes(layer.id));\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.props.userData.currentViewport = null;\n}\n\nfunction onMapMove(deck, map) {\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) {\n if (deck.props.userData.isExternal) {\n return;\n }\n\n const layers = [];\n let layerIndex = 0;\n deck.props.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/esm/deck-utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Deck, WebMercatorViewport } from '@deck.gl/core';
|
|
1
|
+
import { Deck, WebMercatorViewport, MapView } from '@deck.gl/core';
|
|
2
2
|
export function getDeckInstance({
|
|
3
3
|
map,
|
|
4
4
|
gl,
|
|
@@ -21,19 +21,22 @@ export function getDeckInstance({
|
|
|
21
21
|
parameters: {
|
|
22
22
|
depthMask: true,
|
|
23
23
|
depthTest: true,
|
|
24
|
+
blend: true,
|
|
24
25
|
blendFunc: [770, 771, 1, 771],
|
|
26
|
+
polygonOffsetFill: true,
|
|
27
|
+
depthFunc: 515,
|
|
25
28
|
blendEquation: 32774
|
|
26
29
|
},
|
|
27
30
|
userData: {
|
|
28
31
|
isExternal: false,
|
|
29
32
|
mapboxLayers: new Set()
|
|
30
|
-
}
|
|
33
|
+
},
|
|
34
|
+
views: deck && deck.props.views || [new MapView({
|
|
35
|
+
id: 'mapbox'
|
|
36
|
+
})]
|
|
31
37
|
};
|
|
32
38
|
|
|
33
|
-
if (deck) {
|
|
34
|
-
deck.setProps(deckProps);
|
|
35
|
-
deck.props.userData.isExternal = true;
|
|
36
|
-
} else {
|
|
39
|
+
if (!deck || deck.props.gl === gl) {
|
|
37
40
|
Object.assign(deckProps, {
|
|
38
41
|
gl,
|
|
39
42
|
width: false,
|
|
@@ -41,8 +44,14 @@ export function getDeckInstance({
|
|
|
41
44
|
touchAction: 'unset',
|
|
42
45
|
viewState: getViewState(map)
|
|
43
46
|
});
|
|
44
|
-
deck = new Deck(deckProps);
|
|
45
47
|
map.on('move', () => onMapMove(deck, map));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (deck) {
|
|
51
|
+
deck.setProps(deckProps);
|
|
52
|
+
deck.props.userData.isExternal = true;
|
|
53
|
+
} else {
|
|
54
|
+
deck = new Deck(deckProps);
|
|
46
55
|
map.on('remove', () => {
|
|
47
56
|
deck.finalize();
|
|
48
57
|
map.__deck = null;
|
|
@@ -123,6 +132,7 @@ function getViewport(deck, map, useMapboxProjection = true) {
|
|
|
123
132
|
mapboxVersion
|
|
124
133
|
} = deck.props.userData;
|
|
125
134
|
return new WebMercatorViewport(Object.assign({
|
|
135
|
+
id: 'mapbox',
|
|
126
136
|
x: 0,
|
|
127
137
|
y: 0,
|
|
128
138
|
width: deck.width,
|
|
@@ -144,13 +154,19 @@ function afterRender(deck, map) {
|
|
|
144
154
|
if (isExternal) {
|
|
145
155
|
const mapboxLayerIds = Array.from(mapboxLayers, layer => layer.id);
|
|
146
156
|
const hasNonMapboxLayers = deck.props.layers.some(layer => !mapboxLayerIds.includes(layer.id));
|
|
157
|
+
let viewports = deck.getViewports();
|
|
158
|
+
const mapboxViewportIdx = viewports.findIndex(vp => vp.id === 'mapbox');
|
|
159
|
+
const hasNonMapboxViews = viewports.length > 1 || mapboxViewportIdx < 0;
|
|
160
|
+
|
|
161
|
+
if (hasNonMapboxLayers || hasNonMapboxViews) {
|
|
162
|
+
if (mapboxViewportIdx >= 0) {
|
|
163
|
+
viewports = viewports.slice();
|
|
164
|
+
viewports[mapboxViewportIdx] = getViewport(deck, map, false);
|
|
165
|
+
}
|
|
147
166
|
|
|
148
|
-
if (hasNonMapboxLayers) {
|
|
149
167
|
deck._drawLayers('mapbox-repaint', {
|
|
150
|
-
viewports
|
|
151
|
-
layerFilter: (
|
|
152
|
-
layer
|
|
153
|
-
}) => !mapboxLayerIds.includes(layer.id),
|
|
168
|
+
viewports,
|
|
169
|
+
layerFilter: params => (!deck.props.layerFilter || deck.props.layerFilter(params)) && (params.viewport.id !== 'mapbox' || !mapboxLayerIds.includes(params.layer.id)),
|
|
154
170
|
clearCanvas: false
|
|
155
171
|
});
|
|
156
172
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/deck-utils.js"],"names":["Deck","WebMercatorViewport","getDeckInstance","map","gl","deck","__deck","customRender","props","_customRender","deckProps","useDevicePixels","triggerRepaint","parameters","depthMask","depthTest","blendFunc","blendEquation","userData","isExternal","mapboxLayers","Set","setProps","Object","assign","width","height","touchAction","viewState","getViewState","on","onMapMove","finalize","mapboxVersion","getMapboxVersion","layerManager","afterRender","addLayer","layer","add","updateLayers","removeLayer","delete","updateLayer","drawLayer","currentViewport","getViewport","_drawLayers","viewports","layerFilter","deckLayer","id","clearCanvas","lng","lat","getCenter","longitude","latitude","zoom","getZoom","bearing","getBearing","pitch","getPitch","major","minor","version","split","slice","Number","useMapboxProjection","x","y","repeat","getRenderWorldCopies","nearZMultiplier","mapboxLayerIds","Array","from","hasNonMapboxLayers","layers","some","includes","needsRedraw","clearRedrawFlags","layerIndex","forEach","LayerType","type","_offset","push"],"mappings":"AAAA,SAAQA,IAAR,EAAcC,mBAAd,QAAwC,eAAxC;AAEA,OAAO,SAASC,eAAT,CAAyB;AAACC,EAAAA,GAAD;AAAMC,EAAAA,EAAN;AAAUC,EAAAA;AAAV,CAAzB,EAA0C;AAE/C,MAAIF,GAAG,CAACG,MAAR,EAAgB;AACd,WAAOH,GAAG,CAACG,MAAX;AACD;;AAED,QAAMC,YAAY,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gl, deck}) {\n // Only create one deck instance per context\n if (map.__deck) {\n return map.__deck;\n }\n\n const customRender = deck && deck.props._customRender;\n\n const deckProps = {\n useDevicePixels: true,\n _customRender: () => {\n map.triggerRepaint();\n if (customRender) {\n // customRender may be subscribed by DeckGL React component to update child props\n // make sure it is still called\n customRender();\n }\n },\n // TODO: import these defaults from a single source of truth\n parameters: {\n depthMask: true,\n depthTest: true,\n blendFunc: [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA],\n blendEquation: gl.FUNC_ADD\n },\n userData: {\n isExternal: false,\n mapboxLayers: new Set()\n }\n };\n\n if (deck) {\n deck.setProps(deckProps);\n deck.props.userData.isExternal = true;\n } else {\n // Using external gl context - do not set css size\n Object.assign(deckProps, {\n gl,\n width: false,\n height: false,\n touchAction: 'unset',\n viewState: getViewState(map)\n });\n deck = new Deck(deckProps);\n\n // If deck is externally provided (React use case), we use deck's viewState to\n // 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 map.on('remove', () => {\n deck.finalize();\n map.__deck = null;\n });\n }\n deck.props.userData.mapboxVersion = getMapboxVersion(map);\n map.__deck = deck;\n map.on('render', () => {\n if (deck.layerManager) afterRender(deck, map);\n });\n\n return deck;\n}\n\nexport function addLayer(deck, layer) {\n deck.props.userData.mapboxLayers.add(layer);\n updateLayers(deck);\n}\n\nexport function removeLayer(deck, layer) {\n deck.props.userData.mapboxLayers.delete(layer);\n updateLayers(deck);\n}\n\nexport function updateLayer(deck, layer) {\n updateLayers(deck);\n}\n\nexport function drawLayer(deck, map, layer) {\n let {currentViewport} = deck.props.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.props.userData.currentViewport = currentViewport;\n }\n if (!deck.layerManager) {\n return;\n }\n deck._drawLayers('mapbox-repaint', {\n viewports: [currentViewport],\n layerFilter: ({layer: deckLayer}) => layer.id === deckLayer.id,\n clearCanvas: false\n });\n}\n\nfunction getViewState(map) {\n const {lng, lat} = map.getCenter();\n return {\n longitude: lng,\n latitude: lat,\n zoom: map.getZoom(),\n bearing: map.getBearing(),\n pitch: map.getPitch()\n };\n}\n\nfunction getMapboxVersion(map) {\n // parse mapbox version string\n let major = 0;\n let minor = 0;\n if (map.version) {\n [major, minor] = map.version.split('.').slice(0, 2).map(Number);\n }\n return {major, minor};\n}\n\nfunction getViewport(deck, map, useMapboxProjection = true) {\n const {mapboxVersion} = deck.props.userData;\n\n return new WebMercatorViewport(\n Object.assign(\n {\n x: 0,\n y: 0,\n width: deck.width,\n height: deck.height,\n repeat: map.getRenderWorldCopies()\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, map) {\n const {mapboxLayers, isExternal} = deck.props.userData;\n\n if (isExternal) {\n // Draw non-Mapbox layers\n const mapboxLayerIds = Array.from(mapboxLayers, layer => layer.id);\n const hasNonMapboxLayers = deck.props.layers.some(layer => !mapboxLayerIds.includes(layer.id));\n if (hasNonMapboxLayers) {\n deck._drawLayers('mapbox-repaint', {\n viewports: [getViewport(deck, map, false)],\n layerFilter: ({layer}) => !mapboxLayerIds.includes(layer.id),\n clearCanvas: false\n });\n }\n }\n\n // End of render cycle, clear generated viewport\n deck.props.userData.currentViewport = null;\n}\n\nfunction onMapMove(deck, map) {\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) {\n if (deck.props.userData.isExternal) {\n return;\n }\n\n const layers = [];\n let layerIndex = 0;\n deck.props.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.js"],"names":["Deck","WebMercatorViewport","MapView","getDeckInstance","map","gl","deck","__deck","customRender","props","_customRender","deckProps","useDevicePixels","triggerRepaint","parameters","depthMask","depthTest","blend","blendFunc","polygonOffsetFill","depthFunc","blendEquation","userData","isExternal","mapboxLayers","Set","views","id","Object","assign","width","height","touchAction","viewState","getViewState","on","onMapMove","setProps","finalize","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","major","minor","version","split","slice","Number","useMapboxProjection","x","y","repeat","getRenderWorldCopies","nearZMultiplier","mapboxLayerIds","Array","from","hasNonMapboxLayers","layers","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,QAAiD,eAAjD;AAEA,OAAO,SAASC,eAAT,CAAyB;AAACC,EAAAA,GAAD;AAAMC,EAAAA,EAAN;AAAUC,EAAAA;AAAV,CAAzB,EAA0C;AAE/C,MAAIF,GAAG,CAACG,MAAR,EAAgB;AACd,WAAOH,GAAG,CAACG,MAAX;AACD;;AAED,QAAMC,YAAY,GAAGF,IAAI,IAAIA,IAAI,CAACG,KAAL,CAAWC,aAAxC;AAEA,QAAMC,SAAS,GAAG;AAChBC,IAAAA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AAzB,EAA8B;AAC5BE,EAAAA,IAAI,CAAC+B,QAAL,CAAc;AACZJ,IAAAA,SAAS,EAAEC,YAAY,CAAC9B,GAAD;AADX,GAAd;AAMAE,EAAAA,IAAI,CAAC0F,WAAL,CAAiB;AAACC,IAAAA,gBAAgB,EAAE;AAAnB,GAAjB;AACD;;AAED,SAASnD,YAAT,CAAsBxC,IAAtB,EAA4B;AAC1B,MAAIA,IAAI,CAACG,KAAL,CAAWa,QAAX,CAAoBC,UAAxB,EAAoC;AAClC;AACD;;AAED,QAAM8D,MAAM,GAAG,EAAf;AACA,MAAIa,UAAU,GAAG,CAAjB;AACA5F,EAAAA,IAAI,CAACG,KAAL,CAAWa,QAAX,CAAoBE,YAApB,CAAiC2E,OAAjC,CAAyC3C,SAAS,IAAI;AACpD,UAAM4C,SAAS,GAAG5C,SAAS,CAAC/C,KAAV,CAAgB4F,IAAlC;AACA,UAAMzD,KAAK,GAAG,IAAIwD,SAAJ,CAAc5C,SAAS,CAAC/C,KAAxB,EAA+B;AAAC6F,MAAAA,OAAO,EAAEJ,UAAU;AAApB,KAA/B,CAAd;AACAb,IAAAA,MAAM,CAACkB,IAAP,CAAY3D,KAAZ;AACD,GAJD;AAKAtC,EAAAA,IAAI,CAAC+B,QAAL,CAAc;AAACgD,IAAAA;AAAD,GAAd;AACD","sourcesContent":["import {Deck, WebMercatorViewport, MapView} from '@deck.gl/core';\n\nexport function getDeckInstance({map, gl, deck}) {\n // Only create one deck instance per context\n if (map.__deck) {\n return map.__deck;\n }\n\n const customRender = deck && deck.props._customRender;\n\n const deckProps = {\n useDevicePixels: true,\n _customRender: () => {\n map.triggerRepaint();\n if (customRender) {\n // customRender may be subscribed by DeckGL React component to update child props\n // make sure it is still called\n customRender();\n }\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 userData: {\n isExternal: false,\n mapboxLayers: new Set()\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: false,\n height: false,\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.props.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.props.userData.mapboxVersion = getMapboxVersion(map);\n map.__deck = deck;\n map.on('render', () => {\n if (deck.layerManager) afterRender(deck, map);\n });\n\n return deck;\n}\n\nexport function addLayer(deck, layer) {\n deck.props.userData.mapboxLayers.add(layer);\n updateLayers(deck);\n}\n\nexport function removeLayer(deck, layer) {\n deck.props.userData.mapboxLayers.delete(layer);\n updateLayers(deck);\n}\n\nexport function updateLayer(deck, layer) {\n updateLayers(deck);\n}\n\nexport function drawLayer(deck, map, layer) {\n let {currentViewport} = deck.props.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.props.userData.currentViewport = currentViewport;\n }\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\nfunction getViewState(map) {\n const {lng, lat} = map.getCenter();\n return {\n longitude: lng,\n latitude: lat,\n zoom: map.getZoom(),\n bearing: map.getBearing(),\n pitch: map.getPitch()\n };\n}\n\nfunction getMapboxVersion(map) {\n // parse mapbox version string\n let major = 0;\n let minor = 0;\n if (map.version) {\n [major, minor] = map.version.split('.').slice(0, 2).map(Number);\n }\n return {major, minor};\n}\n\nfunction getViewport(deck, map, useMapboxProjection = true) {\n const {mapboxVersion} = deck.props.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 repeat: map.getRenderWorldCopies()\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, map) {\n const {mapboxLayers, isExternal} = deck.props.userData;\n\n if (isExternal) {\n // Draw non-Mapbox layers\n const mapboxLayerIds = Array.from(mapboxLayers, layer => layer.id);\n const hasNonMapboxLayers = deck.props.layers.some(layer => !mapboxLayerIds.includes(layer.id));\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.props.userData.currentViewport = null;\n}\n\nfunction onMapMove(deck, map) {\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) {\n if (deck.props.userData.isExternal) {\n return;\n }\n\n const layers = [];\n let layerIndex = 0;\n deck.props.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,r){"object"==typeof exports&&"object"==typeof module?module.exports=r(require("deck")):"function"==typeof define&&define.amd?define(["deck"],r):"object"==typeof exports?exports.deck=r(require("deck")):e.deck=r(e.deck)}(window,(function(e){return function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=4)}([function(r,t){r.exports=e},function(e,r){e.exports=function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}},function(e,r){function t(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}e.exports=function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}},function(e,r,t){var n=t(5),o=t(6),i=t(7);e.exports=function(e,r){return n(e)||o(e,r)||i()}},function(e,r,t){var n=t(8),o=globalThis.deck||{};if(!o.Layer)throw new Error("@deck.gl/core is not found");e.exports=Object.assign(o,n)},function(e,r){e.exports=function(e){if(Array.isArray(e))return e}},function(e,r){e.exports=function(e,r){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)){var t=[],n=!0,o=!1,i=void 0;try{for(var a,u=e[Symbol.iterator]();!(n=(a=u.next()).done)&&(t.push(a.value),!r||t.length!==r);n=!0);}catch(e){o=!0,i=e}finally{try{n||null==u.return||u.return()}finally{if(o)throw i}}return t}}},function(e,r){e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}},function(e,r,t){"use strict";t.r(r);var n=t(1),o=t.n(n),i=t(2),a=t.n(i),u=t(3),s=t.n(u),
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r(require("deck")):"function"==typeof define&&define.amd?define(["deck"],r):"object"==typeof exports?exports.deck=r(require("deck")):e.deck=r(e.deck)}(window,(function(e){return function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=4)}([function(r,t){r.exports=e},function(e,r){e.exports=function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}},function(e,r){function t(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}e.exports=function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}},function(e,r,t){var n=t(5),o=t(6),i=t(7);e.exports=function(e,r){return n(e)||o(e,r)||i()}},function(e,r,t){var n=t(8),o=globalThis.deck||{};if(!o.Layer)throw new Error("@deck.gl/core is not found");e.exports=Object.assign(o,n)},function(e,r){e.exports=function(e){if(Array.isArray(e))return e}},function(e,r){e.exports=function(e,r){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)){var t=[],n=!0,o=!1,i=void 0;try{for(var a,u=e[Symbol.iterator]();!(n=(a=u.next()).done)&&(t.push(a.value),!r||t.length!==r);n=!0);}catch(e){o=!0,i=e}finally{try{n||null==u.return||u.return()}finally{if(o)throw i}}return t}}},function(e,r){e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}},function(e,r,t){"use strict";t.r(r);var n=t(1),o=t.n(n),i=t(2),a=t.n(i),u=t(3),s=t.n(u),p=t(0);function c(e){var r=e.map,t=e.gl,n=e.deck;if(r.__deck)return r.__deck;var o=n&&n.props._customRender,i={useDevicePixels:!0,_customRender:function(){r.triggerRepaint(),o&&o()},parameters:{depthMask:!0,depthTest:!0,blend:!0,blendFunc:[770,771,1,771],polygonOffsetFill:!0,depthFunc:515,blendEquation:32774},userData:{isExternal:!1,mapboxLayers:new Set},views:n&&n.props.views||[new p.MapView({id:"mapbox"})]};return n&&n.props.gl!==t||(Object.assign(i,{gl:t,width:!1,height:!1,touchAction:"unset",viewState:l(r)}),r.on("move",(function(){return function(e,r){e.setProps({viewState:l(r)}),e.needsRedraw({clearRedrawFlags:!0})}(n,r)}))),n?(n.setProps(i),n.props.userData.isExternal=!0):(n=new p.Deck(i),r.on("remove",(function(){n.finalize(),r.__deck=null}))),n.props.userData.mapboxVersion=function(e){var r=0,t=0;if(e.version){var n=e.version.split(".").slice(0,2).map(Number),o=s()(n,2);r=o[0],t=o[1]}return{major:r,minor:t}}(r),r.__deck=n,r.on("render",(function(){n.layerManager&&function(e,r){var t=e.props.userData,n=t.mapboxLayers;if(t.isExternal){var o=Array.from(n,(function(e){return e.id})),i=e.props.layers.some((function(e){return!o.includes(e.id)})),a=e.getViewports(),u=a.findIndex((function(e){return"mapbox"===e.id})),s=a.length>1||u<0;(i||s)&&(u>=0&&((a=a.slice())[u]=d(e,r,!1)),e._drawLayers("mapbox-repaint",{viewports:a,layerFilter:function(r){return(!e.props.layerFilter||e.props.layerFilter(r))&&("mapbox"!==r.viewport.id||!o.includes(r.layer.id))},clearCanvas:!1}))}e.props.userData.currentViewport=null}(n,r)})),n}function l(e){var r=e.getCenter();return{longitude:r.lng,latitude:r.lat,zoom:e.getZoom(),bearing:e.getBearing(),pitch:e.getPitch()}}function d(e,r){var t=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],n=e.props.userData.mapboxVersion;return new p.WebMercatorViewport(Object.assign({id:"mapbox",x:0,y:0,width:e.width,height:e.height,repeat:r.getRenderWorldCopies()},l(r),t?{nearZMultiplier:1===n.major&&n.minor>=3||n.major>=2?.02:1/(e.height||1)}:{nearZMultiplier:.1}))}function f(e){if(!e.props.userData.isExternal){var r=[],t=0;e.props.userData.mapboxLayers.forEach((function(e){var n=new(0,e.props.type)(e.props,{_offset:t++});r.push(n)})),e.setProps({layers:r})}}var y=function(){function e(r){if(o()(this,e),!r.id)throw new Error("Layer must have an unique id");this.id=r.id,this.type="custom",this.renderingMode=r.renderingMode||"3d",this.map=null,this.deck=null,this.props=r}return a()(e,[{key:"onAdd",value:function(e,r){var t,n;this.map=e,this.deck=c({map:e,gl:r,deck:this.props.deck}),t=this.deck,n=this,t.props.userData.mapboxLayers.add(n),f(t)}},{key:"onRemove",value:function(){var e,r;e=this.deck,r=this,e.props.userData.mapboxLayers.delete(r),f(e)}},{key:"setProps",value:function(e){Object.assign(this.props,e,{id:this.id}),this.deck&&f(this.deck)}},{key:"render",value:function(e,r){var t,n,o,i;t=this.deck,n=this.map,o=this,(i=t.props.userData.currentViewport)||(i=d(t,n,!0),t.props.userData.currentViewport=i),t.layerManager&&t._drawLayers("mapbox-repaint",{viewports:[i],layerFilter:function(e){var r=e.layer;return o.id===r.id},clearCanvas:!1})}}]),e}();t.d(r,"MapboxLayer",(function(){return y}))}])}));
|
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.7.0-beta.
|
|
5
|
+
"version": "8.7.0-beta.7",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"@deck.gl/core": "^8.0.0"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "32b25b0d1c4d2985b021eb15f2b2245d81b574bd"
|
|
35
35
|
}
|
package/src/deck-utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {Deck, WebMercatorViewport} from '@deck.gl/core';
|
|
1
|
+
import {Deck, WebMercatorViewport, MapView} from '@deck.gl/core';
|
|
2
2
|
|
|
3
3
|
export function getDeckInstance({map, gl, deck}) {
|
|
4
4
|
// Only create one deck instance per context
|
|
@@ -22,20 +22,22 @@ export function getDeckInstance({map, gl, deck}) {
|
|
|
22
22
|
parameters: {
|
|
23
23
|
depthMask: true,
|
|
24
24
|
depthTest: true,
|
|
25
|
+
blend: true,
|
|
25
26
|
blendFunc: [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA],
|
|
27
|
+
polygonOffsetFill: true,
|
|
28
|
+
depthFunc: gl.LEQUAL,
|
|
26
29
|
blendEquation: gl.FUNC_ADD
|
|
27
30
|
},
|
|
28
31
|
userData: {
|
|
29
32
|
isExternal: false,
|
|
30
33
|
mapboxLayers: new Set()
|
|
31
|
-
}
|
|
34
|
+
},
|
|
35
|
+
views: (deck && deck.props.views) || [new MapView({id: 'mapbox'})]
|
|
32
36
|
};
|
|
33
37
|
|
|
34
|
-
if (deck) {
|
|
35
|
-
deck
|
|
36
|
-
deck
|
|
37
|
-
} else {
|
|
38
|
-
// Using external gl context - do not set css size
|
|
38
|
+
if (!deck || deck.props.gl === gl) {
|
|
39
|
+
// deck is using the WebGLContext created by mapbox
|
|
40
|
+
// block deck from setting the canvas size
|
|
39
41
|
Object.assign(deckProps, {
|
|
40
42
|
gl,
|
|
41
43
|
width: false,
|
|
@@ -43,17 +45,22 @@ export function getDeckInstance({map, gl, deck}) {
|
|
|
43
45
|
touchAction: 'unset',
|
|
44
46
|
viewState: getViewState(map)
|
|
45
47
|
});
|
|
46
|
-
deck
|
|
47
|
-
|
|
48
|
-
// If deck is externally provided (React use case), we use deck's viewState to
|
|
49
|
-
// drive the map.
|
|
48
|
+
// If using the WebGLContext created by deck (React use case), we use deck's viewState to drive the map.
|
|
50
49
|
// Otherwise (pure JS use case), we use the map's viewState to drive deck.
|
|
51
50
|
map.on('move', () => onMapMove(deck, map));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (deck) {
|
|
54
|
+
deck.setProps(deckProps);
|
|
55
|
+
deck.props.userData.isExternal = true;
|
|
56
|
+
} else {
|
|
57
|
+
deck = new Deck(deckProps);
|
|
52
58
|
map.on('remove', () => {
|
|
53
59
|
deck.finalize();
|
|
54
60
|
map.__deck = null;
|
|
55
61
|
});
|
|
56
62
|
}
|
|
63
|
+
|
|
57
64
|
deck.props.userData.mapboxVersion = getMapboxVersion(map);
|
|
58
65
|
map.__deck = deck;
|
|
59
66
|
map.on('render', () => {
|
|
@@ -88,6 +95,7 @@ export function drawLayer(deck, map, layer) {
|
|
|
88
95
|
if (!deck.layerManager) {
|
|
89
96
|
return;
|
|
90
97
|
}
|
|
98
|
+
|
|
91
99
|
deck._drawLayers('mapbox-repaint', {
|
|
92
100
|
viewports: [currentViewport],
|
|
93
101
|
layerFilter: ({layer: deckLayer}) => layer.id === deckLayer.id,
|
|
@@ -122,6 +130,7 @@ function getViewport(deck, map, useMapboxProjection = true) {
|
|
|
122
130
|
return new WebMercatorViewport(
|
|
123
131
|
Object.assign(
|
|
124
132
|
{
|
|
133
|
+
id: 'mapbox',
|
|
125
134
|
x: 0,
|
|
126
135
|
y: 0,
|
|
127
136
|
width: deck.width,
|
|
@@ -154,10 +163,21 @@ function afterRender(deck, map) {
|
|
|
154
163
|
// Draw non-Mapbox layers
|
|
155
164
|
const mapboxLayerIds = Array.from(mapboxLayers, layer => layer.id);
|
|
156
165
|
const hasNonMapboxLayers = deck.props.layers.some(layer => !mapboxLayerIds.includes(layer.id));
|
|
157
|
-
|
|
166
|
+
let viewports = deck.getViewports();
|
|
167
|
+
const mapboxViewportIdx = viewports.findIndex(vp => vp.id === 'mapbox');
|
|
168
|
+
const hasNonMapboxViews = viewports.length > 1 || mapboxViewportIdx < 0;
|
|
169
|
+
|
|
170
|
+
if (hasNonMapboxLayers || hasNonMapboxViews) {
|
|
171
|
+
if (mapboxViewportIdx >= 0) {
|
|
172
|
+
viewports = viewports.slice();
|
|
173
|
+
viewports[mapboxViewportIdx] = getViewport(deck, map, false);
|
|
174
|
+
}
|
|
175
|
+
|
|
158
176
|
deck._drawLayers('mapbox-repaint', {
|
|
159
|
-
viewports
|
|
160
|
-
layerFilter:
|
|
177
|
+
viewports,
|
|
178
|
+
layerFilter: params =>
|
|
179
|
+
(!deck.props.layerFilter || deck.props.layerFilter(params)) &&
|
|
180
|
+
(params.viewport.id !== 'mapbox' || !mapboxLayerIds.includes(params.layer.id)),
|
|
161
181
|
clearCanvas: false
|
|
162
182
|
});
|
|
163
183
|
}
|