fix: correct viewstate access

This commit is contained in:
ccmdi 2025-11-23 09:24:08 -05:00
parent b839de62d2
commit a8a886c43b
No known key found for this signature in database
2 changed files with 9 additions and 4 deletions

View file

@ -16,6 +16,8 @@ function easeCubic(t: number): number {
type PropertyValue = string | number | boolean | string[] | null;
export let currentViewState: MapViewState | null = null;
interface MapProperty {
name: string;
value: PropertyValue;
@ -708,6 +710,9 @@ export function createMapRenderer(config: MapRendererOptions): Deck<MapViewType[
return layers;
})(),
onViewStateChange: ({ viewState: newViewState }) => {
currentViewState = newViewState;
}
});
mapCanvas.addEventListener('contextmenu', (e: MouseEvent) => {
@ -717,9 +722,8 @@ export function createMapRenderer(config: MapRendererOptions): Deck<MapViewType[
const rect = mapCanvas.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
const viewState = deck.props.viewState?.MapView;
const viewState = currentViewState;
if (viewState) {
const viewport = deck.getViewports()[0];
const [lng, lat] = viewport?.unproject([x, y]) || [0, 0];

View file

@ -14,6 +14,7 @@ import { MapView as MapViewType } from '@deck.gl/core';
import { createMapRenderer, MapPoint, updateMapPoints } from '../map-renderer';
import MapPlugin from '../main';
import { haveLocationsChanged } from '../pointutils';
import { currentViewState } from '../map-renderer';
export const MapBasesViewType = 'map';
@ -75,7 +76,7 @@ export class MapBasesView extends BasesView {
private destroyMap(): void {
if (this.deck) {
try {
const viewState = this.deck.props.viewState?.MapView;
const viewState = currentViewState;
if (viewState) {
this.savedViewState = viewState;
}