Skip to content

Commit 8474b02

Browse files
committed
Use MapboxOverlay
1 parent 53f0d59 commit 8474b02

File tree

3 files changed

+52
-17
lines changed

3 files changed

+52
-17
lines changed

package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"@deck.gl/core": "^8.9.35",
99
"@deck.gl/extensions": "^8.9.35",
1010
"@deck.gl/layers": "^8.9.35",
11+
"@deck.gl/mapbox": "^8.9.35",
1112
"@deck.gl/react": "^8.9.35",
1213
"@geoarrow/deck.gl-layers": "^0.3.0-beta.15",
1314
"apache-arrow": "^15.0.1",

src/index.tsx

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ import * as React from "react";
22
import { useState, useEffect } from "react";
33
import { createRender, useModelState, useModel } from "@anywidget/react";
44
import type { Initialize, Render } from "@anywidget/types";
5-
import Map from "react-map-gl/maplibre";
6-
import DeckGL from "@deck.gl/react/typed";
5+
import { MapboxOverlay, MapboxOverlayProps } from "@deck.gl/mapbox/typed";
6+
import Map, {
7+
FullscreenControl,
8+
NavigationControl,
9+
ScaleControl,
10+
useControl,
11+
} from "react-map-gl/maplibre";
712
import { MapViewState, type Layer } from "@deck.gl/core/typed";
813
import { BaseLayerModel, initializeLayer } from "./model/index.js";
914
import type { WidgetModel } from "@jupyter-widgets/base";
@@ -14,6 +19,8 @@ import { v4 as uuidv4 } from "uuid";
1419
import { Message } from "./types.js";
1520
import { flyTo } from "./actions/fly-to.js";
1621

22+
import "maplibre-gl/dist/maplibre-gl.css";
23+
1724
await initParquetWasm();
1825

1926
const DEFAULT_INITIAL_VIEW_STATE = {
@@ -27,6 +34,16 @@ const DEFAULT_INITIAL_VIEW_STATE = {
2734
const DEFAULT_MAP_STYLE =
2835
"https://basemaps.cartocdn.com/gl/positron-nolabels-gl-style/style.json";
2936

37+
function DeckGLOverlay(
38+
props: MapboxOverlayProps & {
39+
interleaved?: boolean;
40+
},
41+
) {
42+
const overlay = useControl<MapboxOverlay>(() => new MapboxOverlay(props));
43+
overlay.setProps(props);
44+
return null;
45+
}
46+
3047
async function getChildModelState(
3148
childModels: WidgetModel[],
3249
childLayerIds: string[],
@@ -146,29 +163,33 @@ function App() {
146163

147164
return (
148165
<div id={`map-${mapId}`} style={{ height: mapHeight || "100%" }}>
149-
<DeckGL
166+
<Map
150167
initialViewState={
151168
["longitude", "latitude", "zoom"].every((key) =>
152169
Object.keys(initialViewState).includes(key),
153170
)
154171
? initialViewState
155172
: DEFAULT_INITIAL_VIEW_STATE
156173
}
157-
controller={true}
158-
layers={layers}
159-
// @ts-expect-error
160-
getTooltip={showTooltip && getTooltip}
161-
pickingRadius={pickingRadius}
162-
useDevicePixels={isDefined(useDevicePixels) ? useDevicePixels : true}
163-
// https://deck.gl/docs/api-reference/core/deck#_typedarraymanagerprops
164-
_typedArrayManagerProps={{
165-
overAlloc: 1,
166-
poolSize: 0,
167-
}}
168-
parameters={parameters || {}}
174+
mapStyle={mapStyle || DEFAULT_MAP_STYLE}
169175
>
170-
<Map mapStyle={mapStyle || DEFAULT_MAP_STYLE} />
171-
</DeckGL>
176+
<DeckGLOverlay
177+
layers={layers}
178+
// @ts-expect-error
179+
getTooltip={showTooltip && getTooltip}
180+
pickingRadius={pickingRadius}
181+
useDevicePixels={isDefined(useDevicePixels) ? useDevicePixels : true}
182+
// https://deck.gl/docs/api-reference/core/deck#_typedarraymanagerprops
183+
_typedArrayManagerProps={{
184+
overAlloc: 1,
185+
poolSize: 0,
186+
}}
187+
parameters={parameters || {}}
188+
/>
189+
<NavigationControl />
190+
<ScaleControl />
191+
<FullscreenControl />
192+
</Map>
172193
</div>
173194
);
174195
}

0 commit comments

Comments
 (0)