Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use MapboxOverlay for handling Maplibre interaction? #437

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@deck.gl/core": "^8.9.35",
"@deck.gl/extensions": "^8.9.35",
"@deck.gl/layers": "^8.9.35",
"@deck.gl/mapbox": "^8.9.35",
"@deck.gl/react": "^8.9.35",
"@geoarrow/deck.gl-layers": "^0.3.0-beta.15",
"apache-arrow": "^15.0.1",
Expand Down
55 changes: 38 additions & 17 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ import * as React from "react";
import { useState, useEffect } from "react";
import { createRender, useModelState, useModel } from "@anywidget/react";
import type { Initialize, Render } from "@anywidget/types";
import Map from "react-map-gl/maplibre";
import DeckGL from "@deck.gl/react/typed";
import { MapboxOverlay, MapboxOverlayProps } from "@deck.gl/mapbox/typed";
import Map, {
FullscreenControl,
NavigationControl,
ScaleControl,
useControl,
} from "react-map-gl/maplibre";
import { MapViewState, type Layer } from "@deck.gl/core/typed";
import { BaseLayerModel, initializeLayer } from "./model/index.js";
import type { WidgetModel } from "@jupyter-widgets/base";
Expand All @@ -14,6 +19,8 @@ import { v4 as uuidv4 } from "uuid";
import { Message } from "./types.js";
import { flyTo } from "./actions/fly-to.js";

import "maplibre-gl/dist/maplibre-gl.css";

await initParquetWasm();

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

function DeckGLOverlay(
props: MapboxOverlayProps & {
interleaved?: boolean;
},
) {
const overlay = useControl<MapboxOverlay>(() => new MapboxOverlay(props));
overlay.setProps(props);
return null;
}

async function getChildModelState(
childModels: WidgetModel[],
childLayerIds: string[],
Expand Down Expand Up @@ -146,29 +163,33 @@ function App() {

return (
<div id={`map-${mapId}`} style={{ height: mapHeight || "100%" }}>
<DeckGL
<Map
initialViewState={
["longitude", "latitude", "zoom"].every((key) =>
Object.keys(initialViewState).includes(key),
)
? initialViewState
: DEFAULT_INITIAL_VIEW_STATE
}
controller={true}
layers={layers}
// @ts-expect-error
getTooltip={showTooltip && getTooltip}
pickingRadius={pickingRadius}
useDevicePixels={isDefined(useDevicePixels) ? useDevicePixels : true}
// https://deck.gl/docs/api-reference/core/deck#_typedarraymanagerprops
_typedArrayManagerProps={{
overAlloc: 1,
poolSize: 0,
}}
parameters={parameters || {}}
mapStyle={mapStyle || DEFAULT_MAP_STYLE}
>
<Map mapStyle={mapStyle || DEFAULT_MAP_STYLE} />
</DeckGL>
<DeckGLOverlay
layers={layers}
// @ts-expect-error
getTooltip={showTooltip && getTooltip}
pickingRadius={pickingRadius}
useDevicePixels={isDefined(useDevicePixels) ? useDevicePixels : true}
// https://deck.gl/docs/api-reference/core/deck#_typedarraymanagerprops
_typedArrayManagerProps={{
overAlloc: 1,
poolSize: 0,
}}
parameters={parameters || {}}
/>
<NavigationControl />
<ScaleControl />
<FullscreenControl />
</Map>
</div>
);
}
Expand Down