|
1 | 1 | import { MapboxOverlay, MapboxOverlayProps } from "@deck.gl/mapbox"; |
2 | 2 | import React from "react"; |
3 | | -import Map, { useControl } from "react-map-gl/maplibre"; |
| 3 | +import Map, { useControl, ViewStateChangeEvent } from "react-map-gl/maplibre"; |
4 | 4 |
|
5 | 5 | import type { MapRendererProps, OverlayRendererProps } from "./types"; |
6 | 6 | import { isGlobeView } from "../util"; |
@@ -35,15 +35,29 @@ const OverlayRenderer: React.FC<MapRendererProps & OverlayRendererProps> = ( |
35 | 35 | customAttribution, |
36 | 36 | initialViewState, |
37 | 37 | views, |
| 38 | + onViewStateChange, |
38 | 39 | ...deckProps |
39 | 40 | } = mapProps; |
| 41 | + const onMoveEnd = onViewStateChange |
| 42 | + ? (evt: ViewStateChangeEvent) => { |
| 43 | + const viewState = { |
| 44 | + longitude: evt.viewState.longitude, |
| 45 | + latitude: evt.viewState.latitude, |
| 46 | + zoom: evt.viewState.zoom, |
| 47 | + pitch: evt.viewState.pitch, |
| 48 | + bearing: evt.viewState.bearing, |
| 49 | + }; |
| 50 | + onViewStateChange({ viewId: "mapLibreId", viewState }); |
| 51 | + } |
| 52 | + : undefined; |
40 | 53 | return ( |
41 | 54 | <Map |
42 | 55 | reuseMaps |
43 | 56 | initialViewState={initialViewState} |
44 | 57 | mapStyle={mapStyle} |
45 | 58 | attributionControl={{ customAttribution }} |
46 | 59 | style={{ width: "100%", height: "100%" }} |
| 60 | + onMoveEnd={onMoveEnd} |
47 | 61 | {...(isGlobeView(views) && { projection: "globe" })} |
48 | 62 | > |
49 | 63 | {controls.map((control) => control.renderMaplibre())} |
|
0 commit comments