-
Notifications
You must be signed in to change notification settings - Fork 39
feat: Switch to using MapboxOverlay #890
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
base: main
Are you sure you want to change the base?
Conversation
function DeckGLOverlay(props: MapboxOverlayProps) { | ||
const overlay = useControl(() => new DeckOverlay(props)); | ||
|
||
overlay.setProps(props); | ||
return null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the standard way to use DeckOverlay
in react? @felixpalmer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onViewStateChange={(event) => { | ||
const { viewState } = event; | ||
|
||
// This condition is necessary to confirm that the viewState is | ||
// of type MapViewState. | ||
if ("latitude" in viewState) { | ||
const { longitude, latitude, zoom, pitch, bearing } = | ||
viewState; | ||
setViewState({ | ||
longitude, | ||
latitude, | ||
zoom, | ||
pitch, | ||
bearing, | ||
}); | ||
} | ||
}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo: I need to check that deck.gl still sends these events even when the view state is managed by maplibre.
For background: This sets the current view state on the model so that it can be updated on the Python side, which can be accessed via Map.view_state
.
Up to you, but worth noting many more widgets are coming in 9.2 visgl/deck.gl#9784 |
Is it possible to use the deck.gl widgets even with MapboxOverlay? Also, with MapboxOverlay it's not possible to use two views, right? Or at least they can't both have a maplibre map? |
From @felixpalmer, suggestion on how to switch ctrl and shift: diff --git a/examples/get-started/react/maplibre/app.jsx b/examples/get-started/react/maplibre/app.jsx
index 238df7a16..c08899c13 100644
--- a/examples/get-started/react/maplibre/app.jsx
+++ b/examples/get-started/react/maplibre/app.jsx
@@ -22,6 +22,14 @@ const INITIAL_VIEW_STATE = {
};
const MAP_STYLE = 'https://basemaps.cartocdn.com/gl/positron-gl-style/style.json';
+
+function patchDragMoveHandler(handler) {
+ const originalCorrectEvent = handler._moveStateManager._correctEvent;
+ handler._moveStateManager._correctEvent = e => {
+ return originalCorrectEvent({button: e.button, ctrlKey: e.shiftKey});
+ };
+}
+
function DeckGLOverlay(props) {
const overlay = useControl(() => new DeckOverlay(props));
overlay.setProps(props);
@@ -31,6 +39,12 @@ function DeckGLOverlay(props) {
function Root() {
const [selected, setSelected] = useState(null);
+ const handleMapLoad = (event) => {
+ const map = event.target;
+ patchDragMoveHandler(map.dragRotate._mousePitch);
+ patchDragMoveHandler(map.dragRotate._mouseRotate);
+ };
+
const layers = [
new GeoJsonLayer({
id: 'airports',
@@ -61,7 +75,7 @@ function Root() {
];
return (
- <Map initialViewState={INITIAL_VIEW_STATE} mapStyle={MAP_STYLE}>
+ <Map initialViewState={INITIAL_VIEW_STATE} mapStyle={MAP_STYLE} onLoad={handleMapLoad} boxZoom={false}>
{selected && (
<Popup
key={selected.properties.name} |
@HarelM is there any better way to switch the SHIFT/CTRL keys? |
@kylebarron regarding multiview: https://deck.gl/docs/api-reference/mapbox/mapbox-overlay#multi-view-usage, correct only one can have the maplibre map. It turns out you can add the deck widgets, just not the ones used to control the view state. Not sure how well supported this is though return (
<Map initialViewState={INITIAL_VIEW_STATE} mapStyle={MAP_STYLE} onLoad={handleMapLoad} boxZoom={false}>
{selected && (
<Popup
key={selected.properties.name}
@@ -73,7 +101,10 @@ function Root() {
{selected.properties.name} ({selected.properties.abbrev})
</Popup>
)}
<DeckGLOverlay layers={layers} /* interleaved*/ widgets={[
new FullscreenWidget({placement: 'bottom-left'})
]
}/>
<NavigationControl position="top-left" />
</Map>
); |
Not at the moment, but I think there was a PR that requested it, but didn't make it to the finish line. I think that configurable preset might be needed as configuring for each handler can lead to "keys configuration collision". |
This revisits and supersedes #437.
Change list
@deck.gl/mapbox
dependencyFullscreenControl
andNavigationControl
. These are placed on the top-left of the map for now, because the bounding box selection is already on the top right. But perhaps we should move the bbox selection to the left side? 🤷♂️Questions
See also more background information in #437:
I think eventually it may make sense to allow rendering deck.gl without any sort of geospatial basemap, but that's a future topic.
Closes #436, closes #842, closes #437