- Introduced a new MapBookmarkNameModal for adding and editing bookmarks. - Updated MapView to manage selected markers for bookmarking and handle bookmark name submissions. - Enhanced MapContextMenu with an option to add markers to bookmarks. - Improved MapBookmarks component to support editing bookmark names and adding selected markers. - Refactored MapControls and MapControlsContent to integrate selected marker functionality for bookmarks. - Updated useMapBookmarks composable to include bookmark updating logic. - Removed unused grid coordinates toggle from the UI for a cleaner interface.
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import L, { Bounds, LatLng, Point } from 'leaflet'
|
|
|
|
export const TileSize = 100
|
|
export const HnHMaxZoom = 6
|
|
export const HnHMinZoom = 1
|
|
export const HnHDefaultZoom = 6
|
|
|
|
export interface ImageIconOptions extends L.IconOptions {
|
|
/** When the main icon image fails to load, use this URL (e.g. data URL or default marker). */
|
|
fallbackIconUrl?: string
|
|
}
|
|
|
|
export const ImageIcon = L.Icon.extend({
|
|
options: {
|
|
iconSize: [32, 32],
|
|
iconAnchor: [16, 16],
|
|
} as ImageIconOptions,
|
|
|
|
createIcon(oldIcon?: HTMLElement): HTMLElement {
|
|
const img = L.Icon.prototype.createIcon.call(this, oldIcon) as HTMLImageElement
|
|
const fallback = (this.options as ImageIconOptions).fallbackIconUrl
|
|
if (fallback && img && img.tagName === 'IMG') {
|
|
img.onerror = () => {
|
|
img.onerror = null
|
|
img.src = fallback
|
|
}
|
|
}
|
|
return img
|
|
},
|
|
}) as unknown as new (options?: ImageIconOptions) => L.Icon
|
|
|
|
const latNormalization = (90.0 * TileSize) / 2500000.0
|
|
const lngNormalization = (180.0 * TileSize) / 2500000.0
|
|
|
|
const HnHProjection = {
|
|
project(latlng: LatLng) {
|
|
return new Point(latlng.lat / latNormalization, latlng.lng / lngNormalization)
|
|
},
|
|
unproject(point: Point) {
|
|
return new LatLng(point.x * latNormalization, point.y * lngNormalization)
|
|
},
|
|
bounds: (() => new Bounds([-latNormalization, -lngNormalization], [latNormalization, lngNormalization]))(),
|
|
}
|
|
|
|
export const HnHCRS = L.extend({}, L.CRS.Simple, {
|
|
projection: HnHProjection,
|
|
}) as L.CRS
|