@deck.gl/mapbox 8.8.0-alpha.6 → 8.8.0-beta.3
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 +155 -13
- package/dist/es5/deck-utils.js +1 -0
- package/dist/es5/deck-utils.js.map +1 -1
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/mapbox-layer.js.map +1 -1
- package/dist/es5/mapbox-overlay.js +55 -11
- package/dist/es5/mapbox-overlay.js.map +1 -1
- package/dist/es5/resolve-layers.js +134 -0
- package/dist/es5/resolve-layers.js.map +1 -0
- package/dist/esm/deck-utils.js +1 -0
- package/dist/esm/deck-utils.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/mapbox-layer.js.map +1 -1
- package/dist/esm/mapbox-overlay.js +49 -12
- package/dist/esm/mapbox-overlay.js.map +1 -1
- package/dist/esm/resolve-layers.js +73 -0
- package/dist/esm/resolve-layers.js.map +1 -0
- package/dist.min.js +1 -1
- package/package.json +2 -2
- package/src/deck-utils.ts +10 -1
- package/src/index.ts +2 -0
- package/src/mapbox-layer.ts +2 -0
- package/src/mapbox-overlay.ts +69 -14
- package/src/resolve-layers.ts +89 -0
- package/typed/deck-utils.d.ts +6 -0
- package/typed/deck-utils.d.ts.map +1 -1
- package/typed/index.d.ts +1 -0
- package/typed/index.d.ts.map +1 -1
- package/typed/mapbox-layer.d.ts +2 -0
- package/typed/mapbox-layer.d.ts.map +1 -1
- package/typed/mapbox-overlay.d.ts +11 -2
- package/typed/mapbox-overlay.d.ts.map +1 -1
- package/typed/resolve-layers.d.ts +5 -0
- package/typed/resolve-layers.d.ts.map +1 -0
package/dist/dist.dev.js
CHANGED
|
@@ -252,6 +252,7 @@ function getViewState(map) {
|
|
|
252
252
|
zoom: map.getZoom(),
|
|
253
253
|
bearing: map.getBearing(),
|
|
254
254
|
pitch: map.getPitch(),
|
|
255
|
+
padding: map.getPadding(),
|
|
255
256
|
repeat: map.getRenderWorldCopies()
|
|
256
257
|
};
|
|
257
258
|
}
|
|
@@ -471,11 +472,13 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
471
472
|
/* harmony import */ var _deck_gl_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @deck.gl/core */ "@deck.gl/core");
|
|
472
473
|
/* harmony import */ var _deck_gl_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_deck_gl_core__WEBPACK_IMPORTED_MODULE_0__);
|
|
473
474
|
/* harmony import */ var _deck_utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./deck-utils */ "./src/deck-utils.ts");
|
|
475
|
+
/* harmony import */ var _resolve_layers__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./resolve-layers */ "./src/resolve-layers.ts");
|
|
474
476
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
475
477
|
|
|
476
478
|
|
|
477
479
|
|
|
478
480
|
|
|
481
|
+
|
|
479
482
|
/**
|
|
480
483
|
* Implements Mapbox [IControl](https://docs.mapbox.com/mapbox-gl-js/api/markers/#icontrol) interface
|
|
481
484
|
* Renders deck.gl layers over the base map and automatically synchronizes with the map's camera
|
|
@@ -490,6 +493,12 @@ class MapboxOverlay {
|
|
|
490
493
|
|
|
491
494
|
_defineProperty(this, "_container", void 0);
|
|
492
495
|
|
|
496
|
+
_defineProperty(this, "_interleaved", void 0);
|
|
497
|
+
|
|
498
|
+
_defineProperty(this, "_handleStyleChange", () => {
|
|
499
|
+
Object(_resolve_layers__WEBPACK_IMPORTED_MODULE_2__["resolveLayers"])(this._map, this._deck, this._props.layers, this._props.layers);
|
|
500
|
+
});
|
|
501
|
+
|
|
493
502
|
_defineProperty(this, "_updateContainerSize", () => {
|
|
494
503
|
if (this._map && this._container) {
|
|
495
504
|
const {
|
|
@@ -567,19 +576,23 @@ class MapboxOverlay {
|
|
|
567
576
|
}
|
|
568
577
|
});
|
|
569
578
|
|
|
570
|
-
|
|
571
|
-
|
|
579
|
+
const {
|
|
580
|
+
interleaved = false,
|
|
581
|
+
...otherProps
|
|
582
|
+
} = props;
|
|
583
|
+
this._interleaved = interleaved;
|
|
584
|
+
this._props = otherProps;
|
|
572
585
|
}
|
|
573
586
|
/** Update (partial) props of the underlying Deck instance. */
|
|
574
587
|
|
|
575
588
|
|
|
576
589
|
setProps(props) {
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
if ('viewState' in this._props) {
|
|
580
|
-
delete this._props.viewState;
|
|
590
|
+
if (this._interleaved && props.layers) {
|
|
591
|
+
Object(_resolve_layers__WEBPACK_IMPORTED_MODULE_2__["resolveLayers"])(this._map, this._deck, this._props.layers, props.layers);
|
|
581
592
|
}
|
|
582
593
|
|
|
594
|
+
Object.assign(this._props, props);
|
|
595
|
+
|
|
583
596
|
if (this._deck) {
|
|
584
597
|
this._deck.setProps(this._props);
|
|
585
598
|
}
|
|
@@ -589,8 +602,11 @@ class MapboxOverlay {
|
|
|
589
602
|
|
|
590
603
|
onAdd(map) {
|
|
591
604
|
this._map = map;
|
|
592
|
-
|
|
605
|
+
return this._interleaved ? this._onAddInterleaved(map) : this._onAddOverlaid(map);
|
|
606
|
+
}
|
|
593
607
|
|
|
608
|
+
_onAddOverlaid(map) {
|
|
609
|
+
/* global document */
|
|
594
610
|
const container = document.createElement('div');
|
|
595
611
|
Object.assign(container.style, {
|
|
596
612
|
position: 'absolute',
|
|
@@ -614,6 +630,16 @@ class MapboxOverlay {
|
|
|
614
630
|
|
|
615
631
|
return container;
|
|
616
632
|
}
|
|
633
|
+
|
|
634
|
+
_onAddInterleaved(map) {
|
|
635
|
+
this._deck = new _deck_gl_core__WEBPACK_IMPORTED_MODULE_0__["Deck"]({ ...this._props,
|
|
636
|
+
// @ts-ignore non-public map property
|
|
637
|
+
gl: map.painter.context.gl
|
|
638
|
+
});
|
|
639
|
+
map.on('styledata', this._handleStyleChange);
|
|
640
|
+
Object(_resolve_layers__WEBPACK_IMPORTED_MODULE_2__["resolveLayers"])(map, this._deck, [], this._props.layers);
|
|
641
|
+
return document.createElement('div');
|
|
642
|
+
}
|
|
617
643
|
/** Called when the control is removed from a map */
|
|
618
644
|
|
|
619
645
|
|
|
@@ -621,12 +647,11 @@ class MapboxOverlay {
|
|
|
621
647
|
const map = this._map;
|
|
622
648
|
|
|
623
649
|
if (map) {
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
map.off('dblclick', this._handleMouseEvent);
|
|
650
|
+
if (this._interleaved) {
|
|
651
|
+
this._onRemoveInterleaved(map);
|
|
652
|
+
} else {
|
|
653
|
+
this._onRemoveOverlaid(map);
|
|
654
|
+
}
|
|
630
655
|
}
|
|
631
656
|
|
|
632
657
|
this._deck?.finalize();
|
|
@@ -635,6 +660,20 @@ class MapboxOverlay {
|
|
|
635
660
|
this._container = undefined;
|
|
636
661
|
}
|
|
637
662
|
|
|
663
|
+
_onRemoveOverlaid(map) {
|
|
664
|
+
map.off('resize', this._updateContainerSize);
|
|
665
|
+
map.off('render', this._updateViewState);
|
|
666
|
+
map.off('mousemove', this._handleMouseEvent);
|
|
667
|
+
map.off('mouseout', this._handleMouseEvent);
|
|
668
|
+
map.off('click', this._handleMouseEvent);
|
|
669
|
+
map.off('dblclick', this._handleMouseEvent);
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
_onRemoveInterleaved(map) {
|
|
673
|
+
map.off('styledata', this._handleStyleChange);
|
|
674
|
+
Object(_resolve_layers__WEBPACK_IMPORTED_MODULE_2__["resolveLayers"])(map, this._deck, this._props.layers, []);
|
|
675
|
+
}
|
|
676
|
+
|
|
638
677
|
getDefaultPosition() {
|
|
639
678
|
return 'top-left';
|
|
640
679
|
}
|
|
@@ -672,6 +711,109 @@ class MapboxOverlay {
|
|
|
672
711
|
|
|
673
712
|
/***/ }),
|
|
674
713
|
|
|
714
|
+
/***/ "./src/resolve-layers.ts":
|
|
715
|
+
/*!*******************************!*\
|
|
716
|
+
!*** ./src/resolve-layers.ts ***!
|
|
717
|
+
\*******************************/
|
|
718
|
+
/*! exports provided: resolveLayers */
|
|
719
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
720
|
+
|
|
721
|
+
"use strict";
|
|
722
|
+
__webpack_require__.r(__webpack_exports__);
|
|
723
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "resolveLayers", function() { return resolveLayers; });
|
|
724
|
+
/* harmony import */ var _deck_gl_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @deck.gl/core */ "@deck.gl/core");
|
|
725
|
+
/* harmony import */ var _deck_gl_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_deck_gl_core__WEBPACK_IMPORTED_MODULE_0__);
|
|
726
|
+
/* harmony import */ var _mapbox_layer__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./mapbox-layer */ "./src/mapbox-layer.ts");
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
const UNDEFINED_BEFORE_ID = '__UNDEFINED__';
|
|
730
|
+
/** Insert Deck layers into the mapbox Map according to the user-defined order */
|
|
731
|
+
|
|
732
|
+
function resolveLayers(map, deck, oldLayers, newLayers) {
|
|
733
|
+
// Wait until map style is loaded
|
|
734
|
+
// @ts-ignore non-public map property
|
|
735
|
+
if (!map || !deck || !map.style || !map.style._loaded) {
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
const layers = Object(_deck_gl_core__WEBPACK_IMPORTED_MODULE_0__["_flatten"])(newLayers, Boolean);
|
|
740
|
+
|
|
741
|
+
if (oldLayers !== newLayers) {
|
|
742
|
+
// Step 1: remove layers that no longer exist
|
|
743
|
+
const prevLayers = Object(_deck_gl_core__WEBPACK_IMPORTED_MODULE_0__["_flatten"])(oldLayers, Boolean);
|
|
744
|
+
const prevLayerIds = new Set(prevLayers.map(l => l.id));
|
|
745
|
+
|
|
746
|
+
for (const layer of layers) {
|
|
747
|
+
prevLayerIds.delete(layer.id);
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
for (const id of prevLayerIds) {
|
|
751
|
+
if (map.getLayer(id)) {
|
|
752
|
+
map.removeLayer(id);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
} // Step 2: add missing layers
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
for (const layer of layers) {
|
|
759
|
+
if (!map.getLayer(layer.id)) {
|
|
760
|
+
map.addLayer(new _mapbox_layer__WEBPACK_IMPORTED_MODULE_1__["default"]({
|
|
761
|
+
id: layer.id,
|
|
762
|
+
deck
|
|
763
|
+
}), // @ts-expect-error beforeId is not defined in LayerProps
|
|
764
|
+
layer.props.beforeId);
|
|
765
|
+
}
|
|
766
|
+
} // Step 3: check the order of layers
|
|
767
|
+
// If beforeId is defined, the deck layer should always render before the mapbox layer [beforeId]
|
|
768
|
+
// If beforeId is not defined, the deck layer should appear after all mapbox layers
|
|
769
|
+
// When two deck layers share the same beforeId, they are rendered in the order that is passed into Deck props.layers
|
|
770
|
+
// @ts-ignore non-public map property
|
|
771
|
+
|
|
772
|
+
|
|
773
|
+
const mapLayers = map.style._order; // Group deck layers by beforeId
|
|
774
|
+
|
|
775
|
+
const layerGroups = {};
|
|
776
|
+
|
|
777
|
+
for (const layer of layers) {
|
|
778
|
+
// @ts-expect-error beforeId is not defined in LayerProps
|
|
779
|
+
let {
|
|
780
|
+
beforeId
|
|
781
|
+
} = layer.props;
|
|
782
|
+
|
|
783
|
+
if (!beforeId || !mapLayers.includes(beforeId)) {
|
|
784
|
+
beforeId = UNDEFINED_BEFORE_ID;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
layerGroups[beforeId] = layerGroups[beforeId] || [];
|
|
788
|
+
layerGroups[beforeId].push(layer.id);
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
for (const beforeId in layerGroups) {
|
|
792
|
+
const layerGroup = layerGroups[beforeId];
|
|
793
|
+
let lastLayerIndex = beforeId === UNDEFINED_BEFORE_ID ? mapLayers.length : mapLayers.indexOf(beforeId);
|
|
794
|
+
let lastLayerId = beforeId === UNDEFINED_BEFORE_ID ? undefined : beforeId;
|
|
795
|
+
|
|
796
|
+
for (let i = layerGroup.length - 1; i >= 0; i--) {
|
|
797
|
+
const layerId = layerGroup[i];
|
|
798
|
+
const layerIndex = mapLayers.indexOf(layerId);
|
|
799
|
+
|
|
800
|
+
if (layerIndex !== lastLayerIndex - 1) {
|
|
801
|
+
map.moveLayer(layerId, lastLayerId);
|
|
802
|
+
|
|
803
|
+
if (layerIndex > lastLayerIndex) {
|
|
804
|
+
// The last layer's index have changed
|
|
805
|
+
lastLayerIndex++;
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
lastLayerIndex--;
|
|
810
|
+
lastLayerId = layerId;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
/***/ }),
|
|
816
|
+
|
|
675
817
|
/***/ "@deck.gl/core":
|
|
676
818
|
/*!***********************!*\
|
|
677
819
|
!*** external "deck" ***!
|
package/dist/es5/deck-utils.js
CHANGED
|
@@ -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","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;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,IAAIC,aAAJ,CAAY;AAACC,MAAAA,EAAE,EAAE;AAAL,KAAZ,CAAD;AAlBV,GAA7B;;AAqBA,MAAI,CAACnB,IAAD,IAASA,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,MAAIe,UAAU,GAAG,CAAjB;AACClG,EAAAA,IAAI,CAAC8B,QAAN,CAA4BI,YAA5B,CAAyCiE,OAAzC,CAAiD,UAAA9C,SAAS,EAAI;AAC5D,QAAM+C,SAAS,GAAG/C,SAAS,CAAClD,KAAV,CAAgBkG,IAAlC;AACA,QAAM5D,KAAK,GAAG,IAAI2D,SAAJ,CAAc/C,SAAS,CAAClD,KAAxB,EAA+B;AAACmG,MAAAA,OAAO,EAAEJ,UAAU;AAApB,KAA/B,CAAd;AACAf,IAAAA,MAAM,CAACoB,IAAP,CAAY9D,KAAZ;AACD,GAJD;AAKAzC,EAAAA,IAAI,CAAC6B,QAAL,CAAc;AAACsD,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 & {repeat: boolean} {\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 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","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;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,IAAIC,aAAJ,CAAY;AAACC,MAAAA,EAAE,EAAE;AAAL,KAAZ,CAAD;AAlBV,GAA7B;;AAqBA,MAAI,CAACnB,IAAD,IAASA,IAAI,CAACG,KAAL,CAAWJ,EAAX,KAAkBA,EAA/B,EAAmC;AAGjCqB,IAAAA,MAAM,CAACC,MAAP,CAAchB,SAAd,EAAyB;AACvBN,MAAAA,EAAE,EAAFA,EADuB;AAEvBuB,MAAAA,KAAK,EAAE,IAFgB;A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D,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"}
|
package/dist/es5/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;AACA","sourcesContent":["export {default as MapboxLayer} from './mapbox-layer';\nexport {default as MapboxOverlay} from './mapbox-overlay';\n"],"file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;AACA","sourcesContent":["export {default as MapboxLayer} from './mapbox-layer';\nexport {default as MapboxOverlay} from './mapbox-overlay';\n\nexport type {MapboxOverlayProps} from './mapbox-overlay';\n"],"file":"index.js"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mapbox-layer.ts"],"names":["MapboxLayer","props","id","Error","type","renderingMode","map","deck","gl","Object","assign"],"mappings":";;;;;;;;;;;;;;;AAAA;;
|
|
1
|
+
{"version":3,"sources":["../../src/mapbox-layer.ts"],"names":["MapboxLayer","props","id","Error","type","renderingMode","map","deck","gl","Object","assign"],"mappings":";;;;;;;;;;;;;;;AAAA;;IAUqBA,W;AASnB,uBAAYC,KAAZ,EAA6C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAC3C,QAAI,CAACA,KAAK,CAACC,EAAX,EAAe;AACb,YAAM,IAAIC,KAAJ,CAAU,8BAAV,CAAN;AACD;;AAED,SAAKD,EAAL,GAAUD,KAAK,CAACC,EAAhB;AACA,SAAKE,IAAL,GAAY,QAAZ;AACA,SAAKC,aAAL,GAAqBJ,KAAK,CAACI,aAAN,IAAuB,IAA5C;AACA,SAAKC,GAAL,GAAW,IAAX;AACA,SAAKC,IAAL,GAAY,IAAZ;AACA,SAAKN,KAAL,GAAaA,KAAb;AACD;;;;WAID,eAAMK,GAAN,EAAgBE,EAAhB,EAAiD;AAC/C,WAAKF,GAAL,GAAWA,GAAX;AACA,WAAKC,IAAL,GAAY,gCAAgB;AAACD,QAAAA,GAAG,EAAHA,GAAD;AAAME,QAAAA,EAAE,EAAFA,EAAN;AAAUD,QAAAA,IAAI,EAAE,KAAKN,KAAL,CAAWM;AAA3B,OAAhB,CAAZ;AACA,+BAAS,KAAKA,IAAd,EAAoB,IAApB;AACD;;;WAED,oBAAiB;AACf,UAAI,KAAKA,IAAT,EAAe;AACb,oCAAY,KAAKA,IAAjB,EAAuB,IAAvB;AACD;AACF;;;WAED,kBAASN,KAAT,EAA0C;AAExCQ,MAAAA,MAAM,CAACC,MAAP,CAAc,KAAKT,KAAnB,EAA0BA,KAA1B,EAAiC;AAACC,QAAAA,EAAE,EAAE,KAAKA;AAAV,OAAjC;;AAEA,UAAI,KAAKK,IAAT,EAAe;AACb,oCAAY,KAAKA,IAAjB,EAAuB,IAAvB;AACD;AACF;;;WAED,kBAAS;AACP,gCAAU,KAAKA,IAAf,EAAsB,KAAKD,GAA3B,EAAiC,IAAjC;AACD","sourcesContent":["import {getDeckInstance, addLayer, removeLayer, updateLayer, drawLayer} from './deck-utils';\nimport type {Map, CustomLayerInterface} from 'mapbox-gl';\nimport type {Deck, Layer} from '@deck.gl/core';\n\nexport type MapboxLayerProps<LayerT extends Layer> = Partial<LayerT['props']> & {\n id: string;\n renderingMode?: '2d' | '3d';\n deck?: Deck;\n};\n\nexport default class MapboxLayer<LayerT extends Layer> implements CustomLayerInterface {\n id: string;\n type: 'custom';\n renderingMode: '2d' | '3d';\n map: Map | null;\n deck: Deck | null;\n props: MapboxLayerProps<LayerT>;\n\n /* eslint-disable no-this-before-super */\n constructor(props: MapboxLayerProps<LayerT>) {\n if (!props.id) {\n throw new Error('Layer must have an unique id');\n }\n\n this.id = props.id;\n this.type = 'custom';\n this.renderingMode = props.renderingMode || '3d';\n this.map = null;\n this.deck = null;\n this.props = props;\n }\n\n /* Mapbox custom layer methods */\n\n onAdd(map: Map, gl: WebGLRenderingContext): void {\n this.map = map;\n this.deck = getDeckInstance({map, gl, deck: this.props.deck});\n addLayer(this.deck, this);\n }\n\n onRemove(): void {\n if (this.deck) {\n removeLayer(this.deck, this);\n }\n }\n\n setProps(props: MapboxLayerProps<LayerT>) {\n // id cannot be changed\n Object.assign(this.props, props, {id: this.id});\n // safe guard in case setProps is called before onAdd\n if (this.deck) {\n updateLayer(this.deck, this);\n }\n }\n\n render() {\n drawLayer(this.deck!, this.map!, this);\n }\n}\n"],"file":"mapbox-layer.js"}
|
|
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
9
|
|
|
10
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
11
|
+
|
|
10
12
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
13
|
|
|
12
14
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
@@ -17,6 +19,10 @@ var _core = require("@deck.gl/core");
|
|
|
17
19
|
|
|
18
20
|
var _deckUtils = require("./deck-utils");
|
|
19
21
|
|
|
22
|
+
var _resolveLayers = require("./resolve-layers");
|
|
23
|
+
|
|
24
|
+
var _excluded = ["interleaved"];
|
|
25
|
+
|
|
20
26
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
21
27
|
|
|
22
28
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
@@ -30,6 +36,10 @@ var MapboxOverlay = function () {
|
|
|
30
36
|
(0, _defineProperty2.default)(this, "_deck", void 0);
|
|
31
37
|
(0, _defineProperty2.default)(this, "_map", void 0);
|
|
32
38
|
(0, _defineProperty2.default)(this, "_container", void 0);
|
|
39
|
+
(0, _defineProperty2.default)(this, "_interleaved", void 0);
|
|
40
|
+
(0, _defineProperty2.default)(this, "_handleStyleChange", function () {
|
|
41
|
+
(0, _resolveLayers.resolveLayers)(_this._map, _this._deck, _this._props.layers, _this._props.layers);
|
|
42
|
+
});
|
|
33
43
|
(0, _defineProperty2.default)(this, "_updateContainerSize", function () {
|
|
34
44
|
if (_this._map && _this._container) {
|
|
35
45
|
var _this$_map$getContain = _this._map.getContainer(),
|
|
@@ -101,18 +111,22 @@ var MapboxOverlay = function () {
|
|
|
101
111
|
return;
|
|
102
112
|
}
|
|
103
113
|
});
|
|
104
|
-
|
|
114
|
+
var _props$interleaved = props.interleaved,
|
|
115
|
+
interleaved = _props$interleaved === void 0 ? false : _props$interleaved,
|
|
116
|
+
otherProps = (0, _objectWithoutProperties2.default)(props, _excluded);
|
|
117
|
+
this._interleaved = interleaved;
|
|
118
|
+
this._props = otherProps;
|
|
105
119
|
}
|
|
106
120
|
|
|
107
121
|
(0, _createClass2.default)(MapboxOverlay, [{
|
|
108
122
|
key: "setProps",
|
|
109
123
|
value: function setProps(props) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if ('viewState' in this._props) {
|
|
113
|
-
delete this._props.viewState;
|
|
124
|
+
if (this._interleaved && props.layers) {
|
|
125
|
+
(0, _resolveLayers.resolveLayers)(this._map, this._deck, this._props.layers, props.layers);
|
|
114
126
|
}
|
|
115
127
|
|
|
128
|
+
Object.assign(this._props, props);
|
|
129
|
+
|
|
116
130
|
if (this._deck) {
|
|
117
131
|
this._deck.setProps(this._props);
|
|
118
132
|
}
|
|
@@ -121,6 +135,11 @@ var MapboxOverlay = function () {
|
|
|
121
135
|
key: "onAdd",
|
|
122
136
|
value: function onAdd(map) {
|
|
123
137
|
this._map = map;
|
|
138
|
+
return this._interleaved ? this._onAddInterleaved(map) : this._onAddOverlaid(map);
|
|
139
|
+
}
|
|
140
|
+
}, {
|
|
141
|
+
key: "_onAddOverlaid",
|
|
142
|
+
value: function _onAddOverlaid(map) {
|
|
124
143
|
var container = document.createElement('div');
|
|
125
144
|
Object.assign(container.style, {
|
|
126
145
|
position: 'absolute',
|
|
@@ -144,6 +163,16 @@ var MapboxOverlay = function () {
|
|
|
144
163
|
|
|
145
164
|
return container;
|
|
146
165
|
}
|
|
166
|
+
}, {
|
|
167
|
+
key: "_onAddInterleaved",
|
|
168
|
+
value: function _onAddInterleaved(map) {
|
|
169
|
+
this._deck = new _core.Deck(_objectSpread(_objectSpread({}, this._props), {}, {
|
|
170
|
+
gl: map.painter.context.gl
|
|
171
|
+
}));
|
|
172
|
+
map.on('styledata', this._handleStyleChange);
|
|
173
|
+
(0, _resolveLayers.resolveLayers)(map, this._deck, [], this._props.layers);
|
|
174
|
+
return document.createElement('div');
|
|
175
|
+
}
|
|
147
176
|
}, {
|
|
148
177
|
key: "onRemove",
|
|
149
178
|
value: function onRemove() {
|
|
@@ -152,12 +181,11 @@ var MapboxOverlay = function () {
|
|
|
152
181
|
var map = this._map;
|
|
153
182
|
|
|
154
183
|
if (map) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
map.off('dblclick', this._handleMouseEvent);
|
|
184
|
+
if (this._interleaved) {
|
|
185
|
+
this._onRemoveInterleaved(map);
|
|
186
|
+
} else {
|
|
187
|
+
this._onRemoveOverlaid(map);
|
|
188
|
+
}
|
|
161
189
|
}
|
|
162
190
|
|
|
163
191
|
(_this$_deck = this._deck) === null || _this$_deck === void 0 ? void 0 : _this$_deck.finalize();
|
|
@@ -165,6 +193,22 @@ var MapboxOverlay = function () {
|
|
|
165
193
|
this._map = undefined;
|
|
166
194
|
this._container = undefined;
|
|
167
195
|
}
|
|
196
|
+
}, {
|
|
197
|
+
key: "_onRemoveOverlaid",
|
|
198
|
+
value: function _onRemoveOverlaid(map) {
|
|
199
|
+
map.off('resize', this._updateContainerSize);
|
|
200
|
+
map.off('render', this._updateViewState);
|
|
201
|
+
map.off('mousemove', this._handleMouseEvent);
|
|
202
|
+
map.off('mouseout', this._handleMouseEvent);
|
|
203
|
+
map.off('click', this._handleMouseEvent);
|
|
204
|
+
map.off('dblclick', this._handleMouseEvent);
|
|
205
|
+
}
|
|
206
|
+
}, {
|
|
207
|
+
key: "_onRemoveInterleaved",
|
|
208
|
+
value: function _onRemoveInterleaved(map) {
|
|
209
|
+
map.off('styledata', this._handleStyleChange);
|
|
210
|
+
(0, _resolveLayers.resolveLayers)(map, this._deck, this._props.layers, []);
|
|
211
|
+
}
|
|
168
212
|
}, {
|
|
169
213
|
key: "getDefaultPosition",
|
|
170
214
|
value: function getDefaultPosition() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mapbox-overlay.ts"],"names":["MapboxOverlay","props","_map","_container","getContainer","clientWidth","clientHeight","Object","assign","style","width","height","deck","_deck","setProps","viewState","redraw","event","mockEvent","type","offsetCenter","point","srcEvent","tapCount","_onPointerDown","_onEvent","_onPointerMove","_props","map","container","document","createElement","position","left","top","pointerEvents","Deck","parent","on","_updateContainerSize","_updateViewState","_handleMouseEvent","off","finalize","undefined","params","pickObject","pickMultipleObjects","pickObjects","removeControl"],"mappings":";;;;;;;;;;;;;;;AAAA;;AACA;;;;;;IAUqBA,a;AAMnB,yBAAYC,KAAZ,EAA8B;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gEAkGC,YAAM;AACnC,UAAI,KAAI,CAACC,IAAL,IAAa,KAAI,CAACC,UAAtB,EAAkC;AAChC,oCAAoC,KAAI,CAACD,IAAL,CAAUE,YAAV,EAApC;AAAA,YAAOC,WAAP,yBAAOA,WAAP;AAAA,YAAoBC,YAApB,yBAAoBA,YAApB;;AACAC,QAAAA,MAAM,CAACC,MAAP,CAAc,KAAI,CAACL,UAAL,CAAgBM,KAA9B,EAAqC;AACnCC,UAAAA,KAAK,YAAKL,WAAL,OAD8B;AAEnCM,UAAAA,MAAM,YAAKL,YAAL;AAF6B,SAArC;AAID;AACF,KA1G6B;AAAA,4DA4GH,YAAM;AAC/B,UAAMM,IAAI,GAAG,KAAI,CAACC,KAAlB;;AACA,UAAID,IAAJ,EAAU;AAERA,QAAAA,IAAI,CAACE,QAAL,CAAc;AAACC,UAAAA,SAAS,EAAE,6BAAa,KAAI,CAACb,IAAlB;AAAZ,SAAd;AAEAU,QAAAA,IAAI,CAACI,MAAL;AACD;AACF,KApH6B;AAAA,6DAsHF,UAACC,KAAD,EAA0B;AACpD,UAAML,IAAI,GAAG,KAAI,CAACC,KAAlB;;AACA,UAAI,CAACD,IAAL,EAAW;AACT;AACD;;AAED,UAAMM,SAKL,GAAG;AACFC,QAAAA,IAAI,EAAEF,KAAK,CAACE,IADV;AAEFC,QAAAA,YAAY,EAAEH,KAAK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AAQ,UAAR,EAAoB,KAAKD,iBAAzB;AACD;;AAED,0BAAK5B,KAAL,4DAAY8B,QAAZ;AACA,WAAK9B,KAAL,GAAa+B,SAAb;AACA,WAAK1C,IAAL,GAAY0C,SAAZ;AACA,WAAKzC,UAAL,GAAkByC,SAAlB;AACD;;;WAED,8BAAqB;AACnB,aAAO,UAAP;AACD;;;WAGD,oBAAWC,MAAX,EAAsF;AACpF,wBAAO,KAAKhC,KAAZ;AACA,aAAO,KAAKA,KAAL,CAAWiC,UAAX,CAAsBD,MAAtB,CAAP;AACD;;;WAGD,6BACEA,MADF,EAE2C;AACzC,wBAAO,KAAKhC,KAAZ;AACA,aAAO,KAAKA,KAAL,CAAWkC,mBAAX,CAA+BF,MAA/B,CAAP;AACD;;;WAGD,qBAAYA,MAAZ,EAAyF;AACvF,wBAAO,KAAKhC,KAAZ;AACA,aAAO,KAAKA,KAAL,CAAWmC,WAAX,CAAuBH,MAAvB,CAAP;AACD;;;WAGD,oBAAW;AACT,UAAI,KAAK3C,IAAT,EAAe;AACb,aAAKA,IAAL,CAAU+C,aAAV,CAAwB,IAAxB;AACD;AACF","sourcesContent":["import {Deck, assert} from '@deck.gl/core';\nimport {getViewState} from './deck-utils';\n\nimport type {Map, IControl, MapMouseEvent} from 'mapbox-gl';\nimport type {MjolnirGestureEvent, MjolnirPointerEvent} from 'mjolnir.js';\nimport type {DeckProps} from '@deck.gl/core';\n\n/**\n * Implements Mapbox [IControl](https://docs.mapbox.com/mapbox-gl-js/api/markers/#icontrol) interface\n * Renders deck.gl layers over the base map and automatically synchronizes with the map's camera\n */\nexport default class MapboxOverlay implements IControl {\n private _props: DeckProps;\n private _deck?: Deck;\n private _map?: Map;\n private _container?: HTMLDivElement;\n\n constructor(props: DeckProps) {\n this._props = {...props};\n }\n\n /** Update (partial) props of the underlying Deck instance. */\n setProps(props: DeckProps): void {\n Object.assign(this._props, props);\n\n if ('viewState' in this._props) {\n delete this._props.viewState;\n }\n\n if (this._deck) {\n this._deck.setProps(this._props);\n }\n }\n\n /** Called when the control is added to a map */\n onAdd(map: Map): HTMLDivElement {\n this._map = map;\n\n /* global document */\n const container = document.createElement('div');\n Object.assign(container.style, {\n position: 'absolute',\n left: 0,\n top: 0,\n pointerEvents: 'none'\n });\n this._container = container;\n\n this._deck = new Deck({\n ...this._props,\n parent: container,\n viewState: getViewState(map)\n });\n\n map.on('resize', this._updateContainerSize);\n map.on('render', this._updateViewState);\n map.on('mousemove', this._handleMouseEvent);\n map.on('mouseout', this._handleMouseEvent);\n map.on('click', this._handleMouseEvent);\n map.on('dblclick', this._handleMouseEvent);\n\n this._updateContainerSize();\n return container;\n }\n\n /** Called when the control is removed from a map */\n onRemove(): void {\n const map = this._map;\n\n if (map) {\n map.off('resize', this._updateContainerSize);\n map.off('render', this._updateViewState);\n map.off('mousemove', this._handleMouseEvent);\n map.off('mouseout', this._handleMouseEvent);\n map.off('click', this._handleMouseEvent);\n map.off('dblclick', this._handleMouseEvent);\n }\n\n this._deck?.finalize();\n this._deck = undefined;\n this._map = undefined;\n this._container = undefined;\n }\n\n getDefaultPosition() {\n return 'top-left';\n }\n\n /** Forwards the Deck.pickObject method */\n pickObject(params: Parameters<Deck['pickObject']>[0]): ReturnType<Deck['pickObject']> {\n assert(this._deck);\n return this._deck.pickObject(params);\n }\n\n /** Forwards the Deck.pickMultipleObjects method */\n pickMultipleObjects(\n params: Parameters<Deck['pickMultipleObjects']>[0]\n ): ReturnType<Deck['pickMultipleObjects']> {\n assert(this._deck);\n return this._deck.pickMultipleObjects(params);\n }\n\n /** Forwards the Deck.pickObjects method */\n pickObjects(params: Parameters<Deck['pickObjects']>[0]): ReturnType<Deck['pickObjects']> {\n assert(this._deck);\n return this._deck.pickObjects(params);\n }\n\n /** Remove from map and releases all resources */\n finalize() {\n if (this._map) {\n this._map.removeControl(this);\n }\n }\n\n private _updateContainerSize = () => {\n if (this._map && this._container) {\n const {clientWidth, clientHeight} = this._map.getContainer();\n Object.assign(this._container.style, {\n width: `${clientWidth}px`,\n height: `${clientHeight}px`\n });\n }\n };\n\n private _updateViewState = () => {\n const deck = this._deck;\n if (deck) {\n // @ts-ignore (2345) map is always defined if deck is\n deck.setProps({viewState: getViewState(this._map)});\n // Redraw immediately if view state has changed\n deck.redraw();\n }\n };\n\n private _handleMouseEvent = (event: MapMouseEvent) => {\n const deck = this._deck;\n if (!deck) {\n return;\n }\n\n const mockEvent: {\n type: string;\n offsetCenter: {x: number; y: number};\n srcEvent: MapMouseEvent;\n tapCount?: number;\n } = {\n type: event.type,\n offsetCenter: event.point,\n srcEvent: event\n };\n\n switch (event.type) {\n case 'click':\n mockEvent.tapCount = 1;\n // Hack: because we do not listen to pointer down, perform picking now\n deck._onPointerDown(mockEvent as MjolnirGestureEvent);\n deck._onEvent(mockEvent as MjolnirGestureEvent);\n break;\n\n case 'dblclick':\n mockEvent.type = 'click';\n mockEvent.tapCount = 2;\n deck._onEvent(mockEvent as MjolnirGestureEvent);\n break;\n\n case 'mousemove':\n mockEvent.type = 'pointermove';\n deck._onPointerMove(mockEvent as MjolnirPointerEvent);\n break;\n\n case 'mouseout':\n mockEvent.type = 'pointerleave';\n deck._onPointerMove(mockEvent as MjolnirPointerEvent);\n break;\n\n default:\n return;\n }\n };\n}\n"],"file":"mapbox-overlay.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/mapbox-overlay.ts"],"names":["MapboxOverlay","props","_map","_deck","_props","layers","_container","getContainer","clientWidth","clientHeight","Object","assign","style","width","height","deck","setProps","viewState","redraw","event","mockEvent","type","offsetCenter","point","srcEvent","tapCount","_onPointerDown","_onEvent","_onPointerMove","interleaved","otherProps","_interleaved","map","_onAddInterleaved","_onAddOverlaid","container","document","createElement","position","left","top","pointerEvents","Deck","parent","on","_updateContainerSize","_updateViewState","_handleMouseEvent","gl","painter","context","_handleStyleChange","_onRemoveInterleaved","_onRemoveOverlaid","finalize","undefined","off","params","pickObject","pickMultipleObjects","pickObjects","removeControl"],"mappings":";;;;;;;;;;;;;;;;;AA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AmD,EAAnD;AACD;;;WAED,8BAAqB;AACnB,aAAO,UAAP;AACD;;;WAGD,oBAAWoD,MAAX,EAAsF;AACpF,wBAAO,KAAKtD,KAAZ;AACA,aAAO,KAAKA,KAAL,CAAWuD,UAAX,CAAsBD,MAAtB,CAAP;AACD;;;WAGD,6BACEA,MADF,EAE2C;AACzC,wBAAO,KAAKtD,KAAZ;AACA,aAAO,KAAKA,KAAL,CAAWwD,mBAAX,CAA+BF,MAA/B,CAAP;AACD;;;WAGD,qBAAYA,MAAZ,EAAyF;AACvF,wBAAO,KAAKtD,KAAZ;AACA,aAAO,KAAKA,KAAL,CAAWyD,WAAX,CAAuBH,MAAvB,CAAP;AACD;;;WAGD,oBAAW;AACT,UAAI,KAAKvD,IAAT,EAAe;AACb,aAAKA,IAAL,CAAU2D,aAAV,CAAwB,IAAxB;AACD;AACF","sourcesContent":["import {Deck, assert} from '@deck.gl/core';\nimport {getViewState} from './deck-utils';\n\nimport type {Map, IControl, MapMouseEvent} from 'mapbox-gl';\nimport type {MjolnirGestureEvent, MjolnirPointerEvent} from 'mjolnir.js';\nimport type {DeckProps} from '@deck.gl/core';\n\nimport {resolveLayers} from './resolve-layers';\n\nexport type MapboxOverlayProps = Omit<\n DeckProps,\n | 'width'\n | 'height'\n | 'gl'\n | 'parent'\n | 'canvas'\n | '_customRender'\n | 'viewState'\n | 'initialViewState'\n | 'controller'\n>;\n\n/**\n * Implements Mapbox [IControl](https://docs.mapbox.com/mapbox-gl-js/api/markers/#icontrol) interface\n * Renders deck.gl layers over the base map and automatically synchronizes with the map's camera\n */\nexport default class MapboxOverlay implements IControl {\n private _props: MapboxOverlayProps;\n private _deck?: Deck;\n private _map?: Map;\n private _container?: HTMLDivElement;\n private _interleaved: boolean;\n\n constructor(\n props: MapboxOverlayProps & {\n interleaved?: boolean;\n }\n ) {\n const {interleaved = false, ...otherProps} = props;\n this._interleaved = interleaved;\n this._props = otherProps;\n }\n\n /** Update (partial) props of the underlying Deck instance. */\n setProps(props: MapboxOverlayProps): void {\n if (this._interleaved && props.layers) {\n resolveLayers(this._map, this._deck, this._props.layers, props.layers);\n }\n\n Object.assign(this._props, props);\n\n if (this._deck) {\n this._deck.setProps(this._props);\n }\n }\n\n /** Called when the control is added to a map */\n onAdd(map: Map): HTMLDivElement {\n this._map = map;\n return this._interleaved ? this._onAddInterleaved(map) : this._onAddOverlaid(map);\n }\n\n private _onAddOverlaid(map: Map): HTMLDivElement {\n /* global document */\n const container = document.createElement('div');\n Object.assign(container.style, {\n position: 'absolute',\n left: 0,\n top: 0,\n pointerEvents: 'none'\n });\n this._container = container;\n\n this._deck = new Deck({\n ...this._props,\n parent: container,\n viewState: getViewState(map)\n });\n\n map.on('resize', this._updateContainerSize);\n map.on('render', this._updateViewState);\n map.on('mousemove', this._handleMouseEvent);\n map.on('mouseout', this._handleMouseEvent);\n map.on('click', this._handleMouseEvent);\n map.on('dblclick', this._handleMouseEvent);\n\n this._updateContainerSize();\n return container;\n }\n\n private _onAddInterleaved(map: Map): HTMLDivElement {\n this._deck = new Deck({\n ...this._props,\n // @ts-ignore non-public map property\n gl: map.painter.context.gl\n });\n\n map.on('styledata', this._handleStyleChange);\n resolveLayers(map, this._deck, [], this._props.layers);\n\n return document.createElement('div');\n }\n\n /** Called when the control is removed from a map */\n onRemove(): void {\n const map = this._map;\n\n if (map) {\n if (this._interleaved) {\n this._onRemoveInterleaved(map);\n } else {\n this._onRemoveOverlaid(map);\n }\n }\n\n this._deck?.finalize();\n this._deck = undefined;\n this._map = undefined;\n this._container = undefined;\n }\n\n private _onRemoveOverlaid(map: Map): void {\n map.off('resize', this._updateContainerSize);\n map.off('render', this._updateViewState);\n map.off('mousemove', this._handleMouseEvent);\n map.off('mouseout', this._handleMouseEvent);\n map.off('click', this._handleMouseEvent);\n map.off('dblclick', this._handleMouseEvent);\n }\n\n private _onRemoveInterleaved(map: Map): void {\n map.off('styledata', this._handleStyleChange);\n resolveLayers(map, this._deck, this._props.layers, []);\n }\n\n getDefaultPosition() {\n return 'top-left';\n }\n\n /** Forwards the Deck.pickObject method */\n pickObject(params: Parameters<Deck['pickObject']>[0]): ReturnType<Deck['pickObject']> {\n assert(this._deck);\n return this._deck.pickObject(params);\n }\n\n /** Forwards the Deck.pickMultipleObjects method */\n pickMultipleObjects(\n params: Parameters<Deck['pickMultipleObjects']>[0]\n ): ReturnType<Deck['pickMultipleObjects']> {\n assert(this._deck);\n return this._deck.pickMultipleObjects(params);\n }\n\n /** Forwards the Deck.pickObjects method */\n pickObjects(params: Parameters<Deck['pickObjects']>[0]): ReturnType<Deck['pickObjects']> {\n assert(this._deck);\n return this._deck.pickObjects(params);\n }\n\n /** Remove from map and releases all resources */\n finalize() {\n if (this._map) {\n this._map.removeControl(this);\n }\n }\n\n private _handleStyleChange = () => {\n resolveLayers(this._map, this._deck, this._props.layers, this._props.layers);\n };\n\n private _updateContainerSize = () => {\n if (this._map && this._container) {\n const {clientWidth, clientHeight} = this._map.getContainer();\n Object.assign(this._container.style, {\n width: `${clientWidth}px`,\n height: `${clientHeight}px`\n });\n }\n };\n\n private _updateViewState = () => {\n const deck = this._deck;\n if (deck) {\n // @ts-ignore (2345) map is always defined if deck is\n deck.setProps({viewState: getViewState(this._map)});\n // Redraw immediately if view state has changed\n deck.redraw();\n }\n };\n\n private _handleMouseEvent = (event: MapMouseEvent) => {\n const deck = this._deck;\n if (!deck) {\n return;\n }\n\n const mockEvent: {\n type: string;\n offsetCenter: {x: number; y: number};\n srcEvent: MapMouseEvent;\n tapCount?: number;\n } = {\n type: event.type,\n offsetCenter: event.point,\n srcEvent: event\n };\n\n switch (event.type) {\n case 'click':\n mockEvent.tapCount = 1;\n // Hack: because we do not listen to pointer down, perform picking now\n deck._onPointerDown(mockEvent as MjolnirGestureEvent);\n deck._onEvent(mockEvent as MjolnirGestureEvent);\n break;\n\n case 'dblclick':\n mockEvent.type = 'click';\n mockEvent.tapCount = 2;\n deck._onEvent(mockEvent as MjolnirGestureEvent);\n break;\n\n case 'mousemove':\n mockEvent.type = 'pointermove';\n deck._onPointerMove(mockEvent as MjolnirPointerEvent);\n break;\n\n case 'mouseout':\n mockEvent.type = 'pointerleave';\n deck._onPointerMove(mockEvent as MjolnirPointerEvent);\n break;\n\n default:\n return;\n }\n };\n}\n"],"file":"mapbox-overlay.js"}
|