diff --git a/src/map-renderer.ts b/src/map-renderer.ts index 0293ab3..25ff582 100644 --- a/src/map-renderer.ts +++ b/src/map-renderer.ts @@ -9,33 +9,15 @@ import { MapView as MapViewType } from '@deck.gl/core'; import { MapTagSettings } from './settings/map-tag-settings'; import type MapPlugin from './main'; import type { ThumbnailCacheManager } from './thumbnail-cache'; -import { LatLng } from './types/latlng'; +import { LatLng } from './types/LatLng'; +import { MapPoint } from './types/MapPoint'; function easeCubic(t: number): number { return t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2; } -type PropertyValue = string | number | boolean | string[] | null; - export let currentViewState: MapViewState | null = null; -interface MapProperty { - name: string; - value: PropertyValue; -} - -export interface MapPoint { - location: LatLng.Verified; - title: string; - color?: string; - size?: number; - cover?: string; - file?: TFile; - tags?: string[]; - properties?: MapProperty[]; - polygon?: LatLng.Verified[]; -} - interface TileIndex { index: { x: number; diff --git a/src/pointutils.ts b/src/pointutils.ts deleted file mode 100644 index 4f152b5..0000000 --- a/src/pointutils.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { MapPoint } from "./map-renderer"; -import { LatLng } from "./types/latlng"; - -export function haveLocationsChanged(points1: MapPoint[], points2: MapPoint[]): boolean { - return !arePointsEqual(points1, points2); -} - -export function arePointsEqual(points1: MapPoint[], points2: MapPoint[]): boolean { - if (points1.length !== points2.length) return false; - - for (let i = 0; i < points1.length; i++) { - const p1 = points1[i]; - const p2 = points2[i]; - - if (!LatLng.equals(p1.location, p2.location) || - p1.title !== p2.title || - p1.color !== p2.color || - p1.size !== p2.size || - p1.cover !== p2.cover || - p1.file?.path !== p2.file?.path) { - return false; - } - - const tags1 = p1.tags || []; - const tags2 = p2.tags || []; - if (tags1.length !== tags2.length || !tags1.every((tag, idx) => tag === tags2[idx])) { - return false; - } - - const props1 = p1.properties || []; - const props2 = p2.properties || []; - if (props1.length !== props2.length) { - return false; - } - for (let j = 0; j < props1.length; j++) { - if (props1[j].name !== props2[j].name || props1[j].value !== props2[j].value) { - return false; - } - } - } - - return true; -} \ No newline at end of file diff --git a/src/types/MapPoint.ts b/src/types/MapPoint.ts new file mode 100644 index 0000000..e3336ee --- /dev/null +++ b/src/types/MapPoint.ts @@ -0,0 +1,82 @@ +import { TFile } from "obsidian"; +import { LatLng } from "./LatLng"; + +type PropertyValue = string | number | boolean | string[] | null; + +interface MapProperty { + name: string; + value: PropertyValue; +} + +export interface MapPoint { + location: LatLng.Verified; + title: string; + color?: string; + size?: number; + cover?: string; + file?: TFile; + tags?: string[]; + properties?: MapProperty[]; + polygon?: LatLng.Verified[]; +} + +export namespace MapPoint { + export function areSamePlace(point1: MapPoint, point2: MapPoint): boolean { + return point1.location.lat === point2.location.lat && point1.location.lng === point2.location.lng; + } + + export function areEqual(point1: MapPoint[], point2: MapPoint[]): boolean; + export function areEqual(point1: MapPoint, point2: MapPoint): boolean; + + export function areEqual( + point1: MapPoint | MapPoint[], + point2: MapPoint | MapPoint[] + ): boolean { + // Handle array case + if (Array.isArray(point1) && Array.isArray(point2)) { + if (point1.length !== point2.length) return false; + for (let i = 0; i < point1.length; i++) { + if (!areEqual(point1[i], point2[i])) return false; + } + return true; + } + + // Handle single MapPoint case + if (!Array.isArray(point1) && !Array.isArray(point2)) { + if (!LatLng.equals(point1.location, point2.location) || + point1.title !== point2.title || + point1.color !== point2.color || + point1.size !== point2.size || + point1.cover !== point2.cover || + point1.file?.path !== point2.file?.path) { + return false; + } + + const tags1 = point1.tags || []; + const tags2 = point2.tags || []; + if (tags1.length !== tags2.length || !tags1.every((tag, idx) => tag === tags2[idx])) { + return false; + } + + const props1 = point1.properties || []; + const props2 = point2.properties || []; + if (props1.length !== props2.length) { + return false; + } + for (let j = 0; j < props1.length; j++) { + if (props1[j].name !== props2[j].name || props1[j].value !== props2[j].value) { + return false; + } + } + + return true; + } + + return false; + } + + export function haveLocationsChanged(points1: MapPoint[], points2: MapPoint[]): boolean { + return !areEqual(points1, points2); + } +} + diff --git a/src/views/map-bases-view.ts b/src/views/map-bases-view.ts index 64f5bca..04e8b5b 100644 --- a/src/views/map-bases-view.ts +++ b/src/views/map-bases-view.ts @@ -11,12 +11,12 @@ import { } from 'obsidian'; import { Deck, FlyToInterpolator, MapViewState } from '@deck.gl/core'; import { MapView as MapViewType } from '@deck.gl/core'; -import { createMapRenderer, MapPoint, updateMapPoints } from '../map-renderer'; +import { createMapRenderer, updateMapPoints } from '../map-renderer'; import MapPlugin from '../main'; -import { haveLocationsChanged } from '../pointutils'; import { currentViewState } from '../map-renderer'; -import { LatLng } from '../types/latlng'; +import { LatLng } from '../types/LatLng'; import { extractFromFrontmatter } from '../utils'; +import { MapPoint } from '../types/MapPoint'; export const MapBasesViewType = 'map'; export const SEARCH_DEBOUNCE_TIME = 300; @@ -339,7 +339,7 @@ export class MapBasesView extends BasesView { const center = this.getCenter(); const hasConfiguredCenter = center.lat !== 0 || center.lng !== 0; - const locationsChanged = haveLocationsChanged(points, this.lastPoints); + const locationsChanged = MapPoint.haveLocationsChanged(points, this.lastPoints); const configChanged = this.hasConfigMeaningfullyChanged(); this.lastConfigState = { ...this.config.data }; diff --git a/src/views/map-timeline-bases-view.ts b/src/views/map-timeline-bases-view.ts index 19bb0fa..4a936c0 100644 --- a/src/views/map-timeline-bases-view.ts +++ b/src/views/map-timeline-bases-view.ts @@ -5,7 +5,7 @@ import { ViewOption, setIcon, } from 'obsidian'; -import { MapPoint } from '../map-renderer'; +import { MapPoint } from '../types/MapPoint'; import MapPlugin from '../main'; import { MapBasesView } from './map-bases-view';