isard 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/CHANGELOG.md +134 -14
  2. package/README.md +2 -2
  3. package/dist/animation.d.ts +18 -0
  4. package/dist/animation.js +84 -0
  5. package/dist/animation.js.map +1 -0
  6. package/dist/basemap.worker.d.ts +26 -1
  7. package/dist/basemap.worker.js +2 -2
  8. package/dist/basemap.worker.js.map +8 -4
  9. package/dist/basemaps.d.ts +5 -3
  10. package/dist/basemaps.js +5 -3
  11. package/dist/basemaps.js.map +1 -1
  12. package/dist/crs.d.ts +72 -0
  13. package/dist/crs.js +243 -0
  14. package/dist/crs.js.map +1 -0
  15. package/dist/decoder.worker.js +4 -4
  16. package/dist/decoder.worker.js.map +4 -4
  17. package/dist/engine-loader.d.ts +27 -0
  18. package/dist/engine-loader.js +112 -0
  19. package/dist/engine-loader.js.map +1 -0
  20. package/dist/extrusions.js +11 -2
  21. package/dist/extrusions.js.map +1 -1
  22. package/dist/features.d.ts +8 -0
  23. package/dist/features.js +17 -10
  24. package/dist/features.js.map +1 -1
  25. package/dist/geo.d.ts +16 -0
  26. package/dist/geo.js +32 -0
  27. package/dist/geo.js.map +1 -0
  28. package/dist/geoplateforme.d.ts +21 -5
  29. package/dist/geoplateforme.js +47 -12
  30. package/dist/geoplateforme.js.map +1 -1
  31. package/dist/glyphs.d.ts +10 -3
  32. package/dist/glyphs.js +14 -2
  33. package/dist/glyphs.js.map +1 -1
  34. package/dist/gpx.d.ts +11 -0
  35. package/dist/gpx.js +74 -0
  36. package/dist/gpx.js.map +1 -0
  37. package/dist/grid.d.ts +81 -0
  38. package/dist/grid.js +270 -0
  39. package/dist/grid.js.map +1 -0
  40. package/dist/index.d.ts +7 -1
  41. package/dist/index.js +5 -0
  42. package/dist/index.js.map +1 -1
  43. package/dist/interaction.d.ts +3 -4
  44. package/dist/interaction.js +27 -7
  45. package/dist/interaction.js.map +1 -1
  46. package/dist/isard_bg.wasm +0 -0
  47. package/dist/isard_core_bg.wasm +0 -0
  48. package/dist/kml.d.ts +12 -0
  49. package/dist/kml.js +159 -0
  50. package/dist/kml.js.map +1 -0
  51. package/dist/layers.d.ts +5 -2
  52. package/dist/layers.js +22 -18
  53. package/dist/layers.js.map +1 -1
  54. package/dist/lru.d.ts +22 -0
  55. package/dist/lru.js +52 -0
  56. package/dist/lru.js.map +1 -0
  57. package/dist/map.d.ts +26 -6
  58. package/dist/map.js +196 -287
  59. package/dist/map.js.map +1 -1
  60. package/dist/resample.d.ts +41 -0
  61. package/dist/resample.js +164 -0
  62. package/dist/resample.js.map +1 -0
  63. package/dist/settings.d.ts +39 -0
  64. package/dist/settings.js +104 -0
  65. package/dist/settings.js.map +1 -0
  66. package/dist/symbols.d.ts +12 -1
  67. package/dist/symbols.js +124 -26
  68. package/dist/symbols.js.map +1 -1
  69. package/dist/terrain.d.ts +19 -7
  70. package/dist/terrain.js +50 -26
  71. package/dist/terrain.js.map +1 -1
  72. package/dist/topojson.d.ts +29 -0
  73. package/dist/topojson.js +66 -0
  74. package/dist/topojson.js.map +1 -0
  75. package/dist/types.d.ts +23 -7
  76. package/dist/types.js.map +1 -1
  77. package/dist/vectortiles.d.ts +13 -3
  78. package/dist/vectortiles.js +85 -46
  79. package/dist/vectortiles.js.map +1 -1
  80. package/dist/wasm/isard.d.ts +14 -7
  81. package/dist/wasm/isard.js +33 -10
  82. package/dist/wasm/isard_core.d.ts +6 -5
  83. package/dist/wasm/isard_core.js +41 -10
  84. package/dist/wmts.d.ts +14 -0
  85. package/dist/wmts.js +76 -0
  86. package/dist/wmts.js.map +1 -0
  87. package/dist/xml.d.ts +26 -0
  88. package/dist/xml.js +109 -0
  89. package/dist/xml.js.map +1 -0
  90. package/package.json +1 -1
  91. package/dist/equirectangular.d.ts +0 -35
  92. package/dist/equirectangular.js +0 -113
  93. package/dist/equirectangular.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":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C;IAED,gGAAgG;IACxF,MAAM,CAAC,KAAa,EAAE,EAAS,EAAE,MAAM,GAAG,KAAK;QACrD,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YAC5C,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;YACzB,OAAO;QACT,CAAC;QACD,wEAAwE;QACxE,IAAI,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC;QAC5B,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE;YACpB,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,UAAU,CAAC;YACzG,IAAI,CAAC,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC;YAC3B,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YACjE,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,KAAK,CAAC,CAAC;QAClC,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["/**\n * Mouse, touch and keyboard controls. Every gesture only updates the camera and asks for a frame: the engine draws at most\n * once per display refresh, whatever the event rate of the device.\n */\nimport type { GeoMap } from './map.ts';\nimport type { Point } from './types.ts';\nimport type { Camera } from './wasm/isard.js';\n\n/** Zoom levels per wheel pixel (a mouse notch is about 100 px: 1/3 of a level) */\nconst WHEEL_RATE = 1 / 300;\n/** Share of the remaining wheel zoom applied per frame (smooth, about 150 ms to settle) */\nconst WHEEL_EASE = 0.3;\n/** Degrees per pixel when rotating or tilting with the mouse */\nconst ROTATE_RATE = 0.4;\n/** A press that moves less than this (CSS pixels) is a click */\nconst CLICK_TOLERANCE = 4;\n/** Pan speed kept on release, decaying with this time constant (ms) */\nconst INERTIA_DECAY = 280;\n\n/** CSS pixels per arrow key press */\nconst KEY_PAN = 100;\n/** Degrees per Shift + left or right arrow */\nconst KEY_BEARING = 15;\n/** Degrees per Shift + up or down arrow */\nconst KEY_PITCH = 10;\n/** Duration of the moves made by keys, milliseconds */\nconst KEY_DURATION = 300;\n\n/** What a key does to the camera: a pan in CSS pixels, a zoom, rotation or tilt step, or facing north */\nexport type KeyAction = { pan: Point } | { zoom: number } | { bearing: number } | { pitch: number } | { reset: true };\n\n/** The action of a key (`KeyboardEvent.key`), as MapLibre's: arrows pan (with Shift: rotate and tilt), + and - zoom\n * (with Shift: two levels), 0 faces north and levels the view */\nexport function keyAction(key: string, shift: boolean): KeyAction | undefined {\n switch (key) {\n case 'ArrowLeft':\n return shift ? { bearing: -KEY_BEARING } : { pan: [-KEY_PAN, 0] };\n case 'ArrowRight':\n return shift ? { bearing: KEY_BEARING } : { pan: [KEY_PAN, 0] };\n case 'ArrowUp':\n return shift ? { pitch: KEY_PITCH } : { pan: [0, -KEY_PAN] };\n case 'ArrowDown':\n return shift ? { pitch: -KEY_PITCH } : { pan: [0, KEY_PAN] };\n case '+':\n case '=':\n return { zoom: shift ? 2 : 1 };\n case '-':\n case '_':\n return { zoom: shift ? -2 : -1 };\n case '0':\n return { reset: true };\n default:\n return undefined;\n }\n}\n\n/** The camera after a key's action: a pan moves the center by that many CSS pixels on screen (the ground in view,\n * turned with the bearing, stretched by the tilt) */\nexport function keyCamera(action: KeyAction, camera: Camera): Partial<Camera> {\n if ('zoom' in action) return { zoom: camera.zoom + action.zoom };\n if ('bearing' in action) return { bearing: camera.bearing + action.bearing };\n if ('pitch' in action) return { pitch: Math.max(0, camera.pitch + action.pitch) };\n if ('reset' in action) return { bearing: 0, pitch: 0 };\n const b = (camera.bearing * Math.PI) / 180;\n const [sx, sy] = [action.pan[0], action.pan[1] / Math.max(0.25, Math.cos((camera.pitch * Math.PI) / 180))];\n // Web Mercator units (0 to 1 across the world, y down); the world is 512 CSS pixels at zoom 0\n const world = 512 * 2 ** camera.zoom;\n const dx = (sx * Math.cos(b) - sy * Math.sin(b)) / world;\n const dy = (sx * Math.sin(b) + sy * Math.cos(b)) / world;\n const [lon, lat] = camera.center;\n const phi = (Math.max(-85.0511, Math.min(85.0511, lat)) * Math.PI) / 180;\n const x = (lon + 180) / 360 + dx;\n const y = Math.max(0, Math.min(1, (1 - Math.log(Math.tan(phi) + 1 / Math.cos(phi)) / Math.PI) / 2 + dy));\n const wrapped = ((((x * 360) % 360) + 360) % 360) - 180;\n return { center: [wrapped, (Math.atan(Math.sinh(Math.PI * (1 - 2 * y))) * 180) / Math.PI] };\n}\n\n/** An element that takes the keys typed in it */\nfunction editable(target: EventTarget | null): boolean {\n if (!(target instanceof HTMLElement)) return false;\n return target.isContentEditable || ['INPUT', 'TEXTAREA', 'SELECT'].includes(target.tagName);\n}\n\ninterface Pointer {\n point: Point;\n start: Point;\n button: number;\n rotate: boolean;\n}\n\nexport class Interaction {\n private readonly pointers = new Map<number, Pointer>();\n private readonly cleanup: (() => void)[] = [];\n private wheel = { pending: 0, at: [0, 0] as Point };\n /** Recent pan moves, for the release speed: [time, dx, dy] */\n private trail: [number, number, number][] = [];\n private moved = false;\n\n constructor(\n private readonly map: GeoMap,\n options: { keyboard?: boolean } = {},\n ) {\n const canvas = map.canvas;\n const listen = <K extends keyof HTMLElementEventMap>(\n type: K,\n handler: (e: HTMLElementEventMap[K]) => void,\n options?: AddEventListenerOptions,\n ) => {\n canvas.addEventListener(type, handler, options);\n this.cleanup.push(() => canvas.removeEventListener(type, handler));\n };\n listen('pointerdown', (e) => this.down(e));\n listen('pointermove', (e) => this.move(e));\n listen('pointerup', (e) => this.up(e));\n listen('pointercancel', (e) => this.up(e));\n listen('pointerleave', (e) => {\n if (e.pointerType !== 'mouse') return;\n map.hover(undefined);\n map.emit('leave', {});\n });\n // On the container, the wheel zooms over markers and popups too\n const container = map.getContainer();\n const wheel = (e: WheelEvent) => this.onWheel(e);\n container.addEventListener('wheel', wheel, { passive: false });\n this.cleanup.push(() => container.removeEventListener('wheel', wheel));\n listen('dblclick', (e) => this.zoomBy(e.shiftKey ? -1 : 1, this.local(e)));\n listen('contextmenu', (e) => e.preventDefault());\n if (options.keyboard ?? true) {\n // On the container: the keys work with the focus on a marker or a control too\n const key = (e: KeyboardEvent) => this.onKey(e);\n container.addEventListener('keydown', key);\n this.cleanup.push(() => container.removeEventListener('keydown', key));\n }\n }\n\n destroy(): void {\n for (const off of this.cleanup) off();\n }\n\n /** A gesture holds the map (pointers down): the camera has not stopped moving */\n get active(): boolean {\n return this.pointers.size > 0;\n }\n\n private local(e: MouseEvent): Point {\n const r = this.map.canvas.getBoundingClientRect();\n return [e.clientX - r.left, e.clientY - r.top];\n }\n\n private down(e: PointerEvent): void {\n this.map.canvas.setPointerCapture(e.pointerId);\n const point = this.local(e);\n const rotate = e.button === 2 || e.ctrlKey || e.shiftKey;\n this.pointers.set(e.pointerId, { point, start: point, button: e.button, rotate });\n this.trail = [];\n this.moved = false;\n // Grabbing the map stops any running animation (inertia, wheel zoom, easeTo)\n this.wheel.pending = 0;\n this.map.animate(undefined);\n }\n\n private move(e: PointerEvent): void {\n const point = this.local(e);\n const p = this.pointers.get(e.pointerId);\n if (!p) {\n if (e.pointerType === 'mouse') this.map.hover(point);\n return;\n }\n const [dx, dy] = [point[0] - p.point[0], point[1] - p.point[1]];\n if (Math.hypot(point[0] - p.start[0], point[1] - p.start[1]) > CLICK_TOLERANCE) this.moved = true;\n const engine = this.map.engine;\n const other = [...this.pointers.values()].find((q) => q !== p);\n if (this.pointers.size === 2 && other) {\n // Pinch: zoom by the change of spread, turn by the change of angle, pan by the midpoint\n const before = Math.hypot(p.point[0] - other.point[0], p.point[1] - other.point[1]);\n const after = Math.hypot(point[0] - other.point[0], point[1] - other.point[1]);\n const angle = (q: Point) => Math.atan2(q[1] - other.point[1], q[0] - other.point[0]);\n const mid = (q: Point): Point => [(q[0] + other.point[0]) / 2, (q[1] + other.point[1]) / 2];\n engine.pan(...mid(p.point), ...mid(point));\n if (before > 0 && after > 0) engine.zoomAt(Math.log2(after / before), ...mid(point));\n engine.rotate((-(angle(point) - angle(p.point)) * 180) / Math.PI, 0);\n } else if (p.rotate) {\n engine.rotate(-dx * ROTATE_RATE, -dy * ROTATE_RATE);\n } else {\n engine.pan(p.point[0], p.point[1], point[0], point[1]);\n this.trail.push([e.timeStamp, dx, dy]);\n }\n p.point = point;\n this.map.requestRender();\n }\n\n private up(e: PointerEvent): void {\n const p = this.pointers.get(e.pointerId);\n if (!p) return;\n this.pointers.delete(e.pointerId);\n // The next frame sends 'moveend' if the camera stays\n this.map.requestRender();\n if (!this.moved && e.type === 'pointerup' && p.button === 0 && this.pointers.size === 0) {\n this.map.emit('click', { point: p.point, lonLat: this.map.unproject(p.point) });\n return;\n }\n if (!p.rotate && this.pointers.size === 0) this.inertia(e.timeStamp, p.point);\n }\n\n /** Keeps panning at the release speed (last 50 ms), decaying exponentially */\n private inertia(now: number, from: Point): void {\n const recent = this.trail.filter(([t]) => now - t < 50);\n const first = recent[0];\n if (!first || recent.length < 2) return;\n const span = Math.max(16, now - first[0]);\n let vx = recent.reduce((s, [, dx]) => s + dx, 0) / span;\n let vy = recent.reduce((s, [, , dy]) => s + dy, 0) / span;\n if (Math.hypot(vx, vy) < 0.1) return;\n let last = performance.now();\n let point = from;\n this.map.animate((t) => {\n const dt = Math.min(64, t - last);\n last = t;\n const decay = Math.exp(-dt / INERTIA_DECAY);\n const next: Point = [point[0] + vx * dt, point[1] + vy * dt];\n this.map.engine.pan(point[0], point[1], next[0], next[1]);\n point = next;\n vx *= decay;\n vy *= decay;\n return Math.hypot(vx, vy) > 0.02;\n });\n }\n\n private onWheel(e: WheelEvent): void {\n e.preventDefault();\n // Lines (Firefox mouse wheels) are about 33 px\n const pixels = e.deltaMode === 1 ? e.deltaY * 33 : e.deltaY;\n this.zoomBy(\n Math.max(-1, Math.min(1, -pixels * WHEEL_RATE)),\n this.local(e),\n e.deltaMode === 0 && Math.abs(pixels) < 40,\n );\n }\n\n private onKey(e: KeyboardEvent): void {\n if (e.defaultPrevented || e.ctrlKey || e.metaKey || e.altKey || editable(e.target)) return;\n const action = keyAction(e.key, e.shiftKey);\n if (!action) return;\n e.preventDefault();\n this.wheel.pending = 0;\n const reduced = typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;\n this.map.easeTo(keyCamera(action, this.map.getCamera()), reduced ? 0 : KEY_DURATION);\n }\n\n /** Smooth zoom around a screen point; touchpads (`direct`) follow the fingers without easing */\n private zoomBy(delta: number, at: Point, direct = false): void {\n if (direct) {\n this.map.engine.zoomAt(delta, at[0], at[1]);\n this.map.requestRender();\n return;\n }\n // Accumulate: a second notch before the end of the first one adds to it\n this.wheel.pending += delta;\n this.wheel.at = at;\n this.map.animate(() => {\n const step = Math.abs(this.wheel.pending) < 0.002 ? this.wheel.pending : this.wheel.pending * WHEEL_EASE;\n this.wheel.pending -= step;\n this.map.engine.zoomAt(step, this.wheel.at[0], this.wheel.at[1]);\n return this.wheel.pending !== 0;\n });\n }\n}\n"]}
1
+ {"version":3,"file":"interaction.js","sourceRoot":"","sources":["../src/interaction.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAK1D,kFAAkF;AAClF,MAAM,UAAU,GAAG,CAAC,GAAG,GAAG,CAAC;AAC3B,2FAA2F;AAC3F,MAAM,UAAU,GAAG,GAAG,CAAC;AACvB,gEAAgE;AAChE,MAAM,WAAW,GAAG,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vF,CAAC;IAED,gGAAgG;IACxF,MAAM,CAAC,KAAa,EAAE,EAAS,EAAE,MAAM,GAAG,KAAK;QACrD,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YAC5C,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;YACzB,OAAO;QACT,CAAC;QACD,wEAAwE;QACxE,IAAI,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC;QAC5B,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE;YACpB,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,UAAU,CAAC;YACzG,IAAI,CAAC,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC;YAC3B,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YACjE,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,KAAK,CAAC,CAAC;QAClC,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["/**\n * Mouse, touch and keyboard controls. Every gesture only updates the camera and asks for a frame: the engine draws at most\n * once per display refresh, whatever the event rate of the device.\n */\nimport { latitude, mercatorX, mercatorY } from './geo.ts';\nimport type { GeoMap } from './map.ts';\nimport type { Point } from './types.ts';\nimport type { Camera } from './wasm/isard.js';\n\n/** Zoom levels per wheel pixel (a mouse notch is about 100 px: 1/3 of a level) */\nconst WHEEL_RATE = 1 / 300;\n/** Share of the remaining wheel zoom applied per frame (smooth, about 150 ms to settle) */\nconst WHEEL_EASE = 0.3;\n/** Degrees per pixel when rotating or tilting with the mouse */\nconst ROTATE_RATE = 0.4;\n/** A press that moves less than this (CSS pixels) is a click */\nconst CLICK_TOLERANCE = 4;\n/** Pan speed kept on release, decaying with this time constant (ms) */\nconst INERTIA_DECAY = 280;\n\n/** CSS pixels per arrow key press */\nconst KEY_PAN = 100;\n/** Degrees per Shift + left or right arrow */\nconst KEY_BEARING = 15;\n/** Degrees per Shift + up or down arrow */\nconst KEY_PITCH = 10;\n/** Duration of the moves made by keys, milliseconds */\nconst KEY_DURATION = 300;\n\n/** What a key does to the camera: a pan in CSS pixels, a zoom, rotation or tilt step, or facing north */\nexport type KeyAction = { pan: Point } | { zoom: number } | { bearing: number } | { pitch: number } | { reset: true };\n\n/** The action of a key (`KeyboardEvent.key`), as MapLibre's: arrows pan (with Shift: rotate and tilt), + and - zoom\n * (with Shift: two levels), 0 faces north and levels the view */\nexport function keyAction(key: string, shift: boolean): KeyAction | undefined {\n switch (key) {\n case 'ArrowLeft':\n return shift ? { bearing: -KEY_BEARING } : { pan: [-KEY_PAN, 0] };\n case 'ArrowRight':\n return shift ? { bearing: KEY_BEARING } : { pan: [KEY_PAN, 0] };\n case 'ArrowUp':\n return shift ? { pitch: KEY_PITCH } : { pan: [0, -KEY_PAN] };\n case 'ArrowDown':\n return shift ? { pitch: -KEY_PITCH } : { pan: [0, KEY_PAN] };\n case '+':\n case '=':\n return { zoom: shift ? 2 : 1 };\n case '-':\n case '_':\n return { zoom: shift ? -2 : -1 };\n case '0':\n return { reset: true };\n default:\n return undefined;\n }\n}\n\n/** The camera after a key's action: a pan moves the center by that many CSS pixels on screen (the ground in view,\n * turned with the bearing, stretched by the tilt) */\nexport function keyCamera(action: KeyAction, camera: Camera): Partial<Camera> {\n if ('zoom' in action) return { zoom: camera.zoom + action.zoom };\n if ('bearing' in action) return { bearing: camera.bearing + action.bearing };\n if ('pitch' in action) return { pitch: Math.max(0, camera.pitch + action.pitch) };\n if ('reset' in action) return { bearing: 0, pitch: 0 };\n const b = (camera.bearing * Math.PI) / 180;\n const [sx, sy] = [action.pan[0], action.pan[1] / Math.max(0.25, Math.cos((camera.pitch * Math.PI) / 180))];\n // Web Mercator units (0 to 1 across the world, y down); the world is 512 CSS pixels at zoom 0\n const world = 512 * 2 ** camera.zoom;\n const dx = (sx * Math.cos(b) - sy * Math.sin(b)) / world;\n const dy = (sx * Math.sin(b) + sy * Math.cos(b)) / world;\n const [lon, lat] = camera.center;\n const x = mercatorX(lon) + dx;\n const y = Math.max(0, Math.min(1, mercatorY(lat) + dy));\n const wrapped = ((((x * 360) % 360) + 360) % 360) - 180;\n return { center: [wrapped, latitude(y)] };\n}\n\n/** An element that takes the keys typed in it */\nfunction editable(target: EventTarget | null): boolean {\n if (!(target instanceof HTMLElement)) return false;\n return target.isContentEditable || ['INPUT', 'TEXTAREA', 'SELECT'].includes(target.tagName);\n}\n\ninterface Pointer {\n point: Point;\n start: Point;\n button: number;\n rotate: boolean;\n}\n\nexport class Interaction {\n private readonly pointers = new Map<number, Pointer>();\n private readonly cleanup: (() => void)[] = [];\n private wheel = { pending: 0, at: [0, 0] as Point };\n /** Recent pan moves, for the release speed: [time, dx, dy] */\n private trail: [number, number, number][] = [];\n private moved = false;\n /** The canvas's place on the page, read once: reading it on every pointer move would force a layout each time.\n * Read again after a resize, a scroll, and when a pointer comes in or goes down */\n private rect: DOMRect | undefined;\n\n constructor(\n private readonly map: GeoMap,\n options: { keyboard?: boolean } = {},\n ) {\n const canvas = map.canvas;\n const listen = <K extends keyof HTMLElementEventMap>(\n type: K,\n handler: (e: HTMLElementEventMap[K]) => void,\n options?: AddEventListenerOptions,\n ) => {\n canvas.addEventListener(type, handler, options);\n this.cleanup.push(() => canvas.removeEventListener(type, handler));\n };\n const moved = () => {\n this.rect = undefined;\n };\n listen('pointerenter', moved);\n // Scrolls of the page or of any element holding the map\n if (typeof addEventListener === 'function') {\n addEventListener('scroll', moved, { capture: true, passive: true });\n this.cleanup.push(() => removeEventListener('scroll', moved, { capture: true }));\n }\n this.cleanup.push(map.on('resize', moved));\n listen('pointerdown', (e) => {\n this.rect = undefined;\n this.down(e);\n });\n listen('pointermove', (e) => this.move(e));\n listen('pointerup', (e) => this.up(e));\n listen('pointercancel', (e) => this.up(e));\n listen('pointerleave', (e) => {\n if (e.pointerType !== 'mouse') return;\n map.hover(undefined);\n map.emit('leave', {});\n });\n // On the container, the wheel zooms over markers and popups too\n const container = map.getContainer();\n const wheel = (e: WheelEvent) => this.onWheel(e);\n container.addEventListener('wheel', wheel, { passive: false });\n this.cleanup.push(() => container.removeEventListener('wheel', wheel));\n listen('dblclick', (e) => this.zoomBy(e.shiftKey ? -1 : 1, this.local(e)));\n listen('contextmenu', (e) => e.preventDefault());\n if (options.keyboard ?? true) {\n // On the container: the keys work with the focus on a marker or a control too\n const key = (e: KeyboardEvent) => this.onKey(e);\n container.addEventListener('keydown', key);\n this.cleanup.push(() => container.removeEventListener('keydown', key));\n }\n }\n\n destroy(): void {\n for (const off of this.cleanup) off();\n }\n\n /** A gesture holds the map (pointers down): the camera has not stopped moving */\n get active(): boolean {\n return this.pointers.size > 0;\n }\n\n private local(e: MouseEvent): Point {\n this.rect ??= this.map.canvas.getBoundingClientRect();\n return [e.clientX - this.rect.left, e.clientY - this.rect.top];\n }\n\n private down(e: PointerEvent): void {\n this.map.canvas.setPointerCapture(e.pointerId);\n const point = this.local(e);\n const rotate = e.button === 2 || e.ctrlKey || e.shiftKey;\n this.pointers.set(e.pointerId, { point, start: point, button: e.button, rotate });\n this.trail = [];\n this.moved = false;\n // Grabbing the map stops any running animation (inertia, wheel zoom, easeTo)\n this.wheel.pending = 0;\n this.map.animate(undefined);\n }\n\n private move(e: PointerEvent): void {\n const point = this.local(e);\n const p = this.pointers.get(e.pointerId);\n if (!p) {\n if (e.pointerType === 'mouse') this.map.hover(point);\n return;\n }\n const [dx, dy] = [point[0] - p.point[0], point[1] - p.point[1]];\n if (Math.hypot(point[0] - p.start[0], point[1] - p.start[1]) > CLICK_TOLERANCE) this.moved = true;\n const engine = this.map.engine;\n const other = [...this.pointers.values()].find((q) => q !== p);\n if (this.pointers.size === 2 && other) {\n // Pinch: zoom by the change of spread, turn by the change of angle, pan by the midpoint\n const before = Math.hypot(p.point[0] - other.point[0], p.point[1] - other.point[1]);\n const after = Math.hypot(point[0] - other.point[0], point[1] - other.point[1]);\n const angle = (q: Point) => Math.atan2(q[1] - other.point[1], q[0] - other.point[0]);\n const mid = (q: Point): Point => [(q[0] + other.point[0]) / 2, (q[1] + other.point[1]) / 2];\n engine.pan(...mid(p.point), ...mid(point));\n if (before > 0 && after > 0) engine.zoomAt(Math.log2(after / before), ...mid(point));\n engine.rotate((-(angle(point) - angle(p.point)) * 180) / Math.PI, 0);\n } else if (p.rotate) {\n engine.rotate(-dx * ROTATE_RATE, -dy * ROTATE_RATE);\n } else {\n engine.pan(p.point[0], p.point[1], point[0], point[1]);\n this.trail.push([e.timeStamp, dx, dy]);\n }\n p.point = point;\n this.map.requestRender();\n }\n\n private up(e: PointerEvent): void {\n const p = this.pointers.get(e.pointerId);\n if (!p) return;\n this.pointers.delete(e.pointerId);\n // The next frame sends 'moveend' if the camera stays\n this.map.requestRender();\n if (!this.moved && e.type === 'pointerup' && p.button === 0 && this.pointers.size === 0) {\n this.map.emit('click', { point: p.point, lonLat: this.map.unproject(p.point) });\n return;\n }\n if (!p.rotate && this.pointers.size === 0) this.inertia(e.timeStamp, p.point);\n }\n\n /** Keeps panning at the release speed (last 50 ms), decaying exponentially */\n private inertia(now: number, from: Point): void {\n const recent = this.trail.filter(([t]) => now - t < 50);\n const first = recent[0];\n if (!first || recent.length < 2) return;\n const span = Math.max(16, now - first[0]);\n let vx = recent.reduce((s, [, dx]) => s + dx, 0) / span;\n let vy = recent.reduce((s, [, , dy]) => s + dy, 0) / span;\n if (Math.hypot(vx, vy) < 0.1) return;\n let last = performance.now();\n let point = from;\n this.map.animate((t) => {\n const dt = Math.min(64, t - last);\n last = t;\n const decay = Math.exp(-dt / INERTIA_DECAY);\n const next: Point = [point[0] + vx * dt, point[1] + vy * dt];\n this.map.engine.pan(point[0], point[1], next[0], next[1]);\n point = next;\n vx *= decay;\n vy *= decay;\n return Math.hypot(vx, vy) > 0.02;\n });\n }\n\n private onWheel(e: WheelEvent): void {\n e.preventDefault();\n // Lines (Firefox mouse wheels) are about 33 px\n const pixels = e.deltaMode === 1 ? e.deltaY * 33 : e.deltaY;\n this.zoomBy(\n Math.max(-1, Math.min(1, -pixels * WHEEL_RATE)),\n this.local(e),\n e.deltaMode === 0 && Math.abs(pixels) < 40,\n );\n }\n\n private onKey(e: KeyboardEvent): void {\n if (e.defaultPrevented || e.ctrlKey || e.metaKey || e.altKey || editable(e.target)) return;\n const action = keyAction(e.key, e.shiftKey);\n if (!action) return;\n e.preventDefault();\n this.wheel.pending = 0;\n const reduced = typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;\n this.map.easeTo(keyCamera(action, this.map.getCamera()), reduced ? 0 : KEY_DURATION);\n }\n\n /** Smooth zoom around a screen point; touchpads (`direct`) follow the fingers without easing */\n private zoomBy(delta: number, at: Point, direct = false): void {\n if (direct) {\n this.map.engine.zoomAt(delta, at[0], at[1]);\n this.map.requestRender();\n return;\n }\n // Accumulate: a second notch before the end of the first one adds to it\n this.wheel.pending += delta;\n this.wheel.at = at;\n this.map.animate(() => {\n const step = Math.abs(this.wheel.pending) < 0.002 ? this.wheel.pending : this.wheel.pending * WHEEL_EASE;\n this.wheel.pending -= step;\n this.map.engine.zoomAt(step, this.wheel.at[0], this.wheel.at[1]);\n return this.wheel.pending !== 0;\n });\n }\n}\n"]}
Binary file
Binary file
package/dist/kml.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * KML to GeoJSON, for the feature layers: `map.addLines({ data: parseKml(await (await fetch(url)).text()) })`.
3
+ */
4
+ import type { FeatureCollection, Properties } from './features.ts';
5
+ /**
6
+ * The placemarks of a KML document as GeoJSON features: their points, lines (and gx:Track), polygons (with their
7
+ * holes) and MultiGeometry (a Multi… of one type, else a GeometryCollection); their `name`, `description`, extended
8
+ * data (`Data`, `SimpleData`) as properties, and the colors of their style (inline, or shared through `styleUrl` and
9
+ * `StyleMap`) as `stroke`, `stroke-opacity`, `stroke-width`, `fill`, `fill-opacity`, `marker-color`. A placemark
10
+ * without geometry has a null one
11
+ */
12
+ export declare function parseKml<P = Properties>(text: string): FeatureCollection<P>;
package/dist/kml.js ADDED
@@ -0,0 +1,159 @@
1
+ import { child, children, childText, descendants, parseXml } from "./xml.js";
2
+ /** Positions of a `coordinates` element: `lon,lat[,alt]` tuples separated by spaces */
3
+ function positions(element) {
4
+ const out = [];
5
+ for (const tuple of (element?.text ?? '').trim().split(/\s+/)) {
6
+ const values = tuple.split(',').map(Number);
7
+ if (values.length >= 2 && values.every(Number.isFinite))
8
+ out.push(values);
9
+ }
10
+ return out;
11
+ }
12
+ /** The geometries of an element (a Placemark, a MultiGeometry), in order */
13
+ function geometries(parent) {
14
+ const out = [];
15
+ for (const g of parent.children) {
16
+ if (g.name === 'Point') {
17
+ const [p] = positions(child(g, 'coordinates'));
18
+ if (p)
19
+ out.push({ type: 'Point', coordinates: p });
20
+ }
21
+ else if (g.name === 'LineString' || g.name === 'LinearRing') {
22
+ const line = positions(child(g, 'coordinates'));
23
+ if (line.length >= 2)
24
+ out.push({ type: 'LineString', coordinates: line });
25
+ }
26
+ else if (g.name === 'Polygon') {
27
+ const ring = (b) => positions(child(child(b, 'LinearRing'), 'coordinates'));
28
+ const outer = child(g, 'outerBoundaryIs');
29
+ const rings = [...(outer ? [ring(outer)] : []), ...children(g, 'innerBoundaryIs').map(ring)];
30
+ if ((rings[0]?.length ?? 0) >= 4)
31
+ out.push({ type: 'Polygon', coordinates: rings.filter((r) => r.length >= 4) });
32
+ }
33
+ else if (g.name === 'Track') {
34
+ // gx:Track: its gx:coord, `lon lat alt`
35
+ const line = children(g, 'coord')
36
+ .map((c) => c.text.trim().split(/\s+/).map(Number))
37
+ .filter((p) => p.length >= 2 && p.every(Number.isFinite));
38
+ if (line.length >= 2)
39
+ out.push({ type: 'LineString', coordinates: line });
40
+ }
41
+ else if (g.name === 'MultiGeometry' || g.name === 'MultiTrack') {
42
+ out.push(...geometries(g));
43
+ }
44
+ }
45
+ return out;
46
+ }
47
+ /** One geometry of several: a Multi… of one type, else a collection */
48
+ function merge(list) {
49
+ const [first] = list;
50
+ if (!first)
51
+ return null;
52
+ if (list.length === 1)
53
+ return first;
54
+ const same = list.every((g) => g.type === first.type);
55
+ if (same && first.type === 'Point') {
56
+ return { type: 'MultiPoint', coordinates: list.map((g) => g.coordinates) };
57
+ }
58
+ if (same && first.type === 'LineString') {
59
+ return { type: 'MultiLineString', coordinates: list.map((g) => g.coordinates) };
60
+ }
61
+ if (same && first.type === 'Polygon') {
62
+ return { type: 'MultiPolygon', coordinates: list.map((g) => g.coordinates) };
63
+ }
64
+ return { type: 'GeometryCollection', geometries: list };
65
+ }
66
+ /** A KML color (`aabbggrr`, hexadecimal) as a CSS color and an opacity */
67
+ function color(element) {
68
+ const value = childText(element, 'color')?.replace(/^#/, '');
69
+ if (!value || !/^[\da-f]{8}$/i.test(value))
70
+ return undefined;
71
+ const [a, b, g, r] = [0, 2, 4, 6].map((i) => value.slice(i, i + 2));
72
+ return [`#${r}${g}${b}`.toLowerCase(), Math.round((Number.parseInt(a, 16) / 255) * 1000) / 1000];
73
+ }
74
+ /** The properties of a style (simplestyle's names, as togeojson): stroke, stroke-opacity, stroke-width, fill,
75
+ * fill-opacity, marker-color */
76
+ function styleProperties(style) {
77
+ const out = {};
78
+ if (!style)
79
+ return out;
80
+ const line = child(style, 'LineStyle');
81
+ const stroke = color(line);
82
+ if (stroke)
83
+ [out.stroke, out['stroke-opacity']] = stroke;
84
+ const width = Number(childText(line, 'width'));
85
+ if (childText(line, 'width') !== undefined && Number.isFinite(width))
86
+ out['stroke-width'] = width;
87
+ const poly = child(style, 'PolyStyle');
88
+ const fill = color(poly);
89
+ if (fill)
90
+ [out.fill, out['fill-opacity']] = fill;
91
+ if (childText(poly, 'fill') === '0')
92
+ out['fill-opacity'] = 0;
93
+ if (childText(poly, 'outline') === '0')
94
+ out['stroke-opacity'] = 0;
95
+ const icon = color(child(style, 'IconStyle'));
96
+ if (icon)
97
+ out['marker-color'] = icon[0];
98
+ return out;
99
+ }
100
+ /**
101
+ * The placemarks of a KML document as GeoJSON features: their points, lines (and gx:Track), polygons (with their
102
+ * holes) and MultiGeometry (a Multi… of one type, else a GeometryCollection); their `name`, `description`, extended
103
+ * data (`Data`, `SimpleData`) as properties, and the colors of their style (inline, or shared through `styleUrl` and
104
+ * `StyleMap`) as `stroke`, `stroke-opacity`, `stroke-width`, `fill`, `fill-opacity`, `marker-color`. A placemark
105
+ * without geometry has a null one
106
+ */
107
+ export function parseKml(text) {
108
+ const root = parseXml(text);
109
+ const styles = new Map();
110
+ for (const s of descendants(root, 'Style'))
111
+ if (s.attributes.id)
112
+ styles.set(s.attributes.id, s);
113
+ const maps = new Map();
114
+ for (const m of descendants(root, 'StyleMap')) {
115
+ const normal = children(m, 'Pair').find((p) => childText(p, 'key') === 'normal');
116
+ const url = childText(normal, 'styleUrl');
117
+ if (m.attributes.id && url)
118
+ maps.set(m.attributes.id, url);
119
+ }
120
+ /** The style of a `styleUrl` in this document (`#id`, through a StyleMap) */
121
+ const shared = (url, depth = 0) => {
122
+ const id = url?.slice(url.indexOf('#') + 1);
123
+ if (id === undefined || depth > 4)
124
+ return undefined;
125
+ return styles.get(id) ?? shared(maps.get(id), depth + 1);
126
+ };
127
+ const features = descendants(root, 'Placemark').map((placemark) => {
128
+ const properties = { ...styleProperties(shared(childText(placemark, 'styleUrl'))) };
129
+ Object.assign(properties, styleProperties(child(placemark, 'Style')));
130
+ for (const key of ['name', 'description', 'address', 'styleUrl']) {
131
+ const value = childText(placemark, key);
132
+ if (value !== undefined)
133
+ properties[key] = value;
134
+ }
135
+ const time = childText(child(placemark, 'TimeStamp'), 'when');
136
+ if (time !== undefined)
137
+ properties.time = time;
138
+ const extended = child(placemark, 'ExtendedData');
139
+ for (const data of children(extended, 'Data')) {
140
+ if (data.attributes.name)
141
+ properties[data.attributes.name] = childText(data, 'value') ?? '';
142
+ }
143
+ for (const schema of children(extended, 'SchemaData')) {
144
+ for (const data of children(schema, 'SimpleData')) {
145
+ if (data.attributes.name)
146
+ properties[data.attributes.name] = data.text.trim();
147
+ }
148
+ }
149
+ const id = placemark.attributes.id;
150
+ return {
151
+ type: 'Feature',
152
+ geometry: merge(geometries(placemark)),
153
+ properties: properties,
154
+ ...(id === undefined ? {} : { id }),
155
+ };
156
+ });
157
+ return { type: 'FeatureCollection', features };
158
+ }
159
+ //# sourceMappingURL=kml.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kml.js","sourceRoot":"","sources":["../src/kml.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAmB,MAAM,UAAU,CAAC;AAE9F,uFAAuF;AACvF,SAAS,SAAS,CAAC,OAA+B;IAChD,MAAM,GAAG,GAAe,EAAE,CAAC;IAC3B,KAAK,MAAM,KAAK,IAAI,CAAC,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9D,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC5C,IAAI,MAAM,CAAC,MAAM,IAAI,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC;YAAE,GAAG,CAAC,IAAI,CAAC,MAAkB,CAAC,CAAC;IACxF,CAAC;IACD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{ Feature, FeatureCollection, Geometry, Position, Properties } from './features.ts';\nimport { child, children, childText, descendants, parseXml, type XmlElement } from './xml.ts';\n\n/** Positions of a `coordinates` element: `lon,lat[,alt]` tuples separated by spaces */\nfunction positions(element: XmlElement | undefined): Position[] {\n const out: Position[] = [];\n for (const tuple of (element?.text ?? '').trim().split(/\\s+/)) {\n const values = tuple.split(',').map(Number);\n if (values.length >= 2 && values.every(Number.isFinite)) out.push(values as Position);\n }\n return out;\n}\n\n/** The geometries of an element (a Placemark, a MultiGeometry), in order */\nfunction geometries(parent: XmlElement): Geometry[] {\n const out: Geometry[] = [];\n for (const g of parent.children) {\n if (g.name === 'Point') {\n const [p] = positions(child(g, 'coordinates'));\n if (p) out.push({ type: 'Point', coordinates: p });\n } else if (g.name === 'LineString' || g.name === 'LinearRing') {\n const line = positions(child(g, 'coordinates'));\n if (line.length >= 2) out.push({ type: 'LineString', coordinates: line });\n } else if (g.name === 'Polygon') {\n const ring = (b: XmlElement) => positions(child(child(b, 'LinearRing'), 'coordinates'));\n const outer = child(g, 'outerBoundaryIs');\n const rings = [...(outer ? [ring(outer)] : []), ...children(g, 'innerBoundaryIs').map(ring)];\n if ((rings[0]?.length ?? 0) >= 4) out.push({ type: 'Polygon', coordinates: rings.filter((r) => r.length >= 4) });\n } else if (g.name === 'Track') {\n // gx:Track: its gx:coord, `lon lat alt`\n const line = children(g, 'coord')\n .map((c) => c.text.trim().split(/\\s+/).map(Number))\n .filter((p) => p.length >= 2 && p.every(Number.isFinite)) as Position[];\n if (line.length >= 2) out.push({ type: 'LineString', coordinates: line });\n } else if (g.name === 'MultiGeometry' || g.name === 'MultiTrack') {\n out.push(...geometries(g));\n }\n }\n return out;\n}\n\n/** One geometry of several: a Multi… of one type, else a collection */\nfunction merge(list: Geometry[]): Geometry | null {\n const [first] = list;\n if (!first) return null;\n if (list.length === 1) return first;\n const same = list.every((g) => g.type === first.type);\n if (same && first.type === 'Point') {\n return { type: 'MultiPoint', coordinates: list.map((g) => (g as { coordinates: Position }).coordinates) };\n }\n if (same && first.type === 'LineString') {\n return { type: 'MultiLineString', coordinates: list.map((g) => (g as { coordinates: Position[] }).coordinates) };\n }\n if (same && first.type === 'Polygon') {\n return { type: 'MultiPolygon', coordinates: list.map((g) => (g as { coordinates: Position[][] }).coordinates) };\n }\n return { type: 'GeometryCollection', geometries: list };\n}\n\n/** A KML color (`aabbggrr`, hexadecimal) as a CSS color and an opacity */\nfunction color(element: XmlElement | undefined): [css: string, opacity: number] | undefined {\n const value = childText(element, 'color')?.replace(/^#/, '');\n if (!value || !/^[\\da-f]{8}$/i.test(value)) return undefined;\n const [a, b, g, r] = [0, 2, 4, 6].map((i) => value.slice(i, i + 2));\n return [`#${r}${g}${b}`.toLowerCase(), Math.round((Number.parseInt(a as string, 16) / 255) * 1000) / 1000];\n}\n\n/** The properties of a style (simplestyle's names, as togeojson): stroke, stroke-opacity, stroke-width, fill,\n * fill-opacity, marker-color */\nfunction styleProperties(style: XmlElement | undefined): Properties {\n const out: Properties = {};\n if (!style) return out;\n const line = child(style, 'LineStyle');\n const stroke = color(line);\n if (stroke) [out.stroke, out['stroke-opacity']] = stroke;\n const width = Number(childText(line, 'width'));\n if (childText(line, 'width') !== undefined && Number.isFinite(width)) out['stroke-width'] = width;\n const poly = child(style, 'PolyStyle');\n const fill = color(poly);\n if (fill) [out.fill, out['fill-opacity']] = fill;\n if (childText(poly, 'fill') === '0') out['fill-opacity'] = 0;\n if (childText(poly, 'outline') === '0') out['stroke-opacity'] = 0;\n const icon = color(child(style, 'IconStyle'));\n if (icon) out['marker-color'] = icon[0];\n return out;\n}\n\n/**\n * The placemarks of a KML document as GeoJSON features: their points, lines (and gx:Track), polygons (with their\n * holes) and MultiGeometry (a Multi… of one type, else a GeometryCollection); their `name`, `description`, extended\n * data (`Data`, `SimpleData`) as properties, and the colors of their style (inline, or shared through `styleUrl` and\n * `StyleMap`) as `stroke`, `stroke-opacity`, `stroke-width`, `fill`, `fill-opacity`, `marker-color`. A placemark\n * without geometry has a null one\n */\nexport function parseKml<P = Properties>(text: string): FeatureCollection<P> {\n const root = parseXml(text);\n const styles = new Map<string, XmlElement>();\n for (const s of descendants(root, 'Style')) if (s.attributes.id) styles.set(s.attributes.id, s);\n const maps = new Map<string, string>();\n for (const m of descendants(root, 'StyleMap')) {\n const normal = children(m, 'Pair').find((p) => childText(p, 'key') === 'normal');\n const url = childText(normal, 'styleUrl');\n if (m.attributes.id && url) maps.set(m.attributes.id, url);\n }\n /** The style of a `styleUrl` in this document (`#id`, through a StyleMap) */\n const shared = (url: string | undefined, depth = 0): XmlElement | undefined => {\n const id = url?.slice(url.indexOf('#') + 1);\n if (id === undefined || depth > 4) return undefined;\n return styles.get(id) ?? shared(maps.get(id), depth + 1);\n };\n const features = descendants(root, 'Placemark').map((placemark): Feature<P> => {\n const properties: Properties = { ...styleProperties(shared(childText(placemark, 'styleUrl'))) };\n Object.assign(properties, styleProperties(child(placemark, 'Style')));\n for (const key of ['name', 'description', 'address', 'styleUrl']) {\n const value = childText(placemark, key);\n if (value !== undefined) properties[key] = value;\n }\n const time = childText(child(placemark, 'TimeStamp'), 'when');\n if (time !== undefined) properties.time = time;\n const extended = child(placemark, 'ExtendedData');\n for (const data of children(extended, 'Data')) {\n if (data.attributes.name) properties[data.attributes.name] = childText(data, 'value') ?? '';\n }\n for (const schema of children(extended, 'SchemaData')) {\n for (const data of children(schema, 'SimpleData')) {\n if (data.attributes.name) properties[data.attributes.name] = data.text.trim();\n }\n }\n const id = placemark.attributes.id;\n return {\n type: 'Feature',\n geometry: merge(geometries(placemark)),\n properties: properties as P,\n ...(id === undefined ? {} : { id }),\n };\n });\n return { type: 'FeatureCollection', features };\n}\n"]}
package/dist/layers.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { LonLat, NetworkStyle, Tiles3dStyle } from './types.ts';
1
+ import type { LonLat, NetworkStyle, RasterStyle, Tiles3dStyle } from './types.ts';
2
2
  import type { NetworkStats, Tiles3dStats } from './wasm/isard.js';
3
3
  export declare abstract class Layer {
4
4
  #private;
@@ -11,6 +11,9 @@ export declare abstract class Layer {
11
11
  /** Raster tiles (basemaps, overlays) */
12
12
  export declare class RasterLayer extends Layer {
13
13
  private readonly options;
14
+ /** Changes the opacity or saturation, the other kept */
15
+ setStyle(style: Partial<RasterStyle>): void;
16
+ /** @deprecated Positional form (saturation back to 1 when not given): `setStyle({ opacity, saturation })` */
14
17
  setStyle(opacity: number, saturation?: number): void;
15
18
  }
16
19
  /** Line network colored by a value per node (travel time, water depth…) */
@@ -61,7 +64,7 @@ export interface GroundTexture {
61
64
  export interface GroundOptions {
62
65
  /**
63
66
  * GLSL ES 3.0 defining `vec4 ground(vec2 offset)`: the color of the ground (premultiplied alpha, 0 for nothing) at
64
- * `offset`, the Mercator offset of the pixel from `anchor` (times `ISARD_EARTH`: metres of EPSG:3857), exact to
67
+ * `offset`, the Mercator offset of the pixel from `anchor` (times `ISARD_CIRCUMFERENCE`: metres of EPSG:3857), exact to
65
68
  * the millimetre at any zoom. The code declares its own uniforms and samplers; also there: `u_zoom`,
66
69
  * `u_pixel_ratio`
67
70
  */
package/dist/layers.js CHANGED
@@ -3,6 +3,7 @@
3
3
  * the map recreates its engine and every layer in order, with the same handle (its id is updated).
4
4
  */
5
5
  import { parseColor, rampTexels, stops } from "./features.js";
6
+ import { mercatorX, mercatorY, toMercator } from "./geo.js";
6
7
  export class Layer {
7
8
  #id = -1;
8
9
  /** @internal */
@@ -15,14 +16,22 @@ export class Layer {
15
16
  get id() {
16
17
  return this.#id;
17
18
  }
18
- /** @internal Creates the layer in an engine (again after a context loss) */
19
+ /** @internal Creates the layer in an engine (again after a context loss); its id is -1 if that fails */
19
20
  attach(engine) {
21
+ this.#id = -1;
20
22
  this.#id = this.create(engine);
21
23
  }
24
+ /** @internal Forgets its id in an engine that is gone (before the layers are created in a new one) */
25
+ forgetEngine() {
26
+ this.#id = -1;
27
+ }
28
+ /** @internal Sends what refers to other layers, once every layer of a new engine has its id */
29
+ relink(_engine) { }
22
30
  remove() {
23
31
  // Not created yet: a 3D Tiles layer waiting for the engine with 3D Tiles
24
32
  if (this.#id >= 0)
25
33
  this.map.engine.removeLayer(this.#id);
34
+ this.#id = -1;
26
35
  this.map.detach(this);
27
36
  this.map.requestRender();
28
37
  }
@@ -39,10 +48,11 @@ export class RasterLayer extends Layer {
39
48
  super(map);
40
49
  this.options = options;
41
50
  }
42
- setStyle(opacity, saturation = 1) {
43
- this.options.opacity = opacity;
44
- this.options.saturation = saturation;
45
- this.map.engine.setRasterStyle(this.id, opacity, saturation);
51
+ setStyle(style, saturation = 1) {
52
+ const changed = typeof style === 'number' ? { opacity: style, saturation } : style;
53
+ this.options.opacity = changed.opacity ?? this.options.opacity;
54
+ this.options.saturation = changed.saturation ?? this.options.saturation;
55
+ this.map.engine.setRasterStyle(this.id, this.options.opacity, this.options.saturation);
46
56
  this.map.requestRender();
47
57
  }
48
58
  /** @internal */
@@ -111,7 +121,7 @@ export class NetworkLayer extends Layer {
111
121
  }
112
122
  else {
113
123
  // Mercator here: Math.tan and Math.log run natively, several times faster than in WebAssembly
114
- mercator = { nodes: toMercator(nodes), lines: lines && toMercator(lines.points) };
124
+ mercator = { nodes: mercatorPoints(nodes), lines: lines && mercatorPoints(lines.points) };
115
125
  const origin = [mercator.nodes[0] ?? 0, mercator.nodes[1] ?? 0];
116
126
  this.kept = {
117
127
  origin,
@@ -163,14 +173,12 @@ function unpack(points, [ox, oy]) {
163
173
  }
164
174
  return out;
165
175
  }
166
- const MAX_LAT = 85.051128779806589;
167
176
  /** Longitudes and latitudes (degrees, interleaved) to Mercator [0, 1], y towards the south */
168
- function toMercator(lonLat) {
177
+ function mercatorPoints(lonLat) {
169
178
  const out = new Float64Array(lonLat.length);
170
179
  for (let i = 0; i < lonLat.length; i += 2) {
171
- const lat = (Math.max(-MAX_LAT, Math.min(MAX_LAT, lonLat[i + 1] ?? 0)) * Math.PI) / 180;
172
- out[i] = ((lonLat[i] ?? 0) + 180) / 360;
173
- out[i + 1] = 0.5 - Math.log(Math.tan(Math.PI / 4 + lat / 2)) / (2 * Math.PI);
180
+ out[i] = mercatorX(lonLat[i] ?? 0);
181
+ out[i + 1] = mercatorY(lonLat[i + 1] ?? 0);
174
182
  }
175
183
  return out;
176
184
  }
@@ -258,7 +266,7 @@ export class GroundLayer extends Layer {
258
266
  }
259
267
  /** @internal */
260
268
  create(engine) {
261
- const [ax, ay] = mercatorPoint(this.options.anchor);
269
+ const [ax, ay] = toMercator(this.options.anchor);
262
270
  const id = engine.addGround(this.options.code, ax, ay, ...mercatorBox(this.options.bounds ?? [-180, -85.06, 180, 85.06]));
263
271
  for (const [name, texture] of this.textures)
264
272
  this.sendTexture(engine, id, name, texture);
@@ -268,14 +276,10 @@ export class GroundLayer extends Layer {
268
276
  return id;
269
277
  }
270
278
  }
271
- function mercatorPoint([lon, lat]) {
272
- const out = toMercator(Float64Array.of(lon, lat));
273
- return [out[0] ?? 0, out[1] ?? 0];
274
- }
275
279
  /** A lon/lat box to Mercator min x, min y, max x, max y (y towards the south) */
276
280
  function mercatorBox([west, south, east, north]) {
277
- const [x0, y1] = mercatorPoint([west, south]);
278
- const [x1, y0] = mercatorPoint([east, north]);
281
+ const [x0, y1] = toMercator([west, south]);
282
+ const [x1, y0] = toMercator([east, north]);
279
283
  return [x0, y0, x1, y1];
280
284
  }
281
285
  //# sourceMappingURL=layers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"layers.js","sourceRoot":"","sources":["../src/layers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAI9D,MAAM,OAAgB,KAAK;IACzB,GAAG,GAAG,CAAC,CAAC,CAAC;IAET,gBAAgB;IACG,GAAG,CAAY;IAElC,gBAAgB;IAChB,YAAY,GAAc;QACxB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED,oCAAoC;IACpC,IAAI,EAAE;QACJ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,CAAC;CACF;AAED,SAAS,aAAa,CAAC,CAAC,GAAG,EAAE,GAAG,CAAS;IACvC,MAAM,GAAG,GAAG,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IAClD,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AACpC,CAAC;AAED,iFAAiF;AACjF,SAAS,WAAW,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAmC;IAC/E,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IAC9C,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IAC9C,OAAO,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["/**\n * Handles of the layers added to a map. Each one keeps what it needs to be created again: after a WebGL context loss,\n * the map recreates its engine and every layer in order, with the same handle (its id is updated).\n */\nimport { parseColor, rampTexels, stops } from './features.ts';\nimport type { LayerHost, LonLat, NetworkOptions, NetworkStyle, RasterOptions, Tiles3dStyle } from './types.ts';\nimport type { Engine, NetworkStats, Tiles3dStats } from './wasm/isard.js';\n\nexport abstract class Layer {\n #id = -1;\n\n /** @internal */\n protected readonly map: LayerHost;\n\n /** @internal */\n constructor(map: LayerHost) {\n this.map = map;\n }\n\n /** Id of the layer in the engine */\n get id(): number {\n return this.#id;\n }\n\n /** @internal Creates the layer in an engine (again after a context loss) */\n attach(engine: Engine): void {\n this.#id = this.create(engine);\n }\n\n /** @internal */\n protected abstract create(engine: Engine): number;\n\n remove(): void {\n // Not created yet: a 3D Tiles layer waiting for the engine with 3D Tiles\n if (this.#id >= 0) this.map.engine.removeLayer(this.#id);\n this.map.detach(this);\n this.map.requestRender();\n }\n\n /** Moves the layer under `other`, or on top of every layer (above the labels of a vector basemap too) */\n moveBefore(other: Layer | undefined): void {\n this.map.moveLayer(this, other);\n }\n}\n\n/** Raster tiles (basemaps, overlays) */\nexport class RasterLayer extends Layer {\n /** @internal */\n constructor(\n map: LayerHost,\n private readonly options: Required<Omit<RasterOptions, 'size' | 'loader' | 'grid' | 'attribution'>> & {\n size: number | undefined;\n loader: RasterOptions['loader'] | undefined;\n },\n ) {\n super(map);\n }\n\n setStyle(opacity: number, saturation = 1): void {\n this.options.opacity = opacity;\n this.options.saturation = saturation;\n this.map.engine.setRasterStyle(this.id, opacity, saturation);\n this.map.requestRender();\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const { url, minZoom, maxZoom, opacity, saturation, size, loader } = this.options;\n return engine.addRaster(url, minZoom, maxZoom, opacity, saturation, size, loader);\n }\n}\n\n/** Line network colored by a value per node (travel time, water depth…) */\nexport class NetworkLayer extends Layer {\n private values: Float32Array | undefined;\n /** Node and line positions in Mercator, kept for a context loss: f32 offsets from an origin (exact to the centimetre\n * across a region, half the memory of f64) */\n private kept: { origin: [number, number]; nodes: Float32Array; lines: Float32Array | undefined } | undefined;\n\n /** @internal */\n constructor(\n map: LayerHost,\n private geometry: { nodes: Float64Array; edges: Uint32Array; lines: NetworkOptions['lines'] | undefined },\n private costs: Float32Array | undefined,\n private style: NetworkStyle,\n private edgeWidths: Float32Array | undefined,\n ) {\n super(map);\n }\n\n /** One value per node, in node order; negative (or 1e30 and above) = unreached. Costs one texture upload, drawn\n * next frame. */\n setValues(values: Float32Array): void {\n this.values = values;\n this.map.engine.setNetworkValues(this.id, values);\n this.map.requestRender();\n }\n\n /** Costs of the edges, A → B then B → A (see `NetworkOptions.costs`), when the way the network is travelled\n * changes; undefined: values interpolated along the edges. The geometry stays on the graphics card. */\n setCosts(costs: Float32Array | undefined): void {\n this.costs = costs;\n this.map.engine.setNetworkCosts(this.id, costs);\n this.map.requestRender();\n }\n\n setStyle(style: Partial<NetworkStyle>): void {\n const ramp = this.style.ramp;\n this.style = { ...this.style, ...style };\n this.map.engine.setNetworkStyle(this.id, networkStyle(this.style));\n if (this.style.ramp !== ramp)\n this.map.engine.setNetworkRamp(this.id, this.style.ramp && rampTexels(this.style.ramp).rgba);\n this.map.requestRender();\n }\n\n /** Width factor of each edge (undefined: 1 for all) */\n setEdgeWidths(widths: Float32Array | undefined): void {\n this.edgeWidths = widths;\n this.map.engine.setNetworkScales(this.id, widths);\n this.map.requestRender();\n }\n\n /** Pieces in all and drawn in the last frame */\n stats(): NetworkStats | undefined {\n return this.map.engine.networkStats(this.id);\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const { nodes, edges, lines } = this.geometry;\n let mercator: { nodes: Float64Array; lines: Float64Array | undefined };\n if (this.kept) {\n const { origin, nodes: n, lines: l } = this.kept;\n mercator = { nodes: unpack(n, origin), lines: l && unpack(l, origin) };\n } else {\n // Mercator here: Math.tan and Math.log run natively, several times faster than in WebAssembly\n mercator = { nodes: toMercator(nodes), lines: lines && toMercator(lines.points) };\n const origin: [number, number] = [mercator.nodes[0] ?? 0, mercator.nodes[1] ?? 0];\n this.kept = {\n origin,\n nodes: pack(mercator.nodes, origin),\n lines: mercator.lines && pack(mercator.lines, origin),\n };\n // The degrees are not needed again: millions of points for a region\n this.geometry = { nodes: EMPTY, edges, lines: lines && { start: lines.start, points: EMPTY } };\n }\n const id = engine.addNetwork(\n mercator.nodes,\n edges,\n lines?.start,\n mercator.lines,\n this.costs,\n networkStyle(this.style),\n );\n if (this.style.ramp) engine.setNetworkRamp(id, rampTexels(this.style.ramp).rgba);\n if (this.edgeWidths) engine.setNetworkScales(id, this.edgeWidths);\n if (this.values) engine.setNetworkValues(id, this.values);\n return id;\n }\n}\n\n/** The 25 numbers of a network style for the engine */\nfunction networkStyle(style: NetworkStyle): Float32Array {\n const { width, halo, max, contour, opacity, haloOpacity, unreachedColor, fade } = style;\n return Float32Array.from([\n ...stops(width),\n ...stops(halo),\n max,\n contour,\n opacity,\n haloOpacity,\n ...parseColor(unreachedColor),\n fade,\n ]);\n}\n\nconst EMPTY = new Float64Array(0);\n\n/** Interleaved points as f32 offsets from an origin, and back */\nfunction pack(points: Float64Array, [ox, oy]: [number, number]): Float32Array {\n const out = new Float32Array(points.length);\n for (let i = 0; i < points.length; i += 2) {\n out[i] = (points[i] ?? 0) - ox;\n out[i + 1] = (points[i + 1] ?? 0) - oy;\n }\n return out;\n}\n\nfunction unpack(points: Float32Array, [ox, oy]: [number, number]): Float64Array {\n const out = new Float64Array(points.length);\n for (let i = 0; i < points.length; i += 2) {\n out[i] = (points[i] ?? 0) + ox;\n out[i + 1] = (points[i + 1] ?? 0) + oy;\n }\n return out;\n}\n\nconst MAX_LAT = 85.051128779806589;\n\n/** Longitudes and latitudes (degrees, interleaved) to Mercator [0, 1], y towards the south */\nfunction toMercator(lonLat: Float64Array): Float64Array {\n const out = new Float64Array(lonLat.length);\n for (let i = 0; i < lonLat.length; i += 2) {\n const lat = (Math.max(-MAX_LAT, Math.min(MAX_LAT, lonLat[i + 1] ?? 0)) * Math.PI) / 180;\n out[i] = ((lonLat[i] ?? 0) + 180) / 360;\n out[i + 1] = 0.5 - Math.log(Math.tan(Math.PI / 4 + lat / 2)) / (2 * Math.PI);\n }\n return out;\n}\n\n/** Textured meshes in 3D Tiles */\nexport class Tiles3dLayer extends Layer {\n /** @internal */\n constructor(\n map: LayerHost,\n private readonly url: string,\n private style: Tiles3dStyle,\n ) {\n super(map);\n }\n\n setStyle(style: Partial<Tiles3dStyle>): void {\n this.style = { ...this.style, ...style };\n // Kept for its creation while the engine with 3D Tiles loads\n if (this.id < 0) return;\n this.map.engine.setTiles3dStyle(this.id, this.style.maxScreenSpaceError, this.style.opacity);\n this.map.requestRender();\n }\n\n /** Loading counters; undefined once the layer is removed, and while the engine with 3D Tiles loads (see\n * `GeoMapOptions.tiles3d`) */\n stats(): Tiles3dStats | undefined {\n return this.id < 0 ? undefined : this.map.engine.tiles3dStats(this.id);\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const id = engine.addTiles3d(this.url, this.style.maxScreenSpaceError);\n engine.setTiles3dStyle(id, this.style.maxScreenSpaceError, this.style.opacity);\n return id;\n }\n}\n\n/** A texture of a ground layer (see `GroundLayer`) */\nexport interface GroundTexture {\n /** `r8`, `r8ui`, `r16ui`, `r16i`, `r32ui`, `r32f`, `rg16ui`, `rg32f`, `rgba8`, `rgba8ui`, `rgba16ui`, `rgba32f`:\n * integer formats are read with `usampler2D` / `isampler2D` and `texelFetch` */\n format: string;\n width: number;\n height: number;\n /** Layers of a 2D array (`sampler2DArray`, `usampler2DArray`…); 0 or undefined: a 2D texture */\n depth?: number;\n /** Linear filtering (non-integer formats); default nearest */\n linear?: boolean;\n /** Texels row after row (layer after layer), any typed array; undefined: left empty */\n data?: ArrayBufferView;\n}\n\nexport interface GroundOptions {\n /**\n * GLSL ES 3.0 defining `vec4 ground(vec2 offset)`: the color of the ground (premultiplied alpha, 0 for nothing) at\n * `offset`, the Mercator offset of the pixel from `anchor` (times `ISARD_EARTH`: metres of EPSG:3857), exact to\n * the millimetre at any zoom. The code declares its own uniforms and samplers; also there: `u_zoom`,\n * `u_pixel_ratio`\n */\n code: string;\n /** Where the offsets are taken from */\n anchor: LonLat;\n /** Box it shows in, `[west, south, east, north]` (default the world): only the ground there is drawn again */\n bounds?: [west: number, south: number, east: number, north: number];\n textures?: Record<string, GroundTexture>;\n uniforms?: Record<string, number | readonly number[]>;\n}\n\nconst bytesOf = (data: ArrayBufferView) => new Uint8Array(data.buffer, data.byteOffset, data.byteLength);\n\n/** The application's fragment shader run over the ground, draped on the relief (water depth, heat maps…) */\nexport class GroundLayer extends Layer {\n private readonly textures = new Map<string, GroundTexture>();\n private readonly uniforms = new Map<string, number[]>();\n private visible = true;\n\n /** @internal */\n constructor(\n map: LayerHost,\n private readonly options: GroundOptions,\n ) {\n super(map);\n for (const [name, texture] of Object.entries(options.textures ?? {})) this.textures.set(name, texture);\n for (const [name, value] of Object.entries(options.uniforms ?? {})) this.uniforms.set(name, [value].flat());\n }\n\n /** Creates or replaces a texture of the code's sampler `name` */\n setTexture(name: string, texture: GroundTexture): void {\n this.textures.set(name, texture);\n this.sendTexture(this.map.engine, this.id, name, texture);\n this.map.requestRender();\n }\n\n /**\n * Replaces a region of a texture: `data` holds `width` × `height` texels for (`x`, `y`) of `layer` (2D arrays).\n * Keep the texture's own `data` up to date too if it must survive a WebGL context loss.\n */\n updateTexture(\n name: string,\n data: ArrayBufferView,\n region: { x?: number; y?: number; layer?: number; width: number; height: number },\n ): void {\n const { x = 0, y = 0, layer = 0, width, height } = region;\n this.map.engine.updateGroundTexture(this.id, name, x, y, layer, width, height, bytesOf(data));\n this.map.requestRender();\n }\n\n /** A uniform of the code: a number, or numbers for vectors, arrays and matrices (column major) */\n setUniform(name: string, value: number | readonly number[]): void {\n const values = [value].flat();\n this.uniforms.set(name, values);\n this.map.engine.setGroundUniform(this.id, name, Float64Array.from(values));\n this.map.requestRender();\n }\n\n setBounds(bounds: [west: number, south: number, east: number, north: number]): void {\n this.options.bounds = bounds;\n this.map.engine.setGroundBounds(this.id, ...mercatorBox(bounds));\n this.map.requestRender();\n }\n\n setVisible(visible: boolean): void {\n this.visible = visible;\n this.map.engine.setGroundVisible(this.id, visible);\n this.map.requestRender();\n }\n\n private sendTexture(engine: Engine, id: number, name: string, t: GroundTexture): void {\n const data = t.data && bytesOf(t.data);\n engine.setGroundTexture(id, name, t.format, t.width, t.height, t.depth ?? 0, t.linear ?? false, data);\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const [ax, ay] = mercatorPoint(this.options.anchor);\n const id = engine.addGround(\n this.options.code,\n ax,\n ay,\n ...mercatorBox(this.options.bounds ?? [-180, -85.06, 180, 85.06]),\n );\n for (const [name, texture] of this.textures) this.sendTexture(engine, id, name, texture);\n for (const [name, values] of this.uniforms) engine.setGroundUniform(id, name, Float64Array.from(values));\n engine.setGroundVisible(id, this.visible);\n return id;\n }\n}\n\nfunction mercatorPoint([lon, lat]: LonLat): [number, number] {\n const out = toMercator(Float64Array.of(lon, lat));\n return [out[0] ?? 0, out[1] ?? 0];\n}\n\n/** A lon/lat box to Mercator min x, min y, max x, max y (y towards the south) */\nfunction mercatorBox([west, south, east, north]: [number, number, number, number]): [number, number, number, number] {\n const [x0, y1] = mercatorPoint([west, south]);\n const [x1, y0] = mercatorPoint([east, north]);\n return [x0, y0, x1, y1];\n}\n"]}
1
+ {"version":3,"file":"layers.js","sourceRoot":"","sources":["../src/layers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAY5D,MAAM,OAAgB,KAAK;IACzB,GAAG,GAAG,CAAC,CAAC,CAAC;IAET,gBAAgB;IACG,GAAG,CAAY;IAElC,gBAAgB;IAChB,YAAY,GAAc;QACxB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED,oCAAoC;IACpC,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAED,wGAAwG;IACxG,MAAM,CAAC,MAAc;QACnB,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;QACd,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;IAED,sGAAsG;IACtG,YAAY;QACV,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;IAChB,CAAC;IAED,+FAA+F;IAC/F,MAAM,CAAC,OAAe,IAAS,CAAC;IAKhC,MAAM;QACJ,yEAAyE;QACzE,IAAI,IAAI,CAAC,GAAG,IAAI,CAAC;YAAE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CA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EAAE,EAAE,EAAE,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["/**\n * Handles of the layers added to a map. Each one keeps what it needs to be created again: after a WebGL context loss,\n * the map recreates its engine and every layer in order, with the same handle (its id is updated).\n */\nimport { parseColor, rampTexels, stops } from './features.ts';\nimport { mercatorX, mercatorY, toMercator } from './geo.ts';\nimport type {\n LayerHost,\n LonLat,\n NetworkOptions,\n NetworkStyle,\n RasterOptions,\n RasterStyle,\n Tiles3dStyle,\n} from './types.ts';\nimport type { Engine, NetworkStats, Tiles3dStats } from './wasm/isard.js';\n\nexport abstract class Layer {\n #id = -1;\n\n /** @internal */\n protected readonly map: LayerHost;\n\n /** @internal */\n constructor(map: LayerHost) {\n this.map = map;\n }\n\n /** Id of the layer in the engine */\n get id(): number {\n return this.#id;\n }\n\n /** @internal Creates the layer in an engine (again after a context loss); its id is -1 if that fails */\n attach(engine: Engine): void {\n this.#id = -1;\n this.#id = this.create(engine);\n }\n\n /** @internal Forgets its id in an engine that is gone (before the layers are created in a new one) */\n forgetEngine(): void {\n this.#id = -1;\n }\n\n /** @internal Sends what refers to other layers, once every layer of a new engine has its id */\n relink(_engine: Engine): void {}\n\n /** @internal */\n protected abstract create(engine: Engine): number;\n\n remove(): void {\n // Not created yet: a 3D Tiles layer waiting for the engine with 3D Tiles\n if (this.#id >= 0) this.map.engine.removeLayer(this.#id);\n this.#id = -1;\n this.map.detach(this);\n this.map.requestRender();\n }\n\n /** Moves the layer under `other`, or on top of every layer (above the labels of a vector basemap too) */\n moveBefore(other: Layer | undefined): void {\n this.map.moveLayer(this, other);\n }\n}\n\n/** Raster tiles (basemaps, overlays) */\nexport class RasterLayer extends Layer {\n /** @internal */\n constructor(\n map: LayerHost,\n private readonly options: Required<Omit<RasterOptions, 'size' | 'loader' | 'grid' | 'attribution'>> & {\n size: number | undefined;\n loader: RasterOptions['loader'] | undefined;\n },\n ) {\n super(map);\n }\n\n /** Changes the opacity or saturation, the other kept */\n setStyle(style: Partial<RasterStyle>): void;\n /** @deprecated Positional form (saturation back to 1 when not given): `setStyle({ opacity, saturation })` */\n setStyle(opacity: number, saturation?: number): void;\n setStyle(style: Partial<RasterStyle> | number, saturation = 1): void {\n const changed = typeof style === 'number' ? { opacity: style, saturation } : style;\n this.options.opacity = changed.opacity ?? this.options.opacity;\n this.options.saturation = changed.saturation ?? this.options.saturation;\n this.map.engine.setRasterStyle(this.id, this.options.opacity, this.options.saturation);\n this.map.requestRender();\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const { url, minZoom, maxZoom, opacity, saturation, size, loader } = this.options;\n return engine.addRaster(url, minZoom, maxZoom, opacity, saturation, size, loader);\n }\n}\n\n/** Line network colored by a value per node (travel time, water depth…) */\nexport class NetworkLayer extends Layer {\n private values: Float32Array | undefined;\n /** Node and line positions in Mercator, kept for a context loss: f32 offsets from an origin (exact to the centimetre\n * across a region, half the memory of f64) */\n private kept: { origin: [number, number]; nodes: Float32Array; lines: Float32Array | undefined } | undefined;\n\n /** @internal */\n constructor(\n map: LayerHost,\n private geometry: { nodes: Float64Array; edges: Uint32Array; lines: NetworkOptions['lines'] | undefined },\n private costs: Float32Array | undefined,\n private style: NetworkStyle,\n private edgeWidths: Float32Array | undefined,\n ) {\n super(map);\n }\n\n /** One value per node, in node order; negative (or 1e30 and above) = unreached. Costs one texture upload, drawn\n * next frame. */\n setValues(values: Float32Array): void {\n this.values = values;\n this.map.engine.setNetworkValues(this.id, values);\n this.map.requestRender();\n }\n\n /** Costs of the edges, A → B then B → A (see `NetworkOptions.costs`), when the way the network is travelled\n * changes; undefined: values interpolated along the edges. The geometry stays on the graphics card. */\n setCosts(costs: Float32Array | undefined): void {\n this.costs = costs;\n this.map.engine.setNetworkCosts(this.id, costs);\n this.map.requestRender();\n }\n\n setStyle(style: Partial<NetworkStyle>): void {\n const ramp = this.style.ramp;\n this.style = { ...this.style, ...style };\n this.map.engine.setNetworkStyle(this.id, networkStyle(this.style));\n if (this.style.ramp !== ramp)\n this.map.engine.setNetworkRamp(this.id, this.style.ramp && rampTexels(this.style.ramp).rgba);\n this.map.requestRender();\n }\n\n /** Width factor of each edge (undefined: 1 for all) */\n setEdgeWidths(widths: Float32Array | undefined): void {\n this.edgeWidths = widths;\n this.map.engine.setNetworkScales(this.id, widths);\n this.map.requestRender();\n }\n\n /** Pieces in all and drawn in the last frame */\n stats(): NetworkStats | undefined {\n return this.map.engine.networkStats(this.id);\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const { nodes, edges, lines } = this.geometry;\n let mercator: { nodes: Float64Array; lines: Float64Array | undefined };\n if (this.kept) {\n const { origin, nodes: n, lines: l } = this.kept;\n mercator = { nodes: unpack(n, origin), lines: l && unpack(l, origin) };\n } else {\n // Mercator here: Math.tan and Math.log run natively, several times faster than in WebAssembly\n mercator = { nodes: mercatorPoints(nodes), lines: lines && mercatorPoints(lines.points) };\n const origin: [number, number] = [mercator.nodes[0] ?? 0, mercator.nodes[1] ?? 0];\n this.kept = {\n origin,\n nodes: pack(mercator.nodes, origin),\n lines: mercator.lines && pack(mercator.lines, origin),\n };\n // The degrees are not needed again: millions of points for a region\n this.geometry = { nodes: EMPTY, edges, lines: lines && { start: lines.start, points: EMPTY } };\n }\n const id = engine.addNetwork(\n mercator.nodes,\n edges,\n lines?.start,\n mercator.lines,\n this.costs,\n networkStyle(this.style),\n );\n if (this.style.ramp) engine.setNetworkRamp(id, rampTexels(this.style.ramp).rgba);\n if (this.edgeWidths) engine.setNetworkScales(id, this.edgeWidths);\n if (this.values) engine.setNetworkValues(id, this.values);\n return id;\n }\n}\n\n/** The 25 numbers of a network style for the engine */\nfunction networkStyle(style: NetworkStyle): Float32Array {\n const { width, halo, max, contour, opacity, haloOpacity, unreachedColor, fade } = style;\n return Float32Array.from([\n ...stops(width),\n ...stops(halo),\n max,\n contour,\n opacity,\n haloOpacity,\n ...parseColor(unreachedColor),\n fade,\n ]);\n}\n\nconst EMPTY = new Float64Array(0);\n\n/** Interleaved points as f32 offsets from an origin, and back */\nfunction pack(points: Float64Array, [ox, oy]: [number, number]): Float32Array {\n const out = new Float32Array(points.length);\n for (let i = 0; i < points.length; i += 2) {\n out[i] = (points[i] ?? 0) - ox;\n out[i + 1] = (points[i + 1] ?? 0) - oy;\n }\n return out;\n}\n\nfunction unpack(points: Float32Array, [ox, oy]: [number, number]): Float64Array {\n const out = new Float64Array(points.length);\n for (let i = 0; i < points.length; i += 2) {\n out[i] = (points[i] ?? 0) + ox;\n out[i + 1] = (points[i + 1] ?? 0) + oy;\n }\n return out;\n}\n\n/** Longitudes and latitudes (degrees, interleaved) to Mercator [0, 1], y towards the south */\nfunction mercatorPoints(lonLat: Float64Array): Float64Array {\n const out = new Float64Array(lonLat.length);\n for (let i = 0; i < lonLat.length; i += 2) {\n out[i] = mercatorX(lonLat[i] ?? 0);\n out[i + 1] = mercatorY(lonLat[i + 1] ?? 0);\n }\n return out;\n}\n\n/** Textured meshes in 3D Tiles */\nexport class Tiles3dLayer extends Layer {\n /** @internal */\n constructor(\n map: LayerHost,\n private readonly url: string,\n private style: Tiles3dStyle,\n ) {\n super(map);\n }\n\n setStyle(style: Partial<Tiles3dStyle>): void {\n this.style = { ...this.style, ...style };\n // Kept for its creation while the engine with 3D Tiles loads\n if (this.id < 0) return;\n this.map.engine.setTiles3dStyle(this.id, this.style.maxScreenSpaceError, this.style.opacity);\n this.map.requestRender();\n }\n\n /** Loading counters; undefined once the layer is removed, and while the engine with 3D Tiles loads (see\n * `GeoMapOptions.tiles3d`) */\n stats(): Tiles3dStats | undefined {\n return this.id < 0 ? undefined : this.map.engine.tiles3dStats(this.id);\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const id = engine.addTiles3d(this.url, this.style.maxScreenSpaceError);\n engine.setTiles3dStyle(id, this.style.maxScreenSpaceError, this.style.opacity);\n return id;\n }\n}\n\n/** A texture of a ground layer (see `GroundLayer`) */\nexport interface GroundTexture {\n /** `r8`, `r8ui`, `r16ui`, `r16i`, `r32ui`, `r32f`, `rg16ui`, `rg32f`, `rgba8`, `rgba8ui`, `rgba16ui`, `rgba32f`:\n * integer formats are read with `usampler2D` / `isampler2D` and `texelFetch` */\n format: string;\n width: number;\n height: number;\n /** Layers of a 2D array (`sampler2DArray`, `usampler2DArray`…); 0 or undefined: a 2D texture */\n depth?: number;\n /** Linear filtering (non-integer formats); default nearest */\n linear?: boolean;\n /** Texels row after row (layer after layer), any typed array; undefined: left empty */\n data?: ArrayBufferView;\n}\n\nexport interface GroundOptions {\n /**\n * GLSL ES 3.0 defining `vec4 ground(vec2 offset)`: the color of the ground (premultiplied alpha, 0 for nothing) at\n * `offset`, the Mercator offset of the pixel from `anchor` (times `ISARD_CIRCUMFERENCE`: metres of EPSG:3857), exact to\n * the millimetre at any zoom. The code declares its own uniforms and samplers; also there: `u_zoom`,\n * `u_pixel_ratio`\n */\n code: string;\n /** Where the offsets are taken from */\n anchor: LonLat;\n /** Box it shows in, `[west, south, east, north]` (default the world): only the ground there is drawn again */\n bounds?: [west: number, south: number, east: number, north: number];\n textures?: Record<string, GroundTexture>;\n uniforms?: Record<string, number | readonly number[]>;\n}\n\nconst bytesOf = (data: ArrayBufferView) => new Uint8Array(data.buffer, data.byteOffset, data.byteLength);\n\n/** The application's fragment shader run over the ground, draped on the relief (water depth, heat maps…) */\nexport class GroundLayer extends Layer {\n private readonly textures = new Map<string, GroundTexture>();\n private readonly uniforms = new Map<string, number[]>();\n private visible = true;\n\n /** @internal */\n constructor(\n map: LayerHost,\n private readonly options: GroundOptions,\n ) {\n super(map);\n for (const [name, texture] of Object.entries(options.textures ?? {})) this.textures.set(name, texture);\n for (const [name, value] of Object.entries(options.uniforms ?? {})) this.uniforms.set(name, [value].flat());\n }\n\n /** Creates or replaces a texture of the code's sampler `name` */\n setTexture(name: string, texture: GroundTexture): void {\n this.textures.set(name, texture);\n this.sendTexture(this.map.engine, this.id, name, texture);\n this.map.requestRender();\n }\n\n /**\n * Replaces a region of a texture: `data` holds `width` × `height` texels for (`x`, `y`) of `layer` (2D arrays).\n * Keep the texture's own `data` up to date too if it must survive a WebGL context loss.\n */\n updateTexture(\n name: string,\n data: ArrayBufferView,\n region: { x?: number; y?: number; layer?: number; width: number; height: number },\n ): void {\n const { x = 0, y = 0, layer = 0, width, height } = region;\n this.map.engine.updateGroundTexture(this.id, name, x, y, layer, width, height, bytesOf(data));\n this.map.requestRender();\n }\n\n /** A uniform of the code: a number, or numbers for vectors, arrays and matrices (column major) */\n setUniform(name: string, value: number | readonly number[]): void {\n const values = [value].flat();\n this.uniforms.set(name, values);\n this.map.engine.setGroundUniform(this.id, name, Float64Array.from(values));\n this.map.requestRender();\n }\n\n setBounds(bounds: [west: number, south: number, east: number, north: number]): void {\n this.options.bounds = bounds;\n this.map.engine.setGroundBounds(this.id, ...mercatorBox(bounds));\n this.map.requestRender();\n }\n\n setVisible(visible: boolean): void {\n this.visible = visible;\n this.map.engine.setGroundVisible(this.id, visible);\n this.map.requestRender();\n }\n\n private sendTexture(engine: Engine, id: number, name: string, t: GroundTexture): void {\n const data = t.data && bytesOf(t.data);\n engine.setGroundTexture(id, name, t.format, t.width, t.height, t.depth ?? 0, t.linear ?? false, data);\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const [ax, ay] = toMercator(this.options.anchor);\n const id = engine.addGround(\n this.options.code,\n ax,\n ay,\n ...mercatorBox(this.options.bounds ?? [-180, -85.06, 180, 85.06]),\n );\n for (const [name, texture] of this.textures) this.sendTexture(engine, id, name, texture);\n for (const [name, values] of this.uniforms) engine.setGroundUniform(id, name, Float64Array.from(values));\n engine.setGroundVisible(id, this.visible);\n return id;\n }\n}\n\n/** A lon/lat box to Mercator min x, min y, max x, max y (y towards the south) */\nfunction mercatorBox([west, south, east, north]: [number, number, number, number]): [number, number, number, number] {\n const [x0, y1] = toMercator([west, south]);\n const [x1, y0] = toMercator([east, north]);\n return [x0, y0, x1, y1];\n}\n"]}
package/dist/lru.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * A cache keeping its most recently used entries (the decoded tiles and images of the workers, the source tiles of a
3
+ * reprojection, the labels of the vector tiles): a `Map` in order of use, the least recent dropped past `capacity`.
4
+ */
5
+ export declare class Lru<K, V> {
6
+ capacity: number;
7
+ private readonly evict?;
8
+ private readonly entries;
9
+ /** `evict`: told of each entry dropped for room (not of those deleted) */
10
+ constructor(capacity: number, evict?: ((value: V, key: K) => void) | undefined);
11
+ get size(): number;
12
+ /** The value of a key, now the most recently used; undefined if absent */
13
+ get(key: K): V | undefined;
14
+ /** Whether a key is kept, without using it */
15
+ has(key: K): boolean;
16
+ /** Adds or replaces a value, the most recently used; drops the least recent ones past the capacity */
17
+ set(key: K, value: V): void;
18
+ delete(key: K): boolean;
19
+ /** The values, least recently used first */
20
+ values(): IterableIterator<V>;
21
+ clear(): void;
22
+ }