mirror of
https://github.com/ccmdi/obsidian-map-plus.git
synced 2026-07-22 06:43:14 +00:00
fix: correct viewstate access
This commit is contained in:
parent
b839de62d2
commit
a8a886c43b
2 changed files with 9 additions and 4 deletions
|
|
@ -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];
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue