jenosize-ui 0.3.0 → 0.3.1
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/README.md +5 -5
- package/THIRD-PARTY-NOTICES.md +80 -0
- package/dist/{GradientPicker-CQm3GT7F.d.ts → GradientPicker-Bv3V3vL_.d.ts} +1 -1
- package/dist/{PaymentInput-Cz5jFB3p.d.ts → PaymentInput-s7_s3UDi.d.ts} +1 -1
- package/dist/{Select-CXOAMlk7.d.ts → Select-r233iMaU.d.ts} +1 -1
- package/dist/{TagInput-CzIrONr-.d.ts → TagInput-w_l9Fp5i.d.ts} +1 -1
- package/dist/area-chart.d.ts +2 -2
- package/dist/area-chart.js +5 -4
- package/dist/avatar.d.ts +1 -1
- package/dist/avatar.js +4 -3
- package/dist/badge.d.ts +1 -1
- package/dist/badge.js +4 -3
- package/dist/bar-chart.d.ts +2 -2
- package/dist/bar-chart.js +5 -4
- package/dist/breadcrumb.d.ts +1 -1
- package/dist/breadcrumb.js +4 -3
- package/dist/button.d.ts +1 -1
- package/dist/button.js +5 -4
- package/dist/calendar.d.ts +1 -1
- package/dist/calendar.js +7 -6
- package/dist/callout.js +6 -5
- package/dist/card.js +1 -0
- package/dist/carousel.d.ts +1 -1
- package/dist/carousel.js +4 -3
- package/dist/catalog.json +799 -3
- package/dist/checkbox.js +5 -4
- package/dist/{chunk-3JQKVC2K.js → chunk-2EUVBRKG.js} +3 -3
- package/dist/{chunk-B4OVIE2X.js → chunk-2RRPWOKT.js} +5 -5
- package/dist/{chunk-OXNIEIOY.js → chunk-3JFSKCVU.js} +14 -14
- package/dist/{chunk-R25NHHYT.js → chunk-3ZZZPT5G.js} +3 -3
- package/dist/{chunk-7ZA3QZRP.js → chunk-47EOHGXM.js} +3 -3
- package/dist/{chunk-PFAFTLN3.js → chunk-4KRCT3Q2.js} +4 -4
- package/dist/{chunk-QTWRR7IS.js → chunk-4P3JA653.js} +7 -7
- package/dist/{chunk-ZAWGG4H2.js → chunk-5Z26DU23.js} +6 -6
- package/dist/{chunk-BJHLW25G.js → chunk-6CJYVYVN.js} +14 -12
- package/dist/{chunk-XWXXKEG6.js → chunk-6Q4VVBFO.js} +3 -3
- package/dist/chunk-7JOW3LEH.js +4852 -0
- package/dist/{chunk-QSOLK2I2.js → chunk-7RD5RTHU.js} +6 -6
- package/dist/{chunk-A4YPUS6C.js → chunk-A36W77MQ.js} +3 -3
- package/dist/{chunk-U5X3MLM5.js → chunk-AZFHRLYF.js} +4 -4
- package/dist/{chunk-BXQFBFT7.js → chunk-B6LYO33Y.js} +4 -4
- package/dist/{chunk-SGMVB7HD.js → chunk-CH2XMCWX.js} +3 -3
- package/dist/{chunk-CUONE6LA.js → chunk-D46OKHTH.js} +4 -4
- package/dist/{chunk-5SGF47TZ.js → chunk-D4YGYNNY.js} +6 -6
- package/dist/{chunk-YGJL7QS7.js → chunk-D7WD4SUC.js} +5 -5
- package/dist/{chunk-UJ4WEQHR.js → chunk-EBZNUQ6E.js} +5 -5
- package/dist/{chunk-MS6DY4CE.js → chunk-ED5UCYAV.js} +3 -3
- package/dist/{chunk-Z6NSOC6T.js → chunk-EDVYLO2N.js} +3 -3
- package/dist/{chunk-5XSR757T.js → chunk-EKQLIUV5.js} +4 -4
- package/dist/{chunk-BKBINQJZ.js → chunk-EKV3CVTY.js} +4 -4
- package/dist/{chunk-IESEBPYA.js → chunk-G7B2QUQP.js} +3 -3
- package/dist/{chunk-YKPTUANT.js → chunk-GHRZC5LS.js} +5 -5
- package/dist/{chunk-KNW3IUWX.js → chunk-GIC6T647.js} +5 -5
- package/dist/{chunk-EXRVOGJ5.js → chunk-GV2KTRRP.js} +6 -6
- package/dist/{chunk-Q2KR7PSX.js → chunk-GYL4KOPT.js} +3 -3
- package/dist/{chunk-VIKV25VP.js → chunk-HB6UA6EF.js} +4 -4
- package/dist/{chunk-YXYZW6WU.js → chunk-HTWGTTSF.js} +19 -6
- package/dist/{chunk-3P3QZPHV.js → chunk-IH2F5UNQ.js} +4 -4
- package/dist/{chunk-KCM4KEZ2.js → chunk-INYUL4DX.js} +3 -3
- package/dist/{chunk-737A4YNC.js → chunk-IUB5TSSH.js} +3 -3
- package/dist/{chunk-P2BGR77C.js → chunk-JGGSRKHW.js} +3 -3
- package/dist/{chunk-DYRGHXT5.js → chunk-JHHJNIW2.js} +3 -3
- package/dist/{chunk-YGFTNICV.js → chunk-KBI442IB.js} +7 -4
- package/dist/{chunk-XKTD3X6Z.js → chunk-KNKR5TUM.js} +8 -8
- package/dist/{chunk-5ECTNYKU.js → chunk-LKUAVDWP.js} +4 -4
- package/dist/{chunk-GDW6NFYN.js → chunk-LPWSP523.js} +3 -3
- package/dist/{chunk-44AWXIQK.js → chunk-LY7IJOUF.js} +4 -4
- package/dist/{chunk-26XQU3TC.js → chunk-LYWQD5KL.js} +7 -7
- package/dist/{chunk-EHML2DLR.js → chunk-N7DLNDER.js} +4 -4
- package/dist/{chunk-ESDSTS5N.js → chunk-NDRQETOQ.js} +14 -10
- package/dist/{chunk-5GBA6X6A.js → chunk-O7CPRU67.js} +3 -3
- package/dist/{chunk-QZHAL4BL.js → chunk-OEYKTHG7.js} +3 -3
- package/dist/{chunk-LLUWBQK6.js → chunk-OG3H3RP2.js} +4 -4
- package/dist/{chunk-O24HHIQG.js → chunk-PFKPKE6O.js} +5 -5
- package/dist/{chunk-GOCO45FF.js → chunk-PRWPFBA5.js} +4 -4
- package/dist/{chunk-TCTTZHUS.js → chunk-TDKKZA63.js} +6 -6
- package/dist/{chunk-XAQQ4LYL.js → chunk-TDXHBS2C.js} +6 -6
- package/dist/{chunk-JZ4HGFWK.js → chunk-THGGU64E.js} +3 -3
- package/dist/{chunk-S5LLA36K.js → chunk-URAURI6G.js} +7 -7
- package/dist/{chunk-CVCS5G3E.js → chunk-UU6KUS5O.js} +8 -8
- package/dist/{chunk-O5EHNNPS.js → chunk-V7KEEDSF.js} +5 -4
- package/dist/chunk-VHAA22YE.js +11 -0
- package/dist/{chunk-XCFFM2C7.js → chunk-WM6DGNIA.js} +5 -5
- package/dist/{chunk-ZF362B2X.js → chunk-WUXMLJEC.js} +4 -4
- package/dist/{chunk-YQAYAJ2T.js → chunk-XNXBO44X.js} +4 -4
- package/dist/{chunk-SKPKL47Y.js → chunk-XPY3XT7L.js} +13 -13
- package/dist/{chunk-7UCKFULR.js → chunk-XVFRDKZJ.js} +4 -4
- package/dist/{chunk-L7Z6XGBU.js → chunk-YDD46AX2.js} +4 -4
- package/dist/{chunk-MDKVYC6R.js → chunk-YHQJGNXD.js} +6 -6
- package/dist/{chunk-CQGMOPLG.js → chunk-YKRE5NIH.js} +5 -5
- package/dist/{chunk-ZJIY642R.js → chunk-ZIEGUI25.js} +2 -2
- package/dist/{chunk-OIPFTJS6.js → chunk-ZLDWYTDA.js} +3 -3
- package/dist/color-input.d.ts +2 -2
- package/dist/color-input.js +12 -11
- package/dist/color-picker.d.ts +3 -3
- package/dist/color-picker.js +10 -9
- package/dist/combobox.d.ts +1 -1
- package/dist/combobox.js +7 -6
- package/dist/data-map.d.ts +1673 -0
- package/dist/data-map.js +36 -0
- package/dist/date-calendar.d.ts +3 -3
- package/dist/date-calendar.js +5 -4
- package/dist/date-input.d.ts +1 -1
- package/dist/date-input.js +6 -5
- package/dist/date-picker.d.ts +3 -3
- package/dist/date-picker.js +12 -11
- package/dist/{date-types-DrDdF6WJ.d.ts → date-types-CLZek3W2.d.ts} +1 -1
- package/dist/dialog.js +7 -6
- package/dist/drawer.js +6 -5
- package/dist/dropdown-menu.js +3 -2
- package/dist/dropzone.d.ts +3 -3
- package/dist/dropzone.js +8 -7
- package/dist/file-trigger.js +1 -0
- package/dist/form.d.ts +6 -6
- package/dist/form.js +25 -24
- package/dist/header-navigation.d.ts +1 -1
- package/dist/header-navigation.js +9 -8
- package/dist/helper.js +1 -0
- package/dist/illustration.js +1 -0
- package/dist/index.d.ts +9 -8
- package/dist/index.js +66 -64
- package/dist/indicator.js +1 -0
- package/dist/inline-banner.js +6 -5
- package/dist/input.d.ts +1 -1
- package/dist/input.js +6 -5
- package/dist/kanban-board.d.ts +1 -1
- package/dist/kanban-board.js +5 -4
- package/dist/{labels-C992bt7G.d.ts → labels-CuSlirP_.d.ts} +222 -1
- package/dist/line-chart.d.ts +2 -2
- package/dist/line-chart.js +5 -4
- package/dist/number-input.d.ts +1 -1
- package/dist/number-input.js +6 -5
- package/dist/pagination.d.ts +1 -1
- package/dist/pagination.js +8 -7
- package/dist/payment-input.d.ts +3 -3
- package/dist/payment-input.js +6 -5
- package/dist/pie-chart.d.ts +2 -2
- package/dist/pie-chart.js +5 -4
- package/dist/popover.js +6 -5
- package/dist/progress-steps.js +3 -2
- package/dist/progress.js +1 -0
- package/dist/provider.d.ts +1 -1
- package/dist/provider.js +3 -2
- package/dist/qr-code.d.ts +1 -1
- package/dist/qr-code.js +6 -5
- package/dist/radar-chart.d.ts +2 -2
- package/dist/radar-chart.js +5 -4
- package/dist/radial-chart.d.ts +2 -2
- package/dist/radial-chart.js +5 -4
- package/dist/radio.js +5 -4
- package/dist/rich-text-editor.d.ts +1 -1
- package/dist/rich-text-editor.js +19 -18
- package/dist/scroll-area.js +1 -0
- package/dist/select.d.ts +2 -2
- package/dist/select.js +9 -8
- package/dist/separator.js +1 -0
- package/dist/sidebar-navigation.d.ts +1 -1
- package/dist/sidebar-navigation.js +5 -4
- package/dist/skeleton.js +1 -0
- package/dist/slider.d.ts +1 -1
- package/dist/slider.js +5 -4
- package/dist/styles.css +1 -1
- package/dist/switch.js +1 -0
- package/dist/table.d.ts +1 -1
- package/dist/table.js +20 -19
- package/dist/tabs.js +1 -0
- package/dist/tag-input.d.ts +3 -3
- package/dist/tag-input.js +8 -7
- package/dist/tag.d.ts +1 -1
- package/dist/tag.js +4 -3
- package/dist/textarea.js +5 -4
- package/dist/theme.js +6 -5
- package/dist/toast.d.ts +1 -1
- package/dist/toast.js +6 -5
- package/dist/tooltip.js +1 -0
- package/dist/tree.d.ts +1 -1
- package/dist/tree.js +4 -3
- package/dist/{types-DYFl0CEB.d.ts → types-BoZ6XeLB.d.ts} +1 -1
- package/dist/{use-uploads-2E7n0PWT.d.ts → use-uploads-cHo2p7Gn.d.ts} +1 -1
- package/dist/verification-code-input.js +6 -5
- package/package.json +14 -1
|
@@ -0,0 +1,4852 @@
|
|
|
1
|
+
import { Card } from './chunk-6FGLABYH.js';
|
|
2
|
+
import { Skeleton } from './chunk-MTOTPAYZ.js';
|
|
3
|
+
import { Slider } from './chunk-PRWPFBA5.js';
|
|
4
|
+
import { Popover } from './chunk-XNXBO44X.js';
|
|
5
|
+
import { Checkbox } from './chunk-LKUAVDWP.js';
|
|
6
|
+
import { useLocaleConfig } from './chunk-YIHKQ63K.js';
|
|
7
|
+
import { Button } from './chunk-3ZZZPT5G.js';
|
|
8
|
+
import { ButtonUtility } from './chunk-MVF7FA4D.js';
|
|
9
|
+
import { FILL, SOLID, ACCENT } from './chunk-6T3QAO5K.js';
|
|
10
|
+
import { XIcon, PlusIcon, MinusIcon, CrosshairIcon, RotateCcwIcon, ChevronUpIcon, ChevronDownIcon, PauseIcon, PlayIcon, ChevronLeftIcon, LayersIcon, MinimizeIcon, MaximizeIcon } from './chunk-KBI442IB.js';
|
|
11
|
+
import { cn } from './chunk-ZSNJ6UA3.js';
|
|
12
|
+
import { useLabels } from './chunk-ZIEGUI25.js';
|
|
13
|
+
import { devWarn, warnPositiveInt } from './chunk-SF3HCW4G.js';
|
|
14
|
+
import { __privateAdd, __privateSet, __privateGet } from './chunk-VHAA22YE.js';
|
|
15
|
+
import { useId, useState, useCallback, useMemo, useEffect, useRef, useReducer } from 'react';
|
|
16
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
17
|
+
import { createPortal } from 'react-dom';
|
|
18
|
+
|
|
19
|
+
// src/components/data-map/layers.ts
|
|
20
|
+
var MAP_OPACITY = { full: 1, strong: 0.8, medium: 0.6, faint: 0.35 };
|
|
21
|
+
function choroplethLayer(spec) {
|
|
22
|
+
return { ...spec, kind: "choropleth" };
|
|
23
|
+
}
|
|
24
|
+
function pointsLayer(spec) {
|
|
25
|
+
return { ...spec, kind: "points" };
|
|
26
|
+
}
|
|
27
|
+
function heatmapLayer(spec) {
|
|
28
|
+
return { ...spec, kind: "heatmap" };
|
|
29
|
+
}
|
|
30
|
+
function linesLayer(spec) {
|
|
31
|
+
return { ...spec, kind: "lines" };
|
|
32
|
+
}
|
|
33
|
+
function areasLayer(spec) {
|
|
34
|
+
return { ...spec, kind: "areas" };
|
|
35
|
+
}
|
|
36
|
+
function rasterLayer(spec) {
|
|
37
|
+
return { ...spec, kind: "raster" };
|
|
38
|
+
}
|
|
39
|
+
function isLevels(features) {
|
|
40
|
+
return "levels" in features;
|
|
41
|
+
}
|
|
42
|
+
function toneOf(tone, datum, fallback = "brand") {
|
|
43
|
+
if (tone === void 0) return fallback;
|
|
44
|
+
return typeof tone === "function" ? tone(datum) : tone;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/components/data-map/glyphs.ts
|
|
48
|
+
var GLYPHS_URL = "https://tiles.openfreemap.org/fonts/{fontstack}/{range}.pbf";
|
|
49
|
+
var FONT = {
|
|
50
|
+
/** Body labels — places, roads, water. */
|
|
51
|
+
regular: "Noto Sans Regular",
|
|
52
|
+
/** The one emphasis step available. Countries, and the current drill level's own label. */
|
|
53
|
+
bold: "Noto Sans Bold",
|
|
54
|
+
/** Hydrography, by century-old cartographic convention — which is how water labels stay legible
|
|
55
|
+
* without spending colour on them (see `gen-map-style.mjs`'s header). */
|
|
56
|
+
italic: "Noto Sans Italic"
|
|
57
|
+
};
|
|
58
|
+
function labelExpression(locale) {
|
|
59
|
+
const language = locale.split("-", 1)[0]?.toLowerCase() ?? "en";
|
|
60
|
+
return [
|
|
61
|
+
"coalesce",
|
|
62
|
+
["get", `name:${language}`],
|
|
63
|
+
// Only useful when the requested language IS Latin-script; harmless otherwise, because
|
|
64
|
+
// `coalesce` skips a missing property.
|
|
65
|
+
["get", "name:latin"],
|
|
66
|
+
["get", "name"]
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/components/data-map/style-colors.generated.ts
|
|
71
|
+
var MAP_STYLE_COLORS = {
|
|
72
|
+
light: {
|
|
73
|
+
background: "#ffffff",
|
|
74
|
+
water: "#eff6ff",
|
|
75
|
+
waterway: "#bedbff",
|
|
76
|
+
greenspace: "#f0fdf4",
|
|
77
|
+
building: "#fafafa",
|
|
78
|
+
buildingEdge: "#e5e5e5",
|
|
79
|
+
land: "#fafafa",
|
|
80
|
+
roadMajor: "#d4d4d4",
|
|
81
|
+
roadMinor: "#e5e5e5",
|
|
82
|
+
roadPath: "#f5f5f5",
|
|
83
|
+
boundaryCountry: "#a1a1a1",
|
|
84
|
+
boundaryRegion: "#d4d4d4",
|
|
85
|
+
labelCountry: "#171717",
|
|
86
|
+
labelRegion: "#404040",
|
|
87
|
+
labelPlace: "#404040",
|
|
88
|
+
labelPlaceMinor: "#525252",
|
|
89
|
+
labelRoad: "#737373",
|
|
90
|
+
labelWater: "#525252",
|
|
91
|
+
labelHalo: "#ffffff",
|
|
92
|
+
dataStroke: "#e5e5e5",
|
|
93
|
+
dataHoverStroke: "#a1a1a1",
|
|
94
|
+
dataSelectedStroke: "#9e77ed",
|
|
95
|
+
dataNoDataStroke: "#a1a1a1",
|
|
96
|
+
lineCasing: "#ffffff",
|
|
97
|
+
pointCasing: "#ffffff",
|
|
98
|
+
clusterEdge: "#a1a1a1",
|
|
99
|
+
clusterText: "#171717"
|
|
100
|
+
},
|
|
101
|
+
dark: {
|
|
102
|
+
background: "#0a0a0a",
|
|
103
|
+
water: "#162456",
|
|
104
|
+
waterway: "#193cb8",
|
|
105
|
+
greenspace: "#032e15",
|
|
106
|
+
building: "#171717",
|
|
107
|
+
buildingEdge: "#262626",
|
|
108
|
+
land: "#171717",
|
|
109
|
+
roadMajor: "#404040",
|
|
110
|
+
roadMinor: "#262626",
|
|
111
|
+
roadPath: "#171717",
|
|
112
|
+
boundaryCountry: "#525252",
|
|
113
|
+
boundaryRegion: "#404040",
|
|
114
|
+
labelCountry: "#fafafa",
|
|
115
|
+
labelRegion: "#d4d4d4",
|
|
116
|
+
labelPlace: "#d4d4d4",
|
|
117
|
+
labelPlaceMinor: "#a1a1a1",
|
|
118
|
+
labelRoad: "#a1a1a1",
|
|
119
|
+
labelWater: "#a1a1a1",
|
|
120
|
+
labelHalo: "#0a0a0a",
|
|
121
|
+
dataStroke: "#262626",
|
|
122
|
+
dataHoverStroke: "#525252",
|
|
123
|
+
dataSelectedStroke: "#b692f6",
|
|
124
|
+
dataNoDataStroke: "#525252",
|
|
125
|
+
lineCasing: "#0a0a0a",
|
|
126
|
+
pointCasing: "#0a0a0a",
|
|
127
|
+
clusterEdge: "#525252",
|
|
128
|
+
clusterText: "#fafafa"
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
var MAP_SEQUENTIAL_SCALES = {
|
|
132
|
+
light: {
|
|
133
|
+
neutral: ["#d4d4d4", "#a1a1a1", "#737373", "#525252", "#404040"],
|
|
134
|
+
brand: ["#d6bbfb", "#b692f6", "#9e77ed", "#7f56d9", "#6941c6"],
|
|
135
|
+
success: ["#7bf1a8", "#05df72", "#00c950", "#00a63e", "#008236"],
|
|
136
|
+
warning: ["#ffd230", "#ffb900", "#fe9a00", "#e17100", "#bb4d00"],
|
|
137
|
+
error: ["#ffa2a2", "#ff6467", "#fb2c36", "#e7000b", "#c10007"],
|
|
138
|
+
info: ["#8ec5ff", "#51a2ff", "#2b7fff", "#155dfc", "#1447e6"]
|
|
139
|
+
},
|
|
140
|
+
dark: {
|
|
141
|
+
neutral: ["#404040", "#525252", "#737373", "#a1a1a1", "#d4d4d4"],
|
|
142
|
+
brand: ["#6941c6", "#7f56d9", "#9e77ed", "#b692f6", "#d6bbfb"],
|
|
143
|
+
success: ["#008236", "#00a63e", "#00c950", "#05df72", "#7bf1a8"],
|
|
144
|
+
warning: ["#bb4d00", "#e17100", "#fe9a00", "#ffb900", "#ffd230"],
|
|
145
|
+
error: ["#c10007", "#e7000b", "#fb2c36", "#ff6467", "#ffa2a2"],
|
|
146
|
+
info: ["#1447e6", "#155dfc", "#2b7fff", "#51a2ff", "#8ec5ff"]
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
var MAP_CLUSTER_FILLS = {
|
|
150
|
+
light: {
|
|
151
|
+
neutral: { fill: "#e5e5e5", text: "#171717" },
|
|
152
|
+
brand: { fill: "#e9d7fe", text: "#171717" },
|
|
153
|
+
success: { fill: "#b9f8cf", text: "#171717" },
|
|
154
|
+
warning: { fill: "#fee685", text: "#171717" },
|
|
155
|
+
error: { fill: "#ffc9c9", text: "#171717" },
|
|
156
|
+
info: { fill: "#bedbff", text: "#171717" }
|
|
157
|
+
},
|
|
158
|
+
dark: {
|
|
159
|
+
neutral: { fill: "#404040", text: "#fafafa" },
|
|
160
|
+
brand: { fill: "#53389e", text: "#fafafa" },
|
|
161
|
+
success: { fill: "#016630", text: "#fafafa" },
|
|
162
|
+
warning: { fill: "#973c00", text: "#fafafa" },
|
|
163
|
+
error: { fill: "#9f0712", text: "#fafafa" },
|
|
164
|
+
info: { fill: "#193cb8", text: "#fafafa" }
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
var MAP_TONE_COLORS = {
|
|
168
|
+
light: {
|
|
169
|
+
neutral: { soft: "#f5f5f5", fill: "#737373", strong: "#404040" },
|
|
170
|
+
brand: { soft: "#f4ebff", fill: "#9e77ed", strong: "#6941c6" },
|
|
171
|
+
success: { soft: "#dcfce7", fill: "#00c950", strong: "#008236" },
|
|
172
|
+
warning: { soft: "#fef3c6", fill: "#fe9a00", strong: "#bb4d00" },
|
|
173
|
+
error: { soft: "#ffe2e2", fill: "#fb2c36", strong: "#c10007" },
|
|
174
|
+
info: { soft: "#dbeafe", fill: "#2b7fff", strong: "#1447e6" }
|
|
175
|
+
},
|
|
176
|
+
dark: {
|
|
177
|
+
neutral: { soft: "#262626", fill: "#737373", strong: "#d4d4d4" },
|
|
178
|
+
brand: { soft: "#42307d", fill: "#9e77ed", strong: "#d6bbfb" },
|
|
179
|
+
success: { soft: "#0d542b", fill: "#00c950", strong: "#7bf1a8" },
|
|
180
|
+
warning: { soft: "#7b3306", fill: "#fe9a00", strong: "#ffd230" },
|
|
181
|
+
error: { soft: "#82181a", fill: "#fb2c36", strong: "#ffa2a2" },
|
|
182
|
+
info: { soft: "#1c398e", fill: "#2b7fff", strong: "#8ec5ff" }
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
var MAP_DIVERGING_SCALES = {
|
|
186
|
+
light: {
|
|
187
|
+
"error-success": ["#c10007", "#fb2c36", "#ffa2a2", "#fafafa", "#7bf1a8", "#00c950", "#008236"],
|
|
188
|
+
"error-brand": ["#c10007", "#fb2c36", "#ffa2a2", "#fafafa", "#d6bbfb", "#9e77ed", "#6941c6"],
|
|
189
|
+
"warning-brand": ["#bb4d00", "#fe9a00", "#ffd230", "#fafafa", "#d6bbfb", "#9e77ed", "#6941c6"]
|
|
190
|
+
},
|
|
191
|
+
dark: {
|
|
192
|
+
"error-success": ["#ffa2a2", "#fb2c36", "#c10007", "#171717", "#008236", "#00c950", "#7bf1a8"],
|
|
193
|
+
"error-brand": ["#ffa2a2", "#fb2c36", "#c10007", "#171717", "#6941c6", "#9e77ed", "#d6bbfb"],
|
|
194
|
+
"warning-brand": ["#ffd230", "#fe9a00", "#bb4d00", "#171717", "#6941c6", "#9e77ed", "#d6bbfb"]
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
var MAP_HEAT_SCALE = {
|
|
198
|
+
light: ["#bedbff", "#2b7fff", "#9e77ed", "#fe9a00", "#e7000b"],
|
|
199
|
+
dark: ["#193cb8", "#2b7fff", "#9e77ed", "#fe9a00", "#ff6467"]
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
// src/components/data-map/style.ts
|
|
203
|
+
var DEFAULT_MAP_SOURCE = { kind: "tilejson", url: "https://tiles.openfreemap.org/planet" };
|
|
204
|
+
var warnedDefaultSource = false;
|
|
205
|
+
function warnDefaultSource() {
|
|
206
|
+
if (warnedDefaultSource) return;
|
|
207
|
+
warnedDefaultSource = true;
|
|
208
|
+
devWarn(
|
|
209
|
+
"<DataMap> is using the DEFAULT basemap (OpenFreeMap). It is free and needs no key, and it has NO SLA \u2014 set `source` before shipping anything load-bearing. See docs/components/data-map.md \xA7 Choosing a tile source."
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
var BASEMAP_SOURCE_ID = "jz-basemap";
|
|
213
|
+
var DATA_INSERTION_LAYER_ID = "jz-data-slot";
|
|
214
|
+
var lineWidth = (stops) => ["interpolate", ["linear"], ["zoom"], ...stops.flatMap(([zoom, width]) => [zoom, width])];
|
|
215
|
+
var textSize = (stops) => ["interpolate", ["linear"], ["zoom"], ...stops.flatMap(([zoom, size]) => [zoom, size])];
|
|
216
|
+
var HALO_WIDTH = 1.25;
|
|
217
|
+
var span = (from, to, by) => Array.from({ length: Math.floor((to - from) / by) + 1 }, (_, i) => from + i * by);
|
|
218
|
+
var graticuleLine = (coordinates) => ({
|
|
219
|
+
type: "Feature",
|
|
220
|
+
properties: {},
|
|
221
|
+
geometry: { type: "LineString", coordinates }
|
|
222
|
+
});
|
|
223
|
+
function graticuleData(step) {
|
|
224
|
+
return {
|
|
225
|
+
type: "FeatureCollection",
|
|
226
|
+
features: [
|
|
227
|
+
...span(-180, 180, step).map((lng) => graticuleLine(span(-85, 85, 5).map((lat) => [lng, lat]))),
|
|
228
|
+
...span(-80, 80, step).map((lat) => graticuleLine(span(-180, 180, 5).map((lng) => [lng, lat])))
|
|
229
|
+
]
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
function sourceKey(source) {
|
|
233
|
+
const glyphs = source.glyphs ? `@${source.glyphs}` : "";
|
|
234
|
+
switch (source.kind) {
|
|
235
|
+
case "tilejson": {
|
|
236
|
+
return `tilejson:${source.url}${glyphs}`;
|
|
237
|
+
}
|
|
238
|
+
case "tiles": {
|
|
239
|
+
return `tiles:${source.tiles.join("|")}:${source.minzoom ?? ""}:${source.maxzoom ?? ""}${glyphs}`;
|
|
240
|
+
}
|
|
241
|
+
case "geojson": {
|
|
242
|
+
return [
|
|
243
|
+
"geojson",
|
|
244
|
+
source.ground ?? "water",
|
|
245
|
+
source.outline === "none" ? "plate" : "outlined",
|
|
246
|
+
source.water ? "w" : "",
|
|
247
|
+
source.rivers ? "r" : "",
|
|
248
|
+
source.boundaries ? "b" : "",
|
|
249
|
+
source.borders ? "B" : "",
|
|
250
|
+
source.places ? "p" : "",
|
|
251
|
+
source.graticule ?? "none"
|
|
252
|
+
].join(":") + glyphs;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function buildMapStyle(options) {
|
|
257
|
+
const { mode, source, locale = "en" } = options;
|
|
258
|
+
const glyphs = source.glyphs ?? options.glyphs ?? GLYPHS_URL;
|
|
259
|
+
const c = MAP_STYLE_COLORS[mode];
|
|
260
|
+
if (source.kind === "geojson") {
|
|
261
|
+
const label2 = labelExpression(locale);
|
|
262
|
+
const ground = source.ground === "page" ? c.background : c.water;
|
|
263
|
+
const layers = [
|
|
264
|
+
{ id: "background", type: "background", paint: { "background-color": ground } },
|
|
265
|
+
{ id: "land", type: "fill", source: `${BASEMAP_SOURCE_ID}-land`, paint: { "fill-color": c.land } }
|
|
266
|
+
];
|
|
267
|
+
if (source.water) {
|
|
268
|
+
layers.push({
|
|
269
|
+
id: "water",
|
|
270
|
+
type: "fill",
|
|
271
|
+
source: `${BASEMAP_SOURCE_ID}-water`,
|
|
272
|
+
// The SAME role as the surround, so a lake and the sea are one substance. Two blues would
|
|
273
|
+
// read as two kinds of water and there is only one.
|
|
274
|
+
paint: { "fill-color": c.water }
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
if (source.rivers) {
|
|
278
|
+
layers.push({
|
|
279
|
+
id: "waterway",
|
|
280
|
+
type: "line",
|
|
281
|
+
source: `${BASEMAP_SOURCE_ID}-rivers`,
|
|
282
|
+
layout: { "line-cap": "round", "line-join": "round" },
|
|
283
|
+
paint: {
|
|
284
|
+
// The DARKER water role, not the fill's: a river is a hairline and a hairline in the lake
|
|
285
|
+
// colour is invisible. Same pair the vector ground uses, for the same reason.
|
|
286
|
+
"line-color": c.waterway,
|
|
287
|
+
"line-width": lineWidth([
|
|
288
|
+
[3, 0.4],
|
|
289
|
+
[7, 0.9],
|
|
290
|
+
[11, 1.6]
|
|
291
|
+
])
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
if (source.graticule && source.graticule !== "none") {
|
|
296
|
+
layers.push({
|
|
297
|
+
id: "graticule",
|
|
298
|
+
type: "line",
|
|
299
|
+
source: `${BASEMAP_SOURCE_ID}-graticule`,
|
|
300
|
+
paint: {
|
|
301
|
+
"line-color": c.boundaryRegion,
|
|
302
|
+
"line-width": 0.5,
|
|
303
|
+
// Faint enough to read as a grid rather than as geography. At full strength a 20° grid
|
|
304
|
+
// out-reads every coastline on a world frame, which is the opposite of the point.
|
|
305
|
+
"line-opacity": 0.35
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
if (source.boundaries) {
|
|
310
|
+
layers.push({
|
|
311
|
+
id: "boundary-region",
|
|
312
|
+
type: "line",
|
|
313
|
+
source: `${BASEMAP_SOURCE_ID}-boundaries`,
|
|
314
|
+
layout: { "line-cap": "round", "line-join": "round" },
|
|
315
|
+
paint: {
|
|
316
|
+
"line-color": c.boundaryRegion,
|
|
317
|
+
"line-width": lineWidth([
|
|
318
|
+
[3, 0.4],
|
|
319
|
+
[7, 0.7],
|
|
320
|
+
[11, 1]
|
|
321
|
+
]),
|
|
322
|
+
// Internal edges are a SETTING, not information — they must lose to whatever the data
|
|
323
|
+
// layer paints on top of them, and at country zoom there are a lot of them.
|
|
324
|
+
"line-opacity": 0.7
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
if (source.borders) {
|
|
329
|
+
layers.push({
|
|
330
|
+
id: "boundary-country",
|
|
331
|
+
type: "line",
|
|
332
|
+
source: `${BASEMAP_SOURCE_ID}-borders`,
|
|
333
|
+
layout: { "line-cap": "round", "line-join": "round" },
|
|
334
|
+
paint: {
|
|
335
|
+
// The emphatic edge — on a data map an international boundary must out-read every other
|
|
336
|
+
// line on the ground, because it is the one the reader uses to find their country.
|
|
337
|
+
"line-color": c.boundaryCountry,
|
|
338
|
+
"line-width": lineWidth([
|
|
339
|
+
[2, 0.6],
|
|
340
|
+
[6, 1],
|
|
341
|
+
[10, 1.5]
|
|
342
|
+
])
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
if (source.outline !== "none") {
|
|
347
|
+
layers.push({
|
|
348
|
+
id: "land-outline",
|
|
349
|
+
type: "line",
|
|
350
|
+
source: `${BASEMAP_SOURCE_ID}-land`,
|
|
351
|
+
layout: { "line-cap": "round", "line-join": "round" },
|
|
352
|
+
paint: {
|
|
353
|
+
// The country-boundary colour, because that is what a coastline drawn from an admin
|
|
354
|
+
// collection IS. Held near a hairline: the geometry is the SETTING, and the markers or the
|
|
355
|
+
// choropleth on top of it are the information.
|
|
356
|
+
"line-color": c.boundaryCountry,
|
|
357
|
+
"line-width": lineWidth([
|
|
358
|
+
[3, 0.5],
|
|
359
|
+
[6, 0.8],
|
|
360
|
+
[10, 1.2]
|
|
361
|
+
])
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
layers.push({
|
|
366
|
+
id: DATA_INSERTION_LAYER_ID,
|
|
367
|
+
type: "background",
|
|
368
|
+
paint: { "background-color": ground, "background-opacity": 0 }
|
|
369
|
+
});
|
|
370
|
+
if (source.places) {
|
|
371
|
+
const rank = ["coalesce", ["get", "rank"], 0];
|
|
372
|
+
const isCapital = ["==", ["to-boolean", ["coalesce", ["get", "capital"], false]], true];
|
|
373
|
+
const shared = {
|
|
374
|
+
"text-field": label2,
|
|
375
|
+
"text-anchor": "top",
|
|
376
|
+
"text-offset": [0, 0.5],
|
|
377
|
+
"symbol-sort-key": rank,
|
|
378
|
+
// A place plate is a point set with no collision hierarchy of its own, so the engine's is
|
|
379
|
+
// the only thing stopping 400 overlapping names.
|
|
380
|
+
"text-allow-overlap": false
|
|
381
|
+
};
|
|
382
|
+
const paint = {
|
|
383
|
+
"text-color": c.labelPlace,
|
|
384
|
+
"text-halo-color": c.labelHalo,
|
|
385
|
+
"text-halo-width": HALO_WIDTH,
|
|
386
|
+
"text-halo-blur": 0.5
|
|
387
|
+
};
|
|
388
|
+
layers.push(
|
|
389
|
+
{
|
|
390
|
+
id: "label-place",
|
|
391
|
+
type: "symbol",
|
|
392
|
+
source: `${BASEMAP_SOURCE_ID}-places`,
|
|
393
|
+
// Every rank at once would put four hundred names on a world frame and the engine would drop
|
|
394
|
+
// most of them arbitrarily. A ladder makes the thinning a DECISION: only the top rank at z3,
|
|
395
|
+
// everything by z10.
|
|
396
|
+
filter: ["all", ["!", isCapital], ["<=", rank, ["step", ["zoom"], 0, 4, 2, 6, 4, 8, 6, 10, 99]]],
|
|
397
|
+
layout: {
|
|
398
|
+
...shared,
|
|
399
|
+
"text-font": [FONT.regular],
|
|
400
|
+
"text-size": textSize([
|
|
401
|
+
[4, 10],
|
|
402
|
+
[8, 12],
|
|
403
|
+
[12, 14]
|
|
404
|
+
])
|
|
405
|
+
},
|
|
406
|
+
paint: { ...paint, "text-color": c.labelPlaceMinor }
|
|
407
|
+
},
|
|
408
|
+
/* Capitals, above every other name and one step up in weight and size. Their own layer rather
|
|
409
|
+
* than a `case` expression because `text-font` is a LAYOUT property: a data-driven font is not
|
|
410
|
+
* expressible, so two ranks of type means two layers. */
|
|
411
|
+
{
|
|
412
|
+
id: "label-place-capital",
|
|
413
|
+
type: "symbol",
|
|
414
|
+
source: `${BASEMAP_SOURCE_ID}-places`,
|
|
415
|
+
filter: isCapital,
|
|
416
|
+
layout: {
|
|
417
|
+
...shared,
|
|
418
|
+
"text-font": [FONT.bold],
|
|
419
|
+
"text-size": textSize([
|
|
420
|
+
[3, 11],
|
|
421
|
+
[8, 13],
|
|
422
|
+
[12, 15]
|
|
423
|
+
])
|
|
424
|
+
},
|
|
425
|
+
paint
|
|
426
|
+
}
|
|
427
|
+
);
|
|
428
|
+
}
|
|
429
|
+
return {
|
|
430
|
+
version: 8,
|
|
431
|
+
name: `jenosize-ui basemap (${mode}, geojson)`,
|
|
432
|
+
glyphs,
|
|
433
|
+
sources: {
|
|
434
|
+
[`${BASEMAP_SOURCE_ID}-land`]: { type: "geojson", data: source.land },
|
|
435
|
+
...source.water && { [`${BASEMAP_SOURCE_ID}-water`]: { type: "geojson", data: source.water } },
|
|
436
|
+
...source.rivers && { [`${BASEMAP_SOURCE_ID}-rivers`]: { type: "geojson", data: source.rivers } },
|
|
437
|
+
...source.boundaries && { [`${BASEMAP_SOURCE_ID}-boundaries`]: { type: "geojson", data: source.boundaries } },
|
|
438
|
+
...source.borders && { [`${BASEMAP_SOURCE_ID}-borders`]: { type: "geojson", data: source.borders } },
|
|
439
|
+
...source.places && { [`${BASEMAP_SOURCE_ID}-places`]: { type: "geojson", data: source.places } },
|
|
440
|
+
...source.graticule && source.graticule !== "none" && {
|
|
441
|
+
[`${BASEMAP_SOURCE_ID}-graticule`]: { type: "geojson", data: graticuleData(source.graticule === "fine" ? 10 : 20) }
|
|
442
|
+
}
|
|
443
|
+
},
|
|
444
|
+
layers
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
const label = labelExpression(locale);
|
|
448
|
+
const textPaint = (color) => ({
|
|
449
|
+
"text-color": color,
|
|
450
|
+
"text-halo-color": c.labelHalo,
|
|
451
|
+
"text-halo-width": HALO_WIDTH,
|
|
452
|
+
// A halo with no blur has a hard edge that reads as a stroke; a little blur is what makes it
|
|
453
|
+
// read as the page showing through.
|
|
454
|
+
"text-halo-blur": 0.5
|
|
455
|
+
});
|
|
456
|
+
const sourceSpec = source.kind === "tilejson" ? { type: "vector", url: source.url } : { type: "vector", tiles: [...source.tiles], minzoom: source.minzoom ?? 0, maxzoom: source.maxzoom ?? 14 };
|
|
457
|
+
return {
|
|
458
|
+
version: 8,
|
|
459
|
+
name: `jenosize-ui basemap (${mode})`,
|
|
460
|
+
glyphs,
|
|
461
|
+
// No `sprite` key at all — see the header. An empty string here would make MapLibre fetch a
|
|
462
|
+
// sprite from the page root and log a 404 per style load.
|
|
463
|
+
sources: { [BASEMAP_SOURCE_ID]: sourceSpec },
|
|
464
|
+
layers: [
|
|
465
|
+
/* ── surfaces ───────────────────────────────────────────────────────── */
|
|
466
|
+
{
|
|
467
|
+
id: "background",
|
|
468
|
+
type: "background",
|
|
469
|
+
paint: { "background-color": c.background }
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
// Wood and grass share one paint: at basemap weight the distinction is invisible and two
|
|
473
|
+
// layers is two things to keep in step. `park` is separate only because it is a different
|
|
474
|
+
// source-layer, not a different colour.
|
|
475
|
+
id: "landcover",
|
|
476
|
+
type: "fill",
|
|
477
|
+
source: BASEMAP_SOURCE_ID,
|
|
478
|
+
"source-layer": "landcover",
|
|
479
|
+
filter: ["match", ["get", "class"], ["wood", "grass", "scrub", "farmland"], true, false],
|
|
480
|
+
paint: { "fill-color": c.greenspace }
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
id: "park",
|
|
484
|
+
type: "fill",
|
|
485
|
+
source: BASEMAP_SOURCE_ID,
|
|
486
|
+
"source-layer": "park",
|
|
487
|
+
paint: { "fill-color": c.greenspace }
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
id: "water",
|
|
491
|
+
type: "fill",
|
|
492
|
+
source: BASEMAP_SOURCE_ID,
|
|
493
|
+
"source-layer": "water",
|
|
494
|
+
// A tunnelled culvert is not visible water; drawing it puts a river through a hillside.
|
|
495
|
+
filter: ["!=", ["get", "brunnel"], "tunnel"],
|
|
496
|
+
paint: { "fill-color": c.water }
|
|
497
|
+
},
|
|
498
|
+
{
|
|
499
|
+
id: "waterway",
|
|
500
|
+
type: "line",
|
|
501
|
+
source: BASEMAP_SOURCE_ID,
|
|
502
|
+
"source-layer": "waterway",
|
|
503
|
+
filter: ["all", ["!=", ["get", "brunnel"], "tunnel"], ["match", ["get", "class"], ["river", "canal"], true, false]],
|
|
504
|
+
layout: { "line-cap": "round" },
|
|
505
|
+
paint: {
|
|
506
|
+
"line-color": c.waterway,
|
|
507
|
+
"line-width": lineWidth([
|
|
508
|
+
[8, 0.6],
|
|
509
|
+
[12, 1.4],
|
|
510
|
+
[16, 3]
|
|
511
|
+
])
|
|
512
|
+
}
|
|
513
|
+
},
|
|
514
|
+
{
|
|
515
|
+
// Buildings only exist in the tiles from z13, and below z14 they are a grey smear rather than
|
|
516
|
+
// information — so the layer starts where it says something.
|
|
517
|
+
id: "building",
|
|
518
|
+
type: "fill",
|
|
519
|
+
source: BASEMAP_SOURCE_ID,
|
|
520
|
+
"source-layer": "building",
|
|
521
|
+
minzoom: 14,
|
|
522
|
+
paint: {
|
|
523
|
+
"fill-color": c.building,
|
|
524
|
+
"fill-outline-color": c.buildingEdge,
|
|
525
|
+
// Fading in avoids a hard pop of grey across the viewport at exactly z14.
|
|
526
|
+
"fill-opacity": ["interpolate", ["linear"], ["zoom"], 14, 0, 15, 1]
|
|
527
|
+
}
|
|
528
|
+
},
|
|
529
|
+
/* ── roads. One colour step per class; the HIERARCHY is the width curve. ── */
|
|
530
|
+
{
|
|
531
|
+
id: "road-path",
|
|
532
|
+
type: "line",
|
|
533
|
+
source: BASEMAP_SOURCE_ID,
|
|
534
|
+
"source-layer": "transportation",
|
|
535
|
+
minzoom: 13,
|
|
536
|
+
filter: ["match", ["get", "class"], ["path", "track", "service"], true, false],
|
|
537
|
+
layout: { "line-cap": "round", "line-join": "round" },
|
|
538
|
+
paint: {
|
|
539
|
+
"line-color": c.roadPath,
|
|
540
|
+
"line-width": lineWidth([
|
|
541
|
+
[13, 0.5],
|
|
542
|
+
[18, 3]
|
|
543
|
+
])
|
|
544
|
+
}
|
|
545
|
+
},
|
|
546
|
+
{
|
|
547
|
+
id: "road-minor",
|
|
548
|
+
type: "line",
|
|
549
|
+
source: BASEMAP_SOURCE_ID,
|
|
550
|
+
"source-layer": "transportation",
|
|
551
|
+
minzoom: 11,
|
|
552
|
+
filter: ["match", ["get", "class"], ["minor", "tertiary"], true, false],
|
|
553
|
+
layout: { "line-cap": "round", "line-join": "round" },
|
|
554
|
+
paint: {
|
|
555
|
+
"line-color": c.roadMinor,
|
|
556
|
+
"line-width": lineWidth([
|
|
557
|
+
[11, 0.5],
|
|
558
|
+
[14, 1.5],
|
|
559
|
+
[18, 6]
|
|
560
|
+
])
|
|
561
|
+
}
|
|
562
|
+
},
|
|
563
|
+
{
|
|
564
|
+
id: "road-major",
|
|
565
|
+
type: "line",
|
|
566
|
+
source: BASEMAP_SOURCE_ID,
|
|
567
|
+
"source-layer": "transportation",
|
|
568
|
+
minzoom: 8,
|
|
569
|
+
filter: ["match", ["get", "class"], ["primary", "secondary"], true, false],
|
|
570
|
+
layout: { "line-cap": "round", "line-join": "round" },
|
|
571
|
+
paint: {
|
|
572
|
+
"line-color": c.roadMajor,
|
|
573
|
+
"line-width": lineWidth([
|
|
574
|
+
[8, 0.6],
|
|
575
|
+
[12, 1.6],
|
|
576
|
+
[16, 5]
|
|
577
|
+
])
|
|
578
|
+
}
|
|
579
|
+
},
|
|
580
|
+
{
|
|
581
|
+
// Motorway and trunk share `roadMajor`'s COLOUR and differ only in width — the header's
|
|
582
|
+
// "roads differentiate by width, boundaries by colour" rule. Giving a motorway
|
|
583
|
+
// `border-strong` would put it in competition with the country boundary at every zoom, and
|
|
584
|
+
// the boundary is the line a reader is using to find their region.
|
|
585
|
+
id: "road-motorway",
|
|
586
|
+
type: "line",
|
|
587
|
+
source: BASEMAP_SOURCE_ID,
|
|
588
|
+
"source-layer": "transportation",
|
|
589
|
+
minzoom: 5,
|
|
590
|
+
filter: ["match", ["get", "class"], ["motorway", "trunk"], true, false],
|
|
591
|
+
layout: { "line-cap": "round", "line-join": "round" },
|
|
592
|
+
paint: {
|
|
593
|
+
"line-color": c.roadMajor,
|
|
594
|
+
"line-width": lineWidth([
|
|
595
|
+
[5, 0.6],
|
|
596
|
+
[10, 2],
|
|
597
|
+
[14, 4],
|
|
598
|
+
[18, 12]
|
|
599
|
+
])
|
|
600
|
+
}
|
|
601
|
+
},
|
|
602
|
+
/* ── boundaries ─────────────────────────────────────────────────────── */
|
|
603
|
+
{
|
|
604
|
+
// Sub-national: province / state / district. Dashed, because a solid line at this weight
|
|
605
|
+
// reads as a road, and this is the edge a drill-down is about.
|
|
606
|
+
id: "boundary-region",
|
|
607
|
+
type: "line",
|
|
608
|
+
source: BASEMAP_SOURCE_ID,
|
|
609
|
+
"source-layer": "boundary",
|
|
610
|
+
minzoom: 4,
|
|
611
|
+
filter: ["all", [">=", ["get", "admin_level"], 3], ["<=", ["get", "admin_level"], 6], ["!=", ["get", "maritime"], 1], ["!=", ["get", "disputed"], 1]],
|
|
612
|
+
layout: { "line-join": "round" },
|
|
613
|
+
paint: {
|
|
614
|
+
"line-color": c.boundaryRegion,
|
|
615
|
+
"line-dasharray": [3, 2],
|
|
616
|
+
"line-width": lineWidth([
|
|
617
|
+
[4, 0.5],
|
|
618
|
+
[8, 1],
|
|
619
|
+
[12, 1.5]
|
|
620
|
+
])
|
|
621
|
+
}
|
|
622
|
+
},
|
|
623
|
+
{
|
|
624
|
+
// A country edge is the strongest line on the map — `border-strong`, the one role above
|
|
625
|
+
// `border-primary`. `maritime != 1` keeps the ocean-side halves of a coastal border off the
|
|
626
|
+
// water, where they read as a stray line in the sea.
|
|
627
|
+
id: "boundary-country",
|
|
628
|
+
type: "line",
|
|
629
|
+
source: BASEMAP_SOURCE_ID,
|
|
630
|
+
"source-layer": "boundary",
|
|
631
|
+
filter: ["all", ["==", ["get", "admin_level"], 2], ["!=", ["get", "maritime"], 1], ["!=", ["get", "disputed"], 1]],
|
|
632
|
+
layout: { "line-cap": "round", "line-join": "round" },
|
|
633
|
+
paint: {
|
|
634
|
+
"line-color": c.boundaryCountry,
|
|
635
|
+
"line-width": lineWidth([
|
|
636
|
+
[1, 0.6],
|
|
637
|
+
[6, 1.4],
|
|
638
|
+
[12, 2.4]
|
|
639
|
+
])
|
|
640
|
+
}
|
|
641
|
+
},
|
|
642
|
+
/* ── the seam. Data goes BEFORE this; labels stay above it. ───────────
|
|
643
|
+
* An empty `background` with zero opacity: it paints nothing, costs nothing, and gives
|
|
644
|
+
* `addLayer(layer, before)` a real id to insert against. See DATA_INSERTION_LAYER_ID. */
|
|
645
|
+
{
|
|
646
|
+
id: DATA_INSERTION_LAYER_ID,
|
|
647
|
+
type: "background",
|
|
648
|
+
paint: { "background-color": c.background, "background-opacity": 0 }
|
|
649
|
+
},
|
|
650
|
+
/* ── labels ─────────────────────────────────────────────────────────── */
|
|
651
|
+
{
|
|
652
|
+
id: "label-water",
|
|
653
|
+
type: "symbol",
|
|
654
|
+
source: BASEMAP_SOURCE_ID,
|
|
655
|
+
"source-layer": "water_name",
|
|
656
|
+
filter: ["match", ["geometry-type"], ["Point", "MultiPoint"], true, false],
|
|
657
|
+
layout: {
|
|
658
|
+
"text-field": label,
|
|
659
|
+
"text-font": [FONT.italic],
|
|
660
|
+
"text-size": textSize([
|
|
661
|
+
[4, 10],
|
|
662
|
+
[10, 13]
|
|
663
|
+
]),
|
|
664
|
+
"text-max-width": 6,
|
|
665
|
+
"text-letter-spacing": 0.05
|
|
666
|
+
},
|
|
667
|
+
paint: textPaint(c.labelWater)
|
|
668
|
+
},
|
|
669
|
+
{
|
|
670
|
+
id: "label-road",
|
|
671
|
+
type: "symbol",
|
|
672
|
+
source: BASEMAP_SOURCE_ID,
|
|
673
|
+
"source-layer": "transportation_name",
|
|
674
|
+
minzoom: 13,
|
|
675
|
+
filter: ["match", ["get", "class"], ["motorway", "trunk", "primary", "secondary"], true, false],
|
|
676
|
+
layout: {
|
|
677
|
+
"text-field": label,
|
|
678
|
+
"text-font": [FONT.regular],
|
|
679
|
+
// Along the line, and rotating WITH the map — a road name that stays screen-upright
|
|
680
|
+
// detaches from its road the moment the map is rotated.
|
|
681
|
+
"symbol-placement": "line",
|
|
682
|
+
"text-rotation-alignment": "map",
|
|
683
|
+
"text-size": textSize([
|
|
684
|
+
[13, 10],
|
|
685
|
+
[18, 12]
|
|
686
|
+
])
|
|
687
|
+
},
|
|
688
|
+
paint: textPaint(c.labelRoad)
|
|
689
|
+
},
|
|
690
|
+
{
|
|
691
|
+
id: "label-place-minor",
|
|
692
|
+
type: "symbol",
|
|
693
|
+
source: BASEMAP_SOURCE_ID,
|
|
694
|
+
"source-layer": "place",
|
|
695
|
+
minzoom: 9,
|
|
696
|
+
filter: ["match", ["get", "class"], ["village", "suburb", "hamlet", "neighbourhood"], true, false],
|
|
697
|
+
layout: {
|
|
698
|
+
"text-field": label,
|
|
699
|
+
"text-font": [FONT.regular],
|
|
700
|
+
"text-size": textSize([
|
|
701
|
+
[9, 10],
|
|
702
|
+
[14, 13]
|
|
703
|
+
]),
|
|
704
|
+
"text-max-width": 8
|
|
705
|
+
},
|
|
706
|
+
paint: textPaint(c.labelPlaceMinor)
|
|
707
|
+
},
|
|
708
|
+
{
|
|
709
|
+
id: "label-place",
|
|
710
|
+
type: "symbol",
|
|
711
|
+
source: BASEMAP_SOURCE_ID,
|
|
712
|
+
"source-layer": "place",
|
|
713
|
+
minzoom: 5,
|
|
714
|
+
filter: ["match", ["get", "class"], ["city", "town"], true, false],
|
|
715
|
+
layout: {
|
|
716
|
+
"text-field": label,
|
|
717
|
+
"text-font": [FONT.regular],
|
|
718
|
+
"text-size": textSize([
|
|
719
|
+
[5, 11],
|
|
720
|
+
[10, 14],
|
|
721
|
+
[14, 17]
|
|
722
|
+
]),
|
|
723
|
+
"text-max-width": 8,
|
|
724
|
+
// There is no dot to sit above (no sprite — see the header), so the label centres on the
|
|
725
|
+
// point rather than hanging below an anchor that is not drawn.
|
|
726
|
+
"text-anchor": "center"
|
|
727
|
+
},
|
|
728
|
+
paint: textPaint(c.labelPlace)
|
|
729
|
+
},
|
|
730
|
+
{
|
|
731
|
+
// Province / state names. Uppercase + letter-spacing is the cartographic convention for an
|
|
732
|
+
// administrative area, and it is what keeps these distinguishable from a city label without
|
|
733
|
+
// spending a second colour or the one remaining weight.
|
|
734
|
+
id: "label-region",
|
|
735
|
+
type: "symbol",
|
|
736
|
+
source: BASEMAP_SOURCE_ID,
|
|
737
|
+
"source-layer": "place",
|
|
738
|
+
minzoom: 4,
|
|
739
|
+
maxzoom: 10,
|
|
740
|
+
filter: ["match", ["get", "class"], ["state", "province"], true, false],
|
|
741
|
+
layout: {
|
|
742
|
+
"text-field": label,
|
|
743
|
+
"text-font": [FONT.regular],
|
|
744
|
+
"text-size": textSize([
|
|
745
|
+
[4, 10],
|
|
746
|
+
[8, 13]
|
|
747
|
+
]),
|
|
748
|
+
"text-max-width": 9,
|
|
749
|
+
"text-letter-spacing": 0.12
|
|
750
|
+
// NOT `uppercase`: it is a no-op for Thai (which has no case) while mangling nothing, but
|
|
751
|
+
// it also breaks nothing — so the transform stays off and the letter-spacing carries the
|
|
752
|
+
// convention in every script. A style that only reads as "administrative" in Latin is
|
|
753
|
+
// half a style for this component's actual audience.
|
|
754
|
+
},
|
|
755
|
+
paint: textPaint(c.labelRegion)
|
|
756
|
+
},
|
|
757
|
+
{
|
|
758
|
+
id: "label-country",
|
|
759
|
+
type: "symbol",
|
|
760
|
+
source: BASEMAP_SOURCE_ID,
|
|
761
|
+
"source-layer": "place",
|
|
762
|
+
maxzoom: 9,
|
|
763
|
+
filter: ["==", ["get", "class"], "country"],
|
|
764
|
+
layout: {
|
|
765
|
+
"text-field": label,
|
|
766
|
+
// The one emphasis step the atlas has. There is no Medium — see `glyphs.ts`.
|
|
767
|
+
"text-font": [FONT.bold],
|
|
768
|
+
"text-size": textSize([
|
|
769
|
+
[2, 10],
|
|
770
|
+
[6, 15]
|
|
771
|
+
]),
|
|
772
|
+
"text-max-width": 7
|
|
773
|
+
},
|
|
774
|
+
paint: textPaint(c.labelCountry)
|
|
775
|
+
}
|
|
776
|
+
]
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
var OSM_ATTRIBUTION = "\xA9 OpenStreetMap contributors";
|
|
780
|
+
function basemapAttribution(source) {
|
|
781
|
+
return source.kind === "geojson" ? void 0 : OSM_ATTRIBUTION;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
// src/components/data-map/camera.ts
|
|
785
|
+
function resolveTransition(transition, reducedMotion) {
|
|
786
|
+
if (reducedMotion) return "jump";
|
|
787
|
+
return transition ?? "ease";
|
|
788
|
+
}
|
|
789
|
+
function warnCamera(target) {
|
|
790
|
+
const { zoom, pitch, bearing } = target;
|
|
791
|
+
if (zoom !== void 0 && (!Number.isFinite(zoom) || zoom < 0 || zoom > 24)) {
|
|
792
|
+
devWarn(`<DataMap> camera zoom ${zoom} is outside MapLibre's 0\u201324 scale; the engine will clamp it.`);
|
|
793
|
+
}
|
|
794
|
+
if (pitch !== void 0 && (!Number.isFinite(pitch) || pitch < 0 || pitch > 85)) {
|
|
795
|
+
devWarn(`<DataMap> camera pitch ${pitch} is outside MapLibre's 0\u201385 range; the engine will clamp it.`);
|
|
796
|
+
}
|
|
797
|
+
if (bearing !== void 0 && !Number.isFinite(bearing)) {
|
|
798
|
+
devWarn(`<DataMap> camera bearing ${bearing} is not a finite number; it wraps, so any real angle is valid.`);
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
function resolveMove(move, reducedMotion) {
|
|
802
|
+
warnCamera(move);
|
|
803
|
+
const transition = resolveTransition(move.transition, reducedMotion);
|
|
804
|
+
if (transition === "jump") {
|
|
805
|
+
const { duration: _duration, ...rest } = move;
|
|
806
|
+
return { ...rest, transition };
|
|
807
|
+
}
|
|
808
|
+
return { ...move, transition };
|
|
809
|
+
}
|
|
810
|
+
function resolveFit(move, reducedMotion) {
|
|
811
|
+
if (!reducedMotion) return move;
|
|
812
|
+
return { ...move, duration: 0, intro: "instant" };
|
|
813
|
+
}
|
|
814
|
+
function chromePadding(chrome, minimum = 24) {
|
|
815
|
+
const legend = chrome.legendWidth ?? 0;
|
|
816
|
+
const controls = chrome.controlsWidth ?? 0;
|
|
817
|
+
const onLeft = chrome.legendSide === "left";
|
|
818
|
+
return {
|
|
819
|
+
top: Math.max(minimum, chrome.breadcrumbHeight ?? 0),
|
|
820
|
+
// Controls and the legend can share a side; the padding owed is whichever is wider, not the sum.
|
|
821
|
+
right: Math.max(minimum, onLeft ? controls : Math.max(legend, controls)),
|
|
822
|
+
// The attribution and the time bar BOTH sit along the bottom edge and the bar is the taller of
|
|
823
|
+
// the two, so — as with the right edge — the debt is the larger, not the sum.
|
|
824
|
+
bottom: Math.max(minimum, chrome.attributionHeight ?? 0, chrome.timeHeight ?? 0),
|
|
825
|
+
left: Math.max(minimum, onLeft ? legend : 0)
|
|
826
|
+
};
|
|
827
|
+
}
|
|
828
|
+
var TARGET = "pointer-events-auto pointer-coarse:p-3";
|
|
829
|
+
function MapChrome({ view, controls, labels, root, formatNumber }) {
|
|
830
|
+
const has = (control) => controls.includes(control);
|
|
831
|
+
const trail = view.drill.frames;
|
|
832
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-3", children: [
|
|
833
|
+
trail.length > 1 ? /* @__PURE__ */ jsx(Breadcrumb, { view, labels }) : /* @__PURE__ */ jsx("span", {}),
|
|
834
|
+
/* @__PURE__ */ jsxs("div", { className: "pointer-events-auto flex items-start gap-1", children: [
|
|
835
|
+
has("layers") && view.layers.length > 1 ? /* @__PURE__ */ jsx(LayersPanel, { view, labels, formatNumber }) : null,
|
|
836
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
|
|
837
|
+
has("zoom") ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
838
|
+
/* @__PURE__ */ jsx(
|
|
839
|
+
ButtonUtility,
|
|
840
|
+
{
|
|
841
|
+
size: "sm",
|
|
842
|
+
className: TARGET,
|
|
843
|
+
icon: /* @__PURE__ */ jsx(PlusIcon, {}),
|
|
844
|
+
tooltip: labels.zoomIn,
|
|
845
|
+
onClick: () => view.setCamera({ zoom: view.camera.zoom + 1 })
|
|
846
|
+
}
|
|
847
|
+
),
|
|
848
|
+
/* @__PURE__ */ jsx(
|
|
849
|
+
ButtonUtility,
|
|
850
|
+
{
|
|
851
|
+
size: "sm",
|
|
852
|
+
className: TARGET,
|
|
853
|
+
icon: /* @__PURE__ */ jsx(MinusIcon, {}),
|
|
854
|
+
tooltip: labels.zoomOut,
|
|
855
|
+
onClick: () => view.setCamera({ zoom: view.camera.zoom - 1 })
|
|
856
|
+
}
|
|
857
|
+
)
|
|
858
|
+
] }) : null,
|
|
859
|
+
has("fitData") ? /* @__PURE__ */ jsx(ButtonUtility, { size: "sm", className: TARGET, icon: /* @__PURE__ */ jsx(CrosshairIcon, {}), tooltip: labels.fitToData, onClick: () => view.fitTo("data") }) : null,
|
|
860
|
+
has("reset") ? (
|
|
861
|
+
// A RETURN arrow, not the expand glyph it used to wear. `reset` puts the camera back where
|
|
862
|
+
// the map opened; `fullscreen` is the one that expands, and the two shared an icon for as
|
|
863
|
+
// long as only one of them existed.
|
|
864
|
+
/* @__PURE__ */ jsx(ButtonUtility, { size: "sm", className: TARGET, icon: /* @__PURE__ */ jsx(RotateCcwIcon, {}), tooltip: labels.resetView, onClick: () => view.resetView() })
|
|
865
|
+
) : null,
|
|
866
|
+
has("fullscreen") ? /* @__PURE__ */ jsx(FullscreenButton, { root, labels }) : null
|
|
867
|
+
] })
|
|
868
|
+
] })
|
|
869
|
+
] });
|
|
870
|
+
}
|
|
871
|
+
function FullscreenButton({ root, labels }) {
|
|
872
|
+
const [active, setActive] = useState(false);
|
|
873
|
+
useEffect(() => {
|
|
874
|
+
const sync = () => setActive(document.fullscreenElement === root);
|
|
875
|
+
sync();
|
|
876
|
+
document.addEventListener("fullscreenchange", sync);
|
|
877
|
+
return () => document.removeEventListener("fullscreenchange", sync);
|
|
878
|
+
}, [root]);
|
|
879
|
+
if (!root || typeof document === "undefined" || !document.fullscreenEnabled) return null;
|
|
880
|
+
const label = active ? labels.exitFullscreen : labels.fullscreen;
|
|
881
|
+
return /* @__PURE__ */ jsx(
|
|
882
|
+
ButtonUtility,
|
|
883
|
+
{
|
|
884
|
+
size: "sm",
|
|
885
|
+
className: TARGET,
|
|
886
|
+
icon: active ? /* @__PURE__ */ jsx(MinimizeIcon, {}) : /* @__PURE__ */ jsx(MaximizeIcon, {}),
|
|
887
|
+
...active ? {} : { tooltip: label },
|
|
888
|
+
"aria-label": label,
|
|
889
|
+
"aria-pressed": active,
|
|
890
|
+
onClick: () => {
|
|
891
|
+
if (active) void document.exitFullscreen().catch(() => {
|
|
892
|
+
});
|
|
893
|
+
else void root.requestFullscreen().catch(() => {
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
);
|
|
898
|
+
}
|
|
899
|
+
function Breadcrumb({ view, labels }) {
|
|
900
|
+
const trail = view.drill.frames;
|
|
901
|
+
return /* @__PURE__ */ jsx(Card, { variant: "outlined", shadow: "sm", padding: "none", className: "pointer-events-auto", children: /* @__PURE__ */ jsxs("nav", { className: "flex items-center gap-1 px-2 py-1.5", children: [
|
|
902
|
+
/* @__PURE__ */ jsx(ButtonUtility, { size: "xs", variant: "tertiary", icon: /* @__PURE__ */ jsx(ChevronLeftIcon, {}), tooltip: labels.drillUp, onClick: () => view.drillUp() }),
|
|
903
|
+
trail.map((frame, index) => {
|
|
904
|
+
const current = index === trail.length - 1;
|
|
905
|
+
const label = frame.parentLabel ?? labels.drillRoot;
|
|
906
|
+
return /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-1", children: [
|
|
907
|
+
index > 0 ? /* @__PURE__ */ jsx("span", { className: "text-xs text-quaternary", children: "/" }) : null,
|
|
908
|
+
current ? (
|
|
909
|
+
// Where you already are: a control to here is a no-op that would still take a tab
|
|
910
|
+
// stop, so it is marked and left inert.
|
|
911
|
+
/* @__PURE__ */ jsx("span", { className: "rounded-sm px-1 text-xs font-semibold text-primary", "aria-current": "page", children: label })
|
|
912
|
+
) : (
|
|
913
|
+
/* A real destination. `drillUp(index)` jumps straight to that DEPTH — these were
|
|
914
|
+
inert `<span>`s, so a four-level trail took three presses of the back button to
|
|
915
|
+
get home and the crumbs were decoration. */
|
|
916
|
+
/* @__PURE__ */ jsx(
|
|
917
|
+
"button",
|
|
918
|
+
{
|
|
919
|
+
type: "button",
|
|
920
|
+
className: "rounded-sm px-1 text-xs text-tertiary outline-focus-ring hover:text-secondary_hover focus-visible:outline-2 focus-visible:outline-offset-2",
|
|
921
|
+
"aria-label": labels.drillTo({ level: label }),
|
|
922
|
+
onClick: () => view.drillUp(index),
|
|
923
|
+
children: label
|
|
924
|
+
}
|
|
925
|
+
)
|
|
926
|
+
)
|
|
927
|
+
] }, `${frame.level}-${index}`);
|
|
928
|
+
})
|
|
929
|
+
] }) });
|
|
930
|
+
}
|
|
931
|
+
function LayersPanel({
|
|
932
|
+
view,
|
|
933
|
+
labels,
|
|
934
|
+
formatNumber
|
|
935
|
+
}) {
|
|
936
|
+
return /* @__PURE__ */ jsx(
|
|
937
|
+
Popover,
|
|
938
|
+
{
|
|
939
|
+
size: "panel",
|
|
940
|
+
padding: "sm",
|
|
941
|
+
side: "bottom",
|
|
942
|
+
align: "end",
|
|
943
|
+
trigger: /* @__PURE__ */ jsx(ButtonUtility, { size: "sm", className: TARGET, icon: /* @__PURE__ */ jsx(LayersIcon, {}), tooltip: labels.layers }),
|
|
944
|
+
children: /* @__PURE__ */ jsxs("div", { className: "flex w-56 flex-col gap-2", children: [
|
|
945
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs font-semibold text-secondary", children: labels.layers }),
|
|
946
|
+
view.layers.map((layer) => /* @__PURE__ */ jsx(
|
|
947
|
+
Checkbox,
|
|
948
|
+
{
|
|
949
|
+
size: "md",
|
|
950
|
+
checked: layer.visible,
|
|
951
|
+
label: layer.label,
|
|
952
|
+
hint: layer.renderedCount > 0 ? formatNumber(layer.renderedCount) : void 0,
|
|
953
|
+
"aria-label": layer.visible ? labels.hideLayer({ layer: layer.label }) : labels.showLayer({ layer: layer.label }),
|
|
954
|
+
onCheckedChange: (checked) => view.setLayerVisible(layer.id, checked)
|
|
955
|
+
},
|
|
956
|
+
layer.id
|
|
957
|
+
))
|
|
958
|
+
] })
|
|
959
|
+
}
|
|
960
|
+
);
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
// src/components/data-map/cluster.ts
|
|
964
|
+
function clusterPoints(points, zoom, options = {}) {
|
|
965
|
+
const radius = options.radius ?? 48;
|
|
966
|
+
const maxZoom = options.maxZoom ?? 14;
|
|
967
|
+
if (zoom > maxZoom || radius <= 0) {
|
|
968
|
+
return points.map((point) => ({ id: point.id, x: point.x, y: point.y, members: [point] }));
|
|
969
|
+
}
|
|
970
|
+
const cells = /* @__PURE__ */ new Map();
|
|
971
|
+
for (const point of points) {
|
|
972
|
+
const key = `${Math.floor(point.x / radius)}:${Math.floor(point.y / radius)}`;
|
|
973
|
+
const bucket = cells.get(key);
|
|
974
|
+
if (bucket) bucket.push(point);
|
|
975
|
+
else cells.set(key, [point]);
|
|
976
|
+
}
|
|
977
|
+
const clusters = [];
|
|
978
|
+
for (const members of cells.values()) {
|
|
979
|
+
const first = members[0];
|
|
980
|
+
if (!first) continue;
|
|
981
|
+
if (members.length === 1) {
|
|
982
|
+
clusters.push({ id: first.id, x: first.x, y: first.y, members });
|
|
983
|
+
continue;
|
|
984
|
+
}
|
|
985
|
+
let sumX = 0;
|
|
986
|
+
let sumY = 0;
|
|
987
|
+
for (const member of members) {
|
|
988
|
+
sumX += member.x;
|
|
989
|
+
sumY += member.y;
|
|
990
|
+
}
|
|
991
|
+
clusters.push(assemble(members, sumX / members.length, sumY / members.length));
|
|
992
|
+
}
|
|
993
|
+
return deoverlap(clusters, radius);
|
|
994
|
+
}
|
|
995
|
+
function assemble(members, x, y) {
|
|
996
|
+
const ids = members.map((member) => member.id);
|
|
997
|
+
ids.sort((a, b) => a.localeCompare(b));
|
|
998
|
+
return { id: `cluster:${ids.join("|")}`, x, y, members };
|
|
999
|
+
}
|
|
1000
|
+
var DEOVERLAP_PASSES = 4;
|
|
1001
|
+
function deoverlap(clusters, radius) {
|
|
1002
|
+
const minimum = radius;
|
|
1003
|
+
let current = clusters;
|
|
1004
|
+
for (let pass = 0; pass < DEOVERLAP_PASSES; pass++) {
|
|
1005
|
+
const { merged, anyMerge } = mergePass(current, minimum);
|
|
1006
|
+
current = merged;
|
|
1007
|
+
if (!anyMerge) break;
|
|
1008
|
+
}
|
|
1009
|
+
return current;
|
|
1010
|
+
}
|
|
1011
|
+
function mergePass(clusters, minimum) {
|
|
1012
|
+
const sorted = [...clusters];
|
|
1013
|
+
sorted.sort((a, b) => a.x - b.x || a.y - b.y || a.id.localeCompare(b.id));
|
|
1014
|
+
const merged = [];
|
|
1015
|
+
const taken = /* @__PURE__ */ new Set();
|
|
1016
|
+
let anyMerge = false;
|
|
1017
|
+
for (const [i, cluster] of sorted.entries()) {
|
|
1018
|
+
if (taken.has(i)) continue;
|
|
1019
|
+
const grown = absorb(sorted, i, taken, minimum);
|
|
1020
|
+
const same = grown.members.length === cluster.members.length;
|
|
1021
|
+
if (!same) anyMerge = true;
|
|
1022
|
+
merged.push(same ? cluster : assemble(grown.members, grown.sumX / grown.members.length, grown.sumY / grown.members.length));
|
|
1023
|
+
}
|
|
1024
|
+
return { merged, anyMerge };
|
|
1025
|
+
}
|
|
1026
|
+
function absorb(clusters, i, taken, minimum) {
|
|
1027
|
+
const start = clusters[i];
|
|
1028
|
+
if (!start) return { members: [], sumX: 0, sumY: 0 };
|
|
1029
|
+
let members = start.members;
|
|
1030
|
+
let sumX = start.x * start.members.length;
|
|
1031
|
+
let sumY = start.y * start.members.length;
|
|
1032
|
+
for (let j = i + 1; j < clusters.length; j++) {
|
|
1033
|
+
if (taken.has(j)) continue;
|
|
1034
|
+
const other = clusters[j];
|
|
1035
|
+
if (!other) continue;
|
|
1036
|
+
const centreX = sumX / members.length;
|
|
1037
|
+
if (other.x - centreX > minimum) break;
|
|
1038
|
+
if (Math.hypot(other.x - centreX, other.y - sumY / members.length) >= minimum) continue;
|
|
1039
|
+
taken.add(j);
|
|
1040
|
+
members = [...members, ...other.members];
|
|
1041
|
+
sumX += other.x * other.members.length;
|
|
1042
|
+
sumY += other.y * other.members.length;
|
|
1043
|
+
}
|
|
1044
|
+
return { members, sumX, sumY };
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
// src/components/data-map/engine.ts
|
|
1048
|
+
var wrap = (map) => map;
|
|
1049
|
+
var raw = (instance) => instance;
|
|
1050
|
+
var enginePromise;
|
|
1051
|
+
async function loadEngine() {
|
|
1052
|
+
enginePromise ??= (async () => {
|
|
1053
|
+
const m = await import('maplibre-gl');
|
|
1054
|
+
return { Map: m.Map, Marker: m.Marker };
|
|
1055
|
+
})();
|
|
1056
|
+
return enginePromise;
|
|
1057
|
+
}
|
|
1058
|
+
function isEngineLoaded() {
|
|
1059
|
+
return enginePromise !== void 0;
|
|
1060
|
+
}
|
|
1061
|
+
function isEngineSupported() {
|
|
1062
|
+
if (typeof document === "undefined") return false;
|
|
1063
|
+
try {
|
|
1064
|
+
const canvas = document.createElement("canvas");
|
|
1065
|
+
const gl = canvas.getContext("webgl2");
|
|
1066
|
+
const lose = gl?.getExtension("WEBGL_lose_context");
|
|
1067
|
+
lose?.loseContext();
|
|
1068
|
+
return gl !== null;
|
|
1069
|
+
} catch {
|
|
1070
|
+
return false;
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
function defined(options) {
|
|
1074
|
+
const out = {};
|
|
1075
|
+
for (const [key, value] of Object.entries(options)) {
|
|
1076
|
+
if (value !== void 0) out[key] = value;
|
|
1077
|
+
}
|
|
1078
|
+
return out;
|
|
1079
|
+
}
|
|
1080
|
+
var lngLat = (t) => [t[0], t[1]];
|
|
1081
|
+
var bounds = (b) => [
|
|
1082
|
+
[b[0], b[1]],
|
|
1083
|
+
[b[2], b[3]]
|
|
1084
|
+
];
|
|
1085
|
+
var padding = (p) => p ? { top: p.top, right: p.right, bottom: p.bottom, left: p.left } : void 0;
|
|
1086
|
+
function createMap(engine, init) {
|
|
1087
|
+
const framing = init.bounds ? defined({ padding: padding(init.fitPadding), maxZoom: init.fitMaxZoom }) : void 0;
|
|
1088
|
+
const map = new engine.Map(
|
|
1089
|
+
defined({
|
|
1090
|
+
container: init.container,
|
|
1091
|
+
style: init.style,
|
|
1092
|
+
center: init.center ? lngLat(init.center) : [0, 0],
|
|
1093
|
+
zoom: init.zoom ?? 1,
|
|
1094
|
+
bearing: init.bearing ?? 0,
|
|
1095
|
+
pitch: init.pitch ?? 0,
|
|
1096
|
+
minZoom: init.minZoom,
|
|
1097
|
+
maxZoom: init.maxZoom,
|
|
1098
|
+
maxBounds: init.maxBounds ? bounds(init.maxBounds) : void 0,
|
|
1099
|
+
// MapLibre lets `bounds` override `center`/`zoom`, and it resolves BEFORE the first paint —
|
|
1100
|
+
// which is the whole point: nothing else can put the opening frame in front of the reader
|
|
1101
|
+
// rather than behind a post-`load` correction.
|
|
1102
|
+
bounds: init.bounds ? bounds(init.bounds) : void 0,
|
|
1103
|
+
fitBoundsOptions: framing,
|
|
1104
|
+
// Removes the WIDGET. The attribution TEXT is legally required and our own chrome renders it.
|
|
1105
|
+
attributionControl: false,
|
|
1106
|
+
// Not required by MapLibre's licence — it is opt-in upstream — and we do not display it.
|
|
1107
|
+
maplibreLogo: false,
|
|
1108
|
+
// A map in a scrolling page must not eat the wheel: ⌘/ctrl+wheel zooms, a two-finger drag pans.
|
|
1109
|
+
// The same reasoning already refused `embla-carousel-wheel-gestures` in the carousel.
|
|
1110
|
+
cooperativeGestures: init.cooperativeGestures ?? true,
|
|
1111
|
+
// `prefers-reduced-motion` is handled by the CAMERA layer, not here — this flag would also kill
|
|
1112
|
+
// the cross-fade of tile loading, which is not the motion anyone was complaining about.
|
|
1113
|
+
fadeDuration: init.fadeDuration,
|
|
1114
|
+
// D4 / correction C1 — the engine's own chrome, in the app's language. See `MapInit.locale`.
|
|
1115
|
+
locale: init.locale
|
|
1116
|
+
})
|
|
1117
|
+
);
|
|
1118
|
+
return wrap(map);
|
|
1119
|
+
}
|
|
1120
|
+
function destroyMap(instance) {
|
|
1121
|
+
if (!instance) return;
|
|
1122
|
+
const map = raw(instance);
|
|
1123
|
+
try {
|
|
1124
|
+
map.remove();
|
|
1125
|
+
} catch {
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
function onMapEvent(instance, event, listener) {
|
|
1129
|
+
const map = raw(instance);
|
|
1130
|
+
map.on(event, listener);
|
|
1131
|
+
return () => {
|
|
1132
|
+
try {
|
|
1133
|
+
map.off(event, listener);
|
|
1134
|
+
} catch {
|
|
1135
|
+
}
|
|
1136
|
+
};
|
|
1137
|
+
}
|
|
1138
|
+
function getCamera(instance) {
|
|
1139
|
+
const map = raw(instance);
|
|
1140
|
+
const c = map.getCenter();
|
|
1141
|
+
return { center: [c.lng, c.lat], zoom: map.getZoom(), bearing: map.getBearing(), pitch: map.getPitch() };
|
|
1142
|
+
}
|
|
1143
|
+
function moveCamera(instance, move) {
|
|
1144
|
+
const map = raw(instance);
|
|
1145
|
+
const target = defined({
|
|
1146
|
+
center: move.center ? lngLat(move.center) : void 0,
|
|
1147
|
+
zoom: move.zoom,
|
|
1148
|
+
bearing: move.bearing,
|
|
1149
|
+
pitch: move.pitch,
|
|
1150
|
+
padding: padding(move.padding)
|
|
1151
|
+
});
|
|
1152
|
+
if (move.transition === "fly") {
|
|
1153
|
+
map.flyTo(defined({ ...target, duration: move.duration }));
|
|
1154
|
+
return;
|
|
1155
|
+
}
|
|
1156
|
+
if (move.transition === "ease") {
|
|
1157
|
+
map.easeTo(defined({ ...target, duration: move.duration }));
|
|
1158
|
+
return;
|
|
1159
|
+
}
|
|
1160
|
+
map.jumpTo(target);
|
|
1161
|
+
}
|
|
1162
|
+
function fitBounds(instance, move) {
|
|
1163
|
+
if (move.bounds.some((n) => !Number.isFinite(n))) return false;
|
|
1164
|
+
const map = raw(instance);
|
|
1165
|
+
const container = map.getContainer();
|
|
1166
|
+
const width = container?.clientWidth ?? 0;
|
|
1167
|
+
const height = container?.clientHeight ?? 0;
|
|
1168
|
+
if (width <= 0 || height <= 0) return false;
|
|
1169
|
+
const requested = move.padding;
|
|
1170
|
+
let fitted = requested;
|
|
1171
|
+
if (requested) {
|
|
1172
|
+
const horizontal = requested.left + requested.right;
|
|
1173
|
+
const vertical = requested.top + requested.bottom;
|
|
1174
|
+
const scaleX = horizontal > 0 ? Math.min(1, width * 0.8 / horizontal) : 1;
|
|
1175
|
+
const scaleY = vertical > 0 ? Math.min(1, height * 0.8 / vertical) : 1;
|
|
1176
|
+
fitted = {
|
|
1177
|
+
top: Math.floor(requested.top * scaleY),
|
|
1178
|
+
right: Math.floor(requested.right * scaleX),
|
|
1179
|
+
bottom: Math.floor(requested.bottom * scaleY),
|
|
1180
|
+
left: Math.floor(requested.left * scaleX)
|
|
1181
|
+
};
|
|
1182
|
+
}
|
|
1183
|
+
try {
|
|
1184
|
+
const instant = move.intro === "instant";
|
|
1185
|
+
const linear = instant ? true : void 0;
|
|
1186
|
+
const duration = move.duration ?? (instant ? 0 : void 0);
|
|
1187
|
+
if (move.fit !== "cover") {
|
|
1188
|
+
map.fitBounds(bounds(move.bounds), defined({ padding: padding(fitted), duration, maxZoom: move.maxZoom, linear }));
|
|
1189
|
+
return true;
|
|
1190
|
+
}
|
|
1191
|
+
const camera = map.cameraForBounds(bounds(move.bounds), defined({ padding: padding(fitted), maxZoom: move.maxZoom }));
|
|
1192
|
+
if (!camera || camera.zoom === void 0) {
|
|
1193
|
+
map.fitBounds(bounds(move.bounds), defined({ padding: padding(fitted), duration, maxZoom: move.maxZoom, linear }));
|
|
1194
|
+
return true;
|
|
1195
|
+
}
|
|
1196
|
+
const [west, south, east, north] = move.bounds;
|
|
1197
|
+
const mercatorY = (lat) => {
|
|
1198
|
+
const clamped = Math.max(-85.05, Math.min(85.05, lat));
|
|
1199
|
+
const sin = Math.sin(clamped * Math.PI / 180);
|
|
1200
|
+
return 0.5 - Math.log((1 + sin) / (1 - sin)) / (4 * Math.PI);
|
|
1201
|
+
};
|
|
1202
|
+
const spanX = Math.abs(east - west) / 360;
|
|
1203
|
+
const spanY = Math.abs(mercatorY(north) - mercatorY(south));
|
|
1204
|
+
const usableWidth = Math.max(1, width - (fitted?.left ?? 0) - (fitted?.right ?? 0));
|
|
1205
|
+
const usableHeight = Math.max(1, height - (fitted?.top ?? 0) - (fitted?.bottom ?? 0));
|
|
1206
|
+
const delta = spanX > 0 && spanY > 0 ? Math.abs(Math.log2(usableWidth * spanY / (usableHeight * spanX))) : 0;
|
|
1207
|
+
const zoom = Math.min((move.maxZoom ?? 24) + 4, camera.zoom + Math.min(delta, 3));
|
|
1208
|
+
map.easeTo(defined({ center: camera.center, zoom, duration }));
|
|
1209
|
+
return true;
|
|
1210
|
+
} catch {
|
|
1211
|
+
return false;
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
function addSource(instance, id, spec, layers = [], beforeLayerId) {
|
|
1215
|
+
const map = raw(instance);
|
|
1216
|
+
map.addSource(id, spec);
|
|
1217
|
+
for (const layer of layers) {
|
|
1218
|
+
const before = beforeLayerId && map.getLayer(beforeLayerId) ? beforeLayerId : void 0;
|
|
1219
|
+
map.addLayer(layer, before);
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
function removeSourceAndLayers(instance, id, layerIds) {
|
|
1223
|
+
const map = raw(instance);
|
|
1224
|
+
for (const layerId2 of layerIds) {
|
|
1225
|
+
try {
|
|
1226
|
+
if (map.getLayer(layerId2)) map.removeLayer(layerId2);
|
|
1227
|
+
} catch {
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
try {
|
|
1231
|
+
if (map.getSource(id)) map.removeSource(id);
|
|
1232
|
+
} catch {
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
function setSourceData(instance, id, data) {
|
|
1236
|
+
const source = raw(instance).getSource(id);
|
|
1237
|
+
source?.setData?.(data);
|
|
1238
|
+
}
|
|
1239
|
+
function setPaint(instance, layerId2, property, value) {
|
|
1240
|
+
try {
|
|
1241
|
+
raw(instance).setPaintProperty(layerId2, property, value);
|
|
1242
|
+
} catch {
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
function setLayerVisibility(instance, layerId2, visible) {
|
|
1246
|
+
try {
|
|
1247
|
+
raw(instance).setLayoutProperty(layerId2, "visibility", visible ? "visible" : "none");
|
|
1248
|
+
} catch {
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
function hasLayer(instance, layerId2) {
|
|
1252
|
+
try {
|
|
1253
|
+
return raw(instance).getLayer(layerId2) !== void 0;
|
|
1254
|
+
} catch {
|
|
1255
|
+
return false;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
function getBounds(instance) {
|
|
1259
|
+
const b = raw(instance).getBounds();
|
|
1260
|
+
return [b.getWest(), b.getSouth(), b.getEast(), b.getNorth()];
|
|
1261
|
+
}
|
|
1262
|
+
function isMapIdle(instance) {
|
|
1263
|
+
try {
|
|
1264
|
+
return raw(instance).loaded();
|
|
1265
|
+
} catch {
|
|
1266
|
+
return false;
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
function pendingSources(instance) {
|
|
1270
|
+
try {
|
|
1271
|
+
const map = raw(instance);
|
|
1272
|
+
const style = map.style;
|
|
1273
|
+
const reasons = [];
|
|
1274
|
+
if (map._styleDirty) reasons.push("styleDirty");
|
|
1275
|
+
if (map._sourcesDirty) reasons.push("sourcesDirty");
|
|
1276
|
+
if (style?._loaded === false) reasons.push("styleNotLoaded");
|
|
1277
|
+
const updating = Object.keys(style?._updatedSources ?? {});
|
|
1278
|
+
for (const id of updating) reasons.push(`updating:${id}`);
|
|
1279
|
+
if (style?.imageManager?.isLoaded?.() === false) reasons.push("imagesNotLoaded");
|
|
1280
|
+
const managers = Object.entries(style?.tileManagers ?? {});
|
|
1281
|
+
for (const [id, manager] of managers) if (manager.loaded?.() === false) reasons.push(`source:${id}`);
|
|
1282
|
+
return reasons;
|
|
1283
|
+
} catch {
|
|
1284
|
+
return [];
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
function hasSource(instance, id) {
|
|
1288
|
+
try {
|
|
1289
|
+
return raw(instance).getSource(id) !== void 0;
|
|
1290
|
+
} catch {
|
|
1291
|
+
return false;
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
function setFeatureState(instance, sourceId, featureId, state) {
|
|
1295
|
+
try {
|
|
1296
|
+
raw(instance).setFeatureState({ source: sourceId, id: featureId }, state);
|
|
1297
|
+
} catch {
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
function clearFeatureState(instance, sourceId) {
|
|
1301
|
+
try {
|
|
1302
|
+
raw(instance).removeFeatureState({ source: sourceId });
|
|
1303
|
+
} catch {
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
async function createMarker(instance, position, options) {
|
|
1307
|
+
const engine = await loadEngine();
|
|
1308
|
+
const element = document.createElement("div");
|
|
1309
|
+
element.style.position = "absolute";
|
|
1310
|
+
element.style.top = "0";
|
|
1311
|
+
element.style.left = "0";
|
|
1312
|
+
element.style.willChange = "transform";
|
|
1313
|
+
const marker = new engine.Marker({ element, anchor: options?.anchor ?? "center" }).setLngLat(lngLat(position)).addTo(raw(instance));
|
|
1314
|
+
return {
|
|
1315
|
+
element,
|
|
1316
|
+
setPosition: (next) => marker.setLngLat(lngLat(next)),
|
|
1317
|
+
remove: () => {
|
|
1318
|
+
try {
|
|
1319
|
+
marker.remove();
|
|
1320
|
+
} catch {
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
};
|
|
1324
|
+
}
|
|
1325
|
+
function projectPoint(instance, position) {
|
|
1326
|
+
const point = raw(instance).project(lngLat(position));
|
|
1327
|
+
return { x: point.x, y: point.y };
|
|
1328
|
+
}
|
|
1329
|
+
function swapStyle(instance, next, carry) {
|
|
1330
|
+
const map = raw(instance);
|
|
1331
|
+
const sourceIds = carry?.sourceIds ?? [];
|
|
1332
|
+
const layerIds = carry?.layerIds ?? [];
|
|
1333
|
+
if (sourceIds.length === 0 && layerIds.length === 0) {
|
|
1334
|
+
map.setStyle(next, { diff: true });
|
|
1335
|
+
return;
|
|
1336
|
+
}
|
|
1337
|
+
map.setStyle(next, {
|
|
1338
|
+
diff: true,
|
|
1339
|
+
transformStyle: (previous, incoming) => {
|
|
1340
|
+
if (!previous) return incoming;
|
|
1341
|
+
const sources = { ...incoming.sources };
|
|
1342
|
+
for (const id of sourceIds) {
|
|
1343
|
+
const carried = previous.sources?.[id];
|
|
1344
|
+
if (carried) sources[id] = carried;
|
|
1345
|
+
}
|
|
1346
|
+
const keep = new Set(layerIds);
|
|
1347
|
+
const carriedLayers = (previous.layers ?? []).filter((l) => keep.has(l.id));
|
|
1348
|
+
const layers = [...incoming.layers ?? []];
|
|
1349
|
+
const at = layers.findIndex((l) => l.id === carry.beforeLayerId) ;
|
|
1350
|
+
if (at === -1) layers.push(...carriedLayers);
|
|
1351
|
+
else layers.splice(at, 0, ...carriedLayers);
|
|
1352
|
+
return { ...incoming, sources, layers };
|
|
1353
|
+
}
|
|
1354
|
+
});
|
|
1355
|
+
}
|
|
1356
|
+
function stopCamera(instance) {
|
|
1357
|
+
try {
|
|
1358
|
+
raw(instance).stop();
|
|
1359
|
+
} catch {
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
function redraw(instance) {
|
|
1363
|
+
try {
|
|
1364
|
+
raw(instance).resize();
|
|
1365
|
+
} catch {
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
function toRenderedFeature(f) {
|
|
1369
|
+
return {
|
|
1370
|
+
id: f.id === void 0 ? void 0 : String(f.id),
|
|
1371
|
+
properties: f.properties ?? {},
|
|
1372
|
+
layerId: f.layer?.id ?? "",
|
|
1373
|
+
sourceId: f.source ?? ""
|
|
1374
|
+
};
|
|
1375
|
+
}
|
|
1376
|
+
function queryAt(instance, point, layerIds) {
|
|
1377
|
+
try {
|
|
1378
|
+
const found = raw(instance).queryRenderedFeatures([point.x, point.y], layerIds ? { layers: [...layerIds] } : void 0);
|
|
1379
|
+
return found.map(toRenderedFeature);
|
|
1380
|
+
} catch {
|
|
1381
|
+
return [];
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
var HIT_PAD = "absolute left-1/2 top-1/2 size-11 -translate-x-1/2 -translate-y-1/2 -z-1";
|
|
1385
|
+
var CASING = "ring-2 ring-bg-primary";
|
|
1386
|
+
var SELECTED = "shadow-lg ring-2 ring-focus-ring";
|
|
1387
|
+
var DOT_MIN = 8;
|
|
1388
|
+
var DOT_MAX = 32;
|
|
1389
|
+
function dotSize(scale) {
|
|
1390
|
+
if (scale === void 0) return 12;
|
|
1391
|
+
const clamped = Math.min(1, Math.max(0, scale));
|
|
1392
|
+
return Math.round(DOT_MIN + (DOT_MAX - DOT_MIN) * Math.sqrt(clamped));
|
|
1393
|
+
}
|
|
1394
|
+
function MapMarker({ shape, tone, name, scale, selected, children }) {
|
|
1395
|
+
const size = dotSize(scale);
|
|
1396
|
+
const inner = (() => {
|
|
1397
|
+
switch (shape) {
|
|
1398
|
+
case "dot": {
|
|
1399
|
+
return /* @__PURE__ */ jsx("span", { className: cn("block rounded-full", FILL[tone], CASING, selected && SELECTED), style: { width: size, height: size }, "aria-hidden": true });
|
|
1400
|
+
}
|
|
1401
|
+
case "ring": {
|
|
1402
|
+
return /* @__PURE__ */ jsx(
|
|
1403
|
+
"span",
|
|
1404
|
+
{
|
|
1405
|
+
className: cn("block rounded-full bg-primary", ACCENT[tone], CASING, selected && SELECTED),
|
|
1406
|
+
style: { width: size, height: size, borderWidth: Math.max(3, size / 4), borderStyle: "solid", borderColor: "currentColor" },
|
|
1407
|
+
"aria-hidden": true
|
|
1408
|
+
}
|
|
1409
|
+
);
|
|
1410
|
+
}
|
|
1411
|
+
case "teardrop": {
|
|
1412
|
+
return /* @__PURE__ */ jsx(
|
|
1413
|
+
"span",
|
|
1414
|
+
{
|
|
1415
|
+
className: cn("block rotate-45 rounded-tl-full rounded-tr-full rounded-br-full", FILL[tone], CASING, selected && SELECTED),
|
|
1416
|
+
style: { width: size, height: size },
|
|
1417
|
+
"aria-hidden": true
|
|
1418
|
+
}
|
|
1419
|
+
);
|
|
1420
|
+
}
|
|
1421
|
+
case "icon":
|
|
1422
|
+
case "avatar": {
|
|
1423
|
+
return /* @__PURE__ */ jsx("span", { className: cn("flex items-center justify-center rounded-full bg-primary p-1 shadow-md", CASING, selected && SELECTED), children });
|
|
1424
|
+
}
|
|
1425
|
+
case "label": {
|
|
1426
|
+
return /* @__PURE__ */ jsx("span", { className: cn("block max-w-40 truncate rounded-full px-2 py-0.5 text-xs font-medium shadow-sm", SOLID[tone], CASING, selected && SELECTED), children: name });
|
|
1427
|
+
}
|
|
1428
|
+
case "pin": {
|
|
1429
|
+
return /* @__PURE__ */ jsx(
|
|
1430
|
+
"span",
|
|
1431
|
+
{
|
|
1432
|
+
className: cn("flex items-center justify-center rounded-full shadow-md", FILL[tone], CASING, selected && SELECTED),
|
|
1433
|
+
style: { width: size + 4, height: size + 4 },
|
|
1434
|
+
children: /* @__PURE__ */ jsx("span", { className: "size-1.5 rounded-full bg-fg-white/80", "aria-hidden": true })
|
|
1435
|
+
}
|
|
1436
|
+
);
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
})();
|
|
1440
|
+
return /* @__PURE__ */ jsxs("span", { className: cn("relative isolate inline-flex items-center justify-center", selected && "z-10", shape === "teardrop" && "-translate-y-1/2"), children: [
|
|
1441
|
+
/* @__PURE__ */ jsx("span", { className: HIT_PAD, "aria-hidden": true }),
|
|
1442
|
+
inner
|
|
1443
|
+
] });
|
|
1444
|
+
}
|
|
1445
|
+
var BUBBLE = [36, 44, 56];
|
|
1446
|
+
var BUBBLE_FILL = {
|
|
1447
|
+
neutral: "bg-utility-neutral-200 text-primary",
|
|
1448
|
+
brand: "bg-utility-brand-200 text-primary",
|
|
1449
|
+
success: "bg-utility-green-200 text-primary",
|
|
1450
|
+
warning: "bg-utility-amber-200 text-primary",
|
|
1451
|
+
error: "bg-utility-red-200 text-primary",
|
|
1452
|
+
info: "bg-utility-blue-200 text-primary"
|
|
1453
|
+
};
|
|
1454
|
+
var BUBBLE_EDGE = "border border-strong";
|
|
1455
|
+
function ClusterBubble({ count, band, tone, label, onClick }) {
|
|
1456
|
+
const size = BUBBLE[band];
|
|
1457
|
+
return /* @__PURE__ */ jsxs(
|
|
1458
|
+
"button",
|
|
1459
|
+
{
|
|
1460
|
+
type: "button",
|
|
1461
|
+
className: cn(
|
|
1462
|
+
"relative flex items-center justify-center rounded-full text-xs font-semibold tabular-nums shadow-md outline-focus-ring focus-visible:outline-2 focus-visible:outline-offset-2",
|
|
1463
|
+
BUBBLE_FILL[tone],
|
|
1464
|
+
BUBBLE_EDGE,
|
|
1465
|
+
CASING
|
|
1466
|
+
),
|
|
1467
|
+
style: { width: size, height: size },
|
|
1468
|
+
"aria-label": label,
|
|
1469
|
+
onClick,
|
|
1470
|
+
children: [
|
|
1471
|
+
/* @__PURE__ */ jsx("span", { className: HIT_PAD, "aria-hidden": true }),
|
|
1472
|
+
count
|
|
1473
|
+
]
|
|
1474
|
+
}
|
|
1475
|
+
);
|
|
1476
|
+
}
|
|
1477
|
+
function clusterBand(count, largest) {
|
|
1478
|
+
if (largest <= 1) return 0;
|
|
1479
|
+
const position = Math.log(count) / Math.log(largest);
|
|
1480
|
+
if (position < 0.5) return 0;
|
|
1481
|
+
if (position < 0.8) return 1;
|
|
1482
|
+
return 2;
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
// src/components/data-map/bins.ts
|
|
1486
|
+
function quantileAt(sorted, q) {
|
|
1487
|
+
if (sorted.length === 0) return 0;
|
|
1488
|
+
const position = (sorted.length - 1) * q;
|
|
1489
|
+
const low = Math.floor(position);
|
|
1490
|
+
const high = Math.ceil(position);
|
|
1491
|
+
const a = sorted[low] ?? 0;
|
|
1492
|
+
const b = sorted[high] ?? a;
|
|
1493
|
+
return a + (b - a) * (position - low);
|
|
1494
|
+
}
|
|
1495
|
+
function edgesToBins(rawEdges, requested) {
|
|
1496
|
+
const edges = [];
|
|
1497
|
+
for (const edge of rawEdges) {
|
|
1498
|
+
const last = edges.at(-1);
|
|
1499
|
+
if (last === void 0 || edge > last) edges.push(edge);
|
|
1500
|
+
}
|
|
1501
|
+
if (edges.length <= 1) {
|
|
1502
|
+
const only = edges[0] ?? 0;
|
|
1503
|
+
return { bins: [{ index: 0, min: only, max: only }], requested, collapsed: requested > 1 };
|
|
1504
|
+
}
|
|
1505
|
+
const bins = [];
|
|
1506
|
+
const lower = edges.slice(0, -1);
|
|
1507
|
+
for (const [i, min] of lower.entries()) {
|
|
1508
|
+
bins.push({ index: i, min, max: edges[i + 1] ?? min });
|
|
1509
|
+
}
|
|
1510
|
+
return { bins, requested, collapsed: bins.length < requested };
|
|
1511
|
+
}
|
|
1512
|
+
function computeBins(values, strategy = "quantile", count = 6) {
|
|
1513
|
+
const finite = values.filter((v) => Number.isFinite(v));
|
|
1514
|
+
if (finite.length === 0) return { bins: [], requested: count, collapsed: false };
|
|
1515
|
+
if (Array.isArray(strategy)) {
|
|
1516
|
+
const explicit = [...strategy];
|
|
1517
|
+
explicit.sort((a, b) => a - b);
|
|
1518
|
+
return edgesToBins(explicit, explicit.length - 1);
|
|
1519
|
+
}
|
|
1520
|
+
const sorted = [...finite];
|
|
1521
|
+
sorted.sort((a, b) => a - b);
|
|
1522
|
+
if (strategy === "equal") {
|
|
1523
|
+
const min = sorted[0] ?? 0;
|
|
1524
|
+
const max = sorted.at(-1) ?? min;
|
|
1525
|
+
const step = (max - min) / count;
|
|
1526
|
+
return edgesToBins(
|
|
1527
|
+
Array.from({ length: count + 1 }, (_, i) => min + step * i),
|
|
1528
|
+
count
|
|
1529
|
+
);
|
|
1530
|
+
}
|
|
1531
|
+
return edgesToBins(
|
|
1532
|
+
Array.from({ length: count + 1 }, (_, i) => quantileAt(sorted, i / count)),
|
|
1533
|
+
count
|
|
1534
|
+
);
|
|
1535
|
+
}
|
|
1536
|
+
function binOf(bins, value) {
|
|
1537
|
+
if (bins.length === 0) return void 0;
|
|
1538
|
+
const first = bins[0];
|
|
1539
|
+
if (first === void 0) return void 0;
|
|
1540
|
+
if (value < first.min) return 0;
|
|
1541
|
+
for (let i = bins.length - 1; i >= 0; i--) {
|
|
1542
|
+
const bin = bins[i];
|
|
1543
|
+
if (bin && value >= bin.min) return i;
|
|
1544
|
+
}
|
|
1545
|
+
return 0;
|
|
1546
|
+
}
|
|
1547
|
+
function scaleColor(scale, index, count) {
|
|
1548
|
+
if (scale.length === 0) return void 0;
|
|
1549
|
+
if (count <= 1) return scale.at(-1);
|
|
1550
|
+
const position = Math.round(index / (count - 1) * (scale.length - 1));
|
|
1551
|
+
return scale[Math.min(Math.max(position, 0), scale.length - 1)];
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
// src/components/data-map/scale.ts
|
|
1555
|
+
var ENGINE_BLIND = /\b(var|oklch|oklab|lab|lch|hwb|color-mix|color)\s*\(/;
|
|
1556
|
+
function warnEngineColor(where, value) {
|
|
1557
|
+
const blind = ENGINE_BLIND.exec(value);
|
|
1558
|
+
if (blind) {
|
|
1559
|
+
devWarn(
|
|
1560
|
+
`<DataMap> ${where} is "${value}". MapLibre paints from JSON, not from CSS: it cannot resolve \`${blind[1]}(\u2026)\` and drops the declaration SILENTLY, so the layer would paint its default. Pass a resolved colour \u2014 "#7f56d9", "rgb(127 86 217)", "hsl(258 68% 59%)" or a named colour. (\`token()\` is for the chart family, whose colour is a CSS value.)`
|
|
1561
|
+
);
|
|
1562
|
+
return;
|
|
1563
|
+
}
|
|
1564
|
+
if (typeof CSS !== "undefined" && typeof CSS.supports === "function" && !CSS.supports("color", value)) {
|
|
1565
|
+
devWarn(`<DataMap> ${where} is "${value}", which is not a CSS colour.`);
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
function checkRamp(where, colors) {
|
|
1569
|
+
for (const [i, color] of colors.entries()) warnEngineColor(`${where}[${i}]`, color);
|
|
1570
|
+
return colors;
|
|
1571
|
+
}
|
|
1572
|
+
function rampColors(ramp, mode) {
|
|
1573
|
+
if (ramp === void 0) return MAP_SEQUENTIAL_SCALES[mode].brand;
|
|
1574
|
+
if (typeof ramp === "string") return MAP_SEQUENTIAL_SCALES[mode][ramp];
|
|
1575
|
+
return checkRamp("scale.ramp", ramp);
|
|
1576
|
+
}
|
|
1577
|
+
function divergingColors(ramp, mode) {
|
|
1578
|
+
if (ramp === void 0) return MAP_DIVERGING_SCALES[mode]["error-success"];
|
|
1579
|
+
if (typeof ramp === "string") return MAP_DIVERGING_SCALES[mode][ramp];
|
|
1580
|
+
return checkRamp("scale.ramp", ramp);
|
|
1581
|
+
}
|
|
1582
|
+
var CATEGORY_TONES = ["brand", "info", "success", "warning", "error", "neutral"];
|
|
1583
|
+
function warnCategoryCount(categories) {
|
|
1584
|
+
const unspecified = categories.filter((c) => c.color === void 0 && c.tone === void 0).length;
|
|
1585
|
+
if (unspecified <= CATEGORY_TONES.length) return;
|
|
1586
|
+
devWarn(
|
|
1587
|
+
`<DataMap> ${unspecified} categories carry neither \`tone\` nor \`color\`, but the palette has ${CATEGORY_TONES.length} hues \u2014 colours repeat from the ${CATEGORY_TONES.length + 1}th, and two regions painted the same colour cannot be told apart. Give the extra categories an explicit \`tone\` or \`color\`.`
|
|
1588
|
+
);
|
|
1589
|
+
}
|
|
1590
|
+
function categoryColor(category, index, mode) {
|
|
1591
|
+
if (category.color !== void 0) {
|
|
1592
|
+
warnEngineColor(`category "${category.value}"`, category.color);
|
|
1593
|
+
return category.color;
|
|
1594
|
+
}
|
|
1595
|
+
const tone = category.tone ?? CATEGORY_TONES[index % CATEGORY_TONES.length];
|
|
1596
|
+
return toneFill(tone, mode);
|
|
1597
|
+
}
|
|
1598
|
+
function toneFill(tone, mode) {
|
|
1599
|
+
return MAP_TONE_COLORS[mode][tone].fill;
|
|
1600
|
+
}
|
|
1601
|
+
function toneStroke(tone, mode) {
|
|
1602
|
+
return MAP_TONE_COLORS[mode][tone].strong;
|
|
1603
|
+
}
|
|
1604
|
+
function toneWash(tone, mode) {
|
|
1605
|
+
return MAP_TONE_COLORS[mode][tone].soft;
|
|
1606
|
+
}
|
|
1607
|
+
function divergingBins(values, center, stops) {
|
|
1608
|
+
const finite = values.filter((v) => Number.isFinite(v));
|
|
1609
|
+
if (finite.length === 0) return { bins: [], requested: stops, collapsed: false };
|
|
1610
|
+
let span2 = 0;
|
|
1611
|
+
for (const v of finite) span2 = Math.max(span2, Math.abs(v - center));
|
|
1612
|
+
if (span2 === 0) return { bins: [{ index: 0, min: center, max: center }], requested: stops, collapsed: stops > 1 };
|
|
1613
|
+
const wings = Math.max(1, Math.floor((stops - 1) / 2));
|
|
1614
|
+
const step = span2 / (wings + 0.5);
|
|
1615
|
+
const edges = [];
|
|
1616
|
+
for (let i = wings; i >= 1; i--) edges.push(center - step * (i - 0.5) - step * 0.5);
|
|
1617
|
+
edges.push(center - step * 0.5, center + step * 0.5);
|
|
1618
|
+
for (let i = 1; i <= wings; i++) edges.push(center + step * 0.5 + step * i);
|
|
1619
|
+
const bins = Array.from(edges.slice(0, -1).entries(), ([i, min]) => ({ index: i, min, max: edges[i + 1] ?? min }));
|
|
1620
|
+
return { bins, requested: stops, collapsed: false };
|
|
1621
|
+
}
|
|
1622
|
+
function resolveScale(scale, data, options) {
|
|
1623
|
+
const { mode, hasNoData, noDataStroke } = options;
|
|
1624
|
+
const colorByKey = /* @__PURE__ */ new Map();
|
|
1625
|
+
const entries = [];
|
|
1626
|
+
const noDataEntry = { kind: "no-data", id: "no-data", color: noDataStroke };
|
|
1627
|
+
if (scale.kind === "categorical") {
|
|
1628
|
+
const colorOf = /* @__PURE__ */ new Map();
|
|
1629
|
+
const byValue = /* @__PURE__ */ new Map();
|
|
1630
|
+
for (const [i, category] of scale.categories.entries()) {
|
|
1631
|
+
byValue.set(category.value, category);
|
|
1632
|
+
colorOf.set(category.value, categoryColor(category, i, mode));
|
|
1633
|
+
}
|
|
1634
|
+
warnCategoryCount(scale.categories);
|
|
1635
|
+
const present = /* @__PURE__ */ new Set();
|
|
1636
|
+
for (const datum of data) {
|
|
1637
|
+
if (!("category" in datum)) continue;
|
|
1638
|
+
const category = byValue.get(datum.category);
|
|
1639
|
+
if (!category) continue;
|
|
1640
|
+
present.add(category.value);
|
|
1641
|
+
colorByKey.set(datum.key, colorOf.get(category.value));
|
|
1642
|
+
}
|
|
1643
|
+
for (const category of scale.categories) {
|
|
1644
|
+
if (!present.has(category.value)) continue;
|
|
1645
|
+
entries.push({ kind: "category", id: `cat-${category.value}`, color: colorOf.get(category.value), label: category.label });
|
|
1646
|
+
}
|
|
1647
|
+
if (hasNoData) entries.push(noDataEntry);
|
|
1648
|
+
return { colorByKey, entries };
|
|
1649
|
+
}
|
|
1650
|
+
const values = [];
|
|
1651
|
+
for (const datum of data) if ("value" in datum) values.push(datum.value);
|
|
1652
|
+
const colors = scale.kind === "diverging" ? divergingColors(scale.ramp, mode) : rampColors(scale.kind === "steps" || scale.kind === "sequential" ? scale.ramp : void 0, mode);
|
|
1653
|
+
const bins = scale.kind === "diverging" ? divergingBins(values, scale.center ?? 0, colors.length) : computeBins(values, scale.kind === "steps" ? scale.edges : scale.bins, colors.length);
|
|
1654
|
+
for (const datum of data) {
|
|
1655
|
+
if (!("value" in datum)) continue;
|
|
1656
|
+
const index = binOf(bins.bins, datum.value) ?? 0;
|
|
1657
|
+
const color = scaleColor(colors, index, bins.bins.length);
|
|
1658
|
+
if (color) colorByKey.set(datum.key, color);
|
|
1659
|
+
}
|
|
1660
|
+
for (const [i, bin] of bins.bins.entries()) {
|
|
1661
|
+
entries.push({
|
|
1662
|
+
kind: "range",
|
|
1663
|
+
id: `bin-${bin.index}`,
|
|
1664
|
+
color: scaleColor(colors, i, bins.bins.length) ?? colors[0] ?? "transparent",
|
|
1665
|
+
from: bin.min,
|
|
1666
|
+
to: bin.max,
|
|
1667
|
+
last: i === bins.bins.length - 1
|
|
1668
|
+
});
|
|
1669
|
+
}
|
|
1670
|
+
if (hasNoData) entries.push(noDataEntry);
|
|
1671
|
+
return { colorByKey, entries, bins, rateSuffix: "rate" in scale ? scale.rate?.per ?? void 0 : void 0 };
|
|
1672
|
+
}
|
|
1673
|
+
function buildFillExpression(colorByKey, joinProperty) {
|
|
1674
|
+
const byColor = /* @__PURE__ */ new Map();
|
|
1675
|
+
for (const [key, color] of colorByKey) {
|
|
1676
|
+
const keys = byColor.get(color);
|
|
1677
|
+
if (keys) keys.push(key);
|
|
1678
|
+
else byColor.set(color, [key]);
|
|
1679
|
+
}
|
|
1680
|
+
if (byColor.size === 0) return "transparent";
|
|
1681
|
+
const expression = ["match", ["get", joinProperty]];
|
|
1682
|
+
for (const [color, keys] of byColor) expression.push(keys, color);
|
|
1683
|
+
expression.push("transparent");
|
|
1684
|
+
return expression;
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1687
|
+
// src/components/data-map/paint.ts
|
|
1688
|
+
var builtData = /* @__PURE__ */ new WeakMap();
|
|
1689
|
+
function cachedData(projection, build) {
|
|
1690
|
+
let data = builtData.get(projection);
|
|
1691
|
+
if (!data) {
|
|
1692
|
+
data = build();
|
|
1693
|
+
builtData.set(projection, data);
|
|
1694
|
+
}
|
|
1695
|
+
return data;
|
|
1696
|
+
}
|
|
1697
|
+
var sourceIdFor = (layerId2) => `jz-data-${layerId2}`;
|
|
1698
|
+
var layerId = (id, part) => `jz-data-${id}-${part}`;
|
|
1699
|
+
function clusterSteps(total) {
|
|
1700
|
+
return [Math.max(10, Math.round(total * 2e-3)), Math.max(50, Math.round(total * 0.02))];
|
|
1701
|
+
}
|
|
1702
|
+
var CLUSTER_RADII = [18, 22, 28];
|
|
1703
|
+
var CLUSTER_KEYLINE = 3;
|
|
1704
|
+
var HEAT_RADIUS = {
|
|
1705
|
+
tight: [3, 10, 24],
|
|
1706
|
+
medium: [5, 18, 40],
|
|
1707
|
+
wide: [8, 30, 64]
|
|
1708
|
+
};
|
|
1709
|
+
var HEAT_RADIUS_ZOOMS = [4, 10, 15];
|
|
1710
|
+
function dominantTone(points) {
|
|
1711
|
+
const counts = /* @__PURE__ */ new Map();
|
|
1712
|
+
for (const point of points) counts.set(point.tone, (counts.get(point.tone) ?? 0) + 1);
|
|
1713
|
+
let best = "brand";
|
|
1714
|
+
let most = 0;
|
|
1715
|
+
for (const [tone, count] of counts) {
|
|
1716
|
+
if (count <= most) continue;
|
|
1717
|
+
most = count;
|
|
1718
|
+
best = tone;
|
|
1719
|
+
}
|
|
1720
|
+
return best;
|
|
1721
|
+
}
|
|
1722
|
+
var LINE_WIDTH = { hairline: 1, sm: 2, md: 3, lg: 5 };
|
|
1723
|
+
var SIZE_RANGE = { sm: [3, 9], md: [4, 16], lg: [5, 26] };
|
|
1724
|
+
var opacityOf = (opacity) => MAP_OPACITY[opacity];
|
|
1725
|
+
var LINE_DASH = {
|
|
1726
|
+
line: void 0,
|
|
1727
|
+
dot: [0.1, 2],
|
|
1728
|
+
dashed: [2, 1.5]
|
|
1729
|
+
};
|
|
1730
|
+
var ISOLATED_OPACITY = 0.15;
|
|
1731
|
+
function fillOpacity(base, isolate) {
|
|
1732
|
+
if (!isolate) return base;
|
|
1733
|
+
return ["case", ["==", ["feature-state", "selected"], true], base, base * ISOLATED_OPACITY];
|
|
1734
|
+
}
|
|
1735
|
+
function planChoropleth(projection, mode, outline, labelFeatures, isolate) {
|
|
1736
|
+
const c = MAP_STYLE_COLORS[mode];
|
|
1737
|
+
const id = projection.id;
|
|
1738
|
+
const source = sourceIdFor(id);
|
|
1739
|
+
const fillColor = buildFillExpression(projection.scale?.colorByKey ?? /* @__PURE__ */ new Map(), projection.joinProperty);
|
|
1740
|
+
const outlineWidth = { none: 0, hairline: 0.75, strong: 1.5 };
|
|
1741
|
+
const layers = [
|
|
1742
|
+
{
|
|
1743
|
+
id: layerId(id, "fill"),
|
|
1744
|
+
type: "fill",
|
|
1745
|
+
source,
|
|
1746
|
+
paint: { "fill-color": fillColor, "fill-opacity": fillOpacity(opacityOf(projection.opacity) * 0.9, isolate) }
|
|
1747
|
+
},
|
|
1748
|
+
{
|
|
1749
|
+
id: layerId(id, "edge"),
|
|
1750
|
+
type: "line",
|
|
1751
|
+
source,
|
|
1752
|
+
// The caller's own step. It used to be pinned to `hairline` whatever they asked for, so
|
|
1753
|
+
// `outline: "strong"` was a value the type accepted and the painter dropped — a tessellation of
|
|
1754
|
+
// districts where every edge is meant to read got the same 0.75px as a world map.
|
|
1755
|
+
paint: { "line-color": c.dataStroke, "line-width": outlineWidth[outline] }
|
|
1756
|
+
},
|
|
1757
|
+
{
|
|
1758
|
+
/* `no data` is an OUTLINE because there is no fill — the basemap shows through, which is
|
|
1759
|
+
* semantically exact. A grey fill was measured at 1.014 against the palest class, i.e. nothing;
|
|
1760
|
+
* the dashed emphatic edge measures 2.40. The distinction is categorical, not tonal. */
|
|
1761
|
+
id: layerId(id, "nodata"),
|
|
1762
|
+
type: "line",
|
|
1763
|
+
source,
|
|
1764
|
+
paint: {
|
|
1765
|
+
"line-color": c.dataNoDataStroke,
|
|
1766
|
+
"line-width": 1,
|
|
1767
|
+
"line-dasharray": [2, 2],
|
|
1768
|
+
"line-opacity": ["case", ["==", ["feature-state", "nodata"], true], 1, 0]
|
|
1769
|
+
}
|
|
1770
|
+
},
|
|
1771
|
+
{
|
|
1772
|
+
/* Hover and selection are an EDGE, never a fill change: changing the fill would move the
|
|
1773
|
+
* polygon to a different apparent BIN, which is the one thing a choropleth must never do on a
|
|
1774
|
+
* pointer move. */
|
|
1775
|
+
id: layerId(id, "state"),
|
|
1776
|
+
type: "line",
|
|
1777
|
+
source,
|
|
1778
|
+
paint: {
|
|
1779
|
+
"line-color": ["case", ["==", ["feature-state", "selected"], true], c.dataSelectedStroke, c.dataHoverStroke],
|
|
1780
|
+
"line-width": ["case", ["==", ["feature-state", "selected"], true], 2.5, ["==", ["feature-state", "hover"], true], 2, 0],
|
|
1781
|
+
"line-opacity": ["case", ["any", ["==", ["feature-state", "selected"], true], ["==", ["feature-state", "hover"], true]], 1, 0]
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
];
|
|
1785
|
+
const labelled = labelFeatures !== "none" && projection.features !== void 0 && projection.nameByKey.size > 0;
|
|
1786
|
+
if (labelled) {
|
|
1787
|
+
layers.push({
|
|
1788
|
+
id: layerId(id, "label"),
|
|
1789
|
+
type: "symbol",
|
|
1790
|
+
source,
|
|
1791
|
+
...labelFeatures === "top" && { filter: ["==", ["get", "jz:top"], true] },
|
|
1792
|
+
layout: {
|
|
1793
|
+
"text-field": ["get", "jz:name"],
|
|
1794
|
+
"text-font": [FONT.regular],
|
|
1795
|
+
"text-size": ["interpolate", ["linear"], ["zoom"], 4, 10, 9, 12],
|
|
1796
|
+
// A region label has nowhere else to go — it either fits inside its polygon or it is dropped,
|
|
1797
|
+
// and dropping is correct: a name floating over a neighbour is worse than no name.
|
|
1798
|
+
"text-allow-overlap": false,
|
|
1799
|
+
"text-optional": true
|
|
1800
|
+
},
|
|
1801
|
+
paint: {
|
|
1802
|
+
"text-color": c.labelRegion,
|
|
1803
|
+
"text-halo-color": c.labelHalo,
|
|
1804
|
+
"text-halo-width": 1.25,
|
|
1805
|
+
"text-halo-blur": 0.5
|
|
1806
|
+
}
|
|
1807
|
+
});
|
|
1808
|
+
}
|
|
1809
|
+
return {
|
|
1810
|
+
sourceId: source,
|
|
1811
|
+
source: {
|
|
1812
|
+
type: "geojson",
|
|
1813
|
+
// The caller's collection UNCHANGED unless labels were asked for — a copy costs the reference
|
|
1814
|
+
// identity `use-map-paint.ts` compares on, which is why it is built only when it is used (and
|
|
1815
|
+
// memoised on the projection when it is).
|
|
1816
|
+
data: labelled ? cachedData(projection, () => stampLabels(projection)) : projection.features ?? EMPTY_COLLECTION,
|
|
1817
|
+
promoteId: projection.joinProperty
|
|
1818
|
+
},
|
|
1819
|
+
layers,
|
|
1820
|
+
interactiveLayerIds: [layerId(id, "fill")]
|
|
1821
|
+
};
|
|
1822
|
+
}
|
|
1823
|
+
function stampLabels(projection) {
|
|
1824
|
+
const features = projection.features?.features ?? [];
|
|
1825
|
+
const entries = projection.scale?.entries ?? [];
|
|
1826
|
+
const topColor = entries.at(-1)?.color;
|
|
1827
|
+
const colorByKey = projection.scale?.colorByKey;
|
|
1828
|
+
return {
|
|
1829
|
+
type: "FeatureCollection",
|
|
1830
|
+
features: features.map((feature) => {
|
|
1831
|
+
const key = String(feature.properties?.[projection.joinProperty] ?? "");
|
|
1832
|
+
return {
|
|
1833
|
+
...feature,
|
|
1834
|
+
properties: {
|
|
1835
|
+
...feature.properties,
|
|
1836
|
+
"jz:name": projection.nameByKey.get(key) ?? "",
|
|
1837
|
+
"jz:top": topColor !== void 0 && colorByKey?.get(key) === topColor
|
|
1838
|
+
}
|
|
1839
|
+
};
|
|
1840
|
+
})
|
|
1841
|
+
};
|
|
1842
|
+
}
|
|
1843
|
+
function planAreas(projection, mode, fill, outline, isolate) {
|
|
1844
|
+
const id = projection.id;
|
|
1845
|
+
const source = sourceIdFor(id);
|
|
1846
|
+
const data = cachedData(projection, () => ({
|
|
1847
|
+
type: "FeatureCollection",
|
|
1848
|
+
// The tone is stamped into a private property rather than expressed as a per-feature `match`:
|
|
1849
|
+
// an isochrone collection can be thousands of features and a match arm per feature is an
|
|
1850
|
+
// expression MapLibre re-parses on every repaint.
|
|
1851
|
+
features: projection.features.features.map((feature, index) => ({
|
|
1852
|
+
...feature,
|
|
1853
|
+
properties: { ...feature.properties, "jz:tone": projection.toneByIndex[index] ?? "brand", "jz:name": projection.names[index] ?? "" }
|
|
1854
|
+
}))
|
|
1855
|
+
}));
|
|
1856
|
+
const toneMatch = (step) => {
|
|
1857
|
+
const expression = ["match", ["get", "jz:tone"]];
|
|
1858
|
+
for (const tone of ["neutral", "brand", "success", "warning", "error", "info"]) {
|
|
1859
|
+
expression.push(tone, step === "wash" ? toneWash(tone, mode) : step === "stroke" ? toneStroke(tone, mode) : toneFill(tone, mode));
|
|
1860
|
+
}
|
|
1861
|
+
expression.push(step === "wash" ? toneWash("brand", mode) : step === "stroke" ? toneStroke("brand", mode) : toneFill("brand", mode));
|
|
1862
|
+
return expression;
|
|
1863
|
+
};
|
|
1864
|
+
const layers = [];
|
|
1865
|
+
if (fill !== "none") {
|
|
1866
|
+
layers.push({
|
|
1867
|
+
id: layerId(id, "fill"),
|
|
1868
|
+
type: "fill",
|
|
1869
|
+
source,
|
|
1870
|
+
paint: {
|
|
1871
|
+
"fill-color": toneMatch(fill === "wash" ? "wash" : "fill"),
|
|
1872
|
+
// A wash is a layer you look THROUGH — it is usually on top of something. A solid is not.
|
|
1873
|
+
"fill-opacity": fillOpacity(opacityOf(projection.opacity) * (fill === "wash" ? 0.55 : 0.85), isolate)
|
|
1874
|
+
}
|
|
1875
|
+
});
|
|
1876
|
+
}
|
|
1877
|
+
if (outline !== "none") {
|
|
1878
|
+
layers.push({
|
|
1879
|
+
id: layerId(id, "edge"),
|
|
1880
|
+
type: "line",
|
|
1881
|
+
source,
|
|
1882
|
+
paint: { "line-color": toneMatch("stroke"), "line-width": outline === "strong" ? 2 : 1, "line-opacity": opacityOf(projection.opacity) }
|
|
1883
|
+
});
|
|
1884
|
+
}
|
|
1885
|
+
return { sourceId: source, source: { type: "geojson", data }, layers, interactiveLayerIds: layers.map((l) => String(l.id)) };
|
|
1886
|
+
}
|
|
1887
|
+
function planHeatmap(projection, mode, radius) {
|
|
1888
|
+
const id = projection.id;
|
|
1889
|
+
const source = sourceIdFor(id);
|
|
1890
|
+
const ramp = projection.ramp ?? MAP_HEAT_SCALE[mode];
|
|
1891
|
+
if (projection.ramp) for (const [i, stop] of projection.ramp.entries()) warnEngineColor(`heatmap ramp[${i}]`, stop);
|
|
1892
|
+
const color = ["interpolate", ["linear"], ["heatmap-density"], 0, "rgba(0,0,0,0)"];
|
|
1893
|
+
for (const [i, stop] of ramp.entries()) color.push((i + 1) / ramp.length, stop);
|
|
1894
|
+
return {
|
|
1895
|
+
sourceId: source,
|
|
1896
|
+
source: {
|
|
1897
|
+
type: "geojson",
|
|
1898
|
+
data: cachedData(projection, () => ({
|
|
1899
|
+
type: "FeatureCollection",
|
|
1900
|
+
features: projection.weights.map((w) => ({
|
|
1901
|
+
type: "Feature",
|
|
1902
|
+
geometry: { type: "Point", coordinates: [w.position[0], w.position[1]] },
|
|
1903
|
+
properties: { w: w.weight }
|
|
1904
|
+
}))
|
|
1905
|
+
}))
|
|
1906
|
+
},
|
|
1907
|
+
layers: [
|
|
1908
|
+
{
|
|
1909
|
+
id: layerId(id, "heat"),
|
|
1910
|
+
type: "heatmap",
|
|
1911
|
+
source,
|
|
1912
|
+
paint: {
|
|
1913
|
+
// The weights arrive NORMALISED to 0..1 (`projection.ts`), which is the domain this
|
|
1914
|
+
// interpolation reads — an un-normalised count would clamp every point to the top.
|
|
1915
|
+
"heatmap-weight": ["interpolate", ["linear"], ["get", "w"], 0, 0, 1, 1],
|
|
1916
|
+
/* Intensity rises with zoom, or a cluster that reads as hot at z5 washes out at z12 — but
|
|
1917
|
+
* it must START BELOW 1. At intensity 1 a continental frame is already saturated wherever
|
|
1918
|
+
* two points overlap, and the ramp's five stops collapse to its last one. */
|
|
1919
|
+
/* Intensity rises with zoom, and it starts LOW. `heatmap-density` is a sum over every point
|
|
1920
|
+
* inside the kernel, so a thousand points in one city at continental zoom saturate whatever
|
|
1921
|
+
* the weights are — the ramp's five stops collapse to its last one and the surface stops
|
|
1922
|
+
* encoding anything. Starting at 0.15 keeps interior structure visible where a surface is
|
|
1923
|
+
* legible at all; below that a genuinely sparse dataset would vanish. */
|
|
1924
|
+
"heatmap-intensity": ["interpolate", ["linear"], ["zoom"], 0, 0.15, 8, 0.8, 14, 2.2],
|
|
1925
|
+
"heatmap-color": color,
|
|
1926
|
+
"heatmap-radius": ["interpolate", ["linear"], ["zoom"], ...HEAT_RADIUS_ZOOMS.flatMap((zoom, i) => [zoom, HEAT_RADIUS[radius][i]])],
|
|
1927
|
+
"heatmap-opacity": opacityOf(projection.opacity)
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
],
|
|
1931
|
+
// A density surface has no features, so there is nothing for a click to be ABOUT.
|
|
1932
|
+
interactiveLayerIds: []
|
|
1933
|
+
};
|
|
1934
|
+
}
|
|
1935
|
+
function planLines(projection, mode, texture, arrows) {
|
|
1936
|
+
const c = MAP_STYLE_COLORS[mode];
|
|
1937
|
+
const id = projection.id;
|
|
1938
|
+
const source = sourceIdFor(id);
|
|
1939
|
+
const width = LINE_WIDTH[projection.weight];
|
|
1940
|
+
const dash = LINE_DASH[texture];
|
|
1941
|
+
const toneMatch = ["match", ["get", "jz:tone"]];
|
|
1942
|
+
for (const tone of ["neutral", "brand", "success", "warning", "error", "info"]) toneMatch.push(tone, toneFill(tone, mode));
|
|
1943
|
+
toneMatch.push(toneFill("brand", mode));
|
|
1944
|
+
const layers = [
|
|
1945
|
+
{
|
|
1946
|
+
/* The casing. A route is drawn over an unknown ground — a pale field, a dark forest, another
|
|
1947
|
+
* route — so one stroke has no guaranteed separation from what is beneath it. Same mechanism as
|
|
1948
|
+
* a label's halo, and the same role. */
|
|
1949
|
+
id: layerId(id, "casing"),
|
|
1950
|
+
type: "line",
|
|
1951
|
+
source,
|
|
1952
|
+
layout: { "line-cap": "round", "line-join": "round" },
|
|
1953
|
+
paint: { "line-color": c.lineCasing, "line-width": width + 2, "line-opacity": opacityOf(projection.opacity) }
|
|
1954
|
+
},
|
|
1955
|
+
{
|
|
1956
|
+
id: layerId(id, "line"),
|
|
1957
|
+
type: "line",
|
|
1958
|
+
source,
|
|
1959
|
+
layout: { "line-cap": dash ? "butt" : "round", "line-join": "round" },
|
|
1960
|
+
paint: {
|
|
1961
|
+
"line-color": toneMatch,
|
|
1962
|
+
"line-width": width,
|
|
1963
|
+
"line-opacity": opacityOf(projection.opacity),
|
|
1964
|
+
...dash && { "line-dasharray": dash }
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
];
|
|
1968
|
+
if (arrows === "forward") {
|
|
1969
|
+
layers.push({
|
|
1970
|
+
/* Direction, as repeated glyphs along the line. `symbol-placement: "line"` is the only honest
|
|
1971
|
+
* way to say "this route has a direction" without a second geometry — an arrowhead at the end
|
|
1972
|
+
* says nothing about a route that loops. */
|
|
1973
|
+
id: layerId(id, "arrows"),
|
|
1974
|
+
type: "symbol",
|
|
1975
|
+
source,
|
|
1976
|
+
layout: {
|
|
1977
|
+
"symbol-placement": "line",
|
|
1978
|
+
"symbol-spacing": 90,
|
|
1979
|
+
"text-field": "\u25B8",
|
|
1980
|
+
"text-font": ["Noto Sans Regular"],
|
|
1981
|
+
"text-size": 12 + width,
|
|
1982
|
+
"text-keep-upright": false,
|
|
1983
|
+
"text-allow-overlap": true
|
|
1984
|
+
},
|
|
1985
|
+
paint: { "text-color": toneMatch, "text-halo-color": c.lineCasing, "text-halo-width": 1 }
|
|
1986
|
+
});
|
|
1987
|
+
}
|
|
1988
|
+
return {
|
|
1989
|
+
sourceId: source,
|
|
1990
|
+
source: {
|
|
1991
|
+
type: "geojson",
|
|
1992
|
+
data: cachedData(projection, () => ({
|
|
1993
|
+
type: "FeatureCollection",
|
|
1994
|
+
features: projection.lines.map((line) => ({
|
|
1995
|
+
type: "Feature",
|
|
1996
|
+
id: line.key,
|
|
1997
|
+
geometry: { type: "LineString", coordinates: line.path.map((p) => [p[0], p[1]]) },
|
|
1998
|
+
properties: { "jz:tone": line.tone, "jz:key": line.key, "jz:name": line.name ?? "" }
|
|
1999
|
+
}))
|
|
2000
|
+
})),
|
|
2001
|
+
promoteId: "jz:key"
|
|
2002
|
+
},
|
|
2003
|
+
layers,
|
|
2004
|
+
interactiveLayerIds: [layerId(id, "line")]
|
|
2005
|
+
};
|
|
2006
|
+
}
|
|
2007
|
+
function planPointsGl(projection, mode, cluster, isolate) {
|
|
2008
|
+
const c = MAP_STYLE_COLORS[mode];
|
|
2009
|
+
const id = projection.id;
|
|
2010
|
+
const source = sourceIdFor(id);
|
|
2011
|
+
const toneMatch = ["match", ["get", "jz:tone"]];
|
|
2012
|
+
for (const tone of ["neutral", "brand", "success", "warning", "error", "info"]) toneMatch.push(tone, toneFill(tone, mode));
|
|
2013
|
+
toneMatch.push(toneFill("brand", mode));
|
|
2014
|
+
const clusterFill = MAP_CLUSTER_FILLS[mode][dominantTone(projection.points)];
|
|
2015
|
+
const steps = clusterSteps(projection.points.length);
|
|
2016
|
+
const [minRadius, maxRadius] = SIZE_RANGE[projection.sizeRange];
|
|
2017
|
+
const radius = projection.magnitudeRange ? (
|
|
2018
|
+
// Interpolated on the SQUARE ROOT of the value, not the value: a circle's area is what the eye
|
|
2019
|
+
// reads as quantity, and a linear radius makes a value twice as large look four times as big.
|
|
2020
|
+
[
|
|
2021
|
+
"interpolate",
|
|
2022
|
+
["linear"],
|
|
2023
|
+
["sqrt", ["get", "jz:magnitude"]],
|
|
2024
|
+
Math.sqrt(projection.magnitudeRange[0]),
|
|
2025
|
+
minRadius,
|
|
2026
|
+
Math.sqrt(projection.magnitudeRange[1]),
|
|
2027
|
+
maxRadius
|
|
2028
|
+
]
|
|
2029
|
+
) : minRadius + 2;
|
|
2030
|
+
const layers = [];
|
|
2031
|
+
if (cluster) {
|
|
2032
|
+
const band = (values, fallback) => cluster.sizeBy === "none" ? fallback : ["step", ["get", "point_count"], values[0], steps[0], values[1], steps[1], values[2]];
|
|
2033
|
+
layers.push(
|
|
2034
|
+
{
|
|
2035
|
+
/* The KEYLINE — a disc one pixel wider than the bubble PLUS its casing, in the strong edge
|
|
2036
|
+
* role, so a hairline shows outside the white ring.
|
|
2037
|
+
*
|
|
2038
|
+
* A 2px white casing separates a bubble from a pale ground and disappears against a white
|
|
2039
|
+
* one, which is every light-theme basemap we ship. This used to be a translucent disc of the
|
|
2040
|
+
* band's own colour — a "tone-carrying" second separation — and that reasoning expired when
|
|
2041
|
+
* `CLUSTER_BAND_STOPS` became a neutral chrome ladder: there is no tone to carry, and at 25%
|
|
2042
|
+
* opacity band 0 (`#f5f5f5`) glowed white on white. `clusterEdge` is the same `border-strong`
|
|
2043
|
+
* the DOM bubble wears as `BUBBLE_EDGE`, so both renderers bound the mark with one token, and
|
|
2044
|
+
* `gen-map-style.mjs` holds it to `CLUSTER_EDGE_MIN` against the page in both modes. */
|
|
2045
|
+
id: layerId(id, "cluster-halo"),
|
|
2046
|
+
type: "circle",
|
|
2047
|
+
source,
|
|
2048
|
+
filter: ["has", "point_count"],
|
|
2049
|
+
paint: {
|
|
2050
|
+
"circle-color": c.clusterEdge,
|
|
2051
|
+
"circle-radius": cluster.sizeBy === "none" ? CLUSTER_RADII[1] + CLUSTER_KEYLINE : [
|
|
2052
|
+
"step",
|
|
2053
|
+
["get", "point_count"],
|
|
2054
|
+
CLUSTER_RADII[0] + CLUSTER_KEYLINE,
|
|
2055
|
+
steps[0],
|
|
2056
|
+
CLUSTER_RADII[1] + CLUSTER_KEYLINE,
|
|
2057
|
+
steps[1],
|
|
2058
|
+
CLUSTER_RADII[2] + CLUSTER_KEYLINE
|
|
2059
|
+
],
|
|
2060
|
+
"circle-opacity": opacityOf(projection.opacity)
|
|
2061
|
+
}
|
|
2062
|
+
},
|
|
2063
|
+
{
|
|
2064
|
+
id: layerId(id, "cluster"),
|
|
2065
|
+
type: "circle",
|
|
2066
|
+
source,
|
|
2067
|
+
filter: ["has", "point_count"],
|
|
2068
|
+
paint: {
|
|
2069
|
+
"circle-color": clusterFill.fill,
|
|
2070
|
+
"circle-radius": band(CLUSTER_RADII, CLUSTER_RADII[1]),
|
|
2071
|
+
// The casing is what makes a bubble read as ON the map rather than IN it, on any ground.
|
|
2072
|
+
"circle-stroke-color": c.pointCasing,
|
|
2073
|
+
"circle-stroke-width": 2,
|
|
2074
|
+
"circle-opacity": opacityOf(projection.opacity)
|
|
2075
|
+
}
|
|
2076
|
+
},
|
|
2077
|
+
{
|
|
2078
|
+
id: layerId(id, "cluster-count"),
|
|
2079
|
+
type: "symbol",
|
|
2080
|
+
source,
|
|
2081
|
+
filter: ["has", "point_count"],
|
|
2082
|
+
layout: { "text-field": ["get", "point_count_abbreviated"], "text-font": ["Noto Sans Bold"], "text-size": 12, "text-allow-overlap": true },
|
|
2083
|
+
paint: { "text-color": clusterFill.text }
|
|
2084
|
+
}
|
|
2085
|
+
);
|
|
2086
|
+
}
|
|
2087
|
+
layers.push({
|
|
2088
|
+
id: layerId(id, "point"),
|
|
2089
|
+
type: "circle",
|
|
2090
|
+
source,
|
|
2091
|
+
...cluster && { filter: ["!", ["has", "point_count"]] },
|
|
2092
|
+
paint: {
|
|
2093
|
+
"circle-color": toneMatch,
|
|
2094
|
+
"circle-radius": radius,
|
|
2095
|
+
"circle-stroke-color": c.pointCasing,
|
|
2096
|
+
// R6: a white casing is what separates ONE from MANY without reading a number.
|
|
2097
|
+
"circle-stroke-width": 1.5,
|
|
2098
|
+
"circle-opacity": fillOpacity(opacityOf(projection.opacity), isolate)
|
|
2099
|
+
}
|
|
2100
|
+
});
|
|
2101
|
+
return {
|
|
2102
|
+
sourceId: source,
|
|
2103
|
+
source: {
|
|
2104
|
+
type: "geojson",
|
|
2105
|
+
data: cachedData(projection, () => ({
|
|
2106
|
+
type: "FeatureCollection",
|
|
2107
|
+
features: projection.points.map((point) => ({
|
|
2108
|
+
type: "Feature",
|
|
2109
|
+
id: point.key,
|
|
2110
|
+
geometry: { type: "Point", coordinates: [point.position[0], point.position[1]] },
|
|
2111
|
+
properties: { "jz:key": point.key, "jz:tone": point.tone, "jz:name": point.name ?? "", "jz:magnitude": point.magnitude ?? 0 }
|
|
2112
|
+
}))
|
|
2113
|
+
})),
|
|
2114
|
+
promoteId: "jz:key",
|
|
2115
|
+
/* NATIVE source clustering — supercluster inside MapLibre's own worker. No dependency, no
|
|
2116
|
+
* main-thread cost, and it is what gives `getClusterExpansionZoom` a true answer: guessing
|
|
2117
|
+
* `zoom + 2` is what makes a cluster expansion land on another cluster. */
|
|
2118
|
+
...cluster && { cluster: true, clusterRadius: cluster.radius, clusterMaxZoom: cluster.maxZoom }
|
|
2119
|
+
},
|
|
2120
|
+
layers,
|
|
2121
|
+
interactiveLayerIds: layers.map((l) => String(l.id)).filter((l) => !l.endsWith("cluster-count"))
|
|
2122
|
+
};
|
|
2123
|
+
}
|
|
2124
|
+
function planRaster(projection, source) {
|
|
2125
|
+
const id = projection.id;
|
|
2126
|
+
const sourceId = sourceIdFor(id);
|
|
2127
|
+
const spec = source.kind === "image" ? {
|
|
2128
|
+
type: "image",
|
|
2129
|
+
url: source.url,
|
|
2130
|
+
// MapLibre's `ImageSource` takes the four corners CLOCKWISE FROM TOP-LEFT, and a
|
|
2131
|
+
// mis-ordered pair renders a mirrored image with no error anywhere — which is why the
|
|
2132
|
+
// public type names them instead of taking an array.
|
|
2133
|
+
coordinates: [
|
|
2134
|
+
[source.corners.topLeft[0], source.corners.topLeft[1]],
|
|
2135
|
+
[source.corners.topRight[0], source.corners.topRight[1]],
|
|
2136
|
+
[source.corners.bottomRight[0], source.corners.bottomRight[1]],
|
|
2137
|
+
[source.corners.bottomLeft[0], source.corners.bottomLeft[1]]
|
|
2138
|
+
]
|
|
2139
|
+
} : source.kind === "tilejson" ? { type: "raster", url: source.url, tileSize: 256 } : { type: "raster", tiles: [...source.tiles], tileSize: 256, minzoom: source.minzoom, maxzoom: source.maxzoom };
|
|
2140
|
+
return {
|
|
2141
|
+
sourceId,
|
|
2142
|
+
source: spec,
|
|
2143
|
+
layers: [{ id: layerId(id, "raster"), type: "raster", source: sourceId, paint: { "raster-opacity": opacityOf(projection.opacity) } }],
|
|
2144
|
+
interactiveLayerIds: []
|
|
2145
|
+
};
|
|
2146
|
+
}
|
|
2147
|
+
var EMPTY_COLLECTION = { type: "FeatureCollection", features: [] };
|
|
2148
|
+
function planLayer(projection, spec, mode, domPoints, isolate = false) {
|
|
2149
|
+
switch (projection.kind) {
|
|
2150
|
+
case "choropleth": {
|
|
2151
|
+
return planChoropleth(
|
|
2152
|
+
projection,
|
|
2153
|
+
mode,
|
|
2154
|
+
spec.outline ?? "hairline",
|
|
2155
|
+
spec.labelFeatures ?? "none",
|
|
2156
|
+
isolate
|
|
2157
|
+
);
|
|
2158
|
+
}
|
|
2159
|
+
case "areas": {
|
|
2160
|
+
return planAreas(
|
|
2161
|
+
projection,
|
|
2162
|
+
mode,
|
|
2163
|
+
spec.fill ?? "wash",
|
|
2164
|
+
spec.outline ?? "hairline",
|
|
2165
|
+
isolate
|
|
2166
|
+
);
|
|
2167
|
+
}
|
|
2168
|
+
case "heatmap": {
|
|
2169
|
+
return planHeatmap(projection, mode, spec.radius ?? "medium");
|
|
2170
|
+
}
|
|
2171
|
+
case "lines": {
|
|
2172
|
+
return planLines(
|
|
2173
|
+
projection,
|
|
2174
|
+
mode,
|
|
2175
|
+
spec.texture ?? "line",
|
|
2176
|
+
spec.arrows ?? "none"
|
|
2177
|
+
);
|
|
2178
|
+
}
|
|
2179
|
+
case "points": {
|
|
2180
|
+
if (domPoints) return void 0;
|
|
2181
|
+
const cluster = spec.cluster;
|
|
2182
|
+
return planPointsGl(
|
|
2183
|
+
projection,
|
|
2184
|
+
mode,
|
|
2185
|
+
cluster === false || cluster === void 0 ? void 0 : { radius: cluster.radius ?? 48, maxZoom: cluster.maxZoom ?? 14, sizeBy: cluster.sizeBy ?? "count" },
|
|
2186
|
+
isolate
|
|
2187
|
+
);
|
|
2188
|
+
}
|
|
2189
|
+
case "raster": {
|
|
2190
|
+
return planRaster(projection, spec.source);
|
|
2191
|
+
}
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
function DomMarkerLayer(props) {
|
|
2195
|
+
const {
|
|
2196
|
+
instance,
|
|
2197
|
+
ready,
|
|
2198
|
+
layerId: layerId2,
|
|
2199
|
+
points,
|
|
2200
|
+
shape,
|
|
2201
|
+
magnitudeRange,
|
|
2202
|
+
cluster,
|
|
2203
|
+
cameraTick,
|
|
2204
|
+
zoom,
|
|
2205
|
+
selectedKeys,
|
|
2206
|
+
renderMarker,
|
|
2207
|
+
clusterLabel,
|
|
2208
|
+
formatCount,
|
|
2209
|
+
onPick,
|
|
2210
|
+
onExpand,
|
|
2211
|
+
markerTitle,
|
|
2212
|
+
coincident
|
|
2213
|
+
} = props;
|
|
2214
|
+
const handlesRef = useRef(/* @__PURE__ */ new Map());
|
|
2215
|
+
const [mounted, setMounted] = useState([]);
|
|
2216
|
+
const signature = `${zoom.toFixed(3)}|${cluster === false ? "none" : `${cluster.radius}:${cluster.maxZoom}`}|${points.map((point) => `${point.key}:${point.position[0]}:${point.position[1]}:${point.tone}:${point.magnitude ?? ""}`).join(",")}`;
|
|
2217
|
+
const [fanned, setFanned] = useState(null);
|
|
2218
|
+
useEffect(() => setFanned(null), [cameraTick, signature]);
|
|
2219
|
+
const place = useCallback(() => {
|
|
2220
|
+
if (!instance) return [];
|
|
2221
|
+
const placed = points.map((point) => {
|
|
2222
|
+
const screen = projectPoint(instance, point.position);
|
|
2223
|
+
return { ...point, id: point.key, x: screen.x, y: screen.y };
|
|
2224
|
+
});
|
|
2225
|
+
if (cluster === false) return placed.map((point) => ({ id: point.id, x: point.x, y: point.y, members: [point] }));
|
|
2226
|
+
return clusterPoints(placed, zoom, { radius: cluster.radius, maxZoom: cluster.maxZoom });
|
|
2227
|
+
}, [instance, points, cluster, zoom]);
|
|
2228
|
+
useEffect(() => {
|
|
2229
|
+
if (!instance || !ready) return;
|
|
2230
|
+
let cancelled = false;
|
|
2231
|
+
const clusters = place();
|
|
2232
|
+
const wanted = new Map(clusters.map((c) => [c.id, c]));
|
|
2233
|
+
const handles = handlesRef.current;
|
|
2234
|
+
for (const [id, handle] of handles) {
|
|
2235
|
+
if (wanted.has(id)) continue;
|
|
2236
|
+
handle.remove();
|
|
2237
|
+
handles.delete(id);
|
|
2238
|
+
}
|
|
2239
|
+
void (async () => {
|
|
2240
|
+
const next = [];
|
|
2241
|
+
for (const entry of clusters) {
|
|
2242
|
+
const existing = handles.get(entry.id);
|
|
2243
|
+
if (existing) {
|
|
2244
|
+
const anchor2 = entry.members[0];
|
|
2245
|
+
if (anchor2) existing.setPosition(entry.members.length === 1 ? anchor2.position : centroid(entry.members));
|
|
2246
|
+
next.push({ id: entry.id, element: existing.element, cluster: entry });
|
|
2247
|
+
continue;
|
|
2248
|
+
}
|
|
2249
|
+
const anchor = entry.members[0];
|
|
2250
|
+
if (!anchor) continue;
|
|
2251
|
+
const position = entry.members.length === 1 ? anchor.position : centroid(entry.members);
|
|
2252
|
+
const handle = await createMarker(instance, position, { anchor: shape === "teardrop" ? "bottom" : "center" });
|
|
2253
|
+
if (cancelled) {
|
|
2254
|
+
handle.remove();
|
|
2255
|
+
return;
|
|
2256
|
+
}
|
|
2257
|
+
handle.element.removeAttribute("title");
|
|
2258
|
+
handles.set(entry.id, handle);
|
|
2259
|
+
next.push({ id: entry.id, element: handle.element, cluster: entry });
|
|
2260
|
+
}
|
|
2261
|
+
if (cancelled) return;
|
|
2262
|
+
setMounted((current) => sameMounted(current, next) ? current : next);
|
|
2263
|
+
})();
|
|
2264
|
+
return () => {
|
|
2265
|
+
cancelled = true;
|
|
2266
|
+
};
|
|
2267
|
+
}, [instance, ready, signature, shape, markerTitle, cameraTick]);
|
|
2268
|
+
useEffect(() => {
|
|
2269
|
+
const handles = handlesRef.current;
|
|
2270
|
+
return () => {
|
|
2271
|
+
for (const handle of handles.values()) handle.remove();
|
|
2272
|
+
handles.clear();
|
|
2273
|
+
};
|
|
2274
|
+
}, [layerId2]);
|
|
2275
|
+
let largest = 1;
|
|
2276
|
+
for (const entry of mounted) largest = Math.max(largest, entry.cluster.members.length);
|
|
2277
|
+
return /* @__PURE__ */ jsx(Fragment, { children: mounted.map((entry) => {
|
|
2278
|
+
const members = entry.cluster.members;
|
|
2279
|
+
const single = members.length === 1 ? members[0] : void 0;
|
|
2280
|
+
return createPortal(
|
|
2281
|
+
single ? /* @__PURE__ */ jsx(
|
|
2282
|
+
"span",
|
|
2283
|
+
{
|
|
2284
|
+
role: "button",
|
|
2285
|
+
tabIndex: 0,
|
|
2286
|
+
"aria-label": single.name,
|
|
2287
|
+
className: "cursor-pointer outline-focus-ring focus-visible:outline-2 focus-visible:outline-offset-2",
|
|
2288
|
+
onClick: (event) => {
|
|
2289
|
+
event.stopPropagation();
|
|
2290
|
+
onPick(single, { x: single.x, y: single.y });
|
|
2291
|
+
},
|
|
2292
|
+
onKeyDown: (event) => {
|
|
2293
|
+
if (event.key !== "Enter" && event.key !== " ") return;
|
|
2294
|
+
event.preventDefault();
|
|
2295
|
+
onPick(single, { x: single.x, y: single.y });
|
|
2296
|
+
},
|
|
2297
|
+
children: renderMarker ? renderMarker(single.row) : /* @__PURE__ */ jsx(
|
|
2298
|
+
MapMarker,
|
|
2299
|
+
{
|
|
2300
|
+
shape,
|
|
2301
|
+
tone: single.tone,
|
|
2302
|
+
name: single.name,
|
|
2303
|
+
scale: normalise(single.magnitude, magnitudeRange),
|
|
2304
|
+
selected: selectedKeys.has(single.key)
|
|
2305
|
+
}
|
|
2306
|
+
)
|
|
2307
|
+
}
|
|
2308
|
+
) : fanned === entry.id ? /* @__PURE__ */ jsx(Fan, { members, shape, magnitudeRange, selectedKeys, renderMarker, onPick }) : /* @__PURE__ */ jsx(
|
|
2309
|
+
ClusterBubble,
|
|
2310
|
+
{
|
|
2311
|
+
count: formatCount(members.length),
|
|
2312
|
+
band: clusterBand(members.length, largest),
|
|
2313
|
+
tone: dominantTone(members),
|
|
2314
|
+
label: clusterLabel(formatCount(members.length)),
|
|
2315
|
+
onClick: () => {
|
|
2316
|
+
if (coincident === "spiderfy" && coLocated(members)) setFanned(entry.id);
|
|
2317
|
+
else onExpand({ x: entry.cluster.x, y: entry.cluster.y, members });
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
),
|
|
2321
|
+
entry.element,
|
|
2322
|
+
entry.id
|
|
2323
|
+
);
|
|
2324
|
+
}) });
|
|
2325
|
+
}
|
|
2326
|
+
function coLocated(members) {
|
|
2327
|
+
const [first] = members;
|
|
2328
|
+
if (!first) return false;
|
|
2329
|
+
return members.every((m) => m.position[0] === first.position[0] && m.position[1] === first.position[1]);
|
|
2330
|
+
}
|
|
2331
|
+
var FAN_RADIUS = 46;
|
|
2332
|
+
function Fan({
|
|
2333
|
+
members,
|
|
2334
|
+
shape,
|
|
2335
|
+
magnitudeRange,
|
|
2336
|
+
selectedKeys,
|
|
2337
|
+
renderMarker,
|
|
2338
|
+
onPick
|
|
2339
|
+
}) {
|
|
2340
|
+
const at = (index) => {
|
|
2341
|
+
const angle = index / members.length * 2 * Math.PI - Math.PI / 2;
|
|
2342
|
+
return { dx: Math.cos(angle) * FAN_RADIUS, dy: Math.sin(angle) * FAN_RADIUS };
|
|
2343
|
+
};
|
|
2344
|
+
const box = FAN_RADIUS * 2 + 8;
|
|
2345
|
+
return /* @__PURE__ */ jsxs("span", { className: "relative block", style: { width: 0, height: 0 }, children: [
|
|
2346
|
+
/* @__PURE__ */ jsx("svg", { className: "pointer-events-none absolute text-fg-quaternary", style: { left: -box / 2, top: -box / 2, width: box, height: box }, "aria-hidden": true, children: members.map((member, index) => {
|
|
2347
|
+
const { dx, dy } = at(index);
|
|
2348
|
+
return /* @__PURE__ */ jsx("line", { x1: box / 2, y1: box / 2, x2: box / 2 + dx, y2: box / 2 + dy, stroke: "currentColor", strokeWidth: 1 }, member.key);
|
|
2349
|
+
}) }),
|
|
2350
|
+
members.map((member, index) => {
|
|
2351
|
+
const { dx, dy } = at(index);
|
|
2352
|
+
return /* @__PURE__ */ jsx(
|
|
2353
|
+
"span",
|
|
2354
|
+
{
|
|
2355
|
+
role: "button",
|
|
2356
|
+
tabIndex: 0,
|
|
2357
|
+
"aria-label": member.name,
|
|
2358
|
+
className: "absolute cursor-pointer outline-focus-ring focus-visible:outline-2 focus-visible:outline-offset-2",
|
|
2359
|
+
style: { left: dx, top: dy, transform: "translate(-50%, -50%)" },
|
|
2360
|
+
onClick: (event) => {
|
|
2361
|
+
event.stopPropagation();
|
|
2362
|
+
onPick(member, { x: member.x + dx, y: member.y + dy });
|
|
2363
|
+
},
|
|
2364
|
+
onKeyDown: (event) => {
|
|
2365
|
+
if (event.key !== "Enter" && event.key !== " ") return;
|
|
2366
|
+
event.preventDefault();
|
|
2367
|
+
onPick(member, { x: member.x + dx, y: member.y + dy });
|
|
2368
|
+
},
|
|
2369
|
+
children: renderMarker ? renderMarker(member.row) : /* @__PURE__ */ jsx(
|
|
2370
|
+
MapMarker,
|
|
2371
|
+
{
|
|
2372
|
+
shape,
|
|
2373
|
+
tone: member.tone,
|
|
2374
|
+
name: member.name,
|
|
2375
|
+
scale: normalise(member.magnitude, magnitudeRange),
|
|
2376
|
+
selected: selectedKeys.has(member.key)
|
|
2377
|
+
}
|
|
2378
|
+
)
|
|
2379
|
+
},
|
|
2380
|
+
member.key
|
|
2381
|
+
);
|
|
2382
|
+
})
|
|
2383
|
+
] });
|
|
2384
|
+
}
|
|
2385
|
+
function sameMounted(a, b) {
|
|
2386
|
+
return a.length === b.length && a.every((entry, i) => entry.id === b[i]?.id && entry.element === b[i]?.element);
|
|
2387
|
+
}
|
|
2388
|
+
function centroid(members) {
|
|
2389
|
+
let lng = 0;
|
|
2390
|
+
let lat = 0;
|
|
2391
|
+
for (const member of members) {
|
|
2392
|
+
lng += member.position[0];
|
|
2393
|
+
lat += member.position[1];
|
|
2394
|
+
}
|
|
2395
|
+
return [lng / members.length, lat / members.length];
|
|
2396
|
+
}
|
|
2397
|
+
function normalise(magnitude, range) {
|
|
2398
|
+
if (magnitude === void 0 || !range) return void 0;
|
|
2399
|
+
const [low, high] = range;
|
|
2400
|
+
if (high <= low) return void 0;
|
|
2401
|
+
return (magnitude - low) / (high - low);
|
|
2402
|
+
}
|
|
2403
|
+
function useCameraTick(instance, handle) {
|
|
2404
|
+
const [state, setState] = useState({ tick: 0, zoom: 0 });
|
|
2405
|
+
useEffect(() => {
|
|
2406
|
+
if (!instance || !handle) return;
|
|
2407
|
+
let frame = 0;
|
|
2408
|
+
const read = () => {
|
|
2409
|
+
cancelAnimationFrame(frame);
|
|
2410
|
+
frame = requestAnimationFrame(() => setState((current) => ({ tick: current.tick + 1, zoom: handle.getCamera().zoom })));
|
|
2411
|
+
};
|
|
2412
|
+
read();
|
|
2413
|
+
const unsubscribe = subscribeMove(instance, read);
|
|
2414
|
+
return () => {
|
|
2415
|
+
cancelAnimationFrame(frame);
|
|
2416
|
+
unsubscribe();
|
|
2417
|
+
};
|
|
2418
|
+
}, [instance, handle]);
|
|
2419
|
+
return state;
|
|
2420
|
+
}
|
|
2421
|
+
var subscribeMove = (instance, listener) => {
|
|
2422
|
+
const off = onMapEvent(instance, "move", listener);
|
|
2423
|
+
const offEnd = onMapEvent(instance, "moveend", listener);
|
|
2424
|
+
return () => {
|
|
2425
|
+
off();
|
|
2426
|
+
offEnd();
|
|
2427
|
+
};
|
|
2428
|
+
};
|
|
2429
|
+
|
|
2430
|
+
// src/components/data-map/join.ts
|
|
2431
|
+
function featureKey(feature, property) {
|
|
2432
|
+
const raw2 = feature.properties?.[property];
|
|
2433
|
+
if (raw2 === void 0 || raw2 === null) return void 0;
|
|
2434
|
+
return String(raw2);
|
|
2435
|
+
}
|
|
2436
|
+
function renderedFeatureKey(feature, property) {
|
|
2437
|
+
const fromProperties = feature.properties[property];
|
|
2438
|
+
if (fromProperties !== void 0 && fromProperties !== null) return String(fromProperties);
|
|
2439
|
+
return feature.id;
|
|
2440
|
+
}
|
|
2441
|
+
function reduce(numbers, how) {
|
|
2442
|
+
if (how === "count") return numbers.length;
|
|
2443
|
+
if (numbers.length === 0) return 0;
|
|
2444
|
+
switch (how) {
|
|
2445
|
+
case "sum": {
|
|
2446
|
+
return numbers.reduce((a, b) => a + b, 0);
|
|
2447
|
+
}
|
|
2448
|
+
case "mean": {
|
|
2449
|
+
return numbers.reduce((a, b) => a + b, 0) / numbers.length;
|
|
2450
|
+
}
|
|
2451
|
+
case "min": {
|
|
2452
|
+
return Math.min(...numbers);
|
|
2453
|
+
}
|
|
2454
|
+
case "max": {
|
|
2455
|
+
return Math.max(...numbers);
|
|
2456
|
+
}
|
|
2457
|
+
}
|
|
2458
|
+
}
|
|
2459
|
+
function joinRows(features, rows, options) {
|
|
2460
|
+
const { joinOn, scale, warnUnmatchedRows = true } = options;
|
|
2461
|
+
const byRowKey = /* @__PURE__ */ new Map();
|
|
2462
|
+
for (const row of rows) {
|
|
2463
|
+
const key = joinOn.row(row);
|
|
2464
|
+
const bucket = byRowKey.get(key);
|
|
2465
|
+
if (bucket) bucket.push(row);
|
|
2466
|
+
else byRowKey.set(key, [row]);
|
|
2467
|
+
}
|
|
2468
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2469
|
+
const duplicateFeatureKeys = [];
|
|
2470
|
+
const matched = /* @__PURE__ */ new Set();
|
|
2471
|
+
const outcomes = [];
|
|
2472
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
2473
|
+
let featuresMissingKey = 0;
|
|
2474
|
+
let multiRowFeatures = 0;
|
|
2475
|
+
const aggregate = scale.kind === "categorical" ? void 0 : scale.aggregate;
|
|
2476
|
+
const rate = scale.kind === "categorical" ? void 0 : scale.rate;
|
|
2477
|
+
for (const feature of features) {
|
|
2478
|
+
const key = featureKey(feature, joinOn.feature);
|
|
2479
|
+
if (key === void 0) {
|
|
2480
|
+
featuresMissingKey += 1;
|
|
2481
|
+
continue;
|
|
2482
|
+
}
|
|
2483
|
+
if (seen.has(key)) duplicateFeatureKeys.push(key);
|
|
2484
|
+
seen.add(key);
|
|
2485
|
+
const matchedRows = byRowKey.get(key);
|
|
2486
|
+
let measure = { kind: "none" };
|
|
2487
|
+
if (matchedRows && matchedRows.length > 0) {
|
|
2488
|
+
matched.add(key);
|
|
2489
|
+
if (matchedRows.length > 1 && !aggregate && scale.kind !== "categorical") multiRowFeatures += 1;
|
|
2490
|
+
if (scale.kind === "categorical") {
|
|
2491
|
+
const first = matchedRows[0];
|
|
2492
|
+
if (first !== void 0) measure = { kind: "category", category: scale.value(first) };
|
|
2493
|
+
} else {
|
|
2494
|
+
const numbers = matchedRows.map((row) => scale.value(row)).filter((n) => Number.isFinite(n));
|
|
2495
|
+
let value = aggregate ? reduce(numbers, aggregate) : numbers.at(-1) ?? 0;
|
|
2496
|
+
if (rate) {
|
|
2497
|
+
const denominator = matchedRows.map((row) => rate.denominator(row)).reduce((a, b) => a + (Number.isFinite(b) ? b : 0), 0);
|
|
2498
|
+
const numerator = aggregate === "count" ? numbers.length : numbers.reduce((a, b) => a + b, 0);
|
|
2499
|
+
value = denominator === 0 ? 0 : numerator / denominator * (rate.per ?? 1);
|
|
2500
|
+
}
|
|
2501
|
+
measure = { kind: "value", value };
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
const outcome = { key, rows: matchedRows ?? [], measure };
|
|
2505
|
+
outcomes.push(outcome);
|
|
2506
|
+
byKey.set(key, outcome);
|
|
2507
|
+
}
|
|
2508
|
+
const unmatchedRowKeys = [];
|
|
2509
|
+
for (const key of byRowKey.keys()) if (!matched.has(key)) unmatchedRowKeys.push(key);
|
|
2510
|
+
const diagnostics = {
|
|
2511
|
+
unmatchedRowCount: unmatchedRowKeys.length,
|
|
2512
|
+
unmatchedRowKeys,
|
|
2513
|
+
duplicateFeatureKeys,
|
|
2514
|
+
featuresMissingKey,
|
|
2515
|
+
hasNoData: outcomes.some((o) => o.measure.kind === "none")
|
|
2516
|
+
};
|
|
2517
|
+
warnAboutJoin(joinOn.feature, features.length, diagnostics, { warnUnmatchedRows: warnUnmatchedRows && features.length > 0, multiRowFeatures });
|
|
2518
|
+
return { outcomes, byKey, diagnostics };
|
|
2519
|
+
}
|
|
2520
|
+
function warnAboutJoin(property, featureCount, d, context) {
|
|
2521
|
+
if (d.featuresMissingKey > 0) {
|
|
2522
|
+
devWarn(
|
|
2523
|
+
`<DataMap> ${d.featuresMissingKey} of ${featureCount} features have no "${property}" property, so they can never join and will paint as "no data". Check joinOn.feature against the GeoJSON's own property names.`
|
|
2524
|
+
);
|
|
2525
|
+
}
|
|
2526
|
+
if (d.unmatchedRowCount > 0 && context.warnUnmatchedRows) {
|
|
2527
|
+
devWarn(
|
|
2528
|
+
`<DataMap> ${d.unmatchedRowCount} row(s) match no feature \u2014 e.g. ${d.unmatchedRowKeys.slice(0, 3).map((k) => JSON.stringify(k)).join(", ")}. Usually a code-vintage mismatch: administrative codes are versioned by year, so pin the year in the geometry filename.`
|
|
2529
|
+
);
|
|
2530
|
+
}
|
|
2531
|
+
if (context.multiRowFeatures > 0) {
|
|
2532
|
+
devWarn(
|
|
2533
|
+
`<DataMap> ${context.multiRowFeatures} feature(s) matched more than one row and the scale has no \`aggregate\`, so the LAST row wins. Set \`aggregate: "sum" | "mean" | "min" | "max" | "count"\` on the scale, or pre-aggregate before passing rows.`
|
|
2534
|
+
);
|
|
2535
|
+
}
|
|
2536
|
+
if (d.duplicateFeatureKeys.length > 0) {
|
|
2537
|
+
devWarn(
|
|
2538
|
+
`<DataMap> Duplicate "${property}" value(s) across features \u2014 e.g. ${d.duplicateFeatureKeys.slice(0, 3).map((k) => JSON.stringify(k)).join(", ")}. That property is also the feature id, so hover and selection will light every shape sharing a value.`
|
|
2539
|
+
);
|
|
2540
|
+
}
|
|
2541
|
+
}
|
|
2542
|
+
|
|
2543
|
+
// src/components/data-map/labels.ts
|
|
2544
|
+
var MAP_LABELS = {
|
|
2545
|
+
/** The map region's accessible name, when the caller gives no `aria-label`. */
|
|
2546
|
+
region: "Map",
|
|
2547
|
+
/** `aria-roledescription` on the region — a screen reader reads it after the name, so a Thai UI
|
|
2548
|
+
* says "แผนที่" instead of the English word. */
|
|
2549
|
+
roleDescription: "map",
|
|
2550
|
+
/* ── controls. Ours, and the reason is DESIGN CONSISTENCY rather than reach: one focus ring, one
|
|
2551
|
+
* icon set, one token vocabulary. (`10-corrections.md` C1 retired the old reason — MapLibre's
|
|
2552
|
+
* own control strings ARE reachable through `MapOptions.locale`.) ── */
|
|
2553
|
+
zoomIn: "Zoom in",
|
|
2554
|
+
zoomOut: "Zoom out",
|
|
2555
|
+
resetView: "Reset view",
|
|
2556
|
+
/** Frame everything currently drawn. R5 §A — ~84% of the canvas was empty and there was no way to
|
|
2557
|
+
* say "fill the frame". */
|
|
2558
|
+
fitToData: "Fit to data",
|
|
2559
|
+
fullscreen: "Full screen",
|
|
2560
|
+
exitFullscreen: "Exit full screen",
|
|
2561
|
+
scaleBar: "Scale",
|
|
2562
|
+
/** The button that leaves the current level. Distinct from a browser "back". */
|
|
2563
|
+
drillUp: "Back to previous level",
|
|
2564
|
+
/**
|
|
2565
|
+
* The ROOT crumb — the whole dataset, before any drill.
|
|
2566
|
+
*
|
|
2567
|
+
* Its own key because the root frame has no `parentLabel` by construction (nothing was drilled
|
|
2568
|
+
* INTO to reach it), and the trail borrowed `labels.legend` for the fallback — so the first crumb
|
|
2569
|
+
* of every drill on every map read the word **"Legend"**.
|
|
2570
|
+
*/
|
|
2571
|
+
drillRoot: "All",
|
|
2572
|
+
/** A crumb that is a real destination. `level` is the caller's own word for it. */
|
|
2573
|
+
drillTo: (ctx) => `Back to ${ctx.level}`,
|
|
2574
|
+
/* ── the layers panel — R3 row 1's "with a toggle" half ── */
|
|
2575
|
+
layers: "Layers",
|
|
2576
|
+
showLayer: (ctx) => `Show ${ctx.layer}`,
|
|
2577
|
+
hideLayer: (ctx) => `Hide ${ctx.layer}`,
|
|
2578
|
+
/** The kind's own word, used when a layer has no `label` of its own. */
|
|
2579
|
+
kindChoropleth: "Regions",
|
|
2580
|
+
kindPoints: "Locations",
|
|
2581
|
+
kindHeatmap: "Density",
|
|
2582
|
+
kindLines: "Routes",
|
|
2583
|
+
kindAreas: "Areas",
|
|
2584
|
+
kindRaster: "Imagery",
|
|
2585
|
+
/** The popup's own close button. It used to be an `sr-only` "×", so a mouse user had a card and no
|
|
2586
|
+
* visible way to dismiss it. */
|
|
2587
|
+
closePopup: "Close",
|
|
2588
|
+
/* ── the time axis ── */
|
|
2589
|
+
play: "Play",
|
|
2590
|
+
pause: "Pause",
|
|
2591
|
+
timeFrame: "Time frame",
|
|
2592
|
+
/* ── states ── */
|
|
2593
|
+
loading: "Loading map data",
|
|
2594
|
+
/** Shown when WebGL is unavailable — a permanent state, so it must not offer a retry. */
|
|
2595
|
+
unsupported: "This browser cannot display the interactive map. The same data is listed below.",
|
|
2596
|
+
loadError: "Could not load map data.",
|
|
2597
|
+
retry: "Try again",
|
|
2598
|
+
/** No feature joined at all: the geometry loaded and nothing matched. Usually a `joinOn` mismatch,
|
|
2599
|
+
* which is why the wording points at the data rather than at the network. */
|
|
2600
|
+
empty: "No data to display for this area.",
|
|
2601
|
+
/* ── legend ── */
|
|
2602
|
+
legend: "Legend",
|
|
2603
|
+
/** The collapse toggle — `legend="collapsed"` only; no other form folds. */
|
|
2604
|
+
showLegend: "Show legend",
|
|
2605
|
+
hideLegend: "Hide legend",
|
|
2606
|
+
/** A section heading in a STACKED legend — with N layers, "Legend" no longer identifies a ramp. */
|
|
2607
|
+
legendFor: (ctx) => ctx.layer,
|
|
2608
|
+
/**
|
|
2609
|
+
* The `no data` swatch.
|
|
2610
|
+
*
|
|
2611
|
+
* Load-bearing, not decoration: without it a reader has no way to tell an unjoined region from a
|
|
2612
|
+
* region whose value is genuinely `0`, which is the classic choropleth lie.
|
|
2613
|
+
*/
|
|
2614
|
+
noData: "No data",
|
|
2615
|
+
/** A class whose range is a single value — every feature in it shares one number. */
|
|
2616
|
+
binExact: (ctx) => ctx.value,
|
|
2617
|
+
/** A class's range. `from`/`to` arrive ALREADY FORMATTED. */
|
|
2618
|
+
binRange: (ctx) => `${ctx.from} \u2013 ${ctx.to}`,
|
|
2619
|
+
/** The topmost class, which is open-ended. */
|
|
2620
|
+
binFrom: (ctx) => `${ctx.from}+`,
|
|
2621
|
+
/** The denominator, carried into the legend. R3 row 21: a rate whose base is not stated lies. */
|
|
2622
|
+
rateSuffix: (ctx) => `per ${ctx.per}`,
|
|
2623
|
+
/** A density surface has no classes, so its legend is a gradient with two ends. */
|
|
2624
|
+
heatLow: "Fewer",
|
|
2625
|
+
heatHigh: "More",
|
|
2626
|
+
/* ── markers + clusters ── */
|
|
2627
|
+
/**
|
|
2628
|
+
* A cluster bubble's accessible name. `count` arrives ALREADY FORMATTED — see the header.
|
|
2629
|
+
*/
|
|
2630
|
+
clusterOf: (ctx) => `${ctx.count} locations`,
|
|
2631
|
+
/** The list that IS the accessible rendering of a point layer. */
|
|
2632
|
+
markerList: "Map locations",
|
|
2633
|
+
/* ── the text alternative. The replacement coverage for an axe gate that cannot see a canvas. ── */
|
|
2634
|
+
/** The whole projection's heading, when it is shown rather than `sr-only`. */
|
|
2635
|
+
tableHeading: "Map data",
|
|
2636
|
+
/** One section per layer. `kind` is already the localised word from the `kind*` keys above. */
|
|
2637
|
+
layerSection: (ctx) => `${ctx.layer} (${ctx.kind})`,
|
|
2638
|
+
/** The accessible table's caption. Layer-qualified AND level-qualified: with N layers "Provinces"
|
|
2639
|
+
* no longer identifies which table this is. */
|
|
2640
|
+
tableCaption: (ctx) => `${ctx.layer}: data by ${ctx.level}`,
|
|
2641
|
+
tableRegionColumn: "Region",
|
|
2642
|
+
tableValueColumn: "Value",
|
|
2643
|
+
tableCategoryColumn: "Category",
|
|
2644
|
+
/** Above the budget, a section summarises instead of enumerating — see `text-alternative.tsx`. */
|
|
2645
|
+
summaryOf: (ctx) => `${ctx.layer}: ${ctx.count} items shown.`,
|
|
2646
|
+
rangeOf: (ctx) => `Values range from ${ctx.from} to ${ctx.to}.`,
|
|
2647
|
+
topN: (ctx) => `Highest ${ctx.n}`,
|
|
2648
|
+
showAllRows: (ctx) => `Show all ${ctx.count} rows`,
|
|
2649
|
+
/** A layer the reader has switched OFF. Rendered `hidden`, not `sr-only`: it is genuinely not being
|
|
2650
|
+
* shown, and the two spellings mean different things. */
|
|
2651
|
+
hiddenLayer: (ctx) => `${ctx.layer} is hidden.`,
|
|
2652
|
+
/** Imagery has no data to project, and claiming otherwise is a false green. */
|
|
2653
|
+
rasterOnly: (ctx) => `${ctx.layer} is an image overlay and has no listed data.`,
|
|
2654
|
+
/** A density surface has no features to enumerate. */
|
|
2655
|
+
densityOnly: (ctx) => `${ctx.layer} is a density surface computed from ${ctx.count} points.`,
|
|
2656
|
+
/** D2 — the data export the projection makes free, because we hold the rows and nobody else does. */
|
|
2657
|
+
copyData: "Copy data",
|
|
2658
|
+
copiedData: "Copied",
|
|
2659
|
+
/* ── announcements. The canvas is opaque to assistive tech, so these ARE the interaction. ── */
|
|
2660
|
+
drilledInto: (ctx) => `Showing ${ctx.count} ${ctx.level} in ${ctx.parent}`,
|
|
2661
|
+
drilledUpTo: (ctx) => `Showing ${ctx.count} ${ctx.level}`,
|
|
2662
|
+
layerShown: (ctx) => `${ctx.layer} shown`,
|
|
2663
|
+
layerHidden: (ctx) => `${ctx.layer} hidden`,
|
|
2664
|
+
frameChanged: (ctx) => `Showing ${ctx.frame}`,
|
|
2665
|
+
selectionCleared: "Selection cleared",
|
|
2666
|
+
/**
|
|
2667
|
+
* One layer's clause in the live region's opening description, for a map with NO choropleth —
|
|
2668
|
+
* the five kinds the announcement used to return `""` for.
|
|
2669
|
+
*
|
|
2670
|
+
* Its own key rather than a second use of `summaryOf`: that one is the accessible TABLE's section
|
|
2671
|
+
* summary and reads as a caption ("Stores: 400 items shown."), while this is spoken the moment the
|
|
2672
|
+
* map appears. Sharing the string made both sentences the same words in two places, which is how
|
|
2673
|
+
* a translator gets one of them wrong. `count` arrives ALREADY FORMATTED.
|
|
2674
|
+
*/
|
|
2675
|
+
showingLayer: (ctx) => `${ctx.count} ${ctx.layer}`,
|
|
2676
|
+
/* ── the ENGINE's own chrome, patched through `MapOptions.locale` — D4 / correction C1.
|
|
2677
|
+
* These are MapLibre's string ids, spelled as our keys. Anything not listed keeps MapLibre's
|
|
2678
|
+
* English, so this list is the coverage claim: every id the engine can actually reach with our
|
|
2679
|
+
* construction options (a marker, and cooperative gestures) is here. ── */
|
|
2680
|
+
/** MapLibre's `Marker.Title` — a DOM marker's `title` attribute. English on every pin today. */
|
|
2681
|
+
engineMarkerTitle: "Map marker",
|
|
2682
|
+
/** `CooperativeGesturesHandler.WindowsHelpText`. */
|
|
2683
|
+
engineGestureCtrl: "Use Ctrl + scroll to zoom the map",
|
|
2684
|
+
/** `CooperativeGesturesHandler.MacHelpText`. */
|
|
2685
|
+
engineGestureMac: "Use \u2318 + scroll to zoom the map",
|
|
2686
|
+
/** `CooperativeGesturesHandler.MobileHelpText`. */
|
|
2687
|
+
engineGestureTouch: "Use two fingers to move the map",
|
|
2688
|
+
/** `Popup.Close`. We render our own popups, but the engine's is one `addProtocol` away from being
|
|
2689
|
+
* reachable and the string costs nothing to cover. */
|
|
2690
|
+
engineClosePopup: "Close popup"
|
|
2691
|
+
};
|
|
2692
|
+
function resolveLegend(display) {
|
|
2693
|
+
if (display === "none") return null;
|
|
2694
|
+
if (typeof display === "string") return { layout: display, collapse: "none" };
|
|
2695
|
+
return { layout: display.layout ?? "stacked", collapse: display.collapse ?? "none" };
|
|
2696
|
+
}
|
|
2697
|
+
var SWATCH = "size-3 shrink-0 rounded-sm";
|
|
2698
|
+
function entryText(entry, labels, format) {
|
|
2699
|
+
switch (entry.kind) {
|
|
2700
|
+
case "no-data": {
|
|
2701
|
+
return labels.noData;
|
|
2702
|
+
}
|
|
2703
|
+
case "category": {
|
|
2704
|
+
return entry.label;
|
|
2705
|
+
}
|
|
2706
|
+
case "range": {
|
|
2707
|
+
if (entry.from === entry.to) return labels.binExact({ value: format(entry.from) });
|
|
2708
|
+
if (entry.last) return labels.binFrom({ from: format(entry.from) });
|
|
2709
|
+
return labels.binRange({ from: format(entry.from), to: format(entry.to) });
|
|
2710
|
+
}
|
|
2711
|
+
}
|
|
2712
|
+
}
|
|
2713
|
+
function NoDataRow({ color, labels }) {
|
|
2714
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
2715
|
+
/* @__PURE__ */ jsx("span", { className: cn(SWATCH, "border border-dashed bg-transparent"), style: { borderColor: color }, "aria-hidden": true }),
|
|
2716
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-tertiary", children: labels.noData })
|
|
2717
|
+
] });
|
|
2718
|
+
}
|
|
2719
|
+
function CompactRamp({
|
|
2720
|
+
ranges,
|
|
2721
|
+
labels,
|
|
2722
|
+
format
|
|
2723
|
+
}) {
|
|
2724
|
+
const first = ranges[0];
|
|
2725
|
+
const last = ranges.at(-1);
|
|
2726
|
+
if (!first || !last) return null;
|
|
2727
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
|
|
2728
|
+
/* @__PURE__ */ jsx("div", { className: "flex h-2 w-full overflow-hidden rounded-full", "aria-hidden": true, children: ranges.map((entry) => /* @__PURE__ */ jsx("span", { className: "h-full flex-1", style: { backgroundColor: entry.color } }, entry.id)) }),
|
|
2729
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2 text-2xs text-quaternary tabular-nums", children: [
|
|
2730
|
+
/* @__PURE__ */ jsx("span", { children: format(first.from) }),
|
|
2731
|
+
/* @__PURE__ */ jsx("span", { children: last.last ? labels.binFrom({ from: format(last.from) }) : format(last.to) })
|
|
2732
|
+
] })
|
|
2733
|
+
] });
|
|
2734
|
+
}
|
|
2735
|
+
function Section({ section, labels }) {
|
|
2736
|
+
const rate = section.rateSuffix === void 0 || section.rateSuffix === 1 ? void 0 : labels.rateSuffix({ per: section.format(section.rateSuffix) });
|
|
2737
|
+
const ranges = section.entries.filter((entry) => entry.kind === "range");
|
|
2738
|
+
const noData = section.entries.find((entry) => entry.kind === "no-data");
|
|
2739
|
+
const rampable = section.layout === "compact" && ranges.length > 0 && ranges.length === section.entries.length - (noData ? 1 : 0);
|
|
2740
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5", children: [
|
|
2741
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-baseline justify-between gap-2", children: [
|
|
2742
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs font-semibold text-secondary", children: labels.legendFor({ layer: section.label }) }),
|
|
2743
|
+
rate ? /* @__PURE__ */ jsx("span", { className: "text-2xs text-quaternary", children: rate }) : null
|
|
2744
|
+
] }),
|
|
2745
|
+
rampable ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2746
|
+
/* @__PURE__ */ jsx(CompactRamp, { ranges, labels, format: section.format }),
|
|
2747
|
+
noData ? /* @__PURE__ */ jsx(NoDataRow, { color: noData.color, labels }) : null
|
|
2748
|
+
] }) : section.gradient ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
|
|
2749
|
+
/* @__PURE__ */ jsx("span", { className: "h-2 w-full rounded-full", style: { backgroundImage: `linear-gradient(to right, ${section.gradient.join(", ")})` }, "aria-hidden": true }),
|
|
2750
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between text-2xs text-quaternary", children: [
|
|
2751
|
+
/* @__PURE__ */ jsx("span", { children: labels.heatLow }),
|
|
2752
|
+
/* @__PURE__ */ jsx("span", { children: labels.heatHigh })
|
|
2753
|
+
] })
|
|
2754
|
+
] }) : section.entries.map(
|
|
2755
|
+
(entry) => entry.kind === "no-data" ? /* @__PURE__ */ jsx(NoDataRow, { color: entry.color, labels }, entry.id) : /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
2756
|
+
/* @__PURE__ */ jsx("span", { className: SWATCH, style: { backgroundColor: entry.color }, "aria-hidden": true }),
|
|
2757
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-tertiary tabular-nums", children: entryText(entry, labels, section.format) })
|
|
2758
|
+
] }, entry.id)
|
|
2759
|
+
)
|
|
2760
|
+
] });
|
|
2761
|
+
}
|
|
2762
|
+
function Legend({ sections, collapse, labels }) {
|
|
2763
|
+
const collapsible = collapse !== "none";
|
|
2764
|
+
const [open, setOpen] = useState(collapse !== "closed");
|
|
2765
|
+
const [lastCollapse, setLastCollapse] = useState(collapse);
|
|
2766
|
+
if (lastCollapse !== collapse) {
|
|
2767
|
+
setLastCollapse(collapse);
|
|
2768
|
+
setOpen(collapse !== "closed");
|
|
2769
|
+
}
|
|
2770
|
+
const bodyId = useId();
|
|
2771
|
+
if (sections.length === 0) return null;
|
|
2772
|
+
return /* @__PURE__ */ jsxs(
|
|
2773
|
+
Card,
|
|
2774
|
+
{
|
|
2775
|
+
variant: "outlined",
|
|
2776
|
+
shadow: "sm",
|
|
2777
|
+
padding: "none",
|
|
2778
|
+
role: "group",
|
|
2779
|
+
"aria-label": labels.legend,
|
|
2780
|
+
className: "pointer-events-auto flex max-h-full min-h-0 max-w-60 min-w-40 flex-col",
|
|
2781
|
+
children: [
|
|
2782
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2 px-3 py-2", children: [
|
|
2783
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs font-semibold text-secondary", children: labels.legend }),
|
|
2784
|
+
collapsible ? /* @__PURE__ */ jsx(
|
|
2785
|
+
ButtonUtility,
|
|
2786
|
+
{
|
|
2787
|
+
size: "xs",
|
|
2788
|
+
variant: "tertiary",
|
|
2789
|
+
icon: open ? /* @__PURE__ */ jsx(ChevronUpIcon, {}) : /* @__PURE__ */ jsx(ChevronDownIcon, {}),
|
|
2790
|
+
tooltip: open ? labels.hideLegend : labels.showLegend,
|
|
2791
|
+
"aria-expanded": open,
|
|
2792
|
+
"aria-controls": bodyId,
|
|
2793
|
+
onClick: () => setOpen((v) => !v)
|
|
2794
|
+
}
|
|
2795
|
+
) : null
|
|
2796
|
+
] }),
|
|
2797
|
+
open ? (
|
|
2798
|
+
// `min-h-0` for the same reason the card needs it: without it this body will not shrink, so
|
|
2799
|
+
// `overflow-y-auto` never engages and the stack pushes past the canvas instead of scrolling.
|
|
2800
|
+
// `max-h-72` stays as the ceiling on a TALL map, where the legend should not become a column.
|
|
2801
|
+
/* @__PURE__ */ jsx("div", { id: bodyId, className: "flex max-h-72 min-h-0 flex-col gap-3 overflow-y-auto px-3 pb-3", children: sections.map((section) => /* @__PURE__ */ jsx(Section, { section, labels }, section.id)) })
|
|
2802
|
+
) : null
|
|
2803
|
+
]
|
|
2804
|
+
}
|
|
2805
|
+
);
|
|
2806
|
+
}
|
|
2807
|
+
var MAX_WIDTH = 96;
|
|
2808
|
+
var METRES_PER_PIXEL_Z0 = 156543.0339 / 2;
|
|
2809
|
+
var NICE = [1, 2, 5];
|
|
2810
|
+
function niceDistance(budget) {
|
|
2811
|
+
if (!Number.isFinite(budget) || budget <= 0) return 1;
|
|
2812
|
+
const decade = 10 ** Math.floor(Math.log10(budget));
|
|
2813
|
+
let best = decade;
|
|
2814
|
+
for (const step of NICE) if (step * decade <= budget) best = step * decade;
|
|
2815
|
+
return best;
|
|
2816
|
+
}
|
|
2817
|
+
function metresPerPixel(zoom, latitude) {
|
|
2818
|
+
const clamped = Math.max(-85, Math.min(85, latitude));
|
|
2819
|
+
return METRES_PER_PIXEL_Z0 * Math.cos(clamped * Math.PI / 180) / 2 ** zoom;
|
|
2820
|
+
}
|
|
2821
|
+
function ScaleBar({ zoom, latitude, labels }) {
|
|
2822
|
+
const locale = useLocaleConfig().locale?.code ?? "en";
|
|
2823
|
+
const perPixel = metresPerPixel(zoom, latitude);
|
|
2824
|
+
if (!Number.isFinite(perPixel) || perPixel <= 0) return null;
|
|
2825
|
+
const metres = niceDistance(perPixel * MAX_WIDTH);
|
|
2826
|
+
const width = Math.round(metres / perPixel);
|
|
2827
|
+
const value = metres >= 1e3 ? metres / 1e3 : metres;
|
|
2828
|
+
const unit = metres >= 1e3 ? "kilometer" : "meter";
|
|
2829
|
+
return (
|
|
2830
|
+
/* `role="img"` with the name on it: an `aria-label` on a bare `<div>` has no role to attach to
|
|
2831
|
+
and most screen readers drop it, so the bar was nameless in practice. `img` is the right role
|
|
2832
|
+
for a graphic that conveys one fact — the distance — rather than a structure to navigate. */
|
|
2833
|
+
/* @__PURE__ */ jsxs("div", { className: "pointer-events-none flex flex-col items-start gap-0.5", role: "img", "aria-label": labels.scaleBar, children: [
|
|
2834
|
+
/* @__PURE__ */ jsx("span", { className: "text-2xs leading-none font-medium text-secondary tabular-nums", children: new Intl.NumberFormat(locale, { style: "unit", unit, unitDisplay: "short", maximumFractionDigits: 0 }).format(value) }),
|
|
2835
|
+
/* @__PURE__ */ jsx("div", { className: "h-1.5 border-x-2 border-b-2 border-strong", style: { width } })
|
|
2836
|
+
] })
|
|
2837
|
+
);
|
|
2838
|
+
}
|
|
2839
|
+
var ROW_BUDGET = 200;
|
|
2840
|
+
var EXTREMES = 10;
|
|
2841
|
+
function rowsOf(projection, labels) {
|
|
2842
|
+
switch (projection.kind) {
|
|
2843
|
+
case "choropleth": {
|
|
2844
|
+
const outcomes = projection.join?.outcomes ?? [];
|
|
2845
|
+
return outcomes.map((outcome) => {
|
|
2846
|
+
const name = projection.nameByKey.get(outcome.key) ?? outcome.key;
|
|
2847
|
+
if (outcome.measure.kind === "value")
|
|
2848
|
+
return { key: outcome.key, name, text: projection.format(outcome.measure.value), magnitude: outcome.measure.value };
|
|
2849
|
+
if (outcome.measure.kind === "category") return { key: outcome.key, name, text: outcome.measure.category };
|
|
2850
|
+
return { key: outcome.key, name, text: labels.noData };
|
|
2851
|
+
});
|
|
2852
|
+
}
|
|
2853
|
+
case "points": {
|
|
2854
|
+
return projection.points.map((point) => ({
|
|
2855
|
+
key: point.key,
|
|
2856
|
+
name: point.name ?? point.key,
|
|
2857
|
+
text: point.magnitude === void 0 ? `${point.position[1].toFixed(4)}, ${point.position[0].toFixed(4)}` : String(point.magnitude),
|
|
2858
|
+
magnitude: point.magnitude
|
|
2859
|
+
}));
|
|
2860
|
+
}
|
|
2861
|
+
case "lines": {
|
|
2862
|
+
return projection.lines.map((line) => ({ key: line.key, name: line.name ?? line.key, text: `${line.path.length} points` }));
|
|
2863
|
+
}
|
|
2864
|
+
case "areas": {
|
|
2865
|
+
return projection.features.features.map((feature, index) => ({
|
|
2866
|
+
key: String(feature.id ?? index),
|
|
2867
|
+
name: projection.names[index] ?? String(index),
|
|
2868
|
+
text: projection.toneByIndex[index] ?? ""
|
|
2869
|
+
}));
|
|
2870
|
+
}
|
|
2871
|
+
case "heatmap":
|
|
2872
|
+
case "raster": {
|
|
2873
|
+
return [];
|
|
2874
|
+
}
|
|
2875
|
+
}
|
|
2876
|
+
}
|
|
2877
|
+
function toClipboardText(label, rows) {
|
|
2878
|
+
return [label, ...rows.map((row) => `${row.name} ${row.text}`)].join("\n");
|
|
2879
|
+
}
|
|
2880
|
+
function CopyButton({ text, labels }) {
|
|
2881
|
+
const [copied, setCopied] = useState(false);
|
|
2882
|
+
const copy = useCallback(() => {
|
|
2883
|
+
void navigator.clipboard?.writeText(text).then(() => {
|
|
2884
|
+
setCopied(true);
|
|
2885
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
2886
|
+
});
|
|
2887
|
+
}, [text]);
|
|
2888
|
+
return /* @__PURE__ */ jsx(Button, { size: "sm", variant: "tertiary", onClick: copy, children: copied ? labels.copiedData : labels.copyData });
|
|
2889
|
+
}
|
|
2890
|
+
function levelOf(projection) {
|
|
2891
|
+
if (projection.kind === "choropleth") return projection.level.label;
|
|
2892
|
+
return projection.label;
|
|
2893
|
+
}
|
|
2894
|
+
function Table({
|
|
2895
|
+
projection,
|
|
2896
|
+
rows,
|
|
2897
|
+
labels
|
|
2898
|
+
}) {
|
|
2899
|
+
const isChoropleth = projection.kind === "choropleth";
|
|
2900
|
+
const level = levelOf(projection);
|
|
2901
|
+
const categorical = isChoropleth && projection.scale?.bins === void 0;
|
|
2902
|
+
return /* @__PURE__ */ jsxs("table", { className: "w-full border-collapse text-sm", children: [
|
|
2903
|
+
/* @__PURE__ */ jsx("caption", { className: "sr-only", children: level === projection.label ? labels.summaryOf({ count: String(rows.length), layer: projection.label }) : labels.tableCaption({ layer: projection.label, level }) }),
|
|
2904
|
+
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
2905
|
+
/* @__PURE__ */ jsx("th", { scope: "col", className: "border-b border-secondary px-2 py-1 text-left font-medium text-secondary", children: labels.tableRegionColumn }),
|
|
2906
|
+
/* @__PURE__ */ jsx("th", { scope: "col", className: "border-b border-secondary px-2 py-1 text-right font-medium text-secondary", children: categorical ? labels.tableCategoryColumn : labels.tableValueColumn })
|
|
2907
|
+
] }) }),
|
|
2908
|
+
/* @__PURE__ */ jsx("tbody", { children: rows.map((row) => /* @__PURE__ */ jsxs("tr", { children: [
|
|
2909
|
+
/* @__PURE__ */ jsx("th", { scope: "row", className: "border-b border-secondary px-2 py-1 text-left font-normal text-primary", children: row.name }),
|
|
2910
|
+
/* @__PURE__ */ jsx("td", { className: "border-b border-secondary px-2 py-1 text-right text-secondary tabular-nums", children: row.text })
|
|
2911
|
+
] }, row.key)) })
|
|
2912
|
+
] });
|
|
2913
|
+
}
|
|
2914
|
+
function List({ rows, labels }) {
|
|
2915
|
+
return /* @__PURE__ */ jsx("ul", { "aria-label": labels.markerList, className: "flex flex-col gap-0.5 text-sm", children: rows.map((row) => /* @__PURE__ */ jsxs("li", { className: "flex items-baseline justify-between gap-3", children: [
|
|
2916
|
+
/* @__PURE__ */ jsx("span", { className: "text-primary", children: row.name }),
|
|
2917
|
+
/* @__PURE__ */ jsx("span", { className: "text-secondary tabular-nums", children: row.text })
|
|
2918
|
+
] }, row.key)) });
|
|
2919
|
+
}
|
|
2920
|
+
function Section2({
|
|
2921
|
+
projection,
|
|
2922
|
+
labels,
|
|
2923
|
+
kindLabel,
|
|
2924
|
+
visible
|
|
2925
|
+
}) {
|
|
2926
|
+
const heading = labels.layerSection({ layer: projection.label, kind: kindLabel(projection.kind) });
|
|
2927
|
+
if (!projection.visible) {
|
|
2928
|
+
return /* @__PURE__ */ jsxs("section", { hidden: true, children: [
|
|
2929
|
+
/* @__PURE__ */ jsx("h3", { children: heading }),
|
|
2930
|
+
/* @__PURE__ */ jsx("p", { children: labels.hiddenLayer({ layer: projection.label }) })
|
|
2931
|
+
] });
|
|
2932
|
+
}
|
|
2933
|
+
if (projection.kind === "raster") {
|
|
2934
|
+
return /* @__PURE__ */ jsxs("section", { children: [
|
|
2935
|
+
/* @__PURE__ */ jsx("h3", { className: cn(visible && "text-sm font-semibold text-secondary"), children: heading }),
|
|
2936
|
+
/* @__PURE__ */ jsx("p", { className: cn(visible && "text-sm text-tertiary"), children: labels.rasterOnly({ layer: projection.label }) })
|
|
2937
|
+
] });
|
|
2938
|
+
}
|
|
2939
|
+
if (projection.kind === "heatmap") {
|
|
2940
|
+
return /* @__PURE__ */ jsxs("section", { children: [
|
|
2941
|
+
/* @__PURE__ */ jsx("h3", { className: cn(visible && "text-sm font-semibold text-secondary"), children: heading }),
|
|
2942
|
+
/* @__PURE__ */ jsx("p", { className: cn(visible && "text-sm text-tertiary"), children: labels.densityOnly({ layer: projection.label, count: String(projection.renderedCount) }) })
|
|
2943
|
+
] });
|
|
2944
|
+
}
|
|
2945
|
+
const rows = rowsOf(projection, labels);
|
|
2946
|
+
const enumerate = rows.length <= ROW_BUDGET;
|
|
2947
|
+
const isTable = projection.kind === "choropleth";
|
|
2948
|
+
if (enumerate) {
|
|
2949
|
+
return /* @__PURE__ */ jsxs("section", { className: cn(visible && "flex flex-col gap-2"), children: [
|
|
2950
|
+
/* @__PURE__ */ jsxs("div", { className: cn(visible && "flex items-center justify-between gap-3"), children: [
|
|
2951
|
+
/* @__PURE__ */ jsx("h3", { className: cn(visible && "text-sm font-semibold text-secondary"), children: heading }),
|
|
2952
|
+
visible ? /* @__PURE__ */ jsx(CopyButton, { text: toClipboardText(projection.label, rows), labels }) : null
|
|
2953
|
+
] }),
|
|
2954
|
+
isTable ? /* @__PURE__ */ jsx(Table, { projection, rows, labels }) : /* @__PURE__ */ jsx(List, { rows, labels })
|
|
2955
|
+
] });
|
|
2956
|
+
}
|
|
2957
|
+
const ranked = [...rows];
|
|
2958
|
+
ranked.sort((a, b) => (b.magnitude ?? 0) - (a.magnitude ?? 0));
|
|
2959
|
+
const top = ranked.slice(0, EXTREMES);
|
|
2960
|
+
const magnitudes = rows.flatMap((row) => row.magnitude === void 0 ? [] : [row.magnitude]);
|
|
2961
|
+
const low = magnitudes.length > 0 ? Math.min(...magnitudes) : void 0;
|
|
2962
|
+
const high = magnitudes.length > 0 ? Math.max(...magnitudes) : void 0;
|
|
2963
|
+
const format = projection.kind === "choropleth" ? projection.format : String;
|
|
2964
|
+
return /* @__PURE__ */ jsxs("section", { className: cn(visible && "flex flex-col gap-2"), children: [
|
|
2965
|
+
/* @__PURE__ */ jsxs("div", { className: cn(visible && "flex items-center justify-between gap-3"), children: [
|
|
2966
|
+
/* @__PURE__ */ jsx("h3", { className: cn(visible && "text-sm font-semibold text-secondary"), children: heading }),
|
|
2967
|
+
visible ? /* @__PURE__ */ jsx(CopyButton, { text: toClipboardText(projection.label, rows), labels }) : null
|
|
2968
|
+
] }),
|
|
2969
|
+
/* @__PURE__ */ jsxs("p", { className: cn(visible && "text-sm text-tertiary"), children: [
|
|
2970
|
+
labels.summaryOf({ count: String(rows.length), layer: projection.label }),
|
|
2971
|
+
low !== void 0 && high !== void 0 ? ` ${labels.rangeOf({ from: format(low), to: format(high) })}` : null
|
|
2972
|
+
] }),
|
|
2973
|
+
/* @__PURE__ */ jsx("h4", { className: cn(visible && "text-xs font-semibold text-tertiary"), children: labels.topN({ n: String(EXTREMES) }) }),
|
|
2974
|
+
/* @__PURE__ */ jsx(List, { rows: top, labels }),
|
|
2975
|
+
/* @__PURE__ */ jsxs("details", { children: [
|
|
2976
|
+
/* @__PURE__ */ jsx("summary", { className: cn(visible && "cursor-pointer text-sm text-brand-secondary"), children: labels.showAllRows({ count: String(rows.length) }) }),
|
|
2977
|
+
isTable ? /* @__PURE__ */ jsx(Table, { projection, rows, labels }) : /* @__PURE__ */ jsx(List, { rows, labels })
|
|
2978
|
+
] })
|
|
2979
|
+
] });
|
|
2980
|
+
}
|
|
2981
|
+
function TextAlternative({ id, projections, labels, visible, kindLabel }) {
|
|
2982
|
+
return /* @__PURE__ */ jsxs("div", { id, className: visible ? "flex flex-col gap-4 border-t border-secondary px-4 py-4" : "sr-only", children: [
|
|
2983
|
+
/* @__PURE__ */ jsx("h2", { className: cn(visible && "text-sm font-semibold text-primary"), children: labels.tableHeading }),
|
|
2984
|
+
projections.map((projection) => /* @__PURE__ */ jsx(Section2, { projection, labels, kindLabel, visible }, projection.id))
|
|
2985
|
+
] });
|
|
2986
|
+
}
|
|
2987
|
+
function TimeBar({ time, labels, playable, onFrame, onPlaying, onHeight }) {
|
|
2988
|
+
const ref = useRef(null);
|
|
2989
|
+
useEffect(() => {
|
|
2990
|
+
const node = ref.current;
|
|
2991
|
+
if (!node) return;
|
|
2992
|
+
const measure = () => onHeight(node.offsetHeight + 12);
|
|
2993
|
+
measure();
|
|
2994
|
+
const observer = new ResizeObserver(measure);
|
|
2995
|
+
observer.observe(node);
|
|
2996
|
+
return () => {
|
|
2997
|
+
observer.disconnect();
|
|
2998
|
+
onHeight(0);
|
|
2999
|
+
};
|
|
3000
|
+
}, [onHeight]);
|
|
3001
|
+
const current = time.frames.find((frame) => frame.key === time.frame);
|
|
3002
|
+
return /* @__PURE__ */ jsx("div", { ref, className: "pointer-events-auto w-full", children: /* @__PURE__ */ jsx(Card, { variant: "outlined", shadow: "sm", padding: "sm", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
|
|
3003
|
+
playable ? /* @__PURE__ */ jsx(
|
|
3004
|
+
ButtonUtility,
|
|
3005
|
+
{
|
|
3006
|
+
size: "sm",
|
|
3007
|
+
className: "pointer-coarse:p-3",
|
|
3008
|
+
icon: time.playing ? /* @__PURE__ */ jsx(PauseIcon, {}) : /* @__PURE__ */ jsx(PlayIcon, {}),
|
|
3009
|
+
tooltip: time.playing ? labels.pause : labels.play,
|
|
3010
|
+
"aria-pressed": time.playing,
|
|
3011
|
+
onClick: () => onPlaying(!time.playing)
|
|
3012
|
+
}
|
|
3013
|
+
) : null,
|
|
3014
|
+
/* @__PURE__ */ jsx(
|
|
3015
|
+
Slider,
|
|
3016
|
+
{
|
|
3017
|
+
className: "min-w-0 flex-1",
|
|
3018
|
+
size: "sm",
|
|
3019
|
+
band: "ticks",
|
|
3020
|
+
valuePosition: "none",
|
|
3021
|
+
"aria-label": labels.timeFrame,
|
|
3022
|
+
stops: time.frames.map((frame) => ({ value: frame.key, label: frame.label })),
|
|
3023
|
+
value: time.frame,
|
|
3024
|
+
onValueChange: (value) => {
|
|
3025
|
+
onPlaying(false);
|
|
3026
|
+
if (typeof value === "string") onFrame(value);
|
|
3027
|
+
}
|
|
3028
|
+
}
|
|
3029
|
+
),
|
|
3030
|
+
/* @__PURE__ */ jsx("span", { className: "w-24 shrink-0 text-right text-sm text-secondary tabular-nums", children: current?.label ?? "" })
|
|
3031
|
+
] }) }) });
|
|
3032
|
+
}
|
|
3033
|
+
var OFFSET = 14;
|
|
3034
|
+
var FLIP_MARGIN = 220;
|
|
3035
|
+
function MapTooltip({ x, y, width, height, title, value, body }) {
|
|
3036
|
+
const flipX = x > width - FLIP_MARGIN;
|
|
3037
|
+
const flipY = y > height - 80;
|
|
3038
|
+
return /* @__PURE__ */ jsx(
|
|
3039
|
+
"div",
|
|
3040
|
+
{
|
|
3041
|
+
"data-map-tooltip": "",
|
|
3042
|
+
"aria-hidden": "true",
|
|
3043
|
+
className: "pointer-events-none absolute z-20 max-w-56",
|
|
3044
|
+
style: {
|
|
3045
|
+
left: flipX ? void 0 : x + OFFSET,
|
|
3046
|
+
right: flipX ? width - x + OFFSET : void 0,
|
|
3047
|
+
top: flipY ? void 0 : y + OFFSET,
|
|
3048
|
+
bottom: flipY ? height - y + OFFSET : void 0
|
|
3049
|
+
},
|
|
3050
|
+
children: /* @__PURE__ */ jsx(Card, { variant: "outlined", shadow: "md", padding: "sm", children: body ?? /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-0.5", children: [
|
|
3051
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm font-medium text-primary", children: title }),
|
|
3052
|
+
value === void 0 ? null : /* @__PURE__ */ jsx("span", { className: "text-sm text-secondary tabular-nums", children: value })
|
|
3053
|
+
] }) })
|
|
3054
|
+
}
|
|
3055
|
+
);
|
|
3056
|
+
}
|
|
3057
|
+
function useMapEngine(options) {
|
|
3058
|
+
const { container, style, init, reducedMotion = false, interactiveLayerIds, onReady, onError } = options;
|
|
3059
|
+
const [status, setStatus] = useState(() => isEngineLoaded() ? "loading" : "loading");
|
|
3060
|
+
const [error, setError] = useState(void 0);
|
|
3061
|
+
const [instance, setInstance] = useState(void 0);
|
|
3062
|
+
const onReadyRef = useRef(onReady);
|
|
3063
|
+
const onErrorRef = useRef(onError);
|
|
3064
|
+
const reducedMotionRef = useRef(reducedMotion);
|
|
3065
|
+
const layersRef = useRef(interactiveLayerIds);
|
|
3066
|
+
const initRef = useRef(init);
|
|
3067
|
+
const styleRef = useRef(style);
|
|
3068
|
+
onReadyRef.current = onReady;
|
|
3069
|
+
onErrorRef.current = onError;
|
|
3070
|
+
reducedMotionRef.current = reducedMotion;
|
|
3071
|
+
layersRef.current = interactiveLayerIds;
|
|
3072
|
+
initRef.current = init;
|
|
3073
|
+
styleRef.current = style;
|
|
3074
|
+
const handleInstanceRef = useRef(void 0);
|
|
3075
|
+
useEffect(() => {
|
|
3076
|
+
if (!container) return;
|
|
3077
|
+
if (!isEngineSupported()) {
|
|
3078
|
+
setStatus("unsupported");
|
|
3079
|
+
return;
|
|
3080
|
+
}
|
|
3081
|
+
let cancelled = false;
|
|
3082
|
+
let created;
|
|
3083
|
+
let unsubscribeLoad;
|
|
3084
|
+
let unsubscribeError;
|
|
3085
|
+
void (async () => {
|
|
3086
|
+
try {
|
|
3087
|
+
const engine = await loadEngine();
|
|
3088
|
+
if (cancelled) return;
|
|
3089
|
+
created = createMap(engine, { ...initRef.current, container, style: styleRef.current });
|
|
3090
|
+
handleInstanceRef.current = created;
|
|
3091
|
+
setInstance(created);
|
|
3092
|
+
unsubscribeLoad = onMapEvent(created, "load", () => {
|
|
3093
|
+
if (cancelled) return;
|
|
3094
|
+
setStatus("ready");
|
|
3095
|
+
});
|
|
3096
|
+
unsubscribeError = onMapEvent(created, "error", (event) => {
|
|
3097
|
+
if (cancelled) return;
|
|
3098
|
+
const reason = event?.error?.message;
|
|
3099
|
+
if (reason) devWarn(`<DataMap> engine error: ${reason}`);
|
|
3100
|
+
onErrorRef.current?.(reason);
|
|
3101
|
+
});
|
|
3102
|
+
} catch (error_) {
|
|
3103
|
+
if (cancelled) return;
|
|
3104
|
+
setError(error_);
|
|
3105
|
+
setStatus("error");
|
|
3106
|
+
onErrorRef.current?.(error_);
|
|
3107
|
+
}
|
|
3108
|
+
})();
|
|
3109
|
+
return () => {
|
|
3110
|
+
cancelled = true;
|
|
3111
|
+
unsubscribeLoad?.();
|
|
3112
|
+
unsubscribeError?.();
|
|
3113
|
+
destroyMap(created);
|
|
3114
|
+
created = void 0;
|
|
3115
|
+
handleInstanceRef.current = void 0;
|
|
3116
|
+
setInstance(void 0);
|
|
3117
|
+
setStatus("loading");
|
|
3118
|
+
};
|
|
3119
|
+
}, [container]);
|
|
3120
|
+
const [sizeTick, setSizeTick] = useState(0);
|
|
3121
|
+
useEffect(() => {
|
|
3122
|
+
if (!container) return;
|
|
3123
|
+
const observer = new ResizeObserver(() => {
|
|
3124
|
+
const live = handleInstanceRef.current;
|
|
3125
|
+
if (live) redraw(live);
|
|
3126
|
+
setSizeTick((tick) => tick + 1);
|
|
3127
|
+
});
|
|
3128
|
+
observer.observe(container);
|
|
3129
|
+
return () => observer.disconnect();
|
|
3130
|
+
}, [container]);
|
|
3131
|
+
const handleRef = useRef(void 0);
|
|
3132
|
+
const setCamera = useCallback((move) => {
|
|
3133
|
+
const live = handleInstanceRef.current;
|
|
3134
|
+
if (!live) return;
|
|
3135
|
+
stopCamera(live);
|
|
3136
|
+
moveCamera(live, resolveMove(move, reducedMotionRef.current));
|
|
3137
|
+
}, []);
|
|
3138
|
+
const fitBoundsCb = useCallback((move) => {
|
|
3139
|
+
const live = handleInstanceRef.current;
|
|
3140
|
+
if (!live) return;
|
|
3141
|
+
stopCamera(live);
|
|
3142
|
+
fitBounds(live, resolveFit(move, reducedMotionRef.current));
|
|
3143
|
+
}, []);
|
|
3144
|
+
const queryAtCb = useCallback((point) => {
|
|
3145
|
+
const live = handleInstanceRef.current;
|
|
3146
|
+
return live ? queryAt(live, point, layersRef.current) : [];
|
|
3147
|
+
}, []);
|
|
3148
|
+
if (!handleRef.current) {
|
|
3149
|
+
handleRef.current = {
|
|
3150
|
+
getCamera: () => {
|
|
3151
|
+
const live = handleInstanceRef.current;
|
|
3152
|
+
return live ? getCamera(live) : { center: [0, 0], zoom: 0, bearing: 0, pitch: 0 };
|
|
3153
|
+
},
|
|
3154
|
+
setCamera,
|
|
3155
|
+
fitBounds: fitBoundsCb,
|
|
3156
|
+
queryAt: queryAtCb,
|
|
3157
|
+
redraw: () => {
|
|
3158
|
+
const live = handleInstanceRef.current;
|
|
3159
|
+
if (live) redraw(live);
|
|
3160
|
+
}
|
|
3161
|
+
};
|
|
3162
|
+
}
|
|
3163
|
+
const announcedRef = useRef(false);
|
|
3164
|
+
useEffect(() => {
|
|
3165
|
+
if (status !== "ready" || announcedRef.current) return;
|
|
3166
|
+
announcedRef.current = true;
|
|
3167
|
+
const handle = handleRef.current;
|
|
3168
|
+
if (handle) onReadyRef.current?.(handle);
|
|
3169
|
+
}, [status]);
|
|
3170
|
+
useEffect(() => {
|
|
3171
|
+
if (status === "loading") announcedRef.current = false;
|
|
3172
|
+
}, [status]);
|
|
3173
|
+
return { status, error, instance, sizeTick, handle: status === "ready" ? handleRef.current : void 0 };
|
|
3174
|
+
}
|
|
3175
|
+
function useMapPaint(options) {
|
|
3176
|
+
const { instance, ready, mode, projections, specs, domPointLayers, styleGeneration, isolate = false } = options;
|
|
3177
|
+
const appliedRef = useRef(
|
|
3178
|
+
/* @__PURE__ */ new Map()
|
|
3179
|
+
);
|
|
3180
|
+
const resultRef = useRef({ interactiveLayerIds: [], sourceByLayer: /* @__PURE__ */ new Map() });
|
|
3181
|
+
useEffect(() => {
|
|
3182
|
+
if (!instance || !ready) return;
|
|
3183
|
+
const applied = appliedRef.current;
|
|
3184
|
+
const specById = new Map(specs.map((spec) => [spec.id, spec]));
|
|
3185
|
+
const wanted = /* @__PURE__ */ new Set();
|
|
3186
|
+
const interactiveLayerIds = [];
|
|
3187
|
+
const sourceByLayer = /* @__PURE__ */ new Map();
|
|
3188
|
+
for (const projection of projections) {
|
|
3189
|
+
const spec = specById.get(projection.id);
|
|
3190
|
+
if (!spec) continue;
|
|
3191
|
+
const plan = planLayer(projection, spec, mode, domPointLayers.has(projection.id), isolate);
|
|
3192
|
+
if (!plan) continue;
|
|
3193
|
+
wanted.add(projection.id);
|
|
3194
|
+
sourceByLayer.set(projection.id, plan.sourceId);
|
|
3195
|
+
if (projection.visible) interactiveLayerIds.push(...projection.interactive ? plan.interactiveLayerIds : []);
|
|
3196
|
+
const previous = applied.get(projection.id);
|
|
3197
|
+
const live = previous !== void 0 && previous.generation === styleGeneration && hasSource(instance, plan.sourceId);
|
|
3198
|
+
if (live) {
|
|
3199
|
+
const signature = planSignature(plan);
|
|
3200
|
+
if (previous.signature === signature) {
|
|
3201
|
+
if (previous.visible !== projection.visible) {
|
|
3202
|
+
for (const layer of plan.layers) setLayerVisibility(instance, String(layer.id), projection.visible);
|
|
3203
|
+
}
|
|
3204
|
+
applied.set(projection.id, { plan, generation: styleGeneration, signature, visible: projection.visible });
|
|
3205
|
+
continue;
|
|
3206
|
+
}
|
|
3207
|
+
if (plan.source && "data" in plan.source) setSourceData(instance, plan.sourceId, plan.source.data);
|
|
3208
|
+
repaint(instance, plan);
|
|
3209
|
+
} else {
|
|
3210
|
+
if (previous)
|
|
3211
|
+
removeSourceAndLayers(
|
|
3212
|
+
instance,
|
|
3213
|
+
previous.plan.sourceId,
|
|
3214
|
+
previous.plan.layers.map((l) => String(l.id))
|
|
3215
|
+
);
|
|
3216
|
+
addSource(instance, plan.sourceId, plan.source ?? {}, plan.layers, hasLayer(instance, DATA_INSERTION_LAYER_ID) ? DATA_INSERTION_LAYER_ID : void 0);
|
|
3217
|
+
applied.set(projection.id, { plan, generation: styleGeneration, signature: planSignature(plan), visible: projection.visible });
|
|
3218
|
+
}
|
|
3219
|
+
for (const layer of plan.layers) setLayerVisibility(instance, String(layer.id), projection.visible);
|
|
3220
|
+
applied.set(projection.id, { plan, generation: styleGeneration, signature: planSignature(plan), visible: projection.visible });
|
|
3221
|
+
}
|
|
3222
|
+
for (const [id, entry] of applied) {
|
|
3223
|
+
if (wanted.has(id)) continue;
|
|
3224
|
+
removeSourceAndLayers(
|
|
3225
|
+
instance,
|
|
3226
|
+
entry.plan.sourceId,
|
|
3227
|
+
entry.plan.layers.map((l) => String(l.id))
|
|
3228
|
+
);
|
|
3229
|
+
applied.delete(id);
|
|
3230
|
+
}
|
|
3231
|
+
resultRef.current = { interactiveLayerIds, sourceByLayer };
|
|
3232
|
+
}, [instance, ready, mode, projections, specs, domPointLayers, styleGeneration, isolate]);
|
|
3233
|
+
useEffect(
|
|
3234
|
+
() => () => {
|
|
3235
|
+
appliedRef.current = /* @__PURE__ */ new Map();
|
|
3236
|
+
},
|
|
3237
|
+
[]
|
|
3238
|
+
);
|
|
3239
|
+
return resultRef;
|
|
3240
|
+
}
|
|
3241
|
+
function planSignature(plan) {
|
|
3242
|
+
const data = plan.source && "data" in plan.source ? dataId(plan.source.data) : "-";
|
|
3243
|
+
return `${data}|${plan.layers.map((layer) => `${String(layer.id)}:${JSON.stringify(layer.paint ?? {})}:${JSON.stringify(layer.filter ?? null)}`).join("|")}`;
|
|
3244
|
+
}
|
|
3245
|
+
var dataIds = /* @__PURE__ */ new WeakMap();
|
|
3246
|
+
var nextDataId = 0;
|
|
3247
|
+
function dataId(data) {
|
|
3248
|
+
if (!data || typeof data !== "object") return String(data);
|
|
3249
|
+
let id = dataIds.get(data);
|
|
3250
|
+
if (id === void 0) {
|
|
3251
|
+
id = nextDataId++;
|
|
3252
|
+
dataIds.set(data, id);
|
|
3253
|
+
}
|
|
3254
|
+
return `d${id}`;
|
|
3255
|
+
}
|
|
3256
|
+
function repaint(instance, plan) {
|
|
3257
|
+
for (const layer of plan.layers) {
|
|
3258
|
+
const paint = layer.paint;
|
|
3259
|
+
if (!paint) continue;
|
|
3260
|
+
for (const [property, value] of Object.entries(paint)) setPaint(instance, String(layer.id), property, value);
|
|
3261
|
+
}
|
|
3262
|
+
}
|
|
3263
|
+
function useThemeMode() {
|
|
3264
|
+
const [mode, setMode] = useState("light");
|
|
3265
|
+
useEffect(() => {
|
|
3266
|
+
const read = () => setMode(document.documentElement.classList.contains("dark") ? "dark" : "light");
|
|
3267
|
+
read();
|
|
3268
|
+
const observer = new MutationObserver(read);
|
|
3269
|
+
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["class"] });
|
|
3270
|
+
return () => observer.disconnect();
|
|
3271
|
+
}, []);
|
|
3272
|
+
return mode;
|
|
3273
|
+
}
|
|
3274
|
+
function useReducedMotion() {
|
|
3275
|
+
const [reduced, setReduced] = useState(false);
|
|
3276
|
+
useEffect(() => {
|
|
3277
|
+
const query = globalThis.matchMedia("(prefers-reduced-motion: reduce)");
|
|
3278
|
+
const read = () => setReduced(query.matches);
|
|
3279
|
+
read();
|
|
3280
|
+
query.addEventListener("change", read);
|
|
3281
|
+
return () => query.removeEventListener("change", read);
|
|
3282
|
+
}, []);
|
|
3283
|
+
return reduced;
|
|
3284
|
+
}
|
|
3285
|
+
function useCoarsePointer() {
|
|
3286
|
+
const [coarse, setCoarse] = useState(false);
|
|
3287
|
+
useEffect(() => {
|
|
3288
|
+
const query = globalThis.matchMedia("(pointer: coarse)");
|
|
3289
|
+
const read = () => setCoarse(query.matches);
|
|
3290
|
+
read();
|
|
3291
|
+
query.addEventListener("change", read);
|
|
3292
|
+
return () => query.removeEventListener("change", read);
|
|
3293
|
+
}, []);
|
|
3294
|
+
return coarse;
|
|
3295
|
+
}
|
|
3296
|
+
var DEFAULT_CONTROLS = ["zoom", "reset", "fitData", "layers"];
|
|
3297
|
+
var DOM_POINT_CEILING = 300;
|
|
3298
|
+
var FRAMED_BY_BOUNDS = "bounds";
|
|
3299
|
+
function DataMap({
|
|
3300
|
+
source = DEFAULT_MAP_SOURCE,
|
|
3301
|
+
view,
|
|
3302
|
+
legend = "stacked",
|
|
3303
|
+
controls = DEFAULT_CONTROLS,
|
|
3304
|
+
transport = "bar",
|
|
3305
|
+
textAlternative = "sr-only",
|
|
3306
|
+
fallback = "text",
|
|
3307
|
+
gestures = "cooperative",
|
|
3308
|
+
attribution,
|
|
3309
|
+
labels: labelOverrides,
|
|
3310
|
+
onReady,
|
|
3311
|
+
className,
|
|
3312
|
+
...rest
|
|
3313
|
+
}) {
|
|
3314
|
+
const labels = useLabels("map", MAP_LABELS, labelOverrides);
|
|
3315
|
+
const locale = useLocaleConfig().locale?.code ?? "en";
|
|
3316
|
+
const mode = useThemeMode();
|
|
3317
|
+
const reducedMotion = useReducedMotion();
|
|
3318
|
+
const coarsePointer = useCoarsePointer();
|
|
3319
|
+
const textId = useId();
|
|
3320
|
+
const [container, setContainer] = useState(null);
|
|
3321
|
+
const containerRef = useCallback((node) => setContainer(node), []);
|
|
3322
|
+
const [root, setRoot] = useState(null);
|
|
3323
|
+
const rootRef = useCallback((node) => setRoot(node), []);
|
|
3324
|
+
const { internal } = view;
|
|
3325
|
+
const kindLabels = useMemo(
|
|
3326
|
+
() => ({
|
|
3327
|
+
choropleth: labels.kindChoropleth,
|
|
3328
|
+
points: labels.kindPoints,
|
|
3329
|
+
heatmap: labels.kindHeatmap,
|
|
3330
|
+
lines: labels.kindLines,
|
|
3331
|
+
areas: labels.kindAreas,
|
|
3332
|
+
raster: labels.kindRaster
|
|
3333
|
+
}),
|
|
3334
|
+
[labels.kindChoropleth, labels.kindPoints, labels.kindHeatmap, labels.kindLines, labels.kindAreas, labels.kindRaster]
|
|
3335
|
+
);
|
|
3336
|
+
useEffect(() => {
|
|
3337
|
+
internal.setKindLabels(kindLabels);
|
|
3338
|
+
}, [internal, kindLabels]);
|
|
3339
|
+
useEffect(() => {
|
|
3340
|
+
if (source === DEFAULT_MAP_SOURCE) warnDefaultSource();
|
|
3341
|
+
}, [source]);
|
|
3342
|
+
const style = useMemo(
|
|
3343
|
+
() => buildMapStyle({ mode, source, locale, engineLabels: { markerTitle: labels.engineMarkerTitle } }),
|
|
3344
|
+
[mode, source, locale, labels.engineMarkerTitle]
|
|
3345
|
+
);
|
|
3346
|
+
const cameraOptions = internal.cameraOptions;
|
|
3347
|
+
const openingBoundsRef = useRef(void 0);
|
|
3348
|
+
const openingSettledRef = useRef(false);
|
|
3349
|
+
if (!openingSettledRef.current) {
|
|
3350
|
+
const intent = cameraOptions.fit ?? "contain";
|
|
3351
|
+
if (intent === "none" || cameraOptions.center !== void 0) {
|
|
3352
|
+
openingSettledRef.current = true;
|
|
3353
|
+
} else {
|
|
3354
|
+
const opening = cameraOptions.bounds ?? internal.dataBounds();
|
|
3355
|
+
if (opening) {
|
|
3356
|
+
openingBoundsRef.current = opening;
|
|
3357
|
+
openingSettledRef.current = true;
|
|
3358
|
+
}
|
|
3359
|
+
}
|
|
3360
|
+
}
|
|
3361
|
+
const { status, instance, sizeTick, handle } = useMapEngine({
|
|
3362
|
+
container,
|
|
3363
|
+
style,
|
|
3364
|
+
reducedMotion,
|
|
3365
|
+
init: {
|
|
3366
|
+
cooperativeGestures: gestures === "cooperative",
|
|
3367
|
+
center: cameraOptions.center,
|
|
3368
|
+
zoom: cameraOptions.zoom,
|
|
3369
|
+
minZoom: cameraOptions.zoomRange?.min,
|
|
3370
|
+
maxZoom: cameraOptions.zoomRange?.max,
|
|
3371
|
+
bounds: openingBoundsRef.current,
|
|
3372
|
+
// The chrome is measured after the first commit, so the legend has no width yet and this is
|
|
3373
|
+
// the same minimum `padding` initialises to. The opening fit below refines it — a reframe by
|
|
3374
|
+
// the legend's width, rather than a cut out of the ocean.
|
|
3375
|
+
fitPadding: chromePadding({}),
|
|
3376
|
+
fitMaxZoom: cameraOptions.zoomRange?.max,
|
|
3377
|
+
/* D4 / correction C1 — the engine's own chrome, in the app's language. `cooperativeGestures` is
|
|
3378
|
+
* live on every map by default, so this is not theoretical: without it a Thai UI showed an
|
|
3379
|
+
* English "Use ⌘ + scroll to zoom the map" from inside the one file `i18n:check` cannot see. */
|
|
3380
|
+
locale: {
|
|
3381
|
+
"Marker.Title": labels.engineMarkerTitle,
|
|
3382
|
+
"Popup.Close": labels.engineClosePopup,
|
|
3383
|
+
"CooperativeGesturesHandler.WindowsHelpText": labels.engineGestureCtrl,
|
|
3384
|
+
"CooperativeGesturesHandler.MacHelpText": labels.engineGestureMac,
|
|
3385
|
+
"CooperativeGesturesHandler.MobileHelpText": labels.engineGestureTouch
|
|
3386
|
+
}
|
|
3387
|
+
},
|
|
3388
|
+
onReady
|
|
3389
|
+
});
|
|
3390
|
+
const ready = status === "ready";
|
|
3391
|
+
useEffect(() => {
|
|
3392
|
+
internal.setStatus(status);
|
|
3393
|
+
}, [internal, status]);
|
|
3394
|
+
const projections = internal.projections;
|
|
3395
|
+
const resolvedLegend = resolveLegend(legend);
|
|
3396
|
+
const legendLayout = resolvedLegend?.layout;
|
|
3397
|
+
const legendCollapse = resolvedLegend?.collapse ?? "none";
|
|
3398
|
+
const legendRef = useRef(null);
|
|
3399
|
+
const [padding2, setPadding] = useState(() => chromePadding({}));
|
|
3400
|
+
const timeHeightRef = useRef(0);
|
|
3401
|
+
const measureChrome = useCallback(() => {
|
|
3402
|
+
const node = legendRef.current;
|
|
3403
|
+
setPadding(
|
|
3404
|
+
chromePadding({
|
|
3405
|
+
...node && { legendWidth: node.offsetWidth + 24, legendSide: "right" },
|
|
3406
|
+
breadcrumbHeight: 56,
|
|
3407
|
+
timeHeight: timeHeightRef.current
|
|
3408
|
+
})
|
|
3409
|
+
);
|
|
3410
|
+
}, []);
|
|
3411
|
+
useEffect(() => {
|
|
3412
|
+
const node = legendRef.current;
|
|
3413
|
+
if (!node) return;
|
|
3414
|
+
measureChrome();
|
|
3415
|
+
const observer = new ResizeObserver(measureChrome);
|
|
3416
|
+
observer.observe(node);
|
|
3417
|
+
return () => observer.disconnect();
|
|
3418
|
+
}, [legendLayout, legendCollapse, measureChrome]);
|
|
3419
|
+
const onTimeHeight = useCallback(
|
|
3420
|
+
(height) => {
|
|
3421
|
+
if (timeHeightRef.current === height) return;
|
|
3422
|
+
timeHeightRef.current = height;
|
|
3423
|
+
measureChrome();
|
|
3424
|
+
},
|
|
3425
|
+
[measureChrome]
|
|
3426
|
+
);
|
|
3427
|
+
const paddingRef = useRef(padding2);
|
|
3428
|
+
paddingRef.current = padding2;
|
|
3429
|
+
useEffect(() => {
|
|
3430
|
+
if (!handle) return;
|
|
3431
|
+
internal.attach({ handle, padding: () => paddingRef.current });
|
|
3432
|
+
return () => internal.attach(void 0);
|
|
3433
|
+
}, [internal, handle]);
|
|
3434
|
+
const geoData = useMemo(
|
|
3435
|
+
() => source.kind === "geojson" ? [source.land, source.water, source.rivers, source.boundaries, source.borders, source.places] : [],
|
|
3436
|
+
[source]
|
|
3437
|
+
);
|
|
3438
|
+
const styleKey = `${mode}:${locale}:${sourceKey(source)}`;
|
|
3439
|
+
const [styleGeneration, setStyleGeneration] = useState(0);
|
|
3440
|
+
const appliedRef = useRef({ key: styleKey, data: geoData });
|
|
3441
|
+
useEffect(() => {
|
|
3442
|
+
if (!instance || !ready) return;
|
|
3443
|
+
const applied = appliedRef.current;
|
|
3444
|
+
if (applied.key === styleKey && applied.data.length === geoData.length && applied.data.every((d, i) => d === geoData[i])) return;
|
|
3445
|
+
appliedRef.current = { key: styleKey, data: geoData };
|
|
3446
|
+
swapStyle(instance, style, { sourceIds: [], layerIds: [], beforeLayerId: DATA_INSERTION_LAYER_ID });
|
|
3447
|
+
let done = false;
|
|
3448
|
+
const off = onMapEvent(instance, "styledata", () => {
|
|
3449
|
+
if (done) return;
|
|
3450
|
+
done = true;
|
|
3451
|
+
setStyleGeneration((generation) => generation + 1);
|
|
3452
|
+
off();
|
|
3453
|
+
});
|
|
3454
|
+
return off;
|
|
3455
|
+
}, [instance, ready, styleKey, geoData, style]);
|
|
3456
|
+
const domPointLayers = useMemo(() => {
|
|
3457
|
+
const set = /* @__PURE__ */ new Set();
|
|
3458
|
+
for (const spec of internal.layerSpecs) {
|
|
3459
|
+
if (spec.kind !== "points") continue;
|
|
3460
|
+
if (spec.renderMarker !== void 0 && spec.mode === "gl") warnMarkerForcesDom(spec.id);
|
|
3461
|
+
const forced = spec.renderMarker !== void 0 || spec.mode === "dom";
|
|
3462
|
+
const resolved = forced || spec.mode !== "gl" && spec.rows.length <= DOM_POINT_CEILING;
|
|
3463
|
+
if (resolved) set.add(spec.id);
|
|
3464
|
+
}
|
|
3465
|
+
return set;
|
|
3466
|
+
}, [internal.layerSpecs]);
|
|
3467
|
+
const isolate = internal.emphasis === "isolate" && view.selected.length > 0;
|
|
3468
|
+
const paint = useMapPaint({ instance, ready, mode, projections, specs: internal.layerSpecs, domPointLayers, styleGeneration, isolate });
|
|
3469
|
+
const { tick, zoom } = useCameraTick(instance, handle);
|
|
3470
|
+
const [idle, setIdle] = useState(false);
|
|
3471
|
+
useEffect(() => {
|
|
3472
|
+
if (!instance || !ready) return;
|
|
3473
|
+
const report = (settled) => {
|
|
3474
|
+
internal.reportCamera(getCamera(instance), getBounds(instance), settled);
|
|
3475
|
+
};
|
|
3476
|
+
report(false);
|
|
3477
|
+
const offEnd = onMoveEnd(instance, () => {
|
|
3478
|
+
report(true);
|
|
3479
|
+
setIdle(true);
|
|
3480
|
+
});
|
|
3481
|
+
const offStart = onMoveStart(instance, () => setIdle(false));
|
|
3482
|
+
return () => {
|
|
3483
|
+
offEnd();
|
|
3484
|
+
offStart();
|
|
3485
|
+
};
|
|
3486
|
+
}, [instance, ready, internal]);
|
|
3487
|
+
const anyLoading = projections.some((p) => p.kind === "choropleth" && p.loading);
|
|
3488
|
+
const dataGeneration = projections.map((p) => `${p.id}:${p.renderedCount}:${p.visible ? 1 : 0}`).join("|");
|
|
3489
|
+
useEffect(() => {
|
|
3490
|
+
setIdle(false);
|
|
3491
|
+
}, [dataGeneration]);
|
|
3492
|
+
useEffect(() => {
|
|
3493
|
+
if (!instance || !ready) return;
|
|
3494
|
+
if (isMapIdle(instance)) setIdle(true);
|
|
3495
|
+
const off = onIdle(instance, () => setIdle(true));
|
|
3496
|
+
const diagnose = setTimeout(() => {
|
|
3497
|
+
if (isMapIdle(instance)) return;
|
|
3498
|
+
const reasons = pendingSources(instance);
|
|
3499
|
+
if (reasons.length > 0)
|
|
3500
|
+
devWarn(
|
|
3501
|
+
`<DataMap> has not reported idle after 10s. Blocked on: ${reasons.join(", ")}. "sourcesDirty" means something is re-applying paint every frame; "source:<id>" means that source has not loaded.`
|
|
3502
|
+
);
|
|
3503
|
+
}, 1e4);
|
|
3504
|
+
return () => {
|
|
3505
|
+
clearTimeout(diagnose);
|
|
3506
|
+
off();
|
|
3507
|
+
};
|
|
3508
|
+
}, [instance, ready, dataGeneration]);
|
|
3509
|
+
const framedLayersRef = useRef(void 0);
|
|
3510
|
+
const userMovedRef = useRef(false);
|
|
3511
|
+
useEffect(() => {
|
|
3512
|
+
if (!instance || !ready) return;
|
|
3513
|
+
return onMapEvent(instance, "movestart", (payload) => {
|
|
3514
|
+
if (payload && typeof payload === "object" && payload.originalEvent) userMovedRef.current = true;
|
|
3515
|
+
});
|
|
3516
|
+
}, [instance, ready]);
|
|
3517
|
+
useEffect(() => {
|
|
3518
|
+
if (!ready || !handle) return;
|
|
3519
|
+
if (userMovedRef.current) return;
|
|
3520
|
+
const intent = cameraOptions.fit ?? "contain";
|
|
3521
|
+
if (intent === "none" || cameraOptions.center !== void 0) return;
|
|
3522
|
+
if (cameraOptions.bounds) {
|
|
3523
|
+
if (framedLayersRef.current !== void 0) return;
|
|
3524
|
+
framedLayersRef.current = FRAMED_BY_BOUNDS;
|
|
3525
|
+
handle.fitBounds({
|
|
3526
|
+
bounds: cameraOptions.bounds,
|
|
3527
|
+
padding: padding2,
|
|
3528
|
+
fit: intent,
|
|
3529
|
+
maxZoom: cameraOptions.zoomRange?.max,
|
|
3530
|
+
// The OPENING frame cuts unless told otherwise — an arc from [0,0] into the data is a
|
|
3531
|
+
// 280ms flight over the Atlantic, which is the thing `openingBoundsRef` exists to prevent.
|
|
3532
|
+
intro: cameraOptions.intro ?? "instant"
|
|
3533
|
+
});
|
|
3534
|
+
return;
|
|
3535
|
+
}
|
|
3536
|
+
const landed = new Set(projections.filter((p) => p.renderedCount > 0).map((p) => p.id));
|
|
3537
|
+
if (landed.size === 0) return;
|
|
3538
|
+
const framed = framedLayersRef.current === FRAMED_BY_BOUNDS ? void 0 : framedLayersRef.current;
|
|
3539
|
+
if (framed && [...landed].every((id) => framed.has(id))) return;
|
|
3540
|
+
framedLayersRef.current = framed ? /* @__PURE__ */ new Set([...framed, ...landed]) : landed;
|
|
3541
|
+
view.fitTo("data", { intro: cameraOptions.intro ?? "instant", fit: intent });
|
|
3542
|
+
}, [ready, handle, instance, cameraOptions, padding2, projections, view, sizeTick]);
|
|
3543
|
+
const [popup, setPopup] = useState(void 0);
|
|
3544
|
+
const [hovered, setHovered] = useState(void 0);
|
|
3545
|
+
const [cursor, setCursor] = useState("grab");
|
|
3546
|
+
const [canvasBox, setCanvasBox] = useState({ width: 0, height: 0 });
|
|
3547
|
+
const hitAt = useCallback(
|
|
3548
|
+
(x, y) => {
|
|
3549
|
+
if (!instance) return void 0;
|
|
3550
|
+
const [feature] = queryAt(instance, { x, y }, paint.current.interactiveLayerIds);
|
|
3551
|
+
if (!feature) return void 0;
|
|
3552
|
+
const projection = projections.find((p) => feature.layerId.startsWith(`jz-data-${p.id}-`));
|
|
3553
|
+
if (!projection) return void 0;
|
|
3554
|
+
const key = projection.kind === "choropleth" ? renderedFeatureKey(feature, projection.joinProperty) : feature.id ?? String(feature.properties["jz:key"] ?? "");
|
|
3555
|
+
return key === void 0 ? void 0 : { layerId: projection.id, featureId: key };
|
|
3556
|
+
},
|
|
3557
|
+
[instance, paint, projections]
|
|
3558
|
+
);
|
|
3559
|
+
const onPointerMove = useCallback(
|
|
3560
|
+
(event) => {
|
|
3561
|
+
const box = event.currentTarget.getBoundingClientRect();
|
|
3562
|
+
const x = event.clientX - box.left;
|
|
3563
|
+
const y = event.clientY - box.top;
|
|
3564
|
+
const next = hitAt(x, y);
|
|
3565
|
+
setCursor(next ? "pointer" : "grab");
|
|
3566
|
+
setCanvasBox((current) => current.width === box.width && current.height === box.height ? current : { width: box.width, height: box.height });
|
|
3567
|
+
setHovered(() => {
|
|
3568
|
+
if (!next) return;
|
|
3569
|
+
return { ...next, x, y };
|
|
3570
|
+
});
|
|
3571
|
+
},
|
|
3572
|
+
[hitAt]
|
|
3573
|
+
);
|
|
3574
|
+
const onPointerLeave = useCallback(() => {
|
|
3575
|
+
setHovered(void 0);
|
|
3576
|
+
setCursor("grab");
|
|
3577
|
+
}, []);
|
|
3578
|
+
const previousHoverRef = useRef(void 0);
|
|
3579
|
+
const hoveredLayerId = hovered?.layerId;
|
|
3580
|
+
const hoveredFeatureId = hovered?.featureId;
|
|
3581
|
+
useEffect(() => {
|
|
3582
|
+
if (!instance || !ready) return;
|
|
3583
|
+
const previous = previousHoverRef.current;
|
|
3584
|
+
if (previous) setFeatureState(instance, sourceIdFor(previous.layerId), previous.featureId, { hover: false });
|
|
3585
|
+
if (hoveredLayerId !== void 0 && hoveredFeatureId !== void 0) {
|
|
3586
|
+
setFeatureState(instance, sourceIdFor(hoveredLayerId), hoveredFeatureId, { hover: true });
|
|
3587
|
+
}
|
|
3588
|
+
previousHoverRef.current = hoveredLayerId !== void 0 && hoveredFeatureId !== void 0 ? { layerId: hoveredLayerId, featureId: hoveredFeatureId } : void 0;
|
|
3589
|
+
}, [instance, ready, hoveredLayerId, hoveredFeatureId]);
|
|
3590
|
+
useEffect(() => {
|
|
3591
|
+
if (!instance || !ready) return;
|
|
3592
|
+
for (const projection of projections) {
|
|
3593
|
+
if (projection.kind !== "choropleth" || !projection.join) continue;
|
|
3594
|
+
const sourceId = sourceIdFor(projection.id);
|
|
3595
|
+
clearFeatureState(instance, sourceId);
|
|
3596
|
+
for (const outcome of projection.join.outcomes) {
|
|
3597
|
+
if (outcome.measure.kind === "none") setFeatureState(instance, sourceId, outcome.key, { nodata: true });
|
|
3598
|
+
}
|
|
3599
|
+
}
|
|
3600
|
+
}, [instance, ready, projections]);
|
|
3601
|
+
const previousSelectionRef = useRef([]);
|
|
3602
|
+
useEffect(() => {
|
|
3603
|
+
if (!instance || !ready) return;
|
|
3604
|
+
for (const ref of previousSelectionRef.current) setFeatureState(instance, sourceIdFor(ref.layerId), ref.featureId, { selected: false });
|
|
3605
|
+
for (const ref of view.selected) setFeatureState(instance, sourceIdFor(ref.layerId), ref.featureId, { selected: true });
|
|
3606
|
+
previousSelectionRef.current = view.selected;
|
|
3607
|
+
}, [instance, ready, view.selected]);
|
|
3608
|
+
const onClick = useCallback(
|
|
3609
|
+
(event) => {
|
|
3610
|
+
const box = event.currentTarget.getBoundingClientRect();
|
|
3611
|
+
const x = event.clientX - box.left;
|
|
3612
|
+
const y = event.clientY - box.top;
|
|
3613
|
+
const hit = hitAt(x, y);
|
|
3614
|
+
if (!hit) {
|
|
3615
|
+
setPopup(void 0);
|
|
3616
|
+
view.clearSelection();
|
|
3617
|
+
return;
|
|
3618
|
+
}
|
|
3619
|
+
const projection = projections.find((p) => p.id === hit.layerId);
|
|
3620
|
+
if (projection?.kind === "choropleth" && projection.canDrill) {
|
|
3621
|
+
view.drillInto(hit);
|
|
3622
|
+
setPopup(void 0);
|
|
3623
|
+
return;
|
|
3624
|
+
}
|
|
3625
|
+
view.select(
|
|
3626
|
+
internal.selectionMode === "multiple" ? [...view.selected.filter((r) => r.featureId !== hit.featureId || r.layerId !== hit.layerId), hit] : [hit]
|
|
3627
|
+
);
|
|
3628
|
+
setPopup({ ...hit, x, y });
|
|
3629
|
+
},
|
|
3630
|
+
[hitAt, projections, view, internal.selectionMode]
|
|
3631
|
+
);
|
|
3632
|
+
const legendSections = useMemo(() => {
|
|
3633
|
+
const sections = [];
|
|
3634
|
+
if (!legendLayout) return sections;
|
|
3635
|
+
for (const projection of projections) {
|
|
3636
|
+
const spec = internal.layerSpecs.find((s) => s.id === projection.id);
|
|
3637
|
+
if (!projection.visible || spec?.legend === "none") continue;
|
|
3638
|
+
const layout = spec?.legend === "expanded" ? "stacked" : legendLayout;
|
|
3639
|
+
if (projection.kind === "choropleth" && projection.scale) {
|
|
3640
|
+
sections.push({
|
|
3641
|
+
id: projection.id,
|
|
3642
|
+
label: projection.label,
|
|
3643
|
+
layout,
|
|
3644
|
+
entries: projection.scale.entries,
|
|
3645
|
+
format: projection.format,
|
|
3646
|
+
rateSuffix: projection.scale.rateSuffix
|
|
3647
|
+
});
|
|
3648
|
+
} else if (projection.kind === "heatmap") {
|
|
3649
|
+
sections.push({ id: projection.id, label: projection.label, layout, entries: [], gradient: projection.ramp ?? MAP_HEAT_SCALE[mode], format: String });
|
|
3650
|
+
} else {
|
|
3651
|
+
const painted = tonesPainted(projection);
|
|
3652
|
+
const toneLabels = spec && "toneLabels" in spec ? spec.toneLabels : void 0;
|
|
3653
|
+
if (painted.length > 1 && !toneLabels) warnUnkeyedTones(projection.id, painted.length);
|
|
3654
|
+
const entries = painted.flatMap((tone) => {
|
|
3655
|
+
const label = toneLabels?.[tone];
|
|
3656
|
+
if (label === void 0) return [];
|
|
3657
|
+
return [{ kind: "category", id: `${projection.id}-${tone}`, color: MAP_TONE_COLORS[mode][tone].fill, label }];
|
|
3658
|
+
});
|
|
3659
|
+
if (entries.length > 0) sections.push({ id: projection.id, label: projection.label, layout, entries, format: String });
|
|
3660
|
+
}
|
|
3661
|
+
}
|
|
3662
|
+
return sections;
|
|
3663
|
+
}, [projections, internal.layerSpecs, mode, legendLayout]);
|
|
3664
|
+
const formatNumber = useMemo(() => {
|
|
3665
|
+
const nf = new Intl.NumberFormat(locale);
|
|
3666
|
+
return (value) => nf.format(value);
|
|
3667
|
+
}, [locale]);
|
|
3668
|
+
const announcement = useAnnouncement(projections, view, labels, formatNumber);
|
|
3669
|
+
const tooltip = useMemo(() => {
|
|
3670
|
+
if (!hovered || coarsePointer) return;
|
|
3671
|
+
const spec = internal.layerSpecs.find((s) => s.id === hovered.layerId);
|
|
3672
|
+
if (spec?.interactive === false) return;
|
|
3673
|
+
const described = describeFeature(
|
|
3674
|
+
projections.find((p) => p.id === hovered.layerId),
|
|
3675
|
+
spec,
|
|
3676
|
+
hovered.featureId,
|
|
3677
|
+
void 0,
|
|
3678
|
+
"tooltip",
|
|
3679
|
+
formatNumber
|
|
3680
|
+
);
|
|
3681
|
+
return described && { ...described, x: hovered.x, y: hovered.y };
|
|
3682
|
+
}, [hovered, coarsePointer, internal.layerSpecs, projections, formatNumber]);
|
|
3683
|
+
const showText = textAlternative === "visible" || textAlternative === "responsive" && coarsePointer || status === "unsupported" && fallback === "text";
|
|
3684
|
+
const staticImage = typeof fallback === "object" ? fallback : void 0;
|
|
3685
|
+
const credit = [basemapAttribution(source), attribution].filter(Boolean).join(" \xB7 ");
|
|
3686
|
+
return /* @__PURE__ */ jsxs(
|
|
3687
|
+
"div",
|
|
3688
|
+
{
|
|
3689
|
+
ref: rootRef,
|
|
3690
|
+
className: cn(
|
|
3691
|
+
// `w-full` because a map has NO INTRINSIC WIDTH. Left to shrink-to-fit — which is what a
|
|
3692
|
+
// centring flex parent does to a block child — the container measures 0, MapLibre leaves the
|
|
3693
|
+
// canvas at its element default of 300px, and the DOM markers land outside it entirely. Bound
|
|
3694
|
+
// the HEIGHT via `className`; the width is the column's.
|
|
3695
|
+
"relative isolate w-full overflow-hidden rounded-xl ring-1 ring-secondary ring-inset",
|
|
3696
|
+
className
|
|
3697
|
+
),
|
|
3698
|
+
...rest,
|
|
3699
|
+
children: [
|
|
3700
|
+
/* @__PURE__ */ jsx(
|
|
3701
|
+
"div",
|
|
3702
|
+
{
|
|
3703
|
+
ref: containerRef,
|
|
3704
|
+
className: "size-full min-h-64",
|
|
3705
|
+
style: { cursor },
|
|
3706
|
+
role: "region",
|
|
3707
|
+
"aria-label": labels.region,
|
|
3708
|
+
"aria-roledescription": labels.roleDescription,
|
|
3709
|
+
...rest["aria-label"] === void 0 ? {} : { "aria-label": rest["aria-label"] },
|
|
3710
|
+
"aria-describedby": textAlternative === "none" ? void 0 : textId,
|
|
3711
|
+
"aria-busy": anyLoading ? true : void 0,
|
|
3712
|
+
"data-map-idle": idle && !anyLoading ? "true" : "false",
|
|
3713
|
+
"data-map-status": status,
|
|
3714
|
+
onPointerMove,
|
|
3715
|
+
onPointerLeave,
|
|
3716
|
+
onClick
|
|
3717
|
+
}
|
|
3718
|
+
),
|
|
3719
|
+
projections.map((projection) => {
|
|
3720
|
+
if (projection.kind !== "points" || !projection.visible || !domPointLayers.has(projection.id)) return null;
|
|
3721
|
+
const spec = internal.layerSpecs.find((s) => s.id === projection.id);
|
|
3722
|
+
if (spec?.kind !== "points") return null;
|
|
3723
|
+
const clusterOptions = spec.cluster;
|
|
3724
|
+
return /* @__PURE__ */ jsx(
|
|
3725
|
+
DomMarkerLayer,
|
|
3726
|
+
{
|
|
3727
|
+
instance,
|
|
3728
|
+
ready,
|
|
3729
|
+
layerId: projection.id,
|
|
3730
|
+
points: projection.points,
|
|
3731
|
+
shape: projection.marker,
|
|
3732
|
+
magnitudeRange: projection.magnitudeRange,
|
|
3733
|
+
cluster: clusterOptions === false || clusterOptions === void 0 ? false : (
|
|
3734
|
+
// A coarse pointer clusters harder: at a 44px target, two pins closer than 44px have
|
|
3735
|
+
// overlapping targets, so the radius keys off the POINTER rather than being fixed.
|
|
3736
|
+
{ radius: clusterOptions.radius ?? (coarsePointer ? 64 : 48), maxZoom: clusterOptions.maxZoom ?? 14 }
|
|
3737
|
+
),
|
|
3738
|
+
cameraTick: tick,
|
|
3739
|
+
zoom,
|
|
3740
|
+
selectedKeys: new Set(view.selected.filter((r) => r.layerId === projection.id).map((r) => r.featureId)),
|
|
3741
|
+
renderMarker: spec.renderMarker,
|
|
3742
|
+
clusterLabel: (count) => labels.clusterOf({ count }),
|
|
3743
|
+
formatCount: (count) => new Intl.NumberFormat(locale).format(count),
|
|
3744
|
+
markerTitle: labels.engineMarkerTitle,
|
|
3745
|
+
coincident: clusterOptions === false || clusterOptions === void 0 ? "stack" : clusterOptions.coincident ?? "stack",
|
|
3746
|
+
onPick: (point, at) => {
|
|
3747
|
+
view.select([{ layerId: projection.id, featureId: point.key }]);
|
|
3748
|
+
setPopup({ layerId: projection.id, featureId: point.key, x: at.x, y: at.y, point: point.row });
|
|
3749
|
+
},
|
|
3750
|
+
onExpand: (entry) => {
|
|
3751
|
+
if (!instance || !handle) return;
|
|
3752
|
+
const target = centroidOf(entry.members.map((m) => m.position));
|
|
3753
|
+
moveCamera(instance, {
|
|
3754
|
+
center: target,
|
|
3755
|
+
zoom: Math.min(handle.getCamera().zoom + 2, 18),
|
|
3756
|
+
transition: reducedMotion ? "jump" : "ease",
|
|
3757
|
+
duration: 500
|
|
3758
|
+
});
|
|
3759
|
+
}
|
|
3760
|
+
},
|
|
3761
|
+
projection.id
|
|
3762
|
+
);
|
|
3763
|
+
}),
|
|
3764
|
+
/* @__PURE__ */ jsxs("div", { className: "pointer-events-none absolute inset-0 flex min-h-0 flex-col justify-between p-3", children: [
|
|
3765
|
+
/* @__PURE__ */ jsx(MapChrome, { view, controls, labels, root, formatNumber }),
|
|
3766
|
+
/* @__PURE__ */ jsxs("div", { className: "flex min-h-0 flex-col gap-2", children: [
|
|
3767
|
+
/* @__PURE__ */ jsxs("div", { className: "flex min-h-0 items-end justify-between gap-3", children: [
|
|
3768
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col items-start gap-1.5", children: [
|
|
3769
|
+
controls.includes("scale") ? /* @__PURE__ */ jsx(ScaleBar, { zoom: view.camera.zoom, latitude: view.camera.center[1], labels }) : null,
|
|
3770
|
+
credit ? /* @__PURE__ */ jsx("span", { className: "pointer-events-auto rounded-sm bg-primary px-1.5 py-0.5 text-2xs text-quaternary ring-1 ring-secondary ring-inset", children: credit }) : null
|
|
3771
|
+
] }),
|
|
3772
|
+
/* @__PURE__ */ jsx("div", { ref: legendRef, className: "ml-auto", children: legendLayout ? /* @__PURE__ */ jsx(Legend, { sections: legendSections, collapse: legendCollapse, labels }) : null })
|
|
3773
|
+
] }),
|
|
3774
|
+
transport === "bar" && view.time ? /* @__PURE__ */ jsx(
|
|
3775
|
+
TimeBar,
|
|
3776
|
+
{
|
|
3777
|
+
time: view.time,
|
|
3778
|
+
labels,
|
|
3779
|
+
playable: internal.playbackEnabled,
|
|
3780
|
+
onFrame: view.setFrame,
|
|
3781
|
+
onPlaying: view.setPlaying,
|
|
3782
|
+
onHeight: onTimeHeight
|
|
3783
|
+
}
|
|
3784
|
+
) : null
|
|
3785
|
+
] })
|
|
3786
|
+
] }),
|
|
3787
|
+
status === "unsupported" && !staticImage ? /* @__PURE__ */ jsx("div", { className: "absolute inset-x-0 top-0 bg-primary p-4 text-center text-sm text-tertiary", children: labels.unsupported }) : null,
|
|
3788
|
+
status === "unsupported" && staticImage ? (
|
|
3789
|
+
// Coherent ONLY when the caller supplies the image: generating one would need a rendering
|
|
3790
|
+
// service we do not run and would ship the caller's data to it — an operational and privacy
|
|
3791
|
+
// commitment disguised as a convenience.
|
|
3792
|
+
/* @__PURE__ */ jsx("img", { src: staticImage.image, alt: staticImage.alt, className: "absolute inset-0 size-full object-cover" })
|
|
3793
|
+
) : null,
|
|
3794
|
+
ready && anyLoading ? /* @__PURE__ */ jsx("div", { className: "pointer-events-none absolute inset-0", "aria-hidden": "true", children: /* @__PURE__ */ jsx(Skeleton, { className: "size-full rounded-none" }) }) : null,
|
|
3795
|
+
ready && !anyLoading && projections.length > 0 && projections.every((p) => p.renderedCount === 0) ? /* @__PURE__ */ jsx("div", { className: "pointer-events-none absolute inset-0 flex items-center justify-center p-4", children: /* @__PURE__ */ jsx(Card, { variant: "outlined", shadow: "sm", padding: "md", children: /* @__PURE__ */ jsx("span", { className: "text-sm text-tertiary", children: labels.empty }) }) }) : null,
|
|
3796
|
+
projections.some((p) => p.kind === "choropleth" && p.error !== void 0) ? /* @__PURE__ */ jsx("div", { className: "pointer-events-auto absolute inset-x-0 bottom-14 mx-auto w-fit", children: /* @__PURE__ */ jsx(Card, { variant: "outlined", shadow: "md", padding: "sm", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
|
|
3797
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm text-error-primary", children: labels.loadError }),
|
|
3798
|
+
/* @__PURE__ */ jsx(Button, { size: "sm", variant: "secondary", onClick: () => view.drillUp(), children: labels.retry })
|
|
3799
|
+
] }) }) }) : null,
|
|
3800
|
+
/* @__PURE__ */ jsx("div", { "aria-live": "polite", className: "sr-only", children: /* @__PURE__ */ jsx("span", { children: announcement.text }, announcement.seq) }),
|
|
3801
|
+
tooltip ? /* @__PURE__ */ jsx(
|
|
3802
|
+
MapTooltip,
|
|
3803
|
+
{
|
|
3804
|
+
x: tooltip.x,
|
|
3805
|
+
y: tooltip.y,
|
|
3806
|
+
width: canvasBox.width,
|
|
3807
|
+
height: canvasBox.height,
|
|
3808
|
+
title: tooltip.title,
|
|
3809
|
+
value: tooltip.value,
|
|
3810
|
+
body: tooltip.body
|
|
3811
|
+
}
|
|
3812
|
+
) : null,
|
|
3813
|
+
popup ? /* @__PURE__ */ jsx(
|
|
3814
|
+
MapPopup,
|
|
3815
|
+
{
|
|
3816
|
+
popup,
|
|
3817
|
+
projections,
|
|
3818
|
+
specs: internal.layerSpecs,
|
|
3819
|
+
labels,
|
|
3820
|
+
formatNumber,
|
|
3821
|
+
onClose: () => setPopup(void 0)
|
|
3822
|
+
}
|
|
3823
|
+
) : null,
|
|
3824
|
+
textAlternative === "none" && !(status === "unsupported" && fallback === "text") ? null : /* @__PURE__ */ jsx(TextAlternative, { id: textId, projections, labels, visible: showText, kindLabel: (kind) => kindLabels[kind] })
|
|
3825
|
+
]
|
|
3826
|
+
}
|
|
3827
|
+
);
|
|
3828
|
+
}
|
|
3829
|
+
function describeFeature(projection, spec, featureId, point, which, formatNumber) {
|
|
3830
|
+
if (!projection || !spec) return void 0;
|
|
3831
|
+
if (projection.kind === "choropleth" && spec.kind === "choropleth") {
|
|
3832
|
+
const outcome = projection.join?.byKey.get(featureId);
|
|
3833
|
+
const feature = projection.features?.features.find((f) => String(f.properties?.[projection.joinProperty] ?? "") === featureId);
|
|
3834
|
+
const render = which === "tooltip" ? spec.renderTooltip : spec.renderPopup;
|
|
3835
|
+
const measure = outcome?.measure;
|
|
3836
|
+
return {
|
|
3837
|
+
title: projection.nameByKey.get(featureId) ?? featureId,
|
|
3838
|
+
// A categorical scale's answer is a WORD, a quantitative one's is a formatted number, and an
|
|
3839
|
+
// unjoined feature has neither — which is a real state and must read as absent rather than as
|
|
3840
|
+
// zero, the classic choropleth lie.
|
|
3841
|
+
value: measure?.kind === "value" ? projection.format(measure.value) : measure?.kind === "category" ? measure.category : void 0,
|
|
3842
|
+
// `rows` PLURAL and possibly EMPTY — an unjoined feature must render rather than crash.
|
|
3843
|
+
body: feature && render ? render(feature, outcome?.rows ?? []) : void 0
|
|
3844
|
+
};
|
|
3845
|
+
}
|
|
3846
|
+
if (projection.kind === "points" && spec.kind === "points") {
|
|
3847
|
+
const found = projection.points.find((p) => p.key === featureId);
|
|
3848
|
+
const row = point ?? found?.row;
|
|
3849
|
+
const render = which === "tooltip" ? spec.renderTooltip : spec.renderPopup;
|
|
3850
|
+
return {
|
|
3851
|
+
title: found?.name ?? featureId,
|
|
3852
|
+
// Only where the layer actually encodes one: a plain marker has no magnitude, and printing "0"
|
|
3853
|
+
// for it would be inventing a measurement.
|
|
3854
|
+
value: found?.magnitude === void 0 ? void 0 : formatNumber(found.magnitude),
|
|
3855
|
+
body: row === void 0 ? void 0 : render?.(row)
|
|
3856
|
+
};
|
|
3857
|
+
}
|
|
3858
|
+
if (projection.kind === "areas" && spec.kind === "areas") {
|
|
3859
|
+
const index = projection.features.features.findIndex((f) => String(f.id ?? "") === featureId);
|
|
3860
|
+
const feature = projection.features.features[index];
|
|
3861
|
+
return {
|
|
3862
|
+
title: projection.names[index] ?? featureId,
|
|
3863
|
+
body: feature && which === "popup" ? spec.renderPopup?.(feature) : void 0
|
|
3864
|
+
};
|
|
3865
|
+
}
|
|
3866
|
+
if (projection.kind === "lines" && spec.kind === "lines") {
|
|
3867
|
+
const line = projection.lines.find((l) => l.key === featureId);
|
|
3868
|
+
return { title: line?.name ?? featureId, body: line && which === "popup" ? spec.renderPopup?.(line.row) : void 0 };
|
|
3869
|
+
}
|
|
3870
|
+
return void 0;
|
|
3871
|
+
}
|
|
3872
|
+
function MapPopup({
|
|
3873
|
+
popup,
|
|
3874
|
+
projections,
|
|
3875
|
+
specs,
|
|
3876
|
+
labels,
|
|
3877
|
+
formatNumber,
|
|
3878
|
+
onClose
|
|
3879
|
+
}) {
|
|
3880
|
+
const described = describeFeature(
|
|
3881
|
+
projections.find((p) => p.id === popup.layerId),
|
|
3882
|
+
specs.find((s) => s.id === popup.layerId),
|
|
3883
|
+
popup.featureId,
|
|
3884
|
+
popup.point,
|
|
3885
|
+
"popup",
|
|
3886
|
+
formatNumber
|
|
3887
|
+
);
|
|
3888
|
+
if (!described) return null;
|
|
3889
|
+
const body = described.body ?? /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-0.5 pr-5", children: [
|
|
3890
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm font-medium text-primary", children: described.title }),
|
|
3891
|
+
described.value === void 0 ? null : /* @__PURE__ */ jsx("span", { className: "text-sm text-secondary tabular-nums", children: described.value })
|
|
3892
|
+
] });
|
|
3893
|
+
return /* @__PURE__ */ jsx(
|
|
3894
|
+
"div",
|
|
3895
|
+
{
|
|
3896
|
+
className: "pointer-events-auto absolute z-10 max-w-64",
|
|
3897
|
+
style: { left: popup.x, top: popup.y },
|
|
3898
|
+
role: "dialog",
|
|
3899
|
+
"aria-label": described.title,
|
|
3900
|
+
onClick: (event) => event.stopPropagation(),
|
|
3901
|
+
children: /* @__PURE__ */ jsxs(Card, { variant: "outlined", shadow: "lg", padding: "sm", children: [
|
|
3902
|
+
body,
|
|
3903
|
+
/* @__PURE__ */ jsx("div", { className: "absolute top-1 right-1", children: /* @__PURE__ */ jsx(ButtonUtility, { size: "xs", variant: "tertiary", icon: /* @__PURE__ */ jsx(XIcon, {}), tooltip: labels.closePopup, onClick: onClose }) })
|
|
3904
|
+
] })
|
|
3905
|
+
}
|
|
3906
|
+
);
|
|
3907
|
+
}
|
|
3908
|
+
function useAnnouncement(projections, view, labels, format) {
|
|
3909
|
+
const previous = useRef(void 0);
|
|
3910
|
+
const current = useRef({ text: "", seq: 0 });
|
|
3911
|
+
const trail = view.drill.frames;
|
|
3912
|
+
const tip = trail.at(-1);
|
|
3913
|
+
const snapshot = {
|
|
3914
|
+
visible: view.layers.map((layer) => `${layer.id}:${layer.visible ? 1 : 0}`).join(","),
|
|
3915
|
+
frame: view.time?.frame,
|
|
3916
|
+
selected: view.selected.length,
|
|
3917
|
+
depth: trail.length,
|
|
3918
|
+
parent: tip?.parentLabel,
|
|
3919
|
+
/* The rendered counts, and this one is not an EVENT — it is what stops the opening description
|
|
3920
|
+
* freezing. A map's first render happens before its projections have landed, so `describe()` runs
|
|
3921
|
+
* against zeros; without this the live region kept "Showing 0 …" for the rest of the session,
|
|
3922
|
+
* because nothing the reader did had changed. Verified in the browser, not in jsdom: the mock
|
|
3923
|
+
* engine settles synchronously, so every unit test saw the final counts on render one. */
|
|
3924
|
+
counts: projections.map((p) => `${p.id}:${p.renderedCount}`).join(",")
|
|
3925
|
+
};
|
|
3926
|
+
const previousSnapshot = previous.current;
|
|
3927
|
+
previous.current = snapshot;
|
|
3928
|
+
if (!previousSnapshot) {
|
|
3929
|
+
current.current = { text: describe(projections, view, labels, format), seq: 0 };
|
|
3930
|
+
return current.current;
|
|
3931
|
+
}
|
|
3932
|
+
const say = (text) => {
|
|
3933
|
+
if (!text || text === current.current.text) {
|
|
3934
|
+
if (text) current.current = { text, seq: current.current.seq + 1 };
|
|
3935
|
+
return current.current;
|
|
3936
|
+
}
|
|
3937
|
+
current.current = { text, seq: current.current.seq + 1 };
|
|
3938
|
+
return current.current;
|
|
3939
|
+
};
|
|
3940
|
+
if (snapshot.depth !== previousSnapshot.depth || snapshot.parent !== previousSnapshot.parent) {
|
|
3941
|
+
return say(describe(projections, view, labels, format));
|
|
3942
|
+
}
|
|
3943
|
+
if (snapshot.frame !== previousSnapshot.frame) {
|
|
3944
|
+
const frame = view.time?.frames.find((f) => f.key === view.time?.frame);
|
|
3945
|
+
if (frame) return say(labels.frameChanged({ frame: frame.label }));
|
|
3946
|
+
}
|
|
3947
|
+
if (snapshot.visible !== previousSnapshot.visible) {
|
|
3948
|
+
const before = new Map(previousSnapshot.visible.split(",").map((pair) => pair.split(":")));
|
|
3949
|
+
const changed = view.layers.find((layer) => before.get(layer.id) !== (layer.visible ? "1" : "0"));
|
|
3950
|
+
if (changed) return say(changed.visible ? labels.layerShown({ layer: changed.label }) : labels.layerHidden({ layer: changed.label }));
|
|
3951
|
+
}
|
|
3952
|
+
if (snapshot.selected !== previousSnapshot.selected && snapshot.selected === 0) {
|
|
3953
|
+
return say(labels.selectionCleared);
|
|
3954
|
+
}
|
|
3955
|
+
if (snapshot.counts !== previousSnapshot.counts) {
|
|
3956
|
+
const text = describe(projections, view, labels, format);
|
|
3957
|
+
if (text !== current.current.text) current.current = { text, seq: current.current.seq };
|
|
3958
|
+
}
|
|
3959
|
+
return current.current;
|
|
3960
|
+
}
|
|
3961
|
+
function describe(projections, view, labels, format) {
|
|
3962
|
+
if (projections.some((p) => p.kind === "choropleth" && p.loading)) return labels.loading;
|
|
3963
|
+
const trail = view.drill.frames;
|
|
3964
|
+
const choropleth = trail.length > 0 ? projections.find((p) => p.kind === "choropleth") : void 0;
|
|
3965
|
+
if (choropleth?.kind === "choropleth") {
|
|
3966
|
+
const tip = trail.at(-1);
|
|
3967
|
+
if (trail.length > 1 && tip?.parentLabel) {
|
|
3968
|
+
return labels.drilledInto({ parent: tip.parentLabel, level: choropleth.level.label, count: choropleth.renderedCount });
|
|
3969
|
+
}
|
|
3970
|
+
return labels.drilledUpTo({ level: choropleth.level.label, count: choropleth.renderedCount });
|
|
3971
|
+
}
|
|
3972
|
+
const visible = view.layers.filter((layer) => layer.visible);
|
|
3973
|
+
if (visible.length === 0) return "";
|
|
3974
|
+
return visible.map((layer) => labels.showingLayer({ count: format(layer.renderedCount), layer: layer.label })).join(", ");
|
|
3975
|
+
}
|
|
3976
|
+
function tonesPainted(projection) {
|
|
3977
|
+
const source = projection.kind === "points" ? projection.points.map((p) => p.tone) : projection.kind === "lines" ? projection.lines.map((l) => l.tone) : projection.kind === "areas" ? projection.toneByIndex : [];
|
|
3978
|
+
return [...new Set(source)];
|
|
3979
|
+
}
|
|
3980
|
+
var warnedUnkeyed = /* @__PURE__ */ new Set();
|
|
3981
|
+
var warnedForcedDom = /* @__PURE__ */ new Set();
|
|
3982
|
+
function warnMarkerForcesDom(layerId2) {
|
|
3983
|
+
if (warnedForcedDom.has(layerId2)) return;
|
|
3984
|
+
warnedForcedDom.add(layerId2);
|
|
3985
|
+
devWarn(
|
|
3986
|
+
`<DataMap> layer "${layerId2}" sets \`mode: "gl"\` and also supplies \`renderMarker\`, so it is drawing DOM markers instead. A React node cannot live in a WebGL circle \u2014 drop one of the two, and note the DOM path is right only up to ~300 rendered points.`
|
|
3987
|
+
);
|
|
3988
|
+
}
|
|
3989
|
+
function warnUnkeyedTones(layerId2, count) {
|
|
3990
|
+
if (warnedUnkeyed.has(layerId2)) return;
|
|
3991
|
+
warnedUnkeyed.add(layerId2);
|
|
3992
|
+
devWarn(
|
|
3993
|
+
`<DataMap> layer "${layerId2}" paints ${count} different tones but has no \`toneLabels\`, so its colours appear in no legend. Add \`toneLabels: { error: "Closing", success: "Open" }\` \u2014 only you know what a colour means, and a reader who has to guess is reading a picture rather than the data.`
|
|
3994
|
+
);
|
|
3995
|
+
}
|
|
3996
|
+
function centroidOf(positions) {
|
|
3997
|
+
let lng = 0;
|
|
3998
|
+
let lat = 0;
|
|
3999
|
+
for (const position of positions) {
|
|
4000
|
+
lng += position[0];
|
|
4001
|
+
lat += position[1];
|
|
4002
|
+
}
|
|
4003
|
+
return [lng / positions.length, lat / positions.length];
|
|
4004
|
+
}
|
|
4005
|
+
var onMoveStart = (instance, listener) => onMapEvent(instance, "movestart", listener);
|
|
4006
|
+
var onMoveEnd = (instance, listener) => onMapEvent(instance, "moveend", listener);
|
|
4007
|
+
var onIdle = (instance, listener) => onMapEvent(instance, "idle", listener);
|
|
4008
|
+
|
|
4009
|
+
// src/components/data-map/drill.ts
|
|
4010
|
+
function initialDrillState(rootLevel) {
|
|
4011
|
+
return { stack: [{ level: rootLevel }], generation: 0, status: "idle", settledDepth: 0 };
|
|
4012
|
+
}
|
|
4013
|
+
function backTarget(state) {
|
|
4014
|
+
const speculative = state.settledDepth < state.stack.length - 1;
|
|
4015
|
+
return speculative ? state.settledDepth : state.stack.length - 2;
|
|
4016
|
+
}
|
|
4017
|
+
function drillReducer(state, action) {
|
|
4018
|
+
switch (action.type) {
|
|
4019
|
+
case "drill": {
|
|
4020
|
+
const frame = {
|
|
4021
|
+
level: action.level,
|
|
4022
|
+
parentId: action.parentId,
|
|
4023
|
+
parentLabel: action.parentLabel,
|
|
4024
|
+
parentBounds: action.parentBounds
|
|
4025
|
+
};
|
|
4026
|
+
const base = state.stack.slice(0, state.settledDepth + 1);
|
|
4027
|
+
const stack = [...base, frame];
|
|
4028
|
+
return {
|
|
4029
|
+
stack,
|
|
4030
|
+
generation: state.generation + 1,
|
|
4031
|
+
status: action.cached ? "idle" : "loading",
|
|
4032
|
+
data: action.cached ?? state.data,
|
|
4033
|
+
error: void 0,
|
|
4034
|
+
// A cache hit settles immediately; a miss leaves the tip speculative.
|
|
4035
|
+
settledDepth: action.cached ? stack.length - 1 : state.settledDepth
|
|
4036
|
+
};
|
|
4037
|
+
}
|
|
4038
|
+
case "back": {
|
|
4039
|
+
const depth = action.to ?? backTarget(state);
|
|
4040
|
+
if (depth < 0 || depth >= state.stack.length) return state;
|
|
4041
|
+
if (depth === state.settledDepth && depth === state.stack.length - 1) return state;
|
|
4042
|
+
const stack = state.stack.slice(0, depth + 1);
|
|
4043
|
+
return {
|
|
4044
|
+
stack,
|
|
4045
|
+
// Bumped on `back` too: a forward request still in flight must not land afterwards.
|
|
4046
|
+
generation: state.generation + 1,
|
|
4047
|
+
status: action.cached ? "idle" : "loading",
|
|
4048
|
+
data: action.cached ?? state.data,
|
|
4049
|
+
error: void 0,
|
|
4050
|
+
settledDepth: action.cached ? stack.length - 1 : Math.min(state.settledDepth, stack.length - 1)
|
|
4051
|
+
};
|
|
4052
|
+
}
|
|
4053
|
+
case "resolved": {
|
|
4054
|
+
if (action.generation !== state.generation) return state;
|
|
4055
|
+
return {
|
|
4056
|
+
...state,
|
|
4057
|
+
status: "idle",
|
|
4058
|
+
data: action.data,
|
|
4059
|
+
error: void 0,
|
|
4060
|
+
// The tip is no longer speculative: the canvas now paints what the breadcrumb says.
|
|
4061
|
+
settledDepth: state.stack.length - 1
|
|
4062
|
+
};
|
|
4063
|
+
}
|
|
4064
|
+
case "failed": {
|
|
4065
|
+
if (action.generation !== state.generation) return state;
|
|
4066
|
+
return { ...state, status: "error", error: action.error };
|
|
4067
|
+
}
|
|
4068
|
+
}
|
|
4069
|
+
}
|
|
4070
|
+
var settledFrame = (state) => state.stack[state.settledDepth] ?? state.stack.at(-1) ?? state.stack[0];
|
|
4071
|
+
var tipFrame = (state) => state.stack.at(-1) ?? state.stack[0];
|
|
4072
|
+
var cacheKey = (level, parentId) => `${level}:${parentId ?? "*"}`;
|
|
4073
|
+
var _entries;
|
|
4074
|
+
var LevelCache = class {
|
|
4075
|
+
constructor(max = 12) {
|
|
4076
|
+
this.max = max;
|
|
4077
|
+
__privateAdd(this, _entries, /* @__PURE__ */ new Map());
|
|
4078
|
+
}
|
|
4079
|
+
get(key) {
|
|
4080
|
+
const hit = __privateGet(this, _entries).get(key);
|
|
4081
|
+
if (!hit) return void 0;
|
|
4082
|
+
__privateGet(this, _entries).delete(key);
|
|
4083
|
+
__privateGet(this, _entries).set(key, hit);
|
|
4084
|
+
return hit;
|
|
4085
|
+
}
|
|
4086
|
+
set(key, value) {
|
|
4087
|
+
if (__privateGet(this, _entries).has(key)) __privateGet(this, _entries).delete(key);
|
|
4088
|
+
__privateGet(this, _entries).set(key, value);
|
|
4089
|
+
while (__privateGet(this, _entries).size > this.max) {
|
|
4090
|
+
const oldest = __privateGet(this, _entries).keys().next().value;
|
|
4091
|
+
if (oldest === void 0) break;
|
|
4092
|
+
__privateGet(this, _entries).delete(oldest);
|
|
4093
|
+
}
|
|
4094
|
+
}
|
|
4095
|
+
clear() {
|
|
4096
|
+
__privateGet(this, _entries).clear();
|
|
4097
|
+
}
|
|
4098
|
+
get size() {
|
|
4099
|
+
return __privateGet(this, _entries).size;
|
|
4100
|
+
}
|
|
4101
|
+
};
|
|
4102
|
+
_entries = new WeakMap();
|
|
4103
|
+
function boundsOf(data) {
|
|
4104
|
+
if (data.bbox) return data.bbox;
|
|
4105
|
+
let west = Infinity;
|
|
4106
|
+
let south = Infinity;
|
|
4107
|
+
let east = -Infinity;
|
|
4108
|
+
let north = -Infinity;
|
|
4109
|
+
let seen = false;
|
|
4110
|
+
const take = (lng, lat) => {
|
|
4111
|
+
if (!Number.isFinite(lng) || !Number.isFinite(lat)) return;
|
|
4112
|
+
seen = true;
|
|
4113
|
+
if (lng < west) west = lng;
|
|
4114
|
+
if (lng > east) east = lng;
|
|
4115
|
+
if (lat < south) south = lat;
|
|
4116
|
+
if (lat > north) north = lat;
|
|
4117
|
+
};
|
|
4118
|
+
const walk = (node) => {
|
|
4119
|
+
if (!Array.isArray(node)) return;
|
|
4120
|
+
if (typeof node[0] === "number" && typeof node[1] === "number") {
|
|
4121
|
+
take(node[0], node[1]);
|
|
4122
|
+
return;
|
|
4123
|
+
}
|
|
4124
|
+
for (const child of node) walk(child);
|
|
4125
|
+
};
|
|
4126
|
+
for (const feature of data.features) {
|
|
4127
|
+
if (feature.bbox) {
|
|
4128
|
+
const [w, s, e, n] = feature.bbox;
|
|
4129
|
+
take(w, s);
|
|
4130
|
+
take(e, n);
|
|
4131
|
+
continue;
|
|
4132
|
+
}
|
|
4133
|
+
const bboxProperty = feature.properties?.bbox;
|
|
4134
|
+
if (Array.isArray(bboxProperty) && bboxProperty.length === 4) {
|
|
4135
|
+
take(Number(bboxProperty[0]), Number(bboxProperty[1]));
|
|
4136
|
+
take(Number(bboxProperty[2]), Number(bboxProperty[3]));
|
|
4137
|
+
continue;
|
|
4138
|
+
}
|
|
4139
|
+
walk(feature.geometry?.coordinates);
|
|
4140
|
+
}
|
|
4141
|
+
return seen ? [west, south, east, north] : void 0;
|
|
4142
|
+
}
|
|
4143
|
+
|
|
4144
|
+
// src/components/data-map/projection.ts
|
|
4145
|
+
var defaultFeatureName = (feature) => String(feature.properties?.name ?? "");
|
|
4146
|
+
function makeFormatter(locale, span2) {
|
|
4147
|
+
const formatter = new Intl.NumberFormat(locale, { maximumFractionDigits: span2 >= 100 ? 0 : 2 });
|
|
4148
|
+
return (value) => formatter.format(value);
|
|
4149
|
+
}
|
|
4150
|
+
function projectLayer(layer, context) {
|
|
4151
|
+
const override = context.overrides.get(layer.id);
|
|
4152
|
+
const base = {
|
|
4153
|
+
id: layer.id,
|
|
4154
|
+
label: layer.label ?? context.kindLabels[layer.kind],
|
|
4155
|
+
visible: override?.visible ?? layer.visible ?? true,
|
|
4156
|
+
opacity: override?.opacity ?? layer.opacity ?? "full",
|
|
4157
|
+
interactive: layer.interactive ?? layer.kind !== "raster"
|
|
4158
|
+
};
|
|
4159
|
+
switch (layer.kind) {
|
|
4160
|
+
case "choropleth": {
|
|
4161
|
+
const drill = context.drill.get(layer.id);
|
|
4162
|
+
const features = drill?.features ?? (isLevels(layer.features) ? void 0 : layer.features);
|
|
4163
|
+
const level = drill?.level ?? (isLevels(layer.features) ? layer.features.levels[0] : { key: layer.id, label: base.label });
|
|
4164
|
+
if (!features) {
|
|
4165
|
+
return {
|
|
4166
|
+
...base,
|
|
4167
|
+
kind: "choropleth",
|
|
4168
|
+
joinProperty: layer.joinOn.feature,
|
|
4169
|
+
nameByKey: /* @__PURE__ */ new Map(),
|
|
4170
|
+
format: makeFormatter(context.locale, 0),
|
|
4171
|
+
level,
|
|
4172
|
+
loading: drill?.loading ?? true,
|
|
4173
|
+
error: drill?.error,
|
|
4174
|
+
canDrill: drill?.canDrill ?? false,
|
|
4175
|
+
renderedCount: 0
|
|
4176
|
+
};
|
|
4177
|
+
}
|
|
4178
|
+
const join = joinRows(features.features, filterByFrame(layer.rows, layer.frame, context.frame), {
|
|
4179
|
+
joinOn: layer.joinOn,
|
|
4180
|
+
scale: layer.scale,
|
|
4181
|
+
// With a hierarchy, `rows` is ONE flat set covering every level, so most rows are legitimately
|
|
4182
|
+
// unmatched at any moment and the warning would fire on every correct usage.
|
|
4183
|
+
warnUnmatchedRows: !isLevels(layer.features)
|
|
4184
|
+
});
|
|
4185
|
+
const data = [];
|
|
4186
|
+
for (const outcome of join.outcomes) {
|
|
4187
|
+
if (outcome.measure.kind === "value") data.push({ key: outcome.key, value: outcome.measure.value });
|
|
4188
|
+
else if (outcome.measure.kind === "category") data.push({ key: outcome.key, category: outcome.measure.category });
|
|
4189
|
+
}
|
|
4190
|
+
const scale = resolveScale(layer.scale, data, { mode: context.mode, hasNoData: join.diagnostics.hasNoData, noDataStroke: context.noDataStroke });
|
|
4191
|
+
let span2 = 0;
|
|
4192
|
+
if (scale.bins && scale.bins.bins.length > 0) {
|
|
4193
|
+
const first = scale.bins.bins[0];
|
|
4194
|
+
const last = scale.bins.bins.at(-1);
|
|
4195
|
+
if (first && last) span2 = last.max - first.min;
|
|
4196
|
+
}
|
|
4197
|
+
const nameOf = layer.name ?? defaultFeatureName;
|
|
4198
|
+
const nameByKey = /* @__PURE__ */ new Map();
|
|
4199
|
+
for (const feature of features.features) {
|
|
4200
|
+
const key = feature.properties?.[layer.joinOn.feature];
|
|
4201
|
+
if (key !== void 0 && key !== null) nameByKey.set(String(key), nameOf(feature));
|
|
4202
|
+
}
|
|
4203
|
+
return {
|
|
4204
|
+
...base,
|
|
4205
|
+
kind: "choropleth",
|
|
4206
|
+
features,
|
|
4207
|
+
join,
|
|
4208
|
+
scale,
|
|
4209
|
+
joinProperty: layer.joinOn.feature,
|
|
4210
|
+
nameByKey,
|
|
4211
|
+
format: layer.scale.kind === "categorical" ? String : layer.scale.formatValue ?? makeFormatter(context.locale, span2),
|
|
4212
|
+
level,
|
|
4213
|
+
loading: drill?.loading ?? false,
|
|
4214
|
+
error: drill?.error,
|
|
4215
|
+
canDrill: drill?.canDrill ?? false,
|
|
4216
|
+
renderedCount: join.outcomes.length
|
|
4217
|
+
};
|
|
4218
|
+
}
|
|
4219
|
+
case "points": {
|
|
4220
|
+
const rows = filterByFrame(layer.rows, layer.frame, context.frame);
|
|
4221
|
+
const points = rows.map((row) => ({
|
|
4222
|
+
key: layer.key(row),
|
|
4223
|
+
position: layer.position(row),
|
|
4224
|
+
name: layer.name?.(row),
|
|
4225
|
+
tone: toneOf(layer.tone, row),
|
|
4226
|
+
magnitude: layer.size?.value(row),
|
|
4227
|
+
row
|
|
4228
|
+
}));
|
|
4229
|
+
let magnitudeRange;
|
|
4230
|
+
if (layer.size !== void 0) {
|
|
4231
|
+
let min = Infinity;
|
|
4232
|
+
let max = -Infinity;
|
|
4233
|
+
for (const point of points) {
|
|
4234
|
+
if (point.magnitude === void 0 || !Number.isFinite(point.magnitude)) continue;
|
|
4235
|
+
min = Math.min(min, point.magnitude);
|
|
4236
|
+
max = Math.max(max, point.magnitude);
|
|
4237
|
+
}
|
|
4238
|
+
magnitudeRange = Number.isFinite(min) && max > min ? [min, max] : void 0;
|
|
4239
|
+
}
|
|
4240
|
+
if (layer.cluster && "radius" in layer.cluster) warnPositiveInt("<DataMap> points cluster", "radius", layer.cluster.radius);
|
|
4241
|
+
return {
|
|
4242
|
+
...base,
|
|
4243
|
+
kind: "points",
|
|
4244
|
+
points,
|
|
4245
|
+
marker: layer.marker ?? "pin",
|
|
4246
|
+
sizeRange: layer.size?.range ?? "md",
|
|
4247
|
+
magnitudeRange,
|
|
4248
|
+
clustered: layer.cluster !== false && layer.cluster !== void 0,
|
|
4249
|
+
renderedCount: points.length
|
|
4250
|
+
};
|
|
4251
|
+
}
|
|
4252
|
+
case "heatmap": {
|
|
4253
|
+
const rows = filterByFrame(layer.rows, layer.frame, context.frame);
|
|
4254
|
+
const raw2 = rows.map((row) => ({ position: layer.position(row), weight: layer.weight?.(row) ?? 1 }));
|
|
4255
|
+
let max = 0;
|
|
4256
|
+
for (const w of raw2) if (w.weight > max) max = w.weight;
|
|
4257
|
+
const weights = max > 0 && max !== 1 ? raw2.map((w) => ({ position: w.position, weight: w.weight / max })) : raw2;
|
|
4258
|
+
return { ...base, kind: "heatmap", weights, ramp: layer.ramp, renderedCount: weights.length };
|
|
4259
|
+
}
|
|
4260
|
+
case "lines": {
|
|
4261
|
+
const rows = filterByFrame(layer.rows, layer.frame, context.frame);
|
|
4262
|
+
const lines = rows.map((row) => ({
|
|
4263
|
+
key: layer.key(row),
|
|
4264
|
+
path: layer.path(row),
|
|
4265
|
+
name: layer.name?.(row),
|
|
4266
|
+
tone: toneOf(layer.tone, row),
|
|
4267
|
+
row
|
|
4268
|
+
}));
|
|
4269
|
+
return { ...base, kind: "lines", lines, weight: layer.weight ?? "md", renderedCount: lines.length };
|
|
4270
|
+
}
|
|
4271
|
+
case "areas": {
|
|
4272
|
+
const nameOf = layer.name ?? defaultFeatureName;
|
|
4273
|
+
const toneByIndex = layer.features.features.map((feature) => toneOf(layer.tone, feature));
|
|
4274
|
+
const names = layer.features.features.map((feature) => nameOf(feature));
|
|
4275
|
+
return { ...base, kind: "areas", features: layer.features, toneByIndex, names, renderedCount: layer.features.features.length };
|
|
4276
|
+
}
|
|
4277
|
+
case "raster": {
|
|
4278
|
+
return { ...base, kind: "raster", renderedCount: 0 };
|
|
4279
|
+
}
|
|
4280
|
+
}
|
|
4281
|
+
}
|
|
4282
|
+
function filterByFrame(rows, of, frame) {
|
|
4283
|
+
if (frame === void 0 || of === void 0) return rows;
|
|
4284
|
+
return rows.filter((row) => of(row) === frame);
|
|
4285
|
+
}
|
|
4286
|
+
|
|
4287
|
+
// src/components/data-map/use-map-view.ts
|
|
4288
|
+
var SHORTHAND_BUILDERS = {
|
|
4289
|
+
choropleth: choroplethLayer,
|
|
4290
|
+
points: pointsLayer,
|
|
4291
|
+
heatmap: heatmapLayer,
|
|
4292
|
+
lines: linesLayer,
|
|
4293
|
+
areas: areasLayer,
|
|
4294
|
+
raster: rasterLayer
|
|
4295
|
+
};
|
|
4296
|
+
var SHORTHAND_KINDS = Object.keys(SHORTHAND_BUILDERS);
|
|
4297
|
+
function sameSpec(a, b, depth = 2) {
|
|
4298
|
+
if (a === b) return true;
|
|
4299
|
+
if (!a || !b || typeof a !== "object" || typeof b !== "object") return false;
|
|
4300
|
+
if (Array.isArray(a) || Array.isArray(b)) return false;
|
|
4301
|
+
const left = a;
|
|
4302
|
+
const right = b;
|
|
4303
|
+
const keys = Object.keys(left);
|
|
4304
|
+
if (keys.length !== Object.keys(right).length) return false;
|
|
4305
|
+
return keys.every((key) => depth > 1 ? sameSpec(left[key], right[key], depth - 1) : left[key] === right[key]);
|
|
4306
|
+
}
|
|
4307
|
+
var UNSTABLE_SPEC_MISSES = 12;
|
|
4308
|
+
var warnedUnstable = /* @__PURE__ */ new Set();
|
|
4309
|
+
function warnUnstableSpec(layerId2) {
|
|
4310
|
+
if (warnedUnstable.has(layerId2)) return;
|
|
4311
|
+
warnedUnstable.add(layerId2);
|
|
4312
|
+
devWarn(
|
|
4313
|
+
`<DataMap> layer "${layerId2}" has re-projected ${UNSTABLE_SPEC_MISSES} times without its data changing \u2014 its spec is a new object on every render. The usual cause is a function nested inside an inline literal (\`scale: { value: (row) => \u2026 }\`). Wrap the layer, or that accessor, in \`useMemo\`/\`useCallback\`: until then the painter re-uploads every source on every render and the map never reports idle.`
|
|
4314
|
+
);
|
|
4315
|
+
}
|
|
4316
|
+
var EMPTY_CAMERA = { center: [0, 0], zoom: 1, bearing: 0, pitch: 0 };
|
|
4317
|
+
var CENTER_EPSILON = 1e-6;
|
|
4318
|
+
var ZOOM_EPSILON = 1e-3;
|
|
4319
|
+
var near = (a, b, epsilon) => Math.abs(a - b) < epsilon;
|
|
4320
|
+
var sameCamera = (a, b) => near(a.center[0], b.center[0], CENTER_EPSILON) && near(a.center[1], b.center[1], CENTER_EPSILON) && near(a.zoom, b.zoom, ZOOM_EPSILON) && near(a.bearing, b.bearing, ZOOM_EPSILON) && near(a.pitch, b.pitch, ZOOM_EPSILON);
|
|
4321
|
+
var sameBounds = (a, b) => a.every((value, i) => near(value, b[i] ?? value, CENTER_EPSILON));
|
|
4322
|
+
var EMPTY_BBOX = [-180, -85, 180, 85];
|
|
4323
|
+
var EMPTY_LAYERS = [];
|
|
4324
|
+
var FALLBACK_KIND_LABELS = {
|
|
4325
|
+
choropleth: "Regions",
|
|
4326
|
+
points: "Locations",
|
|
4327
|
+
heatmap: "Density",
|
|
4328
|
+
lines: "Routes",
|
|
4329
|
+
areas: "Areas",
|
|
4330
|
+
raster: "Imagery"
|
|
4331
|
+
};
|
|
4332
|
+
function useMapView(options) {
|
|
4333
|
+
const { camera: cameraOptions, selection, time, onDrill, onSelect, onCameraSettle, onLayerToggle } = options;
|
|
4334
|
+
const shorthandKind = SHORTHAND_KINDS.find((kind) => options[kind] !== void 0);
|
|
4335
|
+
const shorthandSpec = shorthandKind ? options[shorthandKind] : void 0;
|
|
4336
|
+
const declared = "layers" in options ? options.layers : void 0;
|
|
4337
|
+
const synthesized = useMemo(
|
|
4338
|
+
() => shorthandKind && shorthandSpec ? [SHORTHAND_BUILDERS[shorthandKind](shorthandSpec)] : void 0,
|
|
4339
|
+
[shorthandKind, shorthandSpec]
|
|
4340
|
+
);
|
|
4341
|
+
const layers = declared ?? synthesized ?? EMPTY_LAYERS;
|
|
4342
|
+
const mode = useThemeMode();
|
|
4343
|
+
const locale = useLocaleConfig().locale?.code ?? "en";
|
|
4344
|
+
useEffect(() => {
|
|
4345
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4346
|
+
for (const layer of layers) {
|
|
4347
|
+
if (seen.has(layer.id))
|
|
4348
|
+
devWarn(
|
|
4349
|
+
`<DataMap> two layers share the id ${JSON.stringify(layer.id)}. Ids must be unique \u2014 one id keys the paint, the legend, the toggle and the accessible section.`
|
|
4350
|
+
);
|
|
4351
|
+
seen.add(layer.id);
|
|
4352
|
+
}
|
|
4353
|
+
}, [layers]);
|
|
4354
|
+
const [overrides, setOverrides] = useState(() => /* @__PURE__ */ new Map());
|
|
4355
|
+
const setLayerVisible = useCallback(
|
|
4356
|
+
(layerId2, visible) => {
|
|
4357
|
+
setOverrides((current) => {
|
|
4358
|
+
const next = new Map(current);
|
|
4359
|
+
next.set(layerId2, { ...next.get(layerId2), visible });
|
|
4360
|
+
return next;
|
|
4361
|
+
});
|
|
4362
|
+
onLayerToggle?.(layerId2, visible);
|
|
4363
|
+
},
|
|
4364
|
+
[onLayerToggle]
|
|
4365
|
+
);
|
|
4366
|
+
const setLayerOpacity = useCallback((layerId2, opacity) => {
|
|
4367
|
+
setOverrides((current) => {
|
|
4368
|
+
const next = new Map(current);
|
|
4369
|
+
next.set(layerId2, { ...next.get(layerId2), opacity });
|
|
4370
|
+
return next;
|
|
4371
|
+
});
|
|
4372
|
+
}, []);
|
|
4373
|
+
const drillable = useMemo(() => layers.filter((layer) => layer.kind === "choropleth" && isLevels(layer.features)), [layers]);
|
|
4374
|
+
const [machines, dispatchDrill] = useReducer(drillMachinesReducer, drillable, (initial) => {
|
|
4375
|
+
const map = /* @__PURE__ */ new Map();
|
|
4376
|
+
for (const layer of initial) {
|
|
4377
|
+
if (layer.kind !== "choropleth" || !isLevels(layer.features)) continue;
|
|
4378
|
+
map.set(layer.id, { state: initialDrillState(layer.features.levels[0].key), cache: new LevelCache() });
|
|
4379
|
+
}
|
|
4380
|
+
return map;
|
|
4381
|
+
});
|
|
4382
|
+
useEffect(() => {
|
|
4383
|
+
for (const layer of drillable) {
|
|
4384
|
+
if (layer.kind !== "choropleth" || !isLevels(layer.features)) continue;
|
|
4385
|
+
if (!machines.has(layer.id)) dispatchDrill({ type: "ensure", layerId: layer.id, rootLevel: layer.features.levels[0].key });
|
|
4386
|
+
}
|
|
4387
|
+
}, [drillable, machines]);
|
|
4388
|
+
const loadRef = useRef(/* @__PURE__ */ new Map());
|
|
4389
|
+
useEffect(() => {
|
|
4390
|
+
const next = /* @__PURE__ */ new Map();
|
|
4391
|
+
for (const layer of layers) if (layer.kind === "choropleth" && isLevels(layer.features)) next.set(layer.id, layer.features.load);
|
|
4392
|
+
loadRef.current = next;
|
|
4393
|
+
}, [layers]);
|
|
4394
|
+
useEffect(() => {
|
|
4395
|
+
let cancelled = false;
|
|
4396
|
+
for (const [layerId2, machine] of machines) {
|
|
4397
|
+
const needsFirstLoad = machine.state.status === "idle" && machine.state.data === void 0;
|
|
4398
|
+
if (machine.state.status !== "loading" && !needsFirstLoad) continue;
|
|
4399
|
+
const load = loadRef.current.get(layerId2);
|
|
4400
|
+
if (!load) continue;
|
|
4401
|
+
const frame2 = tipFrame(machine.state);
|
|
4402
|
+
const generation = machine.state.generation;
|
|
4403
|
+
void (async () => {
|
|
4404
|
+
try {
|
|
4405
|
+
const data = await load(frame2.level, frame2.parentId);
|
|
4406
|
+
if (cancelled) return;
|
|
4407
|
+
machine.cache.set(cacheKey(frame2.level, frame2.parentId), data);
|
|
4408
|
+
dispatchDrill({ type: "result", layerId: layerId2, action: { type: "resolved", generation, data } });
|
|
4409
|
+
} catch (error) {
|
|
4410
|
+
if (cancelled) return;
|
|
4411
|
+
dispatchDrill({ type: "result", layerId: layerId2, action: { type: "failed", generation, error } });
|
|
4412
|
+
}
|
|
4413
|
+
})();
|
|
4414
|
+
}
|
|
4415
|
+
return () => {
|
|
4416
|
+
cancelled = true;
|
|
4417
|
+
};
|
|
4418
|
+
}, [machines]);
|
|
4419
|
+
const selectionMode = selection === false || selection === void 0 ? "single" : selection.mode ?? "single";
|
|
4420
|
+
const selectionEnabled = selection !== false;
|
|
4421
|
+
const emphasis = selection === false || selection === void 0 ? "outline" : selection.emphasis ?? "outline";
|
|
4422
|
+
const controlled = selection === false || selection === void 0 ? void 0 : selection.selected;
|
|
4423
|
+
const [uncontrolledSelection, setUncontrolledSelection] = useState([]);
|
|
4424
|
+
const selected = controlled ?? uncontrolledSelection;
|
|
4425
|
+
const select = useCallback(
|
|
4426
|
+
(refs) => {
|
|
4427
|
+
if (!selectionEnabled) return;
|
|
4428
|
+
setUncontrolledSelection(refs);
|
|
4429
|
+
onSelect?.(refs);
|
|
4430
|
+
},
|
|
4431
|
+
[selectionEnabled, onSelect]
|
|
4432
|
+
);
|
|
4433
|
+
const clearSelection = useCallback(() => select([]), [select]);
|
|
4434
|
+
const timeOptions = time === false ? void 0 : time;
|
|
4435
|
+
const frames = useMemo(() => timeOptions?.frames ?? [], [timeOptions]);
|
|
4436
|
+
const playbackEnabled = frames.length > 0 && timeOptions?.playback !== false;
|
|
4437
|
+
const [frame, setFrameState] = useState(() => timeOptions?.defaultFrame ?? timeOptions?.frames?.[0]?.key);
|
|
4438
|
+
const [playing, setPlaying] = useState(false);
|
|
4439
|
+
const activeFrame = frame !== void 0 && frames.some((f) => f.key === frame) ? frame : frames[0]?.key;
|
|
4440
|
+
const setFrame = useCallback((key) => {
|
|
4441
|
+
setFrameState(key);
|
|
4442
|
+
setPlaying(false);
|
|
4443
|
+
}, []);
|
|
4444
|
+
useEffect(() => {
|
|
4445
|
+
if (!playing || frames.length === 0) return;
|
|
4446
|
+
const playback = timeOptions?.playback;
|
|
4447
|
+
if (playback === false) return;
|
|
4448
|
+
const rawFps = playback && "fps" in playback ? playback.fps : void 0;
|
|
4449
|
+
if (rawFps !== void 0) warnPositiveInt("DataMap", "useMapView({ time: { playback: { fps } } })", rawFps);
|
|
4450
|
+
const fps = rawFps !== void 0 && Number.isFinite(rawFps) && rawFps > 0 ? rawFps : 2;
|
|
4451
|
+
const loop = (playback && "loop" in playback ? playback.loop : void 0) ?? true;
|
|
4452
|
+
const timer = setInterval(
|
|
4453
|
+
() => {
|
|
4454
|
+
setFrameState((current) => {
|
|
4455
|
+
const index = frames.findIndex((f) => f.key === current);
|
|
4456
|
+
const next = index + 1;
|
|
4457
|
+
if (next >= frames.length) {
|
|
4458
|
+
if (!loop) {
|
|
4459
|
+
setPlaying(false);
|
|
4460
|
+
return current;
|
|
4461
|
+
}
|
|
4462
|
+
return frames[0]?.key;
|
|
4463
|
+
}
|
|
4464
|
+
return frames[next]?.key;
|
|
4465
|
+
});
|
|
4466
|
+
},
|
|
4467
|
+
1e3 / Math.max(0.1, fps)
|
|
4468
|
+
);
|
|
4469
|
+
return () => clearInterval(timer);
|
|
4470
|
+
}, [playing, frames, timeOptions]);
|
|
4471
|
+
const bridgeRef = useRef(void 0);
|
|
4472
|
+
const [status, setStatus] = useState("loading");
|
|
4473
|
+
const [cameraPosition, setCameraPosition] = useState(EMPTY_CAMERA);
|
|
4474
|
+
const [bbox, setBbox] = useState(EMPTY_BBOX);
|
|
4475
|
+
const attach = useCallback((bridge) => {
|
|
4476
|
+
bridgeRef.current = bridge;
|
|
4477
|
+
}, []);
|
|
4478
|
+
const onCameraSettleRef = useRef(onCameraSettle);
|
|
4479
|
+
onCameraSettleRef.current = onCameraSettle;
|
|
4480
|
+
const reportCamera = useCallback((next, nextBbox, settled) => {
|
|
4481
|
+
setCameraPosition((current) => sameCamera(current, next) ? current : next);
|
|
4482
|
+
setBbox((current) => sameBounds(current, nextBbox) ? current : nextBbox);
|
|
4483
|
+
if (settled) onCameraSettleRef.current?.(next, nextBbox);
|
|
4484
|
+
}, []);
|
|
4485
|
+
const setCamera = useCallback((move) => {
|
|
4486
|
+
bridgeRef.current?.handle.setCamera(move);
|
|
4487
|
+
}, []);
|
|
4488
|
+
const [kindLabels, setKindLabelsState] = useState(FALLBACK_KIND_LABELS);
|
|
4489
|
+
const setKindLabels = useCallback((next) => {
|
|
4490
|
+
setKindLabelsState((current) => {
|
|
4491
|
+
for (const key of Object.keys(next)) if (current[key] !== next[key]) return next;
|
|
4492
|
+
return current;
|
|
4493
|
+
});
|
|
4494
|
+
}, []);
|
|
4495
|
+
const drillContext = useMemo(() => {
|
|
4496
|
+
const map = /* @__PURE__ */ new Map();
|
|
4497
|
+
for (const layer of layers) {
|
|
4498
|
+
if (layer.kind !== "choropleth" || !isLevels(layer.features)) continue;
|
|
4499
|
+
const machine = machines.get(layer.id);
|
|
4500
|
+
if (!machine) continue;
|
|
4501
|
+
const settled = settledFrame(machine.state);
|
|
4502
|
+
const levels = layer.features.levels;
|
|
4503
|
+
const index = levels.findIndex((l) => l.key === settled.level);
|
|
4504
|
+
map.set(layer.id, {
|
|
4505
|
+
features: machine.state.data,
|
|
4506
|
+
level: levels[index] ?? levels[0],
|
|
4507
|
+
loading: machine.state.status === "loading",
|
|
4508
|
+
error: machine.state.status === "error" ? machine.state.error : void 0,
|
|
4509
|
+
// A level with no child below it is the bottom, and a click there must do nothing rather than
|
|
4510
|
+
// push a frame nothing can load.
|
|
4511
|
+
canDrill: index !== -1 && index < levels.length - 1
|
|
4512
|
+
});
|
|
4513
|
+
}
|
|
4514
|
+
return map;
|
|
4515
|
+
}, [layers, machines]);
|
|
4516
|
+
const projectionCache = useRef(/* @__PURE__ */ new Map());
|
|
4517
|
+
const projections = useMemo(() => {
|
|
4518
|
+
const context = {
|
|
4519
|
+
mode,
|
|
4520
|
+
locale,
|
|
4521
|
+
kindLabels,
|
|
4522
|
+
noDataStroke: MAP_STYLE_COLORS[mode].dataNoDataStroke,
|
|
4523
|
+
overrides,
|
|
4524
|
+
drill: drillContext,
|
|
4525
|
+
frame: activeFrame
|
|
4526
|
+
};
|
|
4527
|
+
const cache = projectionCache.current;
|
|
4528
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4529
|
+
const out = layers.map((layer) => {
|
|
4530
|
+
seen.add(layer.id);
|
|
4531
|
+
const drillEntry = drillContext.get(layer.id);
|
|
4532
|
+
const override = overrides.get(layer.id);
|
|
4533
|
+
const deps = [
|
|
4534
|
+
layer,
|
|
4535
|
+
// Named individually rather than relying on `layer` alone, because `layer` is the identity that
|
|
4536
|
+
// changes for free while these are the ones that mean something changed.
|
|
4537
|
+
"rows" in layer ? layer.rows : void 0,
|
|
4538
|
+
"features" in layer ? layer.features : void 0,
|
|
4539
|
+
"scale" in layer ? layer.scale : void 0,
|
|
4540
|
+
override?.visible,
|
|
4541
|
+
override?.opacity,
|
|
4542
|
+
drillEntry?.features,
|
|
4543
|
+
drillEntry?.loading,
|
|
4544
|
+
drillEntry?.level,
|
|
4545
|
+
mode,
|
|
4546
|
+
locale,
|
|
4547
|
+
kindLabels,
|
|
4548
|
+
activeFrame
|
|
4549
|
+
];
|
|
4550
|
+
const hit = cache.get(layer.id);
|
|
4551
|
+
if (hit && hit.deps.length === deps.length && hit.deps.every((value, i) => value === deps[i] || i === 0 && sameSpec(hit.deps[0], deps[0]))) {
|
|
4552
|
+
hit.misses = 0;
|
|
4553
|
+
return hit.projection;
|
|
4554
|
+
}
|
|
4555
|
+
const sameData = hit !== void 0 && hit.deps[1] === deps[1] && hit.deps[2] === deps[2] && hit.deps[6] === deps[6];
|
|
4556
|
+
const misses = sameData ? (hit?.misses ?? 0) + 1 : 0;
|
|
4557
|
+
if (misses >= UNSTABLE_SPEC_MISSES) warnUnstableSpec(layer.id);
|
|
4558
|
+
const projection = projectLayer(layer, context);
|
|
4559
|
+
cache.set(layer.id, { deps, projection, misses });
|
|
4560
|
+
return projection;
|
|
4561
|
+
});
|
|
4562
|
+
for (const id of cache.keys()) if (!seen.has(id)) cache.delete(id);
|
|
4563
|
+
return out;
|
|
4564
|
+
}, [layers, mode, locale, kindLabels, overrides, drillContext, activeFrame]);
|
|
4565
|
+
const reportedUnmatched = useRef(/* @__PURE__ */ new Map());
|
|
4566
|
+
useEffect(() => {
|
|
4567
|
+
for (const projection of projections) {
|
|
4568
|
+
if (projection.kind !== "choropleth" || !projection.join) continue;
|
|
4569
|
+
const layer = layers.find((l) => l.id === projection.id);
|
|
4570
|
+
const onUnmatched = layer?.kind === "choropleth" ? layer.onUnmatched : void 0;
|
|
4571
|
+
if (!onUnmatched) continue;
|
|
4572
|
+
const keys = projection.join.diagnostics.unmatchedRowKeys;
|
|
4573
|
+
const signature = keys.join("\0");
|
|
4574
|
+
if ((reportedUnmatched.current.get(projection.id) ?? "") === signature) continue;
|
|
4575
|
+
reportedUnmatched.current.set(projection.id, signature);
|
|
4576
|
+
onUnmatched(keys);
|
|
4577
|
+
}
|
|
4578
|
+
}, [projections, layers]);
|
|
4579
|
+
const lastDrilledRef = useRef(void 0);
|
|
4580
|
+
const drillInto = useCallback(
|
|
4581
|
+
(ref) => {
|
|
4582
|
+
const layer = layers.find((l) => l.id === ref.layerId);
|
|
4583
|
+
if (!layer || layer.kind !== "choropleth" || !isLevels(layer.features)) return;
|
|
4584
|
+
const machine = machines.get(ref.layerId);
|
|
4585
|
+
if (!machine) return;
|
|
4586
|
+
const settled = settledFrame(machine.state);
|
|
4587
|
+
const levels = layer.features.levels;
|
|
4588
|
+
const index = levels.findIndex((l) => l.key === settled.level);
|
|
4589
|
+
const child = index === -1 ? void 0 : levels[index + 1];
|
|
4590
|
+
if (!child) return;
|
|
4591
|
+
const projection = projections.find((p) => p.id === ref.layerId);
|
|
4592
|
+
const parentLabel = projection?.kind === "choropleth" ? projection.nameByKey.get(ref.featureId) ?? ref.featureId : ref.featureId;
|
|
4593
|
+
const parentBounds = projection?.kind === "choropleth" ? boundsOfFeature(projection.features, layer.joinOn.feature, ref.featureId) : void 0;
|
|
4594
|
+
lastDrilledRef.current = ref.layerId;
|
|
4595
|
+
dispatchDrill({
|
|
4596
|
+
type: "result",
|
|
4597
|
+
layerId: ref.layerId,
|
|
4598
|
+
action: {
|
|
4599
|
+
type: "drill",
|
|
4600
|
+
level: child.key,
|
|
4601
|
+
parentId: ref.featureId,
|
|
4602
|
+
parentLabel,
|
|
4603
|
+
parentBounds,
|
|
4604
|
+
// A cache HIT arrives inline ⇒ there is never a loading state at all, which is what stops
|
|
4605
|
+
// a re-drill into a level you just came from flashing a spinner.
|
|
4606
|
+
cached: machine.cache.get(cacheKey(child.key, ref.featureId))
|
|
4607
|
+
}
|
|
4608
|
+
});
|
|
4609
|
+
},
|
|
4610
|
+
[layers, machines, projections]
|
|
4611
|
+
);
|
|
4612
|
+
const drillUp = useCallback(
|
|
4613
|
+
(to) => {
|
|
4614
|
+
const layerId2 = lastDrilledRef.current ?? machines.keys().next().value;
|
|
4615
|
+
if (layerId2 === void 0) return;
|
|
4616
|
+
const machine = machines.get(layerId2);
|
|
4617
|
+
const layer = layers.find((l) => l.id === layerId2);
|
|
4618
|
+
if (!machine || !layer || layer.kind !== "choropleth" || !isLevels(layer.features)) return;
|
|
4619
|
+
const depth = to === void 0 ? backTarget(machine.state) : Math.max(0, Math.min(to, machine.state.stack.length - 1));
|
|
4620
|
+
if (depth < 0 || depth >= machine.state.stack.length) return;
|
|
4621
|
+
if (to !== void 0 && depth === machine.state.stack.length - 1) return;
|
|
4622
|
+
const target = machine.state.stack[depth];
|
|
4623
|
+
dispatchDrill({
|
|
4624
|
+
type: "result",
|
|
4625
|
+
layerId: layerId2,
|
|
4626
|
+
action: { type: "back", to: depth, cached: target ? machine.cache.get(cacheKey(target.level, target.parentId)) : void 0 }
|
|
4627
|
+
});
|
|
4628
|
+
},
|
|
4629
|
+
[layers, machines]
|
|
4630
|
+
);
|
|
4631
|
+
const primaryDrill = useMemo(() => {
|
|
4632
|
+
const layerId2 = lastDrilledRef.current ?? machines.keys().next().value;
|
|
4633
|
+
const machine = layerId2 === void 0 ? void 0 : machines.get(layerId2);
|
|
4634
|
+
if (!machine) return { frames: [], level: "", settledDepth: 0, canDrillUp: false, loading: false };
|
|
4635
|
+
return {
|
|
4636
|
+
frames: machine.state.stack,
|
|
4637
|
+
level: settledFrame(machine.state).level,
|
|
4638
|
+
settledDepth: machine.state.settledDepth,
|
|
4639
|
+
canDrillUp: machine.state.stack.length > 1,
|
|
4640
|
+
loading: machine.state.status === "loading"
|
|
4641
|
+
};
|
|
4642
|
+
}, [machines]);
|
|
4643
|
+
const onDrillRef = useRef(onDrill);
|
|
4644
|
+
onDrillRef.current = onDrill;
|
|
4645
|
+
const reportedRef = useRef("");
|
|
4646
|
+
useEffect(() => {
|
|
4647
|
+
if (primaryDrill.loading) return;
|
|
4648
|
+
const settled = primaryDrill.frames.slice(0, primaryDrill.settledDepth + 1);
|
|
4649
|
+
const signature = settled.map((f) => `${f.level}:${f.parentId ?? ""}`).join(">");
|
|
4650
|
+
if (signature === reportedRef.current) return;
|
|
4651
|
+
reportedRef.current = signature;
|
|
4652
|
+
onDrillRef.current?.(settled);
|
|
4653
|
+
}, [primaryDrill]);
|
|
4654
|
+
const dataBounds = useCallback(() => resolveFitTarget("data", internalRef.current?.projections ?? []), []);
|
|
4655
|
+
const fitTo = useCallback((target, options2) => {
|
|
4656
|
+
const bridge = bridgeRef.current;
|
|
4657
|
+
if (!bridge) return;
|
|
4658
|
+
const resolved = "bounds" in (typeof target === "object" ? target : {}) ? target.bounds : resolveFitTarget(target, internalRef.current?.projections ?? []);
|
|
4659
|
+
if (!resolved) return;
|
|
4660
|
+
bridge.handle.fitBounds({
|
|
4661
|
+
bounds: resolved,
|
|
4662
|
+
padding: bridge.padding(),
|
|
4663
|
+
fit: options2?.fit ?? "contain",
|
|
4664
|
+
intro: options2?.intro ?? "fly"
|
|
4665
|
+
});
|
|
4666
|
+
}, []);
|
|
4667
|
+
const pendingResetFit = useRef(false);
|
|
4668
|
+
const resetView = useCallback(() => {
|
|
4669
|
+
let unwinding = false;
|
|
4670
|
+
for (const [layerId2, machine] of machines) {
|
|
4671
|
+
if (machine.state.stack.length === 1) continue;
|
|
4672
|
+
const root = machine.state.stack[0];
|
|
4673
|
+
dispatchDrill({
|
|
4674
|
+
type: "result",
|
|
4675
|
+
layerId: layerId2,
|
|
4676
|
+
action: { type: "back", to: 0, cached: machine.cache.get(cacheKey(root.level, root.parentId)) }
|
|
4677
|
+
});
|
|
4678
|
+
unwinding = true;
|
|
4679
|
+
}
|
|
4680
|
+
setOverrides((current) => current.size === 0 ? current : /* @__PURE__ */ new Map());
|
|
4681
|
+
const options2 = internalRef.current?.cameraOptions ?? {};
|
|
4682
|
+
const intent = options2.fit ?? "contain";
|
|
4683
|
+
if (intent === "none" || options2.center !== void 0) {
|
|
4684
|
+
if (options2.center !== void 0 || options2.zoom !== void 0) {
|
|
4685
|
+
setCamera({ center: options2.center, zoom: options2.zoom, transition: "fly" });
|
|
4686
|
+
}
|
|
4687
|
+
return;
|
|
4688
|
+
}
|
|
4689
|
+
const bridge = bridgeRef.current;
|
|
4690
|
+
if (options2.bounds && bridge) {
|
|
4691
|
+
bridge.handle.fitBounds({
|
|
4692
|
+
bounds: options2.bounds,
|
|
4693
|
+
padding: bridge.padding(),
|
|
4694
|
+
fit: intent,
|
|
4695
|
+
maxZoom: options2.zoomRange?.max
|
|
4696
|
+
});
|
|
4697
|
+
return;
|
|
4698
|
+
}
|
|
4699
|
+
if (unwinding) pendingResetFit.current = true;
|
|
4700
|
+
else fitTo("data", { fit: intent });
|
|
4701
|
+
}, [fitTo, machines, setCamera]);
|
|
4702
|
+
useEffect(() => {
|
|
4703
|
+
if (!pendingResetFit.current) return;
|
|
4704
|
+
for (const [, machine] of machines) if (machine.state.status === "loading") return;
|
|
4705
|
+
pendingResetFit.current = false;
|
|
4706
|
+
const intent = internalRef.current?.cameraOptions.fit ?? "contain";
|
|
4707
|
+
fitTo("data", { fit: intent === "none" ? "contain" : intent });
|
|
4708
|
+
}, [fitTo, machines]);
|
|
4709
|
+
const layerStates = useMemo(
|
|
4710
|
+
() => projections.map((p) => ({ id: p.id, label: p.label, kind: p.kind, visible: p.visible, opacity: p.opacity, renderedCount: p.renderedCount })),
|
|
4711
|
+
[projections]
|
|
4712
|
+
);
|
|
4713
|
+
const drillData = useMemo(() => {
|
|
4714
|
+
const map = /* @__PURE__ */ new Map();
|
|
4715
|
+
for (const [layerId2, machine] of machines) map.set(layerId2, machine.state.data);
|
|
4716
|
+
return map;
|
|
4717
|
+
}, [machines]);
|
|
4718
|
+
const internalRef = useRef(void 0);
|
|
4719
|
+
internalRef.current ??= {
|
|
4720
|
+
projections,
|
|
4721
|
+
layerSpecs: layers,
|
|
4722
|
+
selectionMode: selectionEnabled ? selectionMode : false,
|
|
4723
|
+
emphasis,
|
|
4724
|
+
cameraOptions: cameraOptions ?? {},
|
|
4725
|
+
playbackEnabled,
|
|
4726
|
+
attach,
|
|
4727
|
+
setStatus,
|
|
4728
|
+
reportCamera,
|
|
4729
|
+
setKindLabels,
|
|
4730
|
+
drillData,
|
|
4731
|
+
dataBounds
|
|
4732
|
+
};
|
|
4733
|
+
const internal = internalRef.current;
|
|
4734
|
+
const mutable = internal;
|
|
4735
|
+
mutable.projections = projections;
|
|
4736
|
+
mutable.layerSpecs = layers;
|
|
4737
|
+
mutable.selectionMode = selectionEnabled ? selectionMode : false;
|
|
4738
|
+
mutable.emphasis = emphasis;
|
|
4739
|
+
mutable.cameraOptions = cameraOptions ?? {};
|
|
4740
|
+
mutable.playbackEnabled = playbackEnabled;
|
|
4741
|
+
mutable.drillData = drillData;
|
|
4742
|
+
return {
|
|
4743
|
+
layers: layerStates,
|
|
4744
|
+
camera: cameraPosition,
|
|
4745
|
+
bbox,
|
|
4746
|
+
selected,
|
|
4747
|
+
drill: primaryDrill,
|
|
4748
|
+
time: frames.length > 0 && activeFrame !== void 0 ? { frame: activeFrame, frames, playing } : void 0,
|
|
4749
|
+
status,
|
|
4750
|
+
setLayerVisible,
|
|
4751
|
+
setLayerOpacity,
|
|
4752
|
+
select,
|
|
4753
|
+
clearSelection,
|
|
4754
|
+
drillInto,
|
|
4755
|
+
drillUp,
|
|
4756
|
+
setFrame,
|
|
4757
|
+
setPlaying,
|
|
4758
|
+
setCamera,
|
|
4759
|
+
fitTo,
|
|
4760
|
+
resetView,
|
|
4761
|
+
internal
|
|
4762
|
+
};
|
|
4763
|
+
}
|
|
4764
|
+
function drillMachinesReducer(current, action) {
|
|
4765
|
+
if (action.type === "ensure") {
|
|
4766
|
+
if (current.has(action.layerId)) return current;
|
|
4767
|
+
const next2 = new Map(current);
|
|
4768
|
+
next2.set(action.layerId, { state: initialDrillState(action.rootLevel), cache: new LevelCache() });
|
|
4769
|
+
return next2;
|
|
4770
|
+
}
|
|
4771
|
+
const machine = current.get(action.layerId);
|
|
4772
|
+
if (!machine) return current;
|
|
4773
|
+
const state = drillReducer(machine.state, action.action);
|
|
4774
|
+
if (state === machine.state) return current;
|
|
4775
|
+
const next = new Map(current);
|
|
4776
|
+
next.set(action.layerId, { ...machine, state });
|
|
4777
|
+
return next;
|
|
4778
|
+
}
|
|
4779
|
+
function boundsOfFeature(features, property, key) {
|
|
4780
|
+
const feature = features?.features.find((f) => String(f.properties?.[property] ?? "") === key);
|
|
4781
|
+
if (!feature) return void 0;
|
|
4782
|
+
return boundsOf({ features: [feature] });
|
|
4783
|
+
}
|
|
4784
|
+
function resolveFitTarget(target, projections) {
|
|
4785
|
+
if (typeof target === "object" && "bounds" in target) return target.bounds;
|
|
4786
|
+
const wanted = target === "data" ? projections.filter((p) => p.visible) : "layerId" in target ? projections.filter((p) => p.id === target.layerId) : projections.filter((p) => target.refs.some((ref) => ref.layerId === p.id));
|
|
4787
|
+
const box = new BoundsAccumulator();
|
|
4788
|
+
for (const projection of wanted) extendBounds(box, projection);
|
|
4789
|
+
return box.result();
|
|
4790
|
+
}
|
|
4791
|
+
var _west, _south, _east, _north, _seen;
|
|
4792
|
+
var BoundsAccumulator = class {
|
|
4793
|
+
constructor() {
|
|
4794
|
+
__privateAdd(this, _west, Infinity);
|
|
4795
|
+
__privateAdd(this, _south, Infinity);
|
|
4796
|
+
__privateAdd(this, _east, -Infinity);
|
|
4797
|
+
__privateAdd(this, _north, -Infinity);
|
|
4798
|
+
__privateAdd(this, _seen, false);
|
|
4799
|
+
}
|
|
4800
|
+
take(lng, lat) {
|
|
4801
|
+
if (!Number.isFinite(lng) || !Number.isFinite(lat)) return;
|
|
4802
|
+
__privateSet(this, _seen, true);
|
|
4803
|
+
__privateSet(this, _west, Math.min(__privateGet(this, _west), lng));
|
|
4804
|
+
__privateSet(this, _east, Math.max(__privateGet(this, _east), lng));
|
|
4805
|
+
__privateSet(this, _south, Math.min(__privateGet(this, _south), lat));
|
|
4806
|
+
__privateSet(this, _north, Math.max(__privateGet(this, _north), lat));
|
|
4807
|
+
}
|
|
4808
|
+
takeBox(box) {
|
|
4809
|
+
if (!box) return;
|
|
4810
|
+
this.take(box[0], box[1]);
|
|
4811
|
+
this.take(box[2], box[3]);
|
|
4812
|
+
}
|
|
4813
|
+
result() {
|
|
4814
|
+
return __privateGet(this, _seen) ? [__privateGet(this, _west), __privateGet(this, _south), __privateGet(this, _east), __privateGet(this, _north)] : void 0;
|
|
4815
|
+
}
|
|
4816
|
+
};
|
|
4817
|
+
_west = new WeakMap();
|
|
4818
|
+
_south = new WeakMap();
|
|
4819
|
+
_east = new WeakMap();
|
|
4820
|
+
_north = new WeakMap();
|
|
4821
|
+
_seen = new WeakMap();
|
|
4822
|
+
function extendBounds(box, projection) {
|
|
4823
|
+
switch (projection.kind) {
|
|
4824
|
+
case "choropleth": {
|
|
4825
|
+
if (projection.features) box.takeBox(boundsOf(projection.features));
|
|
4826
|
+
return;
|
|
4827
|
+
}
|
|
4828
|
+
case "areas": {
|
|
4829
|
+
box.takeBox(boundsOf(projection.features));
|
|
4830
|
+
return;
|
|
4831
|
+
}
|
|
4832
|
+
case "points": {
|
|
4833
|
+
for (const point of projection.points) box.take(point.position[0], point.position[1]);
|
|
4834
|
+
return;
|
|
4835
|
+
}
|
|
4836
|
+
case "heatmap": {
|
|
4837
|
+
for (const weight of projection.weights) box.take(weight.position[0], weight.position[1]);
|
|
4838
|
+
return;
|
|
4839
|
+
}
|
|
4840
|
+
case "lines": {
|
|
4841
|
+
for (const line of projection.lines) for (const position of line.path) box.take(position[0], position[1]);
|
|
4842
|
+
return;
|
|
4843
|
+
}
|
|
4844
|
+
case "raster": {
|
|
4845
|
+
return;
|
|
4846
|
+
}
|
|
4847
|
+
}
|
|
4848
|
+
}
|
|
4849
|
+
|
|
4850
|
+
export { DEFAULT_MAP_SOURCE, DataMap, areasLayer, choroplethLayer, heatmapLayer, linesLayer, pointsLayer, rasterLayer, useMapView };
|
|
4851
|
+
//# sourceMappingURL=chunk-7JOW3LEH.js.map
|
|
4852
|
+
//# sourceMappingURL=chunk-7JOW3LEH.js.map
|