@deck.gl/mapbox 8.10.0-alpha.2 → 8.10.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/deck-utils.ts"],"names":["TILE_SIZE","DEGREES_TO_RADIANS","Math","PI","getDeckInstance","map","gl","deck","__deck","customRender","props","_customRender","onLoad","deckProps","getInterleavedProps","triggerRepaint","deckInstance","Object","assign","width","height","touchAction","viewState","getViewState","isInitialized","watchMapMove","setProps","userData","isExternal","Deck","on","removeDeckInstance","mapboxLayers","Set","afterRender","_handleMapMove","onMapMove","off","finalize","currProps","nextProps","parameters","depthMask","depthTest","blend","blendFunc","polygonOffsetFill","depthFunc","blendEquation","views","MapView","id","addLayer","layer","add","updateLayers","removeLayer","delete","updateLayer","drawLayer","currentViewport","clearStack","getViewport","_drawLayers","viewports","layerFilter","deckLayer","clearCanvas","getCenter","lng","lat","longitude","latitude","zoom","getZoom","bearing","getBearing","pitch","getPitch","padding","getPadding","repeat","getRenderWorldCopies","getTerrain","centerCameraOnTerrain","getFreeCameraOptions","position","z","undefined","transform","cameraX","x","cameraY","y","cameraZ","center","dx","dy","cameraToCenterDistanceGround","sqrt","pitchRadians","altitudePixels","scale","cos","sin","log2","cameraZFromSurface","surfaceElevation","elevation","useMapboxProjection","WebMercatorViewport","nearZMultiplier","mapboxLayerIds","Array","from","deckLayers","layers","Boolean","hasNonMapboxLayers","some","includes","getViewports","mapboxViewportIdx","findIndex","vp","hasNonMapboxViews","length","slice","params","viewport","needsRedraw","clearRedrawFlags","forEach","LayerType","type","push"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;AAKA;;;;;;AAWA,IAAMA,SAAS,GAAG,GAAlB;AACA,IAAMC,kBAAkB,GAAGC,IAAI,CAACC,EAAL,GAAU,GAArC;;AAGO,SAASC,eAAT,OAQE;AAAA,MAPPC,GAOO,QAPPA,GAOO;AAAA,MANPC,EAMO,QAN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AhB,KAAuB,QAAvB,IAAmC,CAAC6D,cAAc,CAACQ,QAAf,CAAwBQ,MAAM,CAAC3E,KAAP,CAAaF,EAArC,CADrC,CADiB;AAAA,SAFc;AAKjCgB,QAAAA,WAAW,EAAE;AALoB,OAAnC;AAOD;AACF;;AAGA5D,EAAAA,IAAI,CAACoB,QAAN,CAA4BiC,eAA5B,GAA8C,IAA9C;AACD;;AAED,SAASxB,SAAT,CAAmB7B,IAAnB,EAA+BF,GAA/B,EAA+C;AAC7CE,EAAAA,IAAI,CAACmB,QAAL,CAAc;AACZJ,IAAAA,SAAS,EAAEC,YAAY,CAAClB,GAAD;AADX,GAAd;AAMAE,EAAAA,IAAI,CAAC2H,WAAL,CAAiB;AAACC,IAAAA,gBAAgB,EAAE;AAAnB,GAAjB;AACD;;AAED,SAAS5E,YAAT,CAAsBhD,IAAtB,EAAwC;AACtC,MAAKA,IAAI,CAACoB,QAAN,CAA4BC,UAAhC,EAA4C;AAC1C;AACD;;AAED,MAAMwF,MAAe,GAAG,EAAxB;AACC7G,EAAAA,IAAI,CAACoB,QAAN,CAA4BK,YAA5B,CAAyCoG,OAAzC,CAAiD,UAAAlE,SAAS,EAAI;AAC5D,QAAMmE,SAAS,GAAGnE,SAAS,CAACxD,KAAV,CAAgB4H,IAAlC;AACA,QAAMjF,KAAK,GAAG,IAAIgF,SAAJ,CAAcnE,SAAS,CAACxD,KAAxB,CAAd;AACA0G,IAAAA,MAAM,CAACmB,IAAP,CAAYlF,KAAZ;AACD,GAJD;AAKA9C,EAAAA,IAAI,CAACmB,QAAL,CAAc;AAAC0F,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\nimport {lngLatToWorld, unitsPerMeter} from '@math.gl/web-mercator';\nimport GL from '@luma.gl/constants';\n\ntype UserData = {\n isExternal: boolean;\n currentViewport?: WebMercatorViewport | null;\n mapboxLayers: Set<MapboxLayer<any>>;\n // mapboxVersion: {minor: number; major: number};\n};\n\n// Mercator constants\nconst TILE_SIZE = 512;\nconst DEGREES_TO_RADIANS = Math.PI / 180;\n\n// Create an interleaved deck instance.\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 // Only initialize certain props once per context\n const customRender = deck?.props._customRender;\n const onLoad = deck?.props.onLoad;\n\n const deckProps = getInterleavedProps({\n ...deck?.props,\n _customRender: () => {\n map.triggerRepaint();\n // customRender may be subscribed by DeckGL React component to update child props\n // make sure it is still called\n // Hack - do not pass a redraw reason here to prevent the React component from clearing the context\n // Rerender will be triggered by MapboxLayer's render()\n customRender?.('');\n }\n });\n\n let deckInstance: Deck;\n\n if (!deck || deck.props.gl === gl) {\n // If deck isn't defined (Internal MapboxLayer use case),\n // or if deck is defined and is using the WebGLContext created by mapbox (MapboxOverlay and External MapboxLayer use case),\n // block deck from setting the canvas size, and use the map's viewState to drive deck.\n // Otherwise, we use deck's viewState to drive the map.\n Object.assign(deckProps, {\n gl,\n width: null,\n height: null,\n touchAction: 'unset',\n viewState: getViewState(map)\n });\n if (deck?.isInitialized) {\n watchMapMove(deck, map);\n } else {\n deckProps.onLoad = () => {\n onLoad?.();\n watchMapMove(deckInstance, map);\n };\n }\n }\n\n if (deck) {\n deckInstance = deck;\n deck.setProps(deckProps);\n (deck.userData as UserData).isExternal = true;\n } else {\n deckInstance = new Deck(deckProps);\n map.on('remove', () => {\n removeDeckInstance(map);\n });\n }\n\n (deckInstance.userData as UserData).mapboxLayers = new Set();\n // (deckInstance.userData as UserData).mapboxVersion = getMapboxVersion(map);\n map.__deck = deckInstance;\n map.on('render', () => {\n if (deckInstance.isInitialized) afterRender(deckInstance, map);\n });\n\n return deckInstance;\n}\n\nfunction watchMapMove(deck: Deck, map: Map & {__deck?: Deck | null}) {\n const _handleMapMove = () => {\n if (deck.isInitialized) {\n // call view state methods\n onMapMove(deck, map);\n } else {\n // deregister itself when deck is finalized\n map.off('move', _handleMapMove);\n }\n };\n map.on('move', _handleMapMove);\n}\n\nexport function removeDeckInstance(map: Map & {__deck?: Deck | null}) {\n map.__deck?.finalize();\n map.__deck = null;\n}\n\nexport function getInterleavedProps(currProps: DeckProps) {\n const nextProps: DeckProps = {\n ...currProps,\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 ...currProps.parameters\n },\n views: currProps.views || [new MapView({id: 'mapbox'})]\n };\n\n return nextProps;\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 let clearStack: boolean = false;\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 clearStack = true;\n }\n\n if (!deck.isInitialized) {\n return;\n }\n\n deck._drawLayers('mapbox-repaint', {\n viewports: [currentViewport],\n layerFilter: ({layer: deckLayer}) => layer.id === deckLayer.id,\n clearStack,\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\n const viewState: MapViewState & {\n repeat: boolean;\n padding: {\n left: number;\n right: number;\n top: number;\n bottom: number;\n };\n } = {\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 if (map.getTerrain?.()) {\n // When the base map has terrain, we need to target the camera at the terrain surface\n centerCameraOnTerrain(map, viewState);\n }\n\n return viewState;\n}\n\nfunction centerCameraOnTerrain(map: Map, viewState: MapViewState) {\n if (map.getFreeCameraOptions) {\n // mapbox-gl v2\n const {position} = map.getFreeCameraOptions();\n if (!position || position.z === undefined) {\n return;\n }\n\n // @ts-ignore transform is not typed\n const height = map.transform.height;\n const {longitude, latitude, pitch} = viewState;\n\n // Convert mapbox mercator coordinate to deck common space\n const cameraX = position.x * TILE_SIZE;\n const cameraY = (1 - position.y) * TILE_SIZE;\n const cameraZ = position.z * TILE_SIZE;\n\n // Mapbox manipulates zoom in terrain mode, see discussion here: https://github.com/mapbox/mapbox-gl-js/issues/12040\n const center = lngLatToWorld([longitude, latitude]);\n const dx = cameraX - center[0];\n const dy = cameraY - center[1];\n const cameraToCenterDistanceGround = Math.sqrt(dx * dx + dy * dy);\n\n const pitchRadians = pitch! * DEGREES_TO_RADIANS;\n const altitudePixels = 1.5 * height;\n const scale =\n pitchRadians < 0.001\n ? // Pitch angle too small to deduce the look at point, assume elevation is 0\n (altitudePixels * Math.cos(pitchRadians)) / cameraZ\n : (altitudePixels * Math.sin(pitchRadians)) / cameraToCenterDistanceGround;\n viewState.zoom = Math.log2(scale);\n\n const cameraZFromSurface = (altitudePixels * Math.cos(pitchRadians)) / scale;\n const surfaceElevation = cameraZ - cameraZFromSurface;\n viewState.position = [0, 0, surfaceElevation / unitsPerMeter(latitude)];\n }\n // @ts-ignore transform is not typed\n else if (typeof map.transform.elevation === 'number') {\n // maplibre-gl\n // @ts-ignore transform is not typed\n viewState.position = [0, 0, map.transform.elevation];\n }\n}\n\n// function 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 return new WebMercatorViewport({\n id: 'mapbox',\n x: 0,\n y: 0,\n width: deck.width,\n height: deck.height,\n ...getViewState(map),\n nearZMultiplier: useMapboxProjection\n ? // match mapbox-gl@>=1.3.0's projection matrix\n 0.02\n : // use deck.gl's own default\n 0.1\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 (deck.userData as UserData).mapboxLayers.forEach(deckLayer => {\n const LayerType = deckLayer.props.type;\n const layer = new LayerType(deckLayer.props);\n layers.push(layer);\n });\n deck.setProps({layers});\n}\n"],"file":"deck-utils.js"}
1
+ {"version":3,"sources":["../../src/deck-utils.ts"],"names":["TILE_SIZE","DEGREES_TO_RADIANS","Math","PI","getDeckInstance","map","gl","deck","__deck","customRender","props","_customRender","onLoad","deckProps","getInterleavedProps","triggerRepaint","deckInstance","Object","assign","width","height","touchAction","viewState","getViewState","isInitialized","watchMapMove","setProps","userData","isExternal","Deck","on","removeDeckInstance","mapboxLayers","Set","afterRender","_handleMapMove","onMapMove","off","finalize","currProps","nextProps","parameters","depthMask","depthTest","blend","blendFunc","polygonOffsetFill","depthFunc","blendEquation","views","MapView","id","addLayer","layer","add","updateLayers","removeLayer","delete","updateLayer","drawLayer","currentViewport","clearStack","getViewport","_drawLayers","viewports","layerFilter","deckLayer","operation","includes","clearCanvas","getCenter","lng","lat","longitude","latitude","zoom","getZoom","bearing","getBearing","pitch","getPitch","padding","getPadding","repeat","getRenderWorldCopies","getTerrain","centerCameraOnTerrain","getFreeCameraOptions","position","z","undefined","transform","cameraX","x","cameraY","y","cameraZ","center","dx","dy","cameraToCenterDistanceGround","sqrt","pitchRadians","altitudePixels","scale","cos","sin","log2","cameraZFromSurface","surfaceElevation","elevation","useMapboxProjection","WebMercatorViewport","nearZMultiplier","nearZ","_nearZ","farZ","_farZ","mapboxLayerIds","Array","from","deckLayers","layers","Boolean","hasNonMapboxLayers","some","getViewports","mapboxViewportIdx","findIndex","vp","hasNonMapboxViews","length","slice","params","viewport","needsRedraw","clearRedrawFlags","forEach","LayerType","type","push"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;AAKA;;;;;;AAWA,IAAMA,SAAS,GAAG,GAAlB;AACA,IAAMC,kBAAkB,GAAGC,IAAI,CAACC,EAAL,GAAU,GAArC;;AAGO,SAASC,eAAT,OAQE;AAAA,MAPPC,GAOO,QAPPA,GAOO;AAAA,MANPC,EAMO,QANPA,EAMO;AAAA,MALPC,IAKO,QALPA,IAKO;;AAEP,MAAIF,GAAG,CAACG,MAAR,EAAgB;AACd,WAAOH,GAAG,CAACG,MAAX;AACD;;AAGD,MAAMC,YAAY,GAAGF,IAAH,aAAGA,IAAH,uBAAGA,IAAI,CAAEG,KAAN,CAAYC,aAAjC;AACA,MAAMC,MAAM,GAAGL,IAAH,aAAGA,IAAH,uBAAGA,IAAI,CAAEG,KAAN,CAAYE,MAA3B;AAEA,MAAMC,SAAS,GAAGC,mBAAmB,iCAChCP,IADgC,aAChCA,IADgC,uBAChCA,IAAI,CAAEG,KAD0B;AAEnCC,IAAAA,aAAa,EAAE,yBAAM;AACnBN,MAAAA,GAAG,CAACU,cAAJ;AAKAN,MAAAA,YAAY,SAAZ,IAAAA,YAAY,WAAZ,YAAAA,YAAY,CAAG,EAAH,CAAZ;AACD;AATkC,KAArC;AAYA,MAAIO,YAAJ;;AAEA,MAAI,CAACT,IAAD,IAASA,IAAI,CAACG,KAAL,CAAWJ,EAAX,KAAkBA,EAA/B,EAAmC;AAKjCW,IAAAA,MAAM,CAACC,MAAP,CAAcL,SAAd,EAAyB;AACvBP,MAAAA,EAAE,EAAFA,EADuB;AAEvBa,MAAAA,KAAK,EAAE,IAFgB;AAGvBC,MAAAA,MAAM,EAAE,IAHe;AAIvBC,MAAAA,WAAW,EAAE,OAJU;AAKvBC,MAAAA,SAAS,EAAEC,YAAY,CAAClB,GAAD;AALA,KAAzB;;AAOA,QAAIE,IAAJ,aA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EAAAA,IAAI,CAACoB,QAAN,CAA4BK,YAA5B,CAAyCyG,OAAzC,CAAiD,UAAAvE,SAAS,EAAI;AAC5D,QAAMwE,SAAS,GAAGxE,SAAS,CAACxD,KAAV,CAAgBiI,IAAlC;AACA,QAAMtF,KAAK,GAAG,IAAIqF,SAAJ,CAAcxE,SAAS,CAACxD,KAAxB,CAAd;AACAgH,IAAAA,MAAM,CAACkB,IAAP,CAAYvF,KAAZ;AACD,GAJD;AAKA9C,EAAAA,IAAI,CAACmB,QAAL,CAAc;AAACgG,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\nimport {lngLatToWorld, unitsPerMeter} from '@math.gl/web-mercator';\nimport GL from '@luma.gl/constants';\n\ntype UserData = {\n isExternal: boolean;\n currentViewport?: WebMercatorViewport | null;\n mapboxLayers: Set<MapboxLayer<any>>;\n // mapboxVersion: {minor: number; major: number};\n};\n\n// Mercator constants\nconst TILE_SIZE = 512;\nconst DEGREES_TO_RADIANS = Math.PI / 180;\n\n// Create an interleaved deck instance.\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 // Only initialize certain props once per context\n const customRender = deck?.props._customRender;\n const onLoad = deck?.props.onLoad;\n\n const deckProps = getInterleavedProps({\n ...deck?.props,\n _customRender: () => {\n map.triggerRepaint();\n // customRender may be subscribed by DeckGL React component to update child props\n // make sure it is still called\n // Hack - do not pass a redraw reason here to prevent the React component from clearing the context\n // Rerender will be triggered by MapboxLayer's render()\n customRender?.('');\n }\n });\n\n let deckInstance: Deck;\n\n if (!deck || deck.props.gl === gl) {\n // If deck isn't defined (Internal MapboxLayer use case),\n // or if deck is defined and is using the WebGLContext created by mapbox (MapboxOverlay and External MapboxLayer use case),\n // block deck from setting the canvas size, and use the map's viewState to drive deck.\n // Otherwise, we use deck's viewState to drive the map.\n Object.assign(deckProps, {\n gl,\n width: null,\n height: null,\n touchAction: 'unset',\n viewState: getViewState(map)\n });\n if (deck?.isInitialized) {\n watchMapMove(deck, map);\n } else {\n deckProps.onLoad = () => {\n onLoad?.();\n watchMapMove(deckInstance, map);\n };\n }\n }\n\n if (deck) {\n deckInstance = deck;\n deck.setProps(deckProps);\n (deck.userData as UserData).isExternal = true;\n } else {\n deckInstance = new Deck(deckProps);\n map.on('remove', () => {\n removeDeckInstance(map);\n });\n }\n\n (deckInstance.userData as UserData).mapboxLayers = new Set();\n // (deckInstance.userData as UserData).mapboxVersion = getMapboxVersion(map);\n map.__deck = deckInstance;\n map.on('render', () => {\n if (deckInstance.isInitialized) afterRender(deckInstance, map);\n });\n\n return deckInstance;\n}\n\nfunction watchMapMove(deck: Deck, map: Map & {__deck?: Deck | null}) {\n const _handleMapMove = () => {\n if (deck.isInitialized) {\n // call view state methods\n onMapMove(deck, map);\n } else {\n // deregister itself when deck is finalized\n map.off('move', _handleMapMove);\n }\n };\n map.on('move', _handleMapMove);\n}\n\nexport function removeDeckInstance(map: Map & {__deck?: Deck | null}) {\n map.__deck?.finalize();\n map.__deck = null;\n}\n\nexport function getInterleavedProps(currProps: DeckProps) {\n const nextProps: DeckProps = {\n ...currProps,\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 ...currProps.parameters\n },\n views: currProps.views || [new MapView({id: 'mapbox'})]\n };\n\n return nextProps;\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 let clearStack: boolean = false;\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 clearStack = true;\n }\n\n if (!deck.isInitialized) {\n return;\n }\n\n deck._drawLayers('mapbox-repaint', {\n viewports: [currentViewport],\n layerFilter: ({layer: deckLayer}) =>\n layer.id === deckLayer.id || deckLayer.props.operation.includes('terrain'),\n clearStack,\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\n const viewState: MapViewState & {\n repeat: boolean;\n padding: {\n left: number;\n right: number;\n top: number;\n bottom: number;\n };\n } = {\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 if (map.getTerrain?.()) {\n // When the base map has terrain, we need to target the camera at the terrain surface\n centerCameraOnTerrain(map, viewState);\n }\n\n return viewState;\n}\n\nfunction centerCameraOnTerrain(map: Map, viewState: MapViewState) {\n if (map.getFreeCameraOptions) {\n // mapbox-gl v2\n const {position} = map.getFreeCameraOptions();\n if (!position || position.z === undefined) {\n return;\n }\n\n // @ts-ignore transform is not typed\n const height = map.transform.height;\n const {longitude, latitude, pitch} = viewState;\n\n // Convert mapbox mercator coordinate to deck common space\n const cameraX = position.x * TILE_SIZE;\n const cameraY = (1 - position.y) * TILE_SIZE;\n const cameraZ = position.z * TILE_SIZE;\n\n // Mapbox manipulates zoom in terrain mode, see discussion here: https://github.com/mapbox/mapbox-gl-js/issues/12040\n const center = lngLatToWorld([longitude, latitude]);\n const dx = cameraX - center[0];\n const dy = cameraY - center[1];\n const cameraToCenterDistanceGround = Math.sqrt(dx * dx + dy * dy);\n\n const pitchRadians = pitch! * DEGREES_TO_RADIANS;\n const altitudePixels = 1.5 * height;\n const scale =\n pitchRadians < 0.001\n ? // Pitch angle too small to deduce the look at point, assume elevation is 0\n (altitudePixels * Math.cos(pitchRadians)) / cameraZ\n : (altitudePixels * Math.sin(pitchRadians)) / cameraToCenterDistanceGround;\n viewState.zoom = Math.log2(scale);\n\n const cameraZFromSurface = (altitudePixels * Math.cos(pitchRadians)) / scale;\n const surfaceElevation = cameraZ - cameraZFromSurface;\n viewState.position = [0, 0, surfaceElevation / unitsPerMeter(latitude)];\n }\n // @ts-ignore transform is not typed\n else if (typeof map.transform.elevation === 'number') {\n // maplibre-gl\n // @ts-ignore transform is not typed\n viewState.position = [0, 0, map.transform.elevation];\n }\n}\n\n// function 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 return new WebMercatorViewport({\n id: 'mapbox',\n x: 0,\n y: 0,\n width: deck.width,\n height: deck.height,\n ...getViewState(map),\n nearZMultiplier: useMapboxProjection\n ? // match mapbox-gl@>=1.3.0's projection matrix\n 0.02\n : // use deck.gl's own default\n 0.1,\n // @ts-expect-error Mapbox specific - extract near plane position\n nearZ: map.transform._nearZ / map.transform.height,\n // @ts-expect-error Mapbox specific - extract far plane position\n farZ: map.transform._farZ / map.transform.height\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 (deck.userData as UserData).mapboxLayers.forEach(deckLayer => {\n const LayerType = deckLayer.props.type;\n const layer = new LayerType(deckLayer.props);\n layers.push(layer);\n });\n deck.setProps({layers});\n}\n"],"file":"deck-utils.js"}
@@ -9,21 +9,17 @@ exports.default = void 0;
9
9
 
10
10
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
11
 
12
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
-
14
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
15
-
16
12
  var _deckUtils = require("./deck-utils");
17
13
 
18
14
  var MapboxLayer = function () {
19
15
  function MapboxLayer(props) {
20
16
  (0, _classCallCheck2.default)(this, MapboxLayer);
21
- (0, _defineProperty2.default)(this, "id", void 0);
22
- (0, _defineProperty2.default)(this, "type", void 0);
23
- (0, _defineProperty2.default)(this, "renderingMode", void 0);
24
- (0, _defineProperty2.default)(this, "map", void 0);
25
- (0, _defineProperty2.default)(this, "deck", void 0);
26
- (0, _defineProperty2.default)(this, "props", void 0);
17
+ this.id = void 0;
18
+ this.type = void 0;
19
+ this.renderingMode = void 0;
20
+ this.map = void 0;
21
+ this.deck = void 0;
22
+ this.props = void 0;
27
23
 
28
24
  if (!props.id) {
29
25
  throw new Error('Layer must have an unique id');
@@ -37,41 +33,38 @@ var MapboxLayer = function () {
37
33
  this.props = props;
38
34
  }
39
35
 
40
- (0, _createClass2.default)(MapboxLayer, [{
41
- key: "onAdd",
42
- value: function onAdd(map, gl) {
43
- this.map = map;
44
- this.deck = (0, _deckUtils.getDeckInstance)({
45
- map: map,
46
- gl: gl,
47
- deck: this.props.deck
48
- });
49
- (0, _deckUtils.addLayer)(this.deck, this);
50
- }
51
- }, {
52
- key: "onRemove",
53
- value: function onRemove() {
54
- if (this.deck) {
55
- (0, _deckUtils.removeLayer)(this.deck, this);
56
- }
57
- }
58
- }, {
59
- key: "setProps",
60
- value: function setProps(props) {
61
- Object.assign(this.props, props, {
62
- id: this.id
63
- });
36
+ var _proto = MapboxLayer.prototype;
37
+
38
+ _proto.onAdd = function onAdd(map, gl) {
39
+ this.map = map;
40
+ this.deck = (0, _deckUtils.getDeckInstance)({
41
+ map: map,
42
+ gl: gl,
43
+ deck: this.props.deck
44
+ });
45
+ (0, _deckUtils.addLayer)(this.deck, this);
46
+ };
64
47
 
65
- if (this.deck) {
66
- (0, _deckUtils.updateLayer)(this.deck, this);
67
- }
48
+ _proto.onRemove = function onRemove() {
49
+ if (this.deck) {
50
+ (0, _deckUtils.removeLayer)(this.deck, this);
68
51
  }
69
- }, {
70
- key: "render",
71
- value: function render() {
72
- (0, _deckUtils.drawLayer)(this.deck, this.map, this);
52
+ };
53
+
54
+ _proto.setProps = function setProps(props) {
55
+ Object.assign(this.props, props, {
56
+ id: this.id
57
+ });
58
+
59
+ if (this.deck) {
60
+ (0, _deckUtils.updateLayer)(this.deck, this);
73
61
  }
74
- }]);
62
+ };
63
+
64
+ _proto.render = function render() {
65
+ (0, _deckUtils.drawLayer)(this.deck, this.map, this);
66
+ };
67
+
75
68
  return MapboxLayer;
76
69
  }();
77
70
 
@@ -1 +1 @@
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"}
1
+ {"version":3,"sources":["../../src/mapbox-layer.ts"],"names":["MapboxLayer","props","id","type","renderingMode","map","deck","Error","onAdd","gl","onRemove","setProps","Object","assign","render"],"mappings":";;;;;;;;;;;AAAA;;IAUqBA,W;AASnB,uBAAYC,KAAZ,EAA6C;AAAA;AAAA,SAR7CC,EAQ6C;AAAA,SAP7CC,IAO6C;AAAA,SAN7CC,aAM6C;AAAA,SAL7CC,GAK6C;AAAA,SAJ7CC,IAI6C;AAAA,SAH7CL,KAG6C;;AAC3C,QAAI,CAACA,KAAK,CAACC,EAAX,EAAe;AACb,YAAM,IAAIK,KAAJ,CAAU,8BAAV,CAAN;AACD;;AAED,SAAKL,EAAL,GAAUD,KAAK,CAACC,EAAhB;AACA,SAAKC,IAAL,GAAY,QAAZ;AACA,SAAKC,aAAL,GAAqBH,KAAK,CAACG,aAAN,IAAuB,IAA5C;AACA,SAAKC,GAAL,GAAW,IAAX;AACA,SAAKC,IAAL,GAAY,IAAZ;AACA,SAAKL,KAAL,GAAaA,KAAb;AACD;;;;SAIDO,K,GAAA,eAAMH,GAAN,EAAgBI,EAAhB,EAAiD;AAC/C,SAAKJ,GAAL,GAAWA,GAAX;AACA,SAAKC,IAAL,GAAY,gCAAgB;AAACD,MAAAA,GAAG,EAAHA,GAAD;AAAMI,MAAAA,EAAE,EAAFA,EAAN;AAAUH,MAAAA,IAAI,EAAE,KAAKL,KAAL,CAAWK;AAA3B,KAAhB,CAAZ;AACA,6BAAS,KAAKA,IAAd,EAAoB,IAApB;AACD,G;;SAEDI,Q,GAAA,oBAAiB;AACf,QAAI,KAAKJ,IAAT,EAAe;AACb,kCAAY,KAAKA,IAAjB,EAAuB,IAAvB;AACD;AACF,G;;SAEDK,Q,GAAA,kBAASV,KAAT,EAA0C;AAExCW,IAAAA,MAAM,CAACC,MAAP,CAAc,KAAKZ,KAAnB,EAA0BA,KAA1B,EAAiC;AAACC,MAAAA,EAAE,EAAE,KAAKA;AAAV,KAAjC;;AAEA,QAAI,KAAKI,IAAT,EAAe;AACb,kCAAY,KAAKA,IAAjB,EAAuB,IAAvB;AACD;AACF,G;;SAEDQ,M,GAAA,kBAAS;AACP,8BAAU,KAAKR,IAAf,EAAsB,KAAKD,GAA3B,EAAiC,IAAjC;AACD,G","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"}
@@ -9,12 +9,10 @@ exports.default = void 0;
9
9
 
10
10
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
11
11
 
12
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
-
14
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
15
-
16
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
13
 
14
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
15
+
18
16
  var _core = require("@deck.gl/core");
19
17
 
20
18
  var _deckUtils = require("./deck-utils");
@@ -32,16 +30,18 @@ var MapboxOverlay = function () {
32
30
  var _this = this;
33
31
 
34
32
  (0, _classCallCheck2.default)(this, MapboxOverlay);
35
- (0, _defineProperty2.default)(this, "_props", void 0);
36
- (0, _defineProperty2.default)(this, "_deck", void 0);
37
- (0, _defineProperty2.default)(this, "_map", void 0);
38
- (0, _defineProperty2.default)(this, "_container", void 0);
39
- (0, _defineProperty2.default)(this, "_interleaved", void 0);
40
- (0, _defineProperty2.default)(this, "_lastMouseDownPoint", void 0);
41
- (0, _defineProperty2.default)(this, "_handleStyleChange", function () {
33
+ this._props = void 0;
34
+ this._deck = void 0;
35
+ this._map = void 0;
36
+ this._container = void 0;
37
+ this._interleaved = void 0;
38
+ this._lastMouseDownPoint = void 0;
39
+
40
+ this._handleStyleChange = function () {
42
41
  (0, _resolveLayers.resolveLayers)(_this._map, _this._deck, _this._props.layers, _this._props.layers);
43
- });
44
- (0, _defineProperty2.default)(this, "_updateContainerSize", function () {
42
+ };
43
+
44
+ this._updateContainerSize = function () {
45
45
  if (_this._map && _this._container) {
46
46
  var _this$_map$getContain = _this._map.getContainer(),
47
47
  clientWidth = _this$_map$getContain.clientWidth,
@@ -52,8 +52,9 @@ var MapboxOverlay = function () {
52
52
  height: "".concat(clientHeight, "px")
53
53
  });
54
54
  }
55
- });
56
- (0, _defineProperty2.default)(this, "_updateViewState", function () {
55
+ };
56
+
57
+ this._updateViewState = function () {
57
58
  var deck = _this._deck;
58
59
 
59
60
  if (deck) {
@@ -65,8 +66,9 @@ var MapboxOverlay = function () {
65
66
  deck.redraw();
66
67
  }
67
68
  }
68
- });
69
- (0, _defineProperty2.default)(this, "_handleMouseEvent", function (event) {
69
+ };
70
+
71
+ this._handleMouseEvent = function (event) {
70
72
  var deck = _this._deck;
71
73
 
72
74
  if (!deck || !deck.isInitialized) {
@@ -152,7 +154,8 @@ var MapboxOverlay = function () {
152
154
  default:
153
155
  return;
154
156
  }
155
- });
157
+ };
158
+
156
159
  var _props$interleaved = props.interleaved,
157
160
  interleaved = _props$interleaved === void 0 ? false : _props$interleaved,
158
161
  otherProps = (0, _objectWithoutProperties2.default)(props, _excluded);
@@ -160,141 +163,138 @@ var MapboxOverlay = function () {
160
163
  this._props = otherProps;
161
164
  }
162
165
 
163
- (0, _createClass2.default)(MapboxOverlay, [{
164
- key: "setProps",
165
- value: function setProps(props) {
166
- if (this._interleaved && props.layers) {
167
- (0, _resolveLayers.resolveLayers)(this._map, this._deck, this._props.layers, props.layers);
168
- }
169
-
170
- Object.assign(this._props, props);
166
+ var _proto = MapboxOverlay.prototype;
171
167
 
172
- if (this._deck) {
173
- this._deck.setProps(this._interleaved ? (0, _deckUtils.getInterleavedProps)(this._props) : this._props);
174
- }
175
- }
176
- }, {
177
- key: "onAdd",
178
- value: function onAdd(map) {
179
- this._map = map;
180
- return this._interleaved ? this._onAddInterleaved(map) : this._onAddOverlaid(map);
168
+ _proto.setProps = function setProps(props) {
169
+ if (this._interleaved && props.layers) {
170
+ (0, _resolveLayers.resolveLayers)(this._map, this._deck, this._props.layers, props.layers);
181
171
  }
182
- }, {
183
- key: "_onAddOverlaid",
184
- value: function _onAddOverlaid(map) {
185
- var container = document.createElement('div');
186
- Object.assign(container.style, {
187
- position: 'absolute',
188
- left: 0,
189
- top: 0,
190
- pointerEvents: 'none'
191
- });
192
- this._container = container;
193
- this._deck = new _core.Deck(_objectSpread(_objectSpread({}, this._props), {}, {
194
- parent: container,
195
- viewState: (0, _deckUtils.getViewState)(map)
196
- }));
197
- map.on('resize', this._updateContainerSize);
198
- map.on('render', this._updateViewState);
199
- map.on('mousedown', this._handleMouseEvent);
200
- map.on('dragstart', this._handleMouseEvent);
201
- map.on('drag', this._handleMouseEvent);
202
- map.on('dragend', this._handleMouseEvent);
203
- map.on('mousemove', this._handleMouseEvent);
204
- map.on('mouseout', this._handleMouseEvent);
205
- map.on('click', this._handleMouseEvent);
206
- map.on('dblclick', this._handleMouseEvent);
207
-
208
- this._updateContainerSize();
209
-
210
- return container;
211
- }
212
- }, {
213
- key: "_onAddInterleaved",
214
- value: function _onAddInterleaved(map) {
215
- this._deck = (0, _deckUtils.getDeckInstance)({
216
- map: map,
217
- gl: map.painter.context.gl,
218
- deck: new _core.Deck(_objectSpread(_objectSpread({}, this._props), {}, {
219
- gl: map.painter.context.gl
220
- }))
221
- });
222
- map.on('styledata', this._handleStyleChange);
223
- (0, _resolveLayers.resolveLayers)(map, this._deck, [], this._props.layers);
224
- return document.createElement('div');
225
- }
226
- }, {
227
- key: "onRemove",
228
- value: function onRemove() {
229
- var map = this._map;
230
-
231
- if (map) {
232
- if (this._interleaved) {
233
- this._onRemoveInterleaved(map);
234
- } else {
235
- this._onRemoveOverlaid(map);
236
- }
237
- }
238
172
 
239
- this._deck = undefined;
240
- this._map = undefined;
241
- this._container = undefined;
242
- }
243
- }, {
244
- key: "_onRemoveOverlaid",
245
- value: function _onRemoveOverlaid(map) {
246
- var _this$_deck;
247
-
248
- map.off('resize', this._updateContainerSize);
249
- map.off('render', this._updateViewState);
250
- map.off('mousedown', this._handleMouseEvent);
251
- map.off('dragstart', this._handleMouseEvent);
252
- map.off('drag', this._handleMouseEvent);
253
- map.off('dragend', this._handleMouseEvent);
254
- map.off('mousemove', this._handleMouseEvent);
255
- map.off('mouseout', this._handleMouseEvent);
256
- map.off('click', this._handleMouseEvent);
257
- map.off('dblclick', this._handleMouseEvent);
258
- (_this$_deck = this._deck) === null || _this$_deck === void 0 ? void 0 : _this$_deck.finalize();
259
- }
260
- }, {
261
- key: "_onRemoveInterleaved",
262
- value: function _onRemoveInterleaved(map) {
263
- map.off('styledata', this._handleStyleChange);
264
- (0, _resolveLayers.resolveLayers)(map, this._deck, this._props.layers, []);
265
- (0, _deckUtils.removeDeckInstance)(map);
266
- }
267
- }, {
268
- key: "getDefaultPosition",
269
- value: function getDefaultPosition() {
270
- return 'top-left';
271
- }
272
- }, {
273
- key: "pickObject",
274
- value: function pickObject(params) {
275
- (0, _core.assert)(this._deck);
276
- return this._deck.pickObject(params);
173
+ Object.assign(this._props, props);
174
+
175
+ if (this._deck) {
176
+ this._deck.setProps(this._interleaved ? (0, _deckUtils.getInterleavedProps)(this._props) : this._props);
277
177
  }
278
- }, {
279
- key: "pickMultipleObjects",
280
- value: function pickMultipleObjects(params) {
281
- (0, _core.assert)(this._deck);
282
- return this._deck.pickMultipleObjects(params);
178
+ };
179
+
180
+ _proto.onAdd = function onAdd(map) {
181
+ this._map = map;
182
+ return this._interleaved ? this._onAddInterleaved(map) : this._onAddOverlaid(map);
183
+ };
184
+
185
+ _proto._onAddOverlaid = function _onAddOverlaid(map) {
186
+ var container = document.createElement('div');
187
+ Object.assign(container.style, {
188
+ position: 'absolute',
189
+ left: 0,
190
+ top: 0,
191
+ pointerEvents: 'none'
192
+ });
193
+ this._container = container;
194
+ this._deck = new _core.Deck(_objectSpread(_objectSpread({}, this._props), {}, {
195
+ parent: container,
196
+ viewState: (0, _deckUtils.getViewState)(map)
197
+ }));
198
+ map.on('resize', this._updateContainerSize);
199
+ map.on('render', this._updateViewState);
200
+ map.on('mousedown', this._handleMouseEvent);
201
+ map.on('dragstart', this._handleMouseEvent);
202
+ map.on('drag', this._handleMouseEvent);
203
+ map.on('dragend', this._handleMouseEvent);
204
+ map.on('mousemove', this._handleMouseEvent);
205
+ map.on('mouseout', this._handleMouseEvent);
206
+ map.on('click', this._handleMouseEvent);
207
+ map.on('dblclick', this._handleMouseEvent);
208
+
209
+ this._updateContainerSize();
210
+
211
+ return container;
212
+ };
213
+
214
+ _proto._onAddInterleaved = function _onAddInterleaved(map) {
215
+ this._deck = (0, _deckUtils.getDeckInstance)({
216
+ map: map,
217
+ gl: map.painter.context.gl,
218
+ deck: new _core.Deck(_objectSpread(_objectSpread({}, this._props), {}, {
219
+ gl: map.painter.context.gl
220
+ }))
221
+ });
222
+ map.on('styledata', this._handleStyleChange);
223
+ (0, _resolveLayers.resolveLayers)(map, this._deck, [], this._props.layers);
224
+ return document.createElement('div');
225
+ };
226
+
227
+ _proto.onRemove = function onRemove() {
228
+ var map = this._map;
229
+
230
+ if (map) {
231
+ if (this._interleaved) {
232
+ this._onRemoveInterleaved(map);
233
+ } else {
234
+ this._onRemoveOverlaid(map);
235
+ }
283
236
  }
284
- }, {
285
- key: "pickObjects",
286
- value: function pickObjects(params) {
287
- (0, _core.assert)(this._deck);
288
- return this._deck.pickObjects(params);
237
+
238
+ this._deck = undefined;
239
+ this._map = undefined;
240
+ this._container = undefined;
241
+ };
242
+
243
+ _proto._onRemoveOverlaid = function _onRemoveOverlaid(map) {
244
+ var _this$_deck;
245
+
246
+ map.off('resize', this._updateContainerSize);
247
+ map.off('render', this._updateViewState);
248
+ map.off('mousedown', this._handleMouseEvent);
249
+ map.off('dragstart', this._handleMouseEvent);
250
+ map.off('drag', this._handleMouseEvent);
251
+ map.off('dragend', this._handleMouseEvent);
252
+ map.off('mousemove', this._handleMouseEvent);
253
+ map.off('mouseout', this._handleMouseEvent);
254
+ map.off('click', this._handleMouseEvent);
255
+ map.off('dblclick', this._handleMouseEvent);
256
+ (_this$_deck = this._deck) === null || _this$_deck === void 0 ? void 0 : _this$_deck.finalize();
257
+ };
258
+
259
+ _proto._onRemoveInterleaved = function _onRemoveInterleaved(map) {
260
+ map.off('styledata', this._handleStyleChange);
261
+ (0, _resolveLayers.resolveLayers)(map, this._deck, this._props.layers, []);
262
+ (0, _deckUtils.removeDeckInstance)(map);
263
+ };
264
+
265
+ _proto.getDefaultPosition = function getDefaultPosition() {
266
+ return 'top-left';
267
+ };
268
+
269
+ _proto.pickObject = function pickObject(params) {
270
+ (0, _core.assert)(this._deck);
271
+ return this._deck.pickObject(params);
272
+ };
273
+
274
+ _proto.pickMultipleObjects = function pickMultipleObjects(params) {
275
+ (0, _core.assert)(this._deck);
276
+ return this._deck.pickMultipleObjects(params);
277
+ };
278
+
279
+ _proto.pickObjects = function pickObjects(params) {
280
+ (0, _core.assert)(this._deck);
281
+ return this._deck.pickObjects(params);
282
+ };
283
+
284
+ _proto.finalize = function finalize() {
285
+ if (this._map) {
286
+ this._map.removeControl(this);
289
287
  }
290
- }, {
291
- key: "finalize",
292
- value: function finalize() {
293
- if (this._map) {
294
- this._map.removeControl(this);
295
- }
288
+ };
289
+
290
+ _proto.getCanvas = function getCanvas() {
291
+ if (!this._map) {
292
+ return null;
296
293
  }
297
- }]);
294
+
295
+ return this._interleaved ? this._map.getCanvas() : this._deck.getCanvas();
296
+ };
297
+
298
298
  return MapboxOverlay;
299
299
  }();
300
300