@sjvair/monitor-map 4.3.0 → 5.0.0-beta.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.
- package/LICENSE +21 -0
- package/README.md +59 -138
- package/dist/lib/MonitorDetailPanel.svelte +23 -20
- package/dist/lib/MonitorMapLayout.svelte +147 -77
- package/dist/lib/components/DataBox.svelte +4 -1
- package/dist/lib/components/ui/range-calendar/range-calendar.svelte.d.ts +1 -1
- package/dist/lib/config.svelte.d.ts +7 -0
- package/dist/lib/config.svelte.js +10 -0
- package/dist/lib/core.d.ts +2 -2
- package/dist/lib/core.js +2 -1
- package/dist/lib/data-chart/DataChart.svelte +40 -25
- package/dist/lib/data-chart/DateRange.d.ts +13 -4
- package/dist/lib/data-chart/DateRange.js +50 -14
- package/dist/lib/data-chart/chart-utils.js +5 -7
- package/dist/lib/data-chart/level-colors.d.ts +3 -4
- package/dist/lib/data-chart/level-colors.js +7 -4
- package/dist/lib/data-chart/pacific-time.d.ts +9 -0
- package/dist/lib/data-chart/pacific-time.js +25 -0
- package/dist/lib/data-chart/tooltip.js +2 -2
- package/{src/lib/ev-stations/components/EvStationTooltip.svelte → dist/lib/ev-stations/EvPopup.svelte} +6 -5
- package/dist/lib/ev-stations/EvPopup.svelte.d.ts +7 -0
- package/dist/lib/ev-stations/ev-plugin.svelte.d.ts +14 -0
- package/dist/lib/ev-stations/ev-plugin.svelte.js +71 -0
- package/dist/lib/ev-stations/ev-station-icons.d.ts +1 -4
- package/dist/lib/ev-stations/ev-station-icons.js +1 -13
- package/dist/lib/ev-stations/ev-stations.d.ts +7 -0
- package/dist/lib/ev-stations/ev-stations.js +53 -0
- package/dist/lib/ev-stations/ev-store.svelte.d.ts +21 -0
- package/dist/lib/ev-stations/ev-store.svelte.js +83 -0
- package/dist/lib/ev-stations/station-popup.svelte.d.ts +14 -0
- package/dist/lib/ev-stations/station-popup.svelte.js +54 -0
- package/dist/lib/ev-stations/types.d.ts +0 -29
- package/dist/lib/ev-stations/zip-codes.d.ts +11 -0
- package/dist/lib/ev-stations/zip-codes.js +28 -16
- package/dist/lib/index.d.ts +8 -56
- package/dist/lib/index.js +7 -46
- package/dist/lib/legend/Legend.svelte +18 -19
- package/dist/lib/legend/Legend.svelte.d.ts +2 -2
- package/dist/lib/levels.d.ts +7 -0
- package/dist/lib/levels.js +19 -0
- package/dist/lib/map/MapShell.svelte +17 -24
- package/dist/lib/map/MapShell.svelte.d.ts +4 -4
- package/dist/lib/map/basemaps.d.ts +25 -0
- package/dist/lib/map/basemaps.js +66 -0
- package/dist/lib/map/live-map.svelte.d.ts +3 -0
- package/dist/lib/map/live-map.svelte.js +22 -0
- package/dist/lib/map/sync-plugins.svelte.d.ts +19 -0
- package/dist/lib/map/sync-plugins.svelte.js +52 -0
- package/dist/lib/monitors/components/MonitorSubscriptionManager.svelte +66 -61
- package/dist/lib/monitors/filtered-source.svelte.d.ts +9 -0
- package/dist/lib/monitors/filtered-source.svelte.js +28 -0
- package/dist/lib/monitors/monitors.svelte.d.ts +25 -35
- package/dist/lib/monitors/monitors.svelte.js +35 -218
- package/dist/lib/monitors/retry-load.d.ts +8 -0
- package/dist/lib/monitors/retry-load.js +11 -0
- package/dist/lib/monitors/types.d.ts +1 -41
- package/dist/lib/options/map-option-defaults.d.ts +25 -36
- package/dist/lib/options/map-option-defaults.js +12 -30
- package/dist/lib/options/map-options.svelte.d.ts +13 -0
- package/dist/lib/options/map-options.svelte.js +26 -0
- package/dist/lib/options/menus/LayersMenu.svelte +8 -20
- package/dist/lib/options/menus/LayersMenu.svelte.d.ts +17 -2
- package/dist/lib/options/menus/MonitorsMenu.svelte +34 -18
- package/dist/lib/options/menus/OverlaysMenu.svelte +2 -2
- package/dist/lib/options/menus/PollutantMenu.svelte +4 -9
- package/dist/lib/options/menus/SettingsMenu.svelte +32 -25
- package/dist/lib/options/menus/SettingsMenu.svelte.d.ts +5 -16
- package/dist/lib/options/plugin-order.d.ts +8 -0
- package/dist/lib/options/plugin-order.js +36 -0
- package/dist/lib/options/pollutant-param.d.ts +7 -5
- package/dist/lib/options/pollutant-param.js +9 -5
- package/dist/lib/options/row-icons.d.ts +8 -0
- package/dist/lib/options/row-icons.js +15 -0
- package/dist/lib/options/rows/MarkerIcon.svelte +5 -5
- package/dist/lib/options/rows/MarkerIcon.svelte.d.ts +1 -2
- package/dist/lib/search/Search.svelte +20 -33
- package/dist/lib/search/Search.svelte.d.ts +5 -1
- package/dist/lib/search/search-pin.svelte.d.ts +11 -0
- package/dist/lib/search/search-pin.svelte.js +28 -0
- package/dist/lib/search/service.d.ts +7 -2
- package/dist/lib/search/service.js +17 -10
- package/dist/lib/stores.svelte.d.ts +8 -0
- package/dist/lib/stores.svelte.js +9 -0
- package/dist/lib/wind/wind-plugin.d.ts +11 -0
- package/dist/lib/wind/wind-plugin.js +25 -0
- package/package.json +12 -10
- package/src/lib/MonitorDetailPanel.svelte +23 -20
- package/src/lib/MonitorMapLayout.svelte +147 -77
- package/src/lib/components/DataBox.svelte +4 -1
- package/src/lib/config.svelte.ts +16 -0
- package/src/lib/core.ts +2 -2
- package/src/lib/data-chart/DataChart.svelte +40 -25
- package/src/lib/data-chart/DateRange.ts +58 -15
- package/src/lib/data-chart/chart-utils.ts +6 -7
- package/src/lib/data-chart/level-colors.ts +8 -9
- package/src/lib/data-chart/pacific-time.ts +31 -0
- package/src/lib/data-chart/tooltip.ts +2 -2
- package/{dist/lib/ev-stations/components/EvStationTooltip.svelte → src/lib/ev-stations/EvPopup.svelte} +6 -5
- package/src/lib/ev-stations/ev-plugin.svelte.ts +86 -0
- package/src/lib/ev-stations/ev-station-icons.ts +1 -17
- package/src/lib/ev-stations/ev-stations.ts +72 -0
- package/src/lib/ev-stations/ev-store.svelte.ts +117 -0
- package/src/lib/ev-stations/station-popup.svelte.ts +64 -0
- package/src/lib/ev-stations/types.ts +0 -34
- package/src/lib/ev-stations/zip-codes.ts +29 -16
- package/src/lib/index.ts +8 -99
- package/src/lib/legend/Legend.svelte +18 -19
- package/src/lib/levels.ts +24 -0
- package/src/lib/map/MapShell.svelte +17 -24
- package/src/lib/map/basemaps.ts +76 -0
- package/src/lib/map/live-map.svelte.ts +24 -0
- package/src/lib/map/sync-plugins.svelte.ts +69 -0
- package/src/lib/monitors/components/MonitorSubscriptionManager.svelte +66 -61
- package/src/lib/monitors/filtered-source.svelte.ts +38 -0
- package/src/lib/monitors/monitors.svelte.ts +58 -261
- package/src/lib/monitors/retry-load.ts +14 -0
- package/src/lib/monitors/types.ts +1 -47
- package/src/lib/options/map-option-defaults.ts +30 -53
- package/src/lib/options/map-options.svelte.ts +30 -0
- package/src/lib/options/menus/LayersMenu.svelte +8 -20
- package/src/lib/options/menus/MonitorsMenu.svelte +34 -18
- package/src/lib/options/menus/OverlaysMenu.svelte +2 -2
- package/src/lib/options/menus/PollutantMenu.svelte +4 -9
- package/src/lib/options/menus/SettingsMenu.svelte +32 -25
- package/src/lib/options/plugin-order.ts +38 -0
- package/src/lib/options/pollutant-param.ts +14 -9
- package/src/lib/options/row-icons.ts +17 -0
- package/src/lib/options/rows/MarkerIcon.svelte +5 -5
- package/src/lib/search/Search.svelte +20 -33
- package/src/lib/search/search-pin.svelte.ts +35 -0
- package/src/lib/search/service.ts +34 -15
- package/src/lib/stores.svelte.ts +15 -0
- package/src/lib/wind/wind-plugin.ts +33 -0
- package/dist/lib/collocation-sites/CollocationTooltip.svelte +0 -98
- package/dist/lib/collocation-sites/CollocationTooltip.svelte.d.ts +0 -7
- package/dist/lib/collocation-sites/collocations-icon-manager.svelte.d.ts +0 -7
- package/dist/lib/collocation-sites/collocations-icon-manager.svelte.js +0 -18
- package/dist/lib/collocation-sites/collocations-map-integration.svelte.d.ts +0 -21
- package/dist/lib/collocation-sites/collocations-map-integration.svelte.js +0 -113
- package/dist/lib/collocation-sites/collocations.svelte.d.ts +0 -10
- package/dist/lib/collocation-sites/collocations.svelte.js +0 -21
- package/dist/lib/collocation-sites/types.d.ts +0 -8
- package/dist/lib/collocation-sites/types.js +0 -1
- package/dist/lib/ev-stations/components/EvStationClusterTooltip.svelte +0 -16
- package/dist/lib/ev-stations/components/EvStationClusterTooltip.svelte.d.ts +0 -7
- package/dist/lib/ev-stations/components/EvStationTooltip.svelte.d.ts +0 -7
- package/dist/lib/ev-stations/ev-stations-cluster-renderer.d.ts +0 -19
- package/dist/lib/ev-stations/ev-stations-cluster-renderer.js +0 -131
- package/dist/lib/ev-stations/ev-stations-map-integration.svelte.d.ts +0 -31
- package/dist/lib/ev-stations/ev-stations-map-integration.svelte.js +0 -226
- package/dist/lib/ev-stations/ev-stations.svelte.d.ts +0 -10
- package/dist/lib/ev-stations/ev-stations.svelte.js +0 -57
- package/dist/lib/hms/hms-fire-icon-manager.d.ts +0 -13
- package/dist/lib/hms/hms-fire-icon-manager.js +0 -39
- package/dist/lib/hms/hms-fire-map-integration.svelte.d.ts +0 -23
- package/dist/lib/hms/hms-fire-map-integration.svelte.js +0 -94
- package/dist/lib/hms/hms-smoke-map-integration.svelte.d.ts +0 -39
- package/dist/lib/hms/hms-smoke-map-integration.svelte.js +0 -87
- package/dist/lib/hms/hms.svelte.d.ts +0 -20
- package/dist/lib/hms/hms.svelte.js +0 -237
- package/dist/lib/legend/LegendBar.svelte +0 -45
- package/dist/lib/legend/LegendBar.svelte.d.ts +0 -7
- package/dist/lib/legend/legend-data.d.ts +0 -40
- package/dist/lib/legend/legend-data.js +0 -65
- package/dist/lib/map/Map.svelte +0 -13
- package/dist/lib/map/Map.svelte.d.ts +0 -8
- package/dist/lib/map/basemap.d.ts +0 -14
- package/dist/lib/map/basemap.js +0 -10
- package/dist/lib/map/icons.d.ts +0 -7
- package/dist/lib/map/icons.js +0 -33
- package/dist/lib/map/integrations/base-layer-seperator.d.ts +0 -9
- package/dist/lib/map/integrations/base-layer-seperator.js +0 -11
- package/dist/lib/map/integrations/click-manager.d.ts +0 -14
- package/dist/lib/map/integrations/click-manager.js +0 -52
- package/dist/lib/map/integrations/integrations-manager.d.ts +0 -8
- package/dist/lib/map/integrations/integrations-manager.js +0 -20
- package/dist/lib/map/integrations/map-display-option.svelte.d.ts +0 -7
- package/dist/lib/map/integrations/map-display-option.svelte.js +0 -10
- package/dist/lib/map/integrations/map-geojson-integration.svelte.d.ts +0 -32
- package/dist/lib/map/integrations/map-geojson-integration.svelte.js +0 -60
- package/dist/lib/map/integrations/map-icon-manager.d.ts +0 -15
- package/dist/lib/map/integrations/map-icon-manager.js +0 -52
- package/dist/lib/map/integrations/map-integration.svelte.d.ts +0 -6
- package/dist/lib/map/integrations/map-integration.svelte.js +0 -2
- package/dist/lib/map/integrations/map-layer-integration.svelte.d.ts +0 -11
- package/dist/lib/map/integrations/map-layer-integration.svelte.js +0 -40
- package/dist/lib/map/integrations/tooltip.svelte.d.ts +0 -36
- package/dist/lib/map/integrations/tooltip.svelte.js +0 -131
- package/dist/lib/map/integrations/types.d.ts +0 -14
- package/dist/lib/map/integrations/types.js +0 -1
- package/dist/lib/map/map-manager.svelte.d.ts +0 -20
- package/dist/lib/map/map-manager.svelte.js +0 -63
- package/dist/lib/map/map-style-state.svelte.d.ts +0 -23
- package/dist/lib/map/map-style-state.svelte.js +0 -86
- package/dist/lib/map/utils.d.ts +0 -7
- package/dist/lib/map/utils.js +0 -36
- package/dist/lib/monitors/components/MonitorClusterTooltip.svelte +0 -112
- package/dist/lib/monitors/components/MonitorClusterTooltip.svelte.d.ts +0 -7
- package/dist/lib/monitors/components/MonitorTooltip.svelte +0 -61
- package/dist/lib/monitors/components/MonitorTooltip.svelte.d.ts +0 -7
- package/dist/lib/monitors/monitor-utils.d.ts +0 -4
- package/dist/lib/monitors/monitor-utils.js +0 -41
- package/dist/lib/monitors/monitors-cluster-renderer.d.ts +0 -33
- package/dist/lib/monitors/monitors-cluster-renderer.js +0 -221
- package/dist/lib/monitors/monitors-icon-manager.svelte.d.ts +0 -15
- package/dist/lib/monitors/monitors-icon-manager.svelte.js +0 -78
- package/dist/lib/monitors/monitors-map-integration.svelte.d.ts +0 -43
- package/dist/lib/monitors/monitors-map-integration.svelte.js +0 -301
- package/dist/lib/options/reset-map-options.d.ts +0 -2
- package/dist/lib/options/reset-map-options.js +0 -24
- package/dist/lib/reactivity.svelte.d.ts +0 -0
- package/dist/lib/reactivity.svelte.js +0 -83
- package/dist/lib/wind/wind.svelte.d.ts +0 -10
- package/dist/lib/wind/wind.svelte.js +0 -13
- package/src/lib/collocation-sites/CollocationTooltip.svelte +0 -98
- package/src/lib/collocation-sites/collocations-icon-manager.svelte.ts +0 -21
- package/src/lib/collocation-sites/collocations-map-integration.svelte.ts +0 -136
- package/src/lib/collocation-sites/collocations.svelte.ts +0 -27
- package/src/lib/collocation-sites/types.ts +0 -10
- package/src/lib/ev-stations/components/EvStationClusterTooltip.svelte +0 -16
- package/src/lib/ev-stations/ev-stations-cluster-renderer.ts +0 -162
- package/src/lib/ev-stations/ev-stations-map-integration.svelte.ts +0 -248
- package/src/lib/ev-stations/ev-stations.svelte.ts +0 -84
- package/src/lib/hms/hms-fire-icon-manager.ts +0 -48
- package/src/lib/hms/hms-fire-map-integration.svelte.ts +0 -109
- package/src/lib/hms/hms-smoke-map-integration.svelte.ts +0 -105
- package/src/lib/hms/hms.svelte.ts +0 -270
- package/src/lib/legend/LegendBar.svelte +0 -45
- package/src/lib/legend/legend-data.ts +0 -101
- package/src/lib/map/Map.svelte +0 -13
- package/src/lib/map/basemap.ts +0 -24
- package/src/lib/map/icons.ts +0 -42
- package/src/lib/map/integrations/base-layer-seperator.ts +0 -17
- package/src/lib/map/integrations/click-manager.ts +0 -64
- package/src/lib/map/integrations/integrations-manager.ts +0 -25
- package/src/lib/map/integrations/map-display-option.svelte.ts +0 -13
- package/src/lib/map/integrations/map-geojson-integration.svelte.ts +0 -77
- package/src/lib/map/integrations/map-icon-manager.ts +0 -67
- package/src/lib/map/integrations/map-integration.svelte.ts +0 -8
- package/src/lib/map/integrations/map-layer-integration.svelte.ts +0 -49
- package/src/lib/map/integrations/tooltip.svelte.ts +0 -153
- package/src/lib/map/integrations/types.ts +0 -24
- package/src/lib/map/map-manager.svelte.ts +0 -83
- package/src/lib/map/map-style-state.svelte.ts +0 -94
- package/src/lib/map/utils.ts +0 -53
- package/src/lib/monitors/components/MonitorClusterTooltip.svelte +0 -112
- package/src/lib/monitors/components/MonitorTooltip.svelte +0 -61
- package/src/lib/monitors/monitor-utils.ts +0 -57
- package/src/lib/monitors/monitors-cluster-renderer.ts +0 -285
- package/src/lib/monitors/monitors-icon-manager.svelte.ts +0 -98
- package/src/lib/monitors/monitors-map-integration.svelte.ts +0 -318
- package/src/lib/options/reset-map-options.ts +0 -28
- package/src/lib/reactivity.svelte.ts +0 -82
- package/src/lib/wind/wind.svelte.ts +0 -20
package/src/lib/map/basemap.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/** The slices of MapTiler's MapStyleVariant / ReferenceMapStyle this module needs. */
|
|
2
|
-
export interface StyleVariantLike {
|
|
3
|
-
getType(): string;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export interface ReferenceStyleLike<V extends StyleVariantLike> {
|
|
7
|
-
hasVariant(type: string): boolean;
|
|
8
|
-
getVariant(type: string): V;
|
|
9
|
-
getDefaultVariant(): V;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Variant to show after switching basemaps: the same variant type (e.g. "DARK") when the new
|
|
14
|
-
* basemap offers it, otherwise the new basemap's default.
|
|
15
|
-
*/
|
|
16
|
-
export function variantForStyle<V extends StyleVariantLike>(
|
|
17
|
-
style: ReferenceStyleLike<V>,
|
|
18
|
-
previous: StyleVariantLike | null
|
|
19
|
-
): V {
|
|
20
|
-
if (previous && style.hasVariant(previous.getType())) {
|
|
21
|
-
return style.getVariant(previous.getType());
|
|
22
|
-
}
|
|
23
|
-
return style.getDefaultVariant();
|
|
24
|
-
}
|
package/src/lib/map/icons.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { darken } from "color2k";
|
|
2
|
-
|
|
3
|
-
export function square(color: string, borderWidth: number, borderColor?: string) {
|
|
4
|
-
return `<svg width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
5
|
-
<rect x="${borderWidth / 2}" y="${borderWidth / 2}" width="${24 - borderWidth}" height="${24 - borderWidth}"
|
|
6
|
-
fill="${color}" stroke="${darken(borderColor ?? color, 0.1)}" stroke-width="${borderWidth}"/>
|
|
7
|
-
</svg>`;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function circle(color: string, borderWidth: number, borderColor?: string) {
|
|
11
|
-
return `<svg width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
12
|
-
<circle cx="12" cy="12" r="${12 - borderWidth}" fill="${color}" stroke="${darken(borderColor ?? color, 0.1)}" stroke-width="${borderWidth}"/>
|
|
13
|
-
</svg>`;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function triangle(color: string, borderWidth: number, borderColor?: string) {
|
|
17
|
-
const points = `${12},${borderWidth} ${24 - borderWidth},${24 - borderWidth} ${borderWidth},${24 - borderWidth}`;
|
|
18
|
-
return `<svg width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
19
|
-
<polygon points="${points}"
|
|
20
|
-
fill="${color}" stroke="${darken(borderColor ?? color, 0.1)}" stroke-width="${borderWidth}"/>
|
|
21
|
-
</svg>`;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const CROSSHAIR_PATH =
|
|
25
|
-
"M495.9 248H392c-4.4 0-8 3.6-8 8s3.6 8 8 8H495.9C491.7 390.2 390.2 491.7 264 495.9V392c0-4.4-3.6-8-8-8s-8 3.6-8 8V495.9C121.8 491.7 20.3 390.2 16.1 264H120c4.4 0 8-3.6 8-8s-3.6-8-8-8H16.1C20.3 121.8 121.8 20.3 248 16.1V120c0 4.4 3.6 8 8 8s8-3.6 8-8V16.1C390.2 20.3 491.7 121.8 495.9 248zM0 256a256 256 0 1 0 512 0A256 256 0 1 0 0 256z";
|
|
26
|
-
|
|
27
|
-
const CROSSHAIR_PADDING = 16;
|
|
28
|
-
export const CROSSHAIR_ICON_SIZE = 24 + CROSSHAIR_PADDING * 2;
|
|
29
|
-
|
|
30
|
-
export function withCrosshair(baseSvg: string, color: string = "#ffffff"): string {
|
|
31
|
-
const size = CROSSHAIR_ICON_SIZE;
|
|
32
|
-
const inner = baseSvg.replace("<svg ", `<svg x="${CROSSHAIR_PADDING}" y="${CROSSHAIR_PADDING}" `);
|
|
33
|
-
return `<svg width="${size}" height="${size}" viewBox="0 0 ${size} ${size}" xmlns="http://www.w3.org/2000/svg">${inner}<svg x="0" y="0" width="${size}" height="${size}" viewBox="-8 -8 528 528"><path d="${CROSSHAIR_PATH}" fill="${color}" stroke="${color}" stroke-width="5"/></svg></svg>`;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function asDataURI(svg: string): string {
|
|
37
|
-
return `data:image/svg+xml;utf8,${encodeURIComponent(svg)}`;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function fireIcon(color: string, size: number): string {
|
|
41
|
-
return `<svg width="${size}" height="${size}" viewBox="0 -960 960 960" xmlns="http://www.w3.org/2000/svg" fill="${color}"><path d="M200-400q0 52 21 98.5t60 81.5q-1-5-1-9v-9q0-32 12-60t35-51l113-111 113 111q23 23 35 51t12 60v9q0 4-1 9 39-35 60-81.5t21-98.5q0-50-18.5-94.5T608-574q-20 13-42 19.5t-45 6.5q-62 0-107.5-41T361-690q-39 33-69 68.5t-50.5 72Q221-513 210.5-475T200-400Zm240 52-57 56q-11 11-17 25t-6 29q0 32 23.5 55t56.5 23q33 0 56.5-23t23.5-55q0-16-6-29.5T497-292l-57-56Zm0-492v132q0 34 23.5 57t57.5 23q18 0 33.5-7.5T582-658l18-22q74 42 117 117t43 163q0 134-93 227T440-80q-134 0-227-93t-93-227q0-129 86.5-245T440-840Zm400 320q-17 0-28.5-11.5T800-560q0-17 11.5-28.5T840-600q17 0 28.5 11.5T880-560q0 17-11.5 28.5T840-520Zm-40-120v-200h80v200h-80Z"/></svg>`;
|
|
42
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Map as MaptilerMap } from "@maptiler/sdk";
|
|
2
|
-
import { MapLayerIntegration } from "./map-layer-integration.svelte";
|
|
3
|
-
|
|
4
|
-
class BaseLayerSeperator extends MapLayerIntegration {
|
|
5
|
-
referenceId: string = "Base Layer Seperator";
|
|
6
|
-
|
|
7
|
-
enabled: boolean = true;
|
|
8
|
-
|
|
9
|
-
mapLayer: Parameters<MaptilerMap["addLayer"]>[0] = {
|
|
10
|
-
id: this.referenceId,
|
|
11
|
-
type: "custom",
|
|
12
|
-
render: function () {}
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const baseLayerSeperator = new BaseLayerSeperator();
|
|
17
|
-
export type { BaseLayerSeperator };
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { MapGeoJSONFeature, MapMouseEvent } from "@maptiler/sdk";
|
|
2
|
-
import { mapManager } from "../map-manager.svelte.js";
|
|
3
|
-
|
|
4
|
-
export type ClickHandler = (features: MapGeoJSONFeature[], evt: MapMouseEvent & object) => void;
|
|
5
|
-
|
|
6
|
-
interface ClickRegistration {
|
|
7
|
-
layerIds: string[];
|
|
8
|
-
handler: ClickHandler;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
class ClickManager {
|
|
12
|
-
private registrations: ClickRegistration[] = [];
|
|
13
|
-
private isListening = false;
|
|
14
|
-
|
|
15
|
-
/** Must be called after `mapManager.map` is initialized (i.e. from within `apply()`). */
|
|
16
|
-
register(layerIds: string[], handler: ClickHandler): void {
|
|
17
|
-
const incomingSet = new Set(layerIds);
|
|
18
|
-
const existing = this.registrations.find((r) => r.layerIds.some((id) => incomingSet.has(id)));
|
|
19
|
-
if (existing) {
|
|
20
|
-
existing.layerIds = layerIds;
|
|
21
|
-
existing.handler = handler;
|
|
22
|
-
} else {
|
|
23
|
-
this.registrations.push({ layerIds, handler });
|
|
24
|
-
}
|
|
25
|
-
this.ensureListener();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
unregister(layerIds: string[]): void {
|
|
29
|
-
const set = new Set(layerIds);
|
|
30
|
-
this.registrations = this.registrations.filter((r) => !r.layerIds.some((id) => set.has(id)));
|
|
31
|
-
if (this.registrations.length === 0) {
|
|
32
|
-
this.removeListener();
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
private ensureListener(): void {
|
|
37
|
-
if (this.isListening || !mapManager.map) return;
|
|
38
|
-
mapManager.map.on("click", this.handleClick);
|
|
39
|
-
this.isListening = true;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
private removeListener(): void {
|
|
43
|
-
if (!this.isListening) return;
|
|
44
|
-
mapManager.map?.off("click", this.handleClick);
|
|
45
|
-
this.isListening = false;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
private handleClick = (evt: MapMouseEvent & object): void => {
|
|
49
|
-
if (!mapManager.map) return;
|
|
50
|
-
const allLayerIds = this.registrations.flatMap((r) => r.layerIds);
|
|
51
|
-
const features = mapManager.map.queryRenderedFeatures(evt.point, { layers: allLayerIds });
|
|
52
|
-
if (!features.length) return;
|
|
53
|
-
|
|
54
|
-
const winningLayerId = features[0].layer.id;
|
|
55
|
-
const registration = this.registrations.find((r) => r.layerIds.includes(winningLayerId));
|
|
56
|
-
if (!registration) return;
|
|
57
|
-
|
|
58
|
-
const ownFeatures = features.filter((f) => registration.layerIds.includes(f.layer.id));
|
|
59
|
-
registration.handler(ownFeatures, evt);
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export const clickManager = new ClickManager();
|
|
64
|
-
export type { ClickManager };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { XMap } from "@tstk/builtin-extensions";
|
|
2
|
-
import type { SomeMapIntegration } from "./types";
|
|
3
|
-
|
|
4
|
-
class IntegrationsManager {
|
|
5
|
-
private integrations: XMap<string, SomeMapIntegration> = new XMap();
|
|
6
|
-
|
|
7
|
-
register(...integrations: Array<SomeMapIntegration>): void {
|
|
8
|
-
for (const integration of integrations) {
|
|
9
|
-
this.integrations.set(integration.referenceId, integration);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
refresh(): void {
|
|
14
|
-
for (const integration of this.integrations.values()) {
|
|
15
|
-
if (integration.enabled) {
|
|
16
|
-
integration.apply();
|
|
17
|
-
} else if (integration.remove) {
|
|
18
|
-
integration.remove();
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const integrationsManager = new IntegrationsManager();
|
|
25
|
-
export type { IntegrationsManager };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { MapImageIcon } from "./types";
|
|
2
|
-
|
|
3
|
-
export class MapDisplayOption {
|
|
4
|
-
icon?: MapImageIcon;
|
|
5
|
-
label: string;
|
|
6
|
-
value: boolean;
|
|
7
|
-
|
|
8
|
-
constructor(label: string, value: boolean, icon?: MapImageIcon) {
|
|
9
|
-
this.icon = icon;
|
|
10
|
-
this.label = label;
|
|
11
|
-
this.value = $state(value);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type { Map as MaptilerMap } from "@maptiler/sdk";
|
|
2
|
-
import type { Feature, Geometry } from "geojson";
|
|
3
|
-
import type { MapIconManager } from "./map-icon-manager";
|
|
4
|
-
import { MapLayerIntegration } from "./map-layer-integration.svelte";
|
|
5
|
-
import { mapManager } from "../map-manager.svelte.js";
|
|
6
|
-
|
|
7
|
-
export abstract class MapGeoJSONIntegration<
|
|
8
|
-
T = Record<string, unknown>
|
|
9
|
-
> extends MapLayerIntegration {
|
|
10
|
-
abstract features: Array<Feature<Geometry, T>>;
|
|
11
|
-
abstract mapSource: Parameters<MaptilerMap["addSource"]>[1];
|
|
12
|
-
|
|
13
|
-
remove() {
|
|
14
|
-
this.removeLayerAndSource();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Removes only this integration's own layer and source. Non-virtual on purpose: `apply()`
|
|
19
|
-
* paths call it to clear stale map state before re-adding, without triggering a subclass's
|
|
20
|
-
* `remove()` override (which also tears down tooltips/click handlers that apply just set up).
|
|
21
|
-
*/
|
|
22
|
-
protected removeLayerAndSource(): void {
|
|
23
|
-
if (mapManager.map?.getLayer(this.referenceId)) {
|
|
24
|
-
mapManager.map.removeLayer(this.referenceId);
|
|
25
|
-
}
|
|
26
|
-
if (mapManager.map?.getSource(this.referenceId)) {
|
|
27
|
-
mapManager.map.removeSource(this.referenceId);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export abstract class MapIconLayerIntegration<
|
|
33
|
-
T = Record<string, unknown>
|
|
34
|
-
> extends MapGeoJSONIntegration<T> {
|
|
35
|
-
abstract icons: MapIconManager;
|
|
36
|
-
private generation = 0;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Drops every callback still waiting on icons. `apply()` and `remove()` call it, so a
|
|
40
|
-
* subclass overriding `apply()` without calling `super.apply()` first must call it itself.
|
|
41
|
-
*/
|
|
42
|
-
protected supersedePending(): void {
|
|
43
|
-
this.generation++;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Runs `run` once the icons have loaded, unless an `apply()` or `remove()` has happened
|
|
48
|
-
* since (the state it was scheduled for is gone) or a basemap change is in flight (the
|
|
49
|
-
* refresh on "style.load" re-applies).
|
|
50
|
-
*/
|
|
51
|
-
protected whenIconsLoad(run: () => void): void {
|
|
52
|
-
const generation = this.generation;
|
|
53
|
-
this.icons
|
|
54
|
-
.loadIcons()
|
|
55
|
-
.then(() => {
|
|
56
|
-
if (generation !== this.generation || mapManager.styleLoading) return;
|
|
57
|
-
run();
|
|
58
|
-
})
|
|
59
|
-
.catch(console.error);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
apply() {
|
|
63
|
-
if (!mapManager.map) return;
|
|
64
|
-
|
|
65
|
-
this.supersedePending();
|
|
66
|
-
this.whenIconsLoad(() => {
|
|
67
|
-
this.removeLayerAndSource();
|
|
68
|
-
mapManager.map?.addSource(this.referenceId, this.mapSource);
|
|
69
|
-
super.apply();
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
remove() {
|
|
74
|
-
this.supersedePending();
|
|
75
|
-
super.remove();
|
|
76
|
-
}
|
|
77
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import type { Map as MaptilerMap } from "@maptiler/sdk";
|
|
2
|
-
import { mapManager } from "../map-manager.svelte.js";
|
|
3
|
-
import type { MapImageIcon } from "./types";
|
|
4
|
-
import { SvelteMap } from "svelte/reactivity";
|
|
5
|
-
|
|
6
|
-
export class MapIconManager {
|
|
7
|
-
protected icons: SvelteMap<string, MapImageIcon> = new SvelteMap();
|
|
8
|
-
|
|
9
|
-
constructor(iconMap?: SvelteMap<string, MapImageIcon>) {
|
|
10
|
-
if (iconMap) {
|
|
11
|
-
this.icons = iconMap;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
get iter(): MapIterator<[string, MapImageIcon]> {
|
|
16
|
-
return this.icons.entries();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
get(id: string): MapImageIcon | undefined {
|
|
20
|
-
return this.icons.get(id);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
has(id: string): boolean {
|
|
24
|
-
return this.icons.has(id);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async loadIcons(): Promise<void> {
|
|
28
|
-
if (!mapManager.map) return;
|
|
29
|
-
await Promise.all(this.icons.values().map((icon) => this.loadImage(icon, mapManager.map!)));
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
register(id: string, icon: HTMLImageElement) {
|
|
33
|
-
const imageIcon: MapImageIcon = { id, image: icon };
|
|
34
|
-
this.icons.set(id, imageIcon);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
protected loadImage(icon: MapImageIcon, map: MaptilerMap): Promise<void> {
|
|
38
|
-
return this.applyImage("add", icon, map);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
protected updateImage(icon: MapImageIcon, map: MaptilerMap): Promise<void> {
|
|
42
|
-
return this.applyImage("update", icon, map);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
private applyImage(
|
|
46
|
-
action: "add" | "update",
|
|
47
|
-
icon: MapImageIcon,
|
|
48
|
-
map: MaptilerMap
|
|
49
|
-
): Promise<void> {
|
|
50
|
-
const apply = () =>
|
|
51
|
-
action === "add" ? map.addImage(icon.id, icon.image) : map.updateImage(icon.id, icon.image);
|
|
52
|
-
if (!icon.image.complete) {
|
|
53
|
-
return new Promise((resolve, reject) => {
|
|
54
|
-
icon.image.onload = () => {
|
|
55
|
-
apply();
|
|
56
|
-
resolve();
|
|
57
|
-
};
|
|
58
|
-
icon.image.onerror = (err) => {
|
|
59
|
-
reject(new Error(`Failed to load image ${icon.id}: ${err}`, { cause: err }));
|
|
60
|
-
};
|
|
61
|
-
});
|
|
62
|
-
} else {
|
|
63
|
-
apply();
|
|
64
|
-
return Promise.resolve();
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { Map as MaptilerMap } from "@maptiler/sdk";
|
|
2
|
-
import { untrack } from "svelte";
|
|
3
|
-
import { mapManager } from "../map-manager.svelte.js";
|
|
4
|
-
import { MapIntegration } from "./map-integration.svelte";
|
|
5
|
-
|
|
6
|
-
export abstract class MapLayerIntegration extends MapIntegration {
|
|
7
|
-
abstract referenceId: string;
|
|
8
|
-
abstract mapLayer: Parameters<MaptilerMap["addLayer"]>[0];
|
|
9
|
-
abstract enabled: boolean;
|
|
10
|
-
beforeLayer?: string;
|
|
11
|
-
|
|
12
|
-
constructor() {
|
|
13
|
-
super();
|
|
14
|
-
// Each integration manages its own lifecycle. Tracking both mapManager.map and
|
|
15
|
-
// this.enabled means apply/remove fire automatically on map load and on enabled
|
|
16
|
-
// changes. untrack on the call itself prevents reactive reads inside apply/remove
|
|
17
|
-
// from leaking back into this effect's dependency graph. While a new basemap style is
|
|
18
|
-
// loading nothing is applied or removed: the refresh on "style.load" does both.
|
|
19
|
-
$effect.root(() => {
|
|
20
|
-
$effect(() => {
|
|
21
|
-
const enabled = this.enabled;
|
|
22
|
-
if (!mapManager.map || mapManager.styleLoading) return;
|
|
23
|
-
if (enabled) {
|
|
24
|
-
untrack(() => this.apply());
|
|
25
|
-
} else {
|
|
26
|
-
untrack(() => this.remove());
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
apply() {
|
|
33
|
-
if (!mapManager.map) return;
|
|
34
|
-
if (!mapManager.map.getLayer(this.referenceId)) {
|
|
35
|
-
mapManager.map.addLayer(this.mapLayer, this.beforeLayer);
|
|
36
|
-
}
|
|
37
|
-
mapManager.map.setLayoutProperty(
|
|
38
|
-
this.referenceId,
|
|
39
|
-
"visibility",
|
|
40
|
-
this.enabled ? "visible" : "none"
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
remove() {
|
|
45
|
-
if (mapManager.map?.getLayer(this.referenceId)) {
|
|
46
|
-
mapManager.map.removeLayer(this.referenceId);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import type { MapLayerEventType, Popup } from "@maptiler/sdk";
|
|
2
|
-
import { mapManager } from "../map-manager.svelte.js";
|
|
3
|
-
import { XMap } from "@tstk/builtin-extensions";
|
|
4
|
-
|
|
5
|
-
export type TooltipBuilder = (evt: MapLayerEventType["mousemove"] & object) => Popup | void;
|
|
6
|
-
|
|
7
|
-
function handleZoom() {
|
|
8
|
-
TooltipManager.activeHandle?.clearTooltip();
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function setCursorPointer() {
|
|
12
|
-
mapManager.map!.getCanvas().style.cursor = "pointer";
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function setCursorDefault() {
|
|
16
|
-
mapManager.map!.getCanvas().style.cursor = "";
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export class TooltipManager {
|
|
20
|
-
static activeHandle: TooltipHandle | null = null;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Host-controlled master switch. When false, enable() is a no-op
|
|
24
|
-
* regardless of how many times or when internal code (e.g. a map
|
|
25
|
-
* integration's apply()) calls it -- unlike isEnabled below, this is
|
|
26
|
-
* checked fresh on every enable() call, so it can't be raced by an
|
|
27
|
-
* apply() invocation that fires before a host sets this to false.
|
|
28
|
-
*/
|
|
29
|
-
enabled: boolean = true;
|
|
30
|
-
|
|
31
|
-
private isEnabled: boolean = false;
|
|
32
|
-
private _tooltips: XMap<string, TooltipHandle> = new XMap();
|
|
33
|
-
|
|
34
|
-
get tooltips(): MapIterator<TooltipHandle> {
|
|
35
|
-
return this._tooltips.values();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
enable(layerId?: string) {
|
|
39
|
-
if (!this.enabled || !mapManager.map || this.isEnabled) return;
|
|
40
|
-
mapManager.map.on("zoom", handleZoom);
|
|
41
|
-
this.forEachHandle(layerId, (h) => h.enable());
|
|
42
|
-
this.isEnabled = true;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
disable(layerId?: string) {
|
|
46
|
-
if (!mapManager.map || !this.isEnabled) return;
|
|
47
|
-
mapManager.map.off("zoom", handleZoom);
|
|
48
|
-
this.forEachHandle(layerId, (h) => h.disable());
|
|
49
|
-
this.isEnabled = false;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
get(layerId: string) {
|
|
53
|
-
return this._tooltips.get(layerId);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
has(layerId: string) {
|
|
57
|
-
return this._tooltips.has(layerId);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
register(layerId: string, builder: TooltipBuilder, priority: number = 0) {
|
|
61
|
-
const tooltipHandle = new TooltipHandle(layerId, builder, priority);
|
|
62
|
-
this._tooltips.set(layerId, tooltipHandle);
|
|
63
|
-
return tooltipHandle;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
with(layerId: string | Array<string>, cb: (tooltip: TooltipHandle) => void) {
|
|
67
|
-
const ids = Array.isArray(layerId) ? layerId : [layerId];
|
|
68
|
-
for (const id of ids) {
|
|
69
|
-
const tooltip = this._tooltips.get(id);
|
|
70
|
-
if (tooltip) cb(tooltip);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
private forEachHandle(layerId: string | undefined, cb: (h: TooltipHandle) => void) {
|
|
75
|
-
if (layerId !== undefined && this._tooltips.has(layerId)) {
|
|
76
|
-
cb(this._tooltips.get(layerId)!);
|
|
77
|
-
} else {
|
|
78
|
-
for (const h of this.tooltips) cb(h);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
class TooltipHandle {
|
|
84
|
-
layerId: string;
|
|
85
|
-
priority: number;
|
|
86
|
-
tooltip: Popup | null = null;
|
|
87
|
-
|
|
88
|
-
private activeFeatureId: string | number | undefined = undefined;
|
|
89
|
-
private isEnabled: boolean = false;
|
|
90
|
-
|
|
91
|
-
clearTooltip = () => {
|
|
92
|
-
if (TooltipManager.activeHandle !== this) return;
|
|
93
|
-
this.tooltip?.remove();
|
|
94
|
-
this.tooltip = null;
|
|
95
|
-
TooltipManager.activeHandle = null;
|
|
96
|
-
this.activeFeatureId = undefined;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
private setTooltip: (evt: MapLayerEventType["mousemove"] & object) => void;
|
|
100
|
-
|
|
101
|
-
constructor(layerId: string, builder: TooltipBuilder, priority: number = 0) {
|
|
102
|
-
this.layerId = layerId;
|
|
103
|
-
this.priority = priority;
|
|
104
|
-
|
|
105
|
-
this.setTooltip = (evt: MapLayerEventType["mousemove"] & object) => {
|
|
106
|
-
if (!mapManager.map || !evt.features) return;
|
|
107
|
-
|
|
108
|
-
const featureId = evt.features[0]?.id;
|
|
109
|
-
const isOwner = TooltipManager.activeHandle === this;
|
|
110
|
-
const sameFeature = featureId === this.activeFeatureId;
|
|
111
|
-
|
|
112
|
-
if (isOwner && this.tooltip && sameFeature) {
|
|
113
|
-
this.tooltip.setLngLat(evt.lngLat);
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const activeHandle = TooltipManager.activeHandle;
|
|
118
|
-
if (activeHandle !== null && activeHandle !== this && activeHandle.priority >= this.priority)
|
|
119
|
-
return;
|
|
120
|
-
|
|
121
|
-
activeHandle?.clearTooltip();
|
|
122
|
-
this.activeFeatureId = undefined;
|
|
123
|
-
|
|
124
|
-
const tooltip = builder(evt);
|
|
125
|
-
|
|
126
|
-
if (tooltip) {
|
|
127
|
-
this.tooltip = tooltip;
|
|
128
|
-
TooltipManager.activeHandle = this;
|
|
129
|
-
this.activeFeatureId = featureId;
|
|
130
|
-
tooltip.addTo(mapManager.map);
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
enable() {
|
|
136
|
-
if (!mapManager.map || this.isEnabled) return;
|
|
137
|
-
mapManager.map.on("mousemove", this.layerId, setCursorPointer);
|
|
138
|
-
mapManager.map.on("mouseleave", this.layerId, setCursorDefault);
|
|
139
|
-
mapManager.map.on("mousemove", this.layerId, this.setTooltip);
|
|
140
|
-
mapManager.map.on("mouseleave", this.layerId, this.clearTooltip);
|
|
141
|
-
this.isEnabled = true;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
disable() {
|
|
145
|
-
if (!mapManager.map || !this.isEnabled) return;
|
|
146
|
-
this.clearTooltip();
|
|
147
|
-
mapManager.map.off("mousemove", this.layerId, setCursorPointer);
|
|
148
|
-
mapManager.map.off("mouseleave", this.layerId, setCursorDefault);
|
|
149
|
-
mapManager.map.off("mousemove", this.layerId, this.setTooltip);
|
|
150
|
-
mapManager.map.off("mouseleave", this.layerId, this.clearTooltip);
|
|
151
|
-
this.isEnabled = false;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { MapLayerEventType, Map as MaptilerMap, Popup } from "@maptiler/sdk";
|
|
2
|
-
import type { MapIntegration } from "./map-integration.svelte";
|
|
3
|
-
import type {
|
|
4
|
-
MapGeoJSONIntegration,
|
|
5
|
-
MapIconLayerIntegration
|
|
6
|
-
} from "./map-geojson-integration.svelte";
|
|
7
|
-
|
|
8
|
-
export type TooltipPopup = <T extends TooltipController>(
|
|
9
|
-
mapCtrl: T
|
|
10
|
-
) => (evt: MapLayerEventType["mousemove"] & object) => void;
|
|
11
|
-
export type SomeMapIntegration =
|
|
12
|
-
| MapIntegration
|
|
13
|
-
| MapGeoJSONIntegration<Record<string, unknown>>
|
|
14
|
-
| MapIconLayerIntegration<Record<string, unknown>>;
|
|
15
|
-
|
|
16
|
-
interface TooltipController {
|
|
17
|
-
tooltip: Popup | null;
|
|
18
|
-
map?: MaptilerMap;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface MapImageIcon {
|
|
22
|
-
id: string;
|
|
23
|
-
image: HTMLImageElement;
|
|
24
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
MapStyle,
|
|
3
|
-
MapStyleVariant,
|
|
4
|
-
config as MaptilerConfig,
|
|
5
|
-
Map as MaptilerMap
|
|
6
|
-
} from "@maptiler/sdk";
|
|
7
|
-
import type { Attachment } from "svelte/attachments";
|
|
8
|
-
import { isGeoJSONSource } from "./utils";
|
|
9
|
-
import type { Feature, GeoJsonProperties, Geometry } from "geojson";
|
|
10
|
-
|
|
11
|
-
MaptilerConfig.apiKey = import.meta.env.VITE_MAPTILER_KEY;
|
|
12
|
-
|
|
13
|
-
export const DefaultMapStyle: MapStyleVariant = MapStyle.STREETS_V4.DEFAULT;
|
|
14
|
-
const excludeLayers = ["Sport", "Tourism", "Culture", "Shopping", "Food", "Transport"];
|
|
15
|
-
|
|
16
|
-
class MapManager {
|
|
17
|
-
map: MaptilerMap | null = $state(null);
|
|
18
|
-
/**
|
|
19
|
-
* True between `setStyle()` and the new style's "style.load". Plain (non-reactive) on purpose:
|
|
20
|
-
* integrations skip touching the style while it's set, and the `integrationsManager.refresh()`
|
|
21
|
-
* that runs on "style.load" applies/removes every integration afterwards.
|
|
22
|
-
*/
|
|
23
|
-
styleLoading: boolean = false;
|
|
24
|
-
|
|
25
|
-
setDataSource(sourceId: string, features: Array<Feature<Geometry, GeoJsonProperties>>): void {
|
|
26
|
-
const source = mapManager.map?.getSource(sourceId);
|
|
27
|
-
|
|
28
|
-
if (isGeoJSONSource(source)) {
|
|
29
|
-
source.setData({
|
|
30
|
-
type: "FeatureCollection",
|
|
31
|
-
features
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
refreshMap(): void {
|
|
37
|
-
if (mapManager.map) {
|
|
38
|
-
this.removeExcludedLayers();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
removeExcludedLayers(): void {
|
|
43
|
-
for (const toExclude of excludeLayers) {
|
|
44
|
-
if (mapManager.map?.getLayer(toExclude)) {
|
|
45
|
-
mapManager.map.removeLayer(toExclude);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
removeMap(): void {
|
|
51
|
-
return mapManager.map?.remove();
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export const mapManager = new MapManager();
|
|
56
|
-
export type { MapManager };
|
|
57
|
-
|
|
58
|
-
export const initializeMap: Attachment<HTMLDivElement> = (container: string | HTMLElement) => {
|
|
59
|
-
const map = new MaptilerMap({
|
|
60
|
-
container: container,
|
|
61
|
-
center: [-119.7987626619462, 36.76272050981146],
|
|
62
|
-
zoom: 7,
|
|
63
|
-
style: DefaultMapStyle,
|
|
64
|
-
projection: "globe",
|
|
65
|
-
space: {
|
|
66
|
-
preset: "milkyway"
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
// "load" fires once the style and initial viewport tiles have loaded --
|
|
71
|
-
// in practice this can hang indefinitely (observed: never fires, even
|
|
72
|
-
// after 20+s, despite the style/tiles being independently fetchable) for
|
|
73
|
-
// reasons that don't affect "idle", which fires once the map has
|
|
74
|
-
// finished rendering after becoming idle. MapShell's own effect no
|
|
75
|
-
// longer waits for a *second* idle event to hide the load screen (see
|
|
76
|
-
// its comment), so listening for "idle" here doesn't reintroduce the
|
|
77
|
-
// hang that change was fixing.
|
|
78
|
-
map.once("idle", () => {
|
|
79
|
-
mapManager.map = map;
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
return () => map.remove();
|
|
83
|
-
};
|