@classic-homes/maps-core 0.2.8 → 0.2.10
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/dist/{chunk-2NISJ7WE.js → chunk-6WMCIBJJ.js} +41 -194
- package/dist/chunk-EXGGK4H7.js +2822 -0
- package/dist/chunk-ZGUACUEF.js +156 -0
- package/dist/{data-CICLgvT6.d.cts → data-k7o-Rne0.d.cts} +1 -1
- package/dist/{data-CICLgvT6.d.ts → data-k7o-Rne0.d.ts} +1 -1
- package/dist/generator-CGfqiHvG.d.cts +139 -0
- package/dist/generator-CGfqiHvG.d.ts +139 -0
- package/dist/index.d.cts +7 -1481
- package/dist/index.d.ts +7 -1481
- package/dist/index.js +6 -2786
- package/dist/marker-BjzgxVwm.d.ts +1490 -0
- package/dist/marker-zuhH2WoS.d.cts +1490 -0
- package/dist/{spatial-D4ZJ4Ul7.d.ts → spatial-Bo8nM3fC.d.ts} +2 -2
- package/dist/{spatial-D9o4mvDO.d.cts → spatial-CU60awl8.d.cts} +2 -2
- package/dist/theme/index.d.cts +3 -138
- package/dist/theme/index.d.ts +3 -138
- package/dist/theme/index.js +2 -1
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/utils/index.cjs +3078 -0
- package/dist/utils/index.d.cts +50 -0
- package/dist/utils/index.d.ts +50 -0
- package/dist/utils/index.js +2 -0
- package/dist/workers/index.d.cts +2 -2
- package/dist/workers/index.d.ts +2 -2
- package/package.json +9 -1
|
@@ -0,0 +1,3078 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var themeTokens = require('@classic-homes/theme-tokens');
|
|
4
|
+
var RBush = require('rbush');
|
|
5
|
+
|
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
|
|
8
|
+
var RBush__default = /*#__PURE__*/_interopDefault(RBush);
|
|
9
|
+
|
|
10
|
+
// src/utils/accessibility.ts
|
|
11
|
+
var KEYBOARD_CONTROLS = {
|
|
12
|
+
pan: {
|
|
13
|
+
up: "Arrow Up",
|
|
14
|
+
down: "Arrow Down",
|
|
15
|
+
left: "Arrow Left",
|
|
16
|
+
right: "Arrow Right"
|
|
17
|
+
},
|
|
18
|
+
zoom: {
|
|
19
|
+
in: "Plus (+) or Equals (=)",
|
|
20
|
+
out: "Minus (-)"
|
|
21
|
+
},
|
|
22
|
+
rotate: {
|
|
23
|
+
left: "Shift + Arrow Left",
|
|
24
|
+
right: "Shift + Arrow Right"
|
|
25
|
+
},
|
|
26
|
+
pitch: {
|
|
27
|
+
increase: "Shift + Arrow Up",
|
|
28
|
+
decrease: "Shift + Arrow Down"
|
|
29
|
+
},
|
|
30
|
+
reset: {
|
|
31
|
+
bearing: "N key (reset north)",
|
|
32
|
+
view: "R key (reset view)"
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
function generateKeyboardControlsDescription() {
|
|
36
|
+
return `
|
|
37
|
+
Map keyboard controls:
|
|
38
|
+
Pan: Use arrow keys to move the map.
|
|
39
|
+
Zoom: Press plus to zoom in, minus to zoom out.
|
|
40
|
+
Rotate: Hold Shift and press left or right arrows.
|
|
41
|
+
Tilt: Hold Shift and press up or down arrows.
|
|
42
|
+
Press N to reset north orientation.
|
|
43
|
+
`.trim().replace(/\s+/g, " ");
|
|
44
|
+
}
|
|
45
|
+
function generateMapDescription(title, options) {
|
|
46
|
+
let description = `${title}. Interactive map`;
|
|
47
|
+
if (options?.center) {
|
|
48
|
+
const [lng, lat] = options.center;
|
|
49
|
+
const latDir = lat >= 0 ? "N" : "S";
|
|
50
|
+
const lngDir = lng >= 0 ? "E" : "W";
|
|
51
|
+
description += ` centered at ${Math.abs(lat).toFixed(2)} degrees ${latDir}, ${Math.abs(lng).toFixed(2)} degrees ${lngDir}`;
|
|
52
|
+
}
|
|
53
|
+
if (options?.zoom !== void 0) {
|
|
54
|
+
description += ` at zoom level ${options.zoom}`;
|
|
55
|
+
}
|
|
56
|
+
if (options?.featureCount !== void 0 && options.featureCount > 0) {
|
|
57
|
+
description += `. Contains ${options.featureCount} ${options.featureCount === 1 ? "feature" : "features"}`;
|
|
58
|
+
}
|
|
59
|
+
if (options?.markerCount !== void 0 && options.markerCount > 0) {
|
|
60
|
+
description += options.featureCount ? ` and ` : `. Contains `;
|
|
61
|
+
description += `${options.markerCount} ${options.markerCount === 1 ? "marker" : "markers"}`;
|
|
62
|
+
}
|
|
63
|
+
if (options?.layerTypes && options.layerTypes.length > 0) {
|
|
64
|
+
description += `. Showing ${options.layerTypes.join(", ")} layers`;
|
|
65
|
+
}
|
|
66
|
+
description += ". Use keyboard to navigate.";
|
|
67
|
+
return description;
|
|
68
|
+
}
|
|
69
|
+
function generateFeatureCollectionDescription(title, data) {
|
|
70
|
+
const featureCount = data.features.length;
|
|
71
|
+
if (featureCount === 0) {
|
|
72
|
+
return `${title}. Map layer with no features.`;
|
|
73
|
+
}
|
|
74
|
+
const geometryTypes = {};
|
|
75
|
+
data.features.forEach((feature) => {
|
|
76
|
+
const type = feature.geometry.type;
|
|
77
|
+
geometryTypes[type] = (geometryTypes[type] || 0) + 1;
|
|
78
|
+
});
|
|
79
|
+
const typeDescriptions = Object.entries(geometryTypes).map(([type, count]) => `${count} ${formatGeometryType(type, count)}`).join(", ");
|
|
80
|
+
return `${title}. Map layer with ${featureCount} features: ${typeDescriptions}.`;
|
|
81
|
+
}
|
|
82
|
+
function formatGeometryType(type, count) {
|
|
83
|
+
const singular = {
|
|
84
|
+
Point: "point",
|
|
85
|
+
MultiPoint: "multi-point",
|
|
86
|
+
LineString: "line",
|
|
87
|
+
MultiLineString: "multi-line",
|
|
88
|
+
Polygon: "polygon",
|
|
89
|
+
MultiPolygon: "multi-polygon"
|
|
90
|
+
};
|
|
91
|
+
const plural = {
|
|
92
|
+
Point: "points",
|
|
93
|
+
MultiPoint: "multi-points",
|
|
94
|
+
LineString: "lines",
|
|
95
|
+
MultiLineString: "multi-lines",
|
|
96
|
+
Polygon: "polygons",
|
|
97
|
+
MultiPolygon: "multi-polygons"
|
|
98
|
+
};
|
|
99
|
+
return count === 1 ? singular[type] || type.toLowerCase() : plural[type] || `${type.toLowerCase()}s`;
|
|
100
|
+
}
|
|
101
|
+
function generateMarkersDescription(title, markers) {
|
|
102
|
+
const count = markers.length;
|
|
103
|
+
if (count === 0) {
|
|
104
|
+
return `${title}. No markers on the map.`;
|
|
105
|
+
}
|
|
106
|
+
let description = `${title}. Map with ${count} ${count === 1 ? "marker" : "markers"}`;
|
|
107
|
+
const labeledMarkers = markers.filter((m) => m.label).slice(0, 3);
|
|
108
|
+
if (labeledMarkers.length > 0) {
|
|
109
|
+
const labels = labeledMarkers.map((m) => m.label).join(", ");
|
|
110
|
+
description += ` including ${labels}`;
|
|
111
|
+
if (count > labeledMarkers.length) {
|
|
112
|
+
description += ` and ${count - labeledMarkers.length} more`;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return description + ".";
|
|
116
|
+
}
|
|
117
|
+
function generateFeatureTable(features, propertyKeys) {
|
|
118
|
+
if (features.features.length === 0) {
|
|
119
|
+
return "";
|
|
120
|
+
}
|
|
121
|
+
const headers = ["Type", ...propertyKeys];
|
|
122
|
+
const headerRow = headers.map((h) => `<th scope="col">${escapeHtml(h)}</th>`).join("");
|
|
123
|
+
const bodyRows = features.features.slice(0, 100).map((feature) => {
|
|
124
|
+
const type = feature.geometry.type;
|
|
125
|
+
const cells = propertyKeys.map((key) => {
|
|
126
|
+
const value = feature.properties?.[key];
|
|
127
|
+
return `<td>${escapeHtml(String(value ?? ""))}</td>`;
|
|
128
|
+
});
|
|
129
|
+
return `<tr><td>${escapeHtml(type)}</td>${cells.join("")}</tr>`;
|
|
130
|
+
}).join("");
|
|
131
|
+
return `
|
|
132
|
+
<table class="sr-only" role="table" aria-label="Map feature data">
|
|
133
|
+
<thead><tr>${headerRow}</tr></thead>
|
|
134
|
+
<tbody>${bodyRows}</tbody>
|
|
135
|
+
</table>
|
|
136
|
+
`.trim();
|
|
137
|
+
}
|
|
138
|
+
function generateMarkerList(markers) {
|
|
139
|
+
if (markers.length === 0) {
|
|
140
|
+
return "";
|
|
141
|
+
}
|
|
142
|
+
const items = markers.slice(0, 50).map((marker) => {
|
|
143
|
+
const label = marker.label || "Marker";
|
|
144
|
+
const [lng, lat] = marker.coordinates;
|
|
145
|
+
return `<li>${escapeHtml(label)} at ${lat.toFixed(4)}, ${lng.toFixed(4)}</li>`;
|
|
146
|
+
}).join("");
|
|
147
|
+
return `
|
|
148
|
+
<ul class="sr-only" role="list" aria-label="Map markers">
|
|
149
|
+
${items}
|
|
150
|
+
</ul>
|
|
151
|
+
`.trim();
|
|
152
|
+
}
|
|
153
|
+
function generateMoveAnnouncement(center, zoom, action) {
|
|
154
|
+
const [lng, lat] = center;
|
|
155
|
+
const latDir = lat >= 0 ? "north" : "south";
|
|
156
|
+
const lngDir = lng >= 0 ? "east" : "west";
|
|
157
|
+
switch (action) {
|
|
158
|
+
case "pan":
|
|
159
|
+
return `Panned to ${Math.abs(lat).toFixed(2)} ${latDir}, ${Math.abs(lng).toFixed(2)} ${lngDir}`;
|
|
160
|
+
case "zoom":
|
|
161
|
+
return `Zoom level ${zoom.toFixed(1)}`;
|
|
162
|
+
case "move":
|
|
163
|
+
default:
|
|
164
|
+
return `Map moved to ${Math.abs(lat).toFixed(2)} ${latDir}, ${Math.abs(lng).toFixed(2)} ${lngDir} at zoom ${zoom.toFixed(1)}`;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function escapeHtml(str) {
|
|
168
|
+
const htmlEntities = {
|
|
169
|
+
"&": "&",
|
|
170
|
+
"<": "<",
|
|
171
|
+
">": ">",
|
|
172
|
+
'"': """,
|
|
173
|
+
"'": "'"
|
|
174
|
+
};
|
|
175
|
+
return str.replace(/[&<>"']/g, (char) => htmlEntities[char] || char);
|
|
176
|
+
}
|
|
177
|
+
var THEME_LIGHT = "classic-light";
|
|
178
|
+
var THEME_DARK = "classic-dark";
|
|
179
|
+
function generateLightColors() {
|
|
180
|
+
return {
|
|
181
|
+
background: themeTokens.colors.white,
|
|
182
|
+
water: themeTokens.colors.sky[200],
|
|
183
|
+
land: themeTokens.colors.sage[50],
|
|
184
|
+
park: themeTokens.colors.forest[100],
|
|
185
|
+
building: themeTokens.colors.gray[200],
|
|
186
|
+
buildingOutline: themeTokens.colors.gray[300],
|
|
187
|
+
roadPrimary: themeTokens.colors.white,
|
|
188
|
+
roadSecondary: themeTokens.colors.gray[100],
|
|
189
|
+
roadCasing: themeTokens.colors.gray[300],
|
|
190
|
+
rail: themeTokens.colors.gray[400],
|
|
191
|
+
boundary: themeTokens.colors.gray[400],
|
|
192
|
+
adminBoundary: themeTokens.colors.plum[300],
|
|
193
|
+
residential: themeTokens.colors.sage[100],
|
|
194
|
+
commercial: themeTokens.colors.stone[100],
|
|
195
|
+
industrial: themeTokens.colors.gray[200],
|
|
196
|
+
highlight: themeTokens.colors.teal[500],
|
|
197
|
+
// Core 1 - brand teal
|
|
198
|
+
highlightSecondary: themeTokens.colors.teal[300],
|
|
199
|
+
selection: themeTokens.colors.red[500],
|
|
200
|
+
// Brand red
|
|
201
|
+
textPrimary: themeTokens.semanticColors.light.foreground,
|
|
202
|
+
textSecondary: themeTokens.semanticColors.light.mutedForeground,
|
|
203
|
+
textHalo: themeTokens.colors.white,
|
|
204
|
+
poi: themeTokens.colors.navy[700],
|
|
205
|
+
// Core 2 - brand navy
|
|
206
|
+
labelBackground: "rgba(255, 255, 255, 0.85)"
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function generateDarkColors() {
|
|
210
|
+
return {
|
|
211
|
+
background: themeTokens.colors.charcoal[900],
|
|
212
|
+
water: themeTokens.colors.navy[800],
|
|
213
|
+
land: themeTokens.colors.charcoal[800],
|
|
214
|
+
park: themeTokens.colors.forest[900],
|
|
215
|
+
building: themeTokens.colors.charcoal[700],
|
|
216
|
+
buildingOutline: themeTokens.colors.charcoal[600],
|
|
217
|
+
roadPrimary: themeTokens.colors.charcoal[600],
|
|
218
|
+
roadSecondary: themeTokens.colors.charcoal[700],
|
|
219
|
+
roadCasing: themeTokens.colors.charcoal[500],
|
|
220
|
+
rail: themeTokens.colors.gray[600],
|
|
221
|
+
boundary: themeTokens.colors.gray[600],
|
|
222
|
+
adminBoundary: themeTokens.colors.plum[400],
|
|
223
|
+
residential: themeTokens.colors.charcoal[700],
|
|
224
|
+
commercial: themeTokens.colors.stone[800],
|
|
225
|
+
industrial: themeTokens.colors.charcoal[700],
|
|
226
|
+
highlight: themeTokens.colors.teal[400],
|
|
227
|
+
// Lighter for dark mode
|
|
228
|
+
highlightSecondary: themeTokens.colors.teal[500],
|
|
229
|
+
selection: themeTokens.colors.red[400],
|
|
230
|
+
// Lighter for dark mode
|
|
231
|
+
textPrimary: themeTokens.semanticColors.dark.foreground,
|
|
232
|
+
textSecondary: themeTokens.semanticColors.dark.mutedForeground,
|
|
233
|
+
textHalo: themeTokens.colors.charcoal[900],
|
|
234
|
+
poi: themeTokens.colors.navy[400],
|
|
235
|
+
// Lighter for dark mode
|
|
236
|
+
labelBackground: "rgba(41, 36, 36, 0.85)"
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
function generateLightDataColors() {
|
|
240
|
+
return {
|
|
241
|
+
sequence: [
|
|
242
|
+
themeTokens.colors.teal[500],
|
|
243
|
+
// chart.1
|
|
244
|
+
themeTokens.colors.navy[700],
|
|
245
|
+
// chart.2
|
|
246
|
+
themeTokens.colors.plum[700],
|
|
247
|
+
// chart.3
|
|
248
|
+
themeTokens.colors.forest[500],
|
|
249
|
+
// chart.4
|
|
250
|
+
themeTokens.colors.sky[600]
|
|
251
|
+
// chart.5
|
|
252
|
+
],
|
|
253
|
+
positive: themeTokens.colors.forest[500],
|
|
254
|
+
negative: themeTokens.colors.red[500],
|
|
255
|
+
neutral: themeTokens.colors.gray[500],
|
|
256
|
+
heatmapRamp: [
|
|
257
|
+
"rgba(59, 164, 167, 0)",
|
|
258
|
+
// teal transparent
|
|
259
|
+
themeTokens.colors.teal[200],
|
|
260
|
+
themeTokens.colors.teal[400],
|
|
261
|
+
themeTokens.colors.teal[500],
|
|
262
|
+
themeTokens.colors.red[400],
|
|
263
|
+
themeTokens.colors.red[500],
|
|
264
|
+
themeTokens.colors.red[600]
|
|
265
|
+
]
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
function generateDarkDataColors() {
|
|
269
|
+
return {
|
|
270
|
+
sequence: [
|
|
271
|
+
themeTokens.colors.teal[400],
|
|
272
|
+
// chart.1
|
|
273
|
+
themeTokens.colors.navy[400],
|
|
274
|
+
// chart.2
|
|
275
|
+
themeTokens.colors.plum[400],
|
|
276
|
+
// chart.3
|
|
277
|
+
themeTokens.colors.forest[400],
|
|
278
|
+
// chart.4
|
|
279
|
+
themeTokens.colors.sky[400]
|
|
280
|
+
// chart.5
|
|
281
|
+
],
|
|
282
|
+
positive: themeTokens.colors.forest[400],
|
|
283
|
+
negative: themeTokens.colors.red[400],
|
|
284
|
+
neutral: themeTokens.colors.gray[400],
|
|
285
|
+
heatmapRamp: [
|
|
286
|
+
"rgba(103, 204, 207, 0)",
|
|
287
|
+
// teal transparent
|
|
288
|
+
themeTokens.colors.teal[300],
|
|
289
|
+
themeTokens.colors.teal[400],
|
|
290
|
+
themeTokens.colors.teal[500],
|
|
291
|
+
themeTokens.colors.red[400],
|
|
292
|
+
themeTokens.colors.red[500],
|
|
293
|
+
themeTokens.colors.red[600]
|
|
294
|
+
]
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
function getTypography() {
|
|
298
|
+
return {
|
|
299
|
+
fontFamily: themeTokens.fontFamily.sans.join(", "),
|
|
300
|
+
fontFamilySerif: themeTokens.fontFamily.serif.join(", "),
|
|
301
|
+
fontFamilyMono: themeTokens.fontFamily.mono.join(", ")
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
function generateLightTheme() {
|
|
305
|
+
return {
|
|
306
|
+
name: THEME_LIGHT,
|
|
307
|
+
colors: generateLightColors(),
|
|
308
|
+
dataColors: generateLightDataColors(),
|
|
309
|
+
typography: getTypography()
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
function generateDarkTheme() {
|
|
313
|
+
return {
|
|
314
|
+
name: THEME_DARK,
|
|
315
|
+
colors: generateDarkColors(),
|
|
316
|
+
dataColors: generateDarkDataColors(),
|
|
317
|
+
typography: getTypography()
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
var lightTheme = generateLightTheme();
|
|
321
|
+
generateDarkTheme();
|
|
322
|
+
|
|
323
|
+
// src/utils/styles.ts
|
|
324
|
+
function createFillStyle(options) {
|
|
325
|
+
const paint = {
|
|
326
|
+
"fill-color": options.color
|
|
327
|
+
};
|
|
328
|
+
if (options.opacity !== void 0) {
|
|
329
|
+
paint["fill-opacity"] = options.opacity;
|
|
330
|
+
}
|
|
331
|
+
if (options.outlineColor !== void 0) {
|
|
332
|
+
paint["fill-outline-color"] = options.outlineColor;
|
|
333
|
+
}
|
|
334
|
+
return { paint };
|
|
335
|
+
}
|
|
336
|
+
function createLineStyle(options) {
|
|
337
|
+
const paint = {
|
|
338
|
+
"line-color": options.color,
|
|
339
|
+
"line-width": options.width
|
|
340
|
+
};
|
|
341
|
+
const layout = {};
|
|
342
|
+
if (options.opacity !== void 0) {
|
|
343
|
+
paint["line-opacity"] = options.opacity;
|
|
344
|
+
}
|
|
345
|
+
if (options.dashArray) {
|
|
346
|
+
paint["line-dasharray"] = options.dashArray;
|
|
347
|
+
}
|
|
348
|
+
if (options.cap) {
|
|
349
|
+
layout["line-cap"] = options.cap;
|
|
350
|
+
}
|
|
351
|
+
if (options.join) {
|
|
352
|
+
layout["line-join"] = options.join;
|
|
353
|
+
}
|
|
354
|
+
return { paint, layout };
|
|
355
|
+
}
|
|
356
|
+
function createCircleStyle(options) {
|
|
357
|
+
const paint = {
|
|
358
|
+
"circle-radius": options.radius,
|
|
359
|
+
"circle-color": options.color
|
|
360
|
+
};
|
|
361
|
+
if (options.opacity !== void 0) {
|
|
362
|
+
paint["circle-opacity"] = options.opacity;
|
|
363
|
+
}
|
|
364
|
+
if (options.strokeWidth !== void 0) {
|
|
365
|
+
paint["circle-stroke-width"] = options.strokeWidth;
|
|
366
|
+
}
|
|
367
|
+
if (options.strokeColor !== void 0) {
|
|
368
|
+
paint["circle-stroke-color"] = options.strokeColor;
|
|
369
|
+
}
|
|
370
|
+
if (options.blur !== void 0) {
|
|
371
|
+
paint["circle-blur"] = options.blur;
|
|
372
|
+
}
|
|
373
|
+
return { paint };
|
|
374
|
+
}
|
|
375
|
+
function createExtrusionStyle(options) {
|
|
376
|
+
const paint = {
|
|
377
|
+
"fill-extrusion-height": options.height,
|
|
378
|
+
"fill-extrusion-color": options.color
|
|
379
|
+
};
|
|
380
|
+
if (options.baseHeight !== void 0) {
|
|
381
|
+
paint["fill-extrusion-base"] = options.baseHeight;
|
|
382
|
+
}
|
|
383
|
+
if (options.opacity !== void 0) {
|
|
384
|
+
paint["fill-extrusion-opacity"] = options.opacity;
|
|
385
|
+
}
|
|
386
|
+
if (options.verticalGradient !== void 0) {
|
|
387
|
+
paint["fill-extrusion-vertical-gradient"] = options.verticalGradient;
|
|
388
|
+
}
|
|
389
|
+
return { paint };
|
|
390
|
+
}
|
|
391
|
+
function createHeatmapStyle(options) {
|
|
392
|
+
const paint = {};
|
|
393
|
+
if (options.weight !== void 0) {
|
|
394
|
+
paint["heatmap-weight"] = options.weight;
|
|
395
|
+
}
|
|
396
|
+
if (options.intensity !== void 0) {
|
|
397
|
+
paint["heatmap-intensity"] = options.intensity;
|
|
398
|
+
}
|
|
399
|
+
if (options.radius !== void 0) {
|
|
400
|
+
paint["heatmap-radius"] = options.radius;
|
|
401
|
+
}
|
|
402
|
+
if (options.opacity !== void 0) {
|
|
403
|
+
paint["heatmap-opacity"] = options.opacity;
|
|
404
|
+
}
|
|
405
|
+
if (options.colorRamp) {
|
|
406
|
+
const stops = ["interpolate", ["linear"], ["heatmap-density"]];
|
|
407
|
+
options.colorRamp.forEach((color, index) => {
|
|
408
|
+
stops.push(index / (options.colorRamp.length - 1));
|
|
409
|
+
stops.push(color);
|
|
410
|
+
});
|
|
411
|
+
paint["heatmap-color"] = stops;
|
|
412
|
+
}
|
|
413
|
+
return { paint };
|
|
414
|
+
}
|
|
415
|
+
function createHoverExpression(baseValue, hoverValue, featureStateName = "hover") {
|
|
416
|
+
return ["case", ["boolean", ["feature-state", featureStateName], false], hoverValue, baseValue];
|
|
417
|
+
}
|
|
418
|
+
function createSelectionExpression(baseValue, selectedValue, featureStateName = "selected") {
|
|
419
|
+
return [
|
|
420
|
+
"case",
|
|
421
|
+
["boolean", ["feature-state", featureStateName], false],
|
|
422
|
+
selectedValue,
|
|
423
|
+
baseValue
|
|
424
|
+
];
|
|
425
|
+
}
|
|
426
|
+
function createInteractiveExpression(baseValue, hoverValue, selectedValue) {
|
|
427
|
+
return [
|
|
428
|
+
"case",
|
|
429
|
+
["boolean", ["feature-state", "selected"], false],
|
|
430
|
+
selectedValue,
|
|
431
|
+
["boolean", ["feature-state", "hover"], false],
|
|
432
|
+
hoverValue,
|
|
433
|
+
baseValue
|
|
434
|
+
];
|
|
435
|
+
}
|
|
436
|
+
function createCategoricalColorExpression(property, colorMap, defaultColor) {
|
|
437
|
+
const expression = ["match", ["get", property]];
|
|
438
|
+
Object.entries(colorMap).forEach(([value, color]) => {
|
|
439
|
+
expression.push(value, color);
|
|
440
|
+
});
|
|
441
|
+
expression.push(defaultColor);
|
|
442
|
+
return expression;
|
|
443
|
+
}
|
|
444
|
+
function createContinuousColorExpression(property, stops, interpolation = "linear") {
|
|
445
|
+
const expression = ["interpolate"];
|
|
446
|
+
if (interpolation === "linear") {
|
|
447
|
+
expression.push(["linear"]);
|
|
448
|
+
} else if (interpolation === "exponential") {
|
|
449
|
+
expression.push(["exponential", 1]);
|
|
450
|
+
} else {
|
|
451
|
+
expression.push(interpolation);
|
|
452
|
+
}
|
|
453
|
+
expression.push(["get", property]);
|
|
454
|
+
stops.forEach(([value, color]) => {
|
|
455
|
+
expression.push(value, color);
|
|
456
|
+
});
|
|
457
|
+
return expression;
|
|
458
|
+
}
|
|
459
|
+
function createZoomExpression(stops) {
|
|
460
|
+
const expression = ["interpolate", ["linear"], ["zoom"]];
|
|
461
|
+
stops.forEach(([zoom, value]) => {
|
|
462
|
+
expression.push(zoom, value);
|
|
463
|
+
});
|
|
464
|
+
return expression;
|
|
465
|
+
}
|
|
466
|
+
function getHighlightStyle(theme = lightTheme) {
|
|
467
|
+
const { highlight, highlightSecondary } = theme.colors;
|
|
468
|
+
return {
|
|
469
|
+
fill: {
|
|
470
|
+
"fill-color": createHoverExpression(highlightSecondary, highlight),
|
|
471
|
+
"fill-opacity": createHoverExpression(0.3, 0.5),
|
|
472
|
+
"fill-outline-color": highlight
|
|
473
|
+
},
|
|
474
|
+
line: {
|
|
475
|
+
"line-color": createHoverExpression(highlightSecondary, highlight),
|
|
476
|
+
"line-width": createHoverExpression(2, 3)
|
|
477
|
+
},
|
|
478
|
+
circle: {
|
|
479
|
+
"circle-color": createHoverExpression(highlightSecondary, highlight),
|
|
480
|
+
"circle-radius": createHoverExpression(6, 8),
|
|
481
|
+
"circle-stroke-color": highlight,
|
|
482
|
+
"circle-stroke-width": 2
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
function getSelectionStyle(theme = lightTheme) {
|
|
487
|
+
const { selection, highlight } = theme.colors;
|
|
488
|
+
return {
|
|
489
|
+
fill: {
|
|
490
|
+
"fill-color": createInteractiveExpression(highlight, highlight, selection),
|
|
491
|
+
"fill-opacity": createInteractiveExpression(0.2, 0.4, 0.6),
|
|
492
|
+
"fill-outline-color": createInteractiveExpression(highlight, highlight, selection)
|
|
493
|
+
},
|
|
494
|
+
line: {
|
|
495
|
+
"line-color": createInteractiveExpression(highlight, highlight, selection),
|
|
496
|
+
"line-width": createInteractiveExpression(2, 3, 4)
|
|
497
|
+
},
|
|
498
|
+
circle: {
|
|
499
|
+
"circle-color": createInteractiveExpression(highlight, highlight, selection),
|
|
500
|
+
"circle-radius": createInteractiveExpression(6, 8, 10),
|
|
501
|
+
"circle-stroke-color": createInteractiveExpression(highlight, highlight, selection),
|
|
502
|
+
"circle-stroke-width": 2
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
function createLotFillStyle(options) {
|
|
507
|
+
const { defaultColor, hoverColor, selectedColor, opacity = 0.7 } = options;
|
|
508
|
+
const fillColor = selectedColor ? createInteractiveExpression(defaultColor, hoverColor, selectedColor) : createHoverExpression(defaultColor, hoverColor);
|
|
509
|
+
return {
|
|
510
|
+
"fill-color": fillColor,
|
|
511
|
+
"fill-opacity": opacity
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
function createLotOutlineStyle(options) {
|
|
515
|
+
const {
|
|
516
|
+
defaultColor,
|
|
517
|
+
hoverColor,
|
|
518
|
+
selectedColor,
|
|
519
|
+
defaultWidth = 1,
|
|
520
|
+
hoverWidth = 2,
|
|
521
|
+
selectedWidth = 3
|
|
522
|
+
} = options;
|
|
523
|
+
const lineColor = selectedColor ? createInteractiveExpression(defaultColor, hoverColor, selectedColor) : createHoverExpression(defaultColor, hoverColor);
|
|
524
|
+
const lineWidth = selectedColor ? createInteractiveExpression(defaultWidth, hoverWidth, selectedWidth) : createHoverExpression(defaultWidth, hoverWidth);
|
|
525
|
+
return {
|
|
526
|
+
"line-color": lineColor,
|
|
527
|
+
"line-width": lineWidth
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
function createExtrusionHeightExpression(property, options = {}) {
|
|
531
|
+
const { scale = 1, minHeight = 0, maxHeight, defaultHeight = 0 } = options;
|
|
532
|
+
let heightExpr = ["coalesce", ["get", property], defaultHeight];
|
|
533
|
+
if (scale !== 1) {
|
|
534
|
+
heightExpr = ["*", heightExpr, scale];
|
|
535
|
+
}
|
|
536
|
+
if (minHeight > 0) {
|
|
537
|
+
heightExpr = ["max", heightExpr, minHeight];
|
|
538
|
+
}
|
|
539
|
+
if (maxHeight !== void 0) {
|
|
540
|
+
heightExpr = ["min", heightExpr, maxHeight];
|
|
541
|
+
}
|
|
542
|
+
return heightExpr;
|
|
543
|
+
}
|
|
544
|
+
function createStatusColorExpression(statusColors, defaultColor = "#888888") {
|
|
545
|
+
return createCategoricalColorExpression("status", statusColors, defaultColor);
|
|
546
|
+
}
|
|
547
|
+
function createInteractiveStatusColorExpression(statusColors, options) {
|
|
548
|
+
const { hoverColor, selectedColor, defaultColor = "#888888" } = options;
|
|
549
|
+
const baseExpr = createCategoricalColorExpression("status", statusColors, defaultColor);
|
|
550
|
+
if (selectedColor) {
|
|
551
|
+
return [
|
|
552
|
+
"case",
|
|
553
|
+
["boolean", ["feature-state", "selected"], false],
|
|
554
|
+
selectedColor,
|
|
555
|
+
["boolean", ["feature-state", "hover"], false],
|
|
556
|
+
hoverColor,
|
|
557
|
+
baseExpr
|
|
558
|
+
];
|
|
559
|
+
}
|
|
560
|
+
return ["case", ["boolean", ["feature-state", "hover"], false], hoverColor, baseExpr];
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
// src/utils/format.ts
|
|
564
|
+
function formatCoordinates(coordinates, precision = 6, format = "decimal") {
|
|
565
|
+
const [lng, lat] = coordinates;
|
|
566
|
+
switch (format) {
|
|
567
|
+
case "dms":
|
|
568
|
+
return `${decimalToDMS(lat, "lat")}, ${decimalToDMS(lng, "lng")}`;
|
|
569
|
+
case "dd":
|
|
570
|
+
return `${lat.toFixed(precision)}, ${lng.toFixed(precision)}`;
|
|
571
|
+
case "decimal":
|
|
572
|
+
default:
|
|
573
|
+
return `${lng.toFixed(precision)}, ${lat.toFixed(precision)}`;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
function decimalToDMS(decimal, type) {
|
|
577
|
+
const absolute = Math.abs(decimal);
|
|
578
|
+
const degrees = Math.floor(absolute);
|
|
579
|
+
const minutesDecimal = (absolute - degrees) * 60;
|
|
580
|
+
const minutes = Math.floor(minutesDecimal);
|
|
581
|
+
const seconds = ((minutesDecimal - minutes) * 60).toFixed(1);
|
|
582
|
+
let direction;
|
|
583
|
+
if (type === "lat") {
|
|
584
|
+
direction = decimal >= 0 ? "N" : "S";
|
|
585
|
+
} else {
|
|
586
|
+
direction = decimal >= 0 ? "E" : "W";
|
|
587
|
+
}
|
|
588
|
+
return `${degrees}\xB0 ${minutes}' ${seconds}" ${direction}`;
|
|
589
|
+
}
|
|
590
|
+
function formatDistance(meters, unit = "metric") {
|
|
591
|
+
if (unit === "imperial") {
|
|
592
|
+
const feet = meters * 3.28084;
|
|
593
|
+
if (feet < 1e3) {
|
|
594
|
+
return `${Math.round(feet)} ft`;
|
|
595
|
+
}
|
|
596
|
+
const miles = feet / 5280;
|
|
597
|
+
if (miles < 10) {
|
|
598
|
+
return `${miles.toFixed(1)} mi`;
|
|
599
|
+
}
|
|
600
|
+
return `${Math.round(miles)} mi`;
|
|
601
|
+
}
|
|
602
|
+
if (meters < 1e3) {
|
|
603
|
+
return `${Math.round(meters)} m`;
|
|
604
|
+
}
|
|
605
|
+
const km = meters / 1e3;
|
|
606
|
+
if (km < 10) {
|
|
607
|
+
return `${km.toFixed(1)} km`;
|
|
608
|
+
}
|
|
609
|
+
return `${Math.round(km)} km`;
|
|
610
|
+
}
|
|
611
|
+
function formatArea(sqMeters, unit = "metric") {
|
|
612
|
+
if (unit === "imperial") {
|
|
613
|
+
const sqFeet = sqMeters * 10.7639;
|
|
614
|
+
if (sqFeet < 43560) {
|
|
615
|
+
return `${Math.round(sqFeet).toLocaleString()} sq ft`;
|
|
616
|
+
}
|
|
617
|
+
const acres = sqFeet / 43560;
|
|
618
|
+
if (acres < 640) {
|
|
619
|
+
return `${acres.toFixed(2)} acres`;
|
|
620
|
+
}
|
|
621
|
+
const sqMiles = acres / 640;
|
|
622
|
+
return `${sqMiles.toFixed(2)} sq mi`;
|
|
623
|
+
}
|
|
624
|
+
if (sqMeters < 1e4) {
|
|
625
|
+
return `${Math.round(sqMeters).toLocaleString()} m\xB2`;
|
|
626
|
+
}
|
|
627
|
+
const hectares = sqMeters / 1e4;
|
|
628
|
+
if (hectares < 100) {
|
|
629
|
+
return `${hectares.toFixed(2)} ha`;
|
|
630
|
+
}
|
|
631
|
+
const sqKm = sqMeters / 1e6;
|
|
632
|
+
return `${sqKm.toFixed(2)} km\xB2`;
|
|
633
|
+
}
|
|
634
|
+
function formatBounds(bounds) {
|
|
635
|
+
let sw;
|
|
636
|
+
let ne;
|
|
637
|
+
if (Array.isArray(bounds) && Array.isArray(bounds[0])) {
|
|
638
|
+
const arr = bounds;
|
|
639
|
+
sw = arr[0];
|
|
640
|
+
ne = arr[1];
|
|
641
|
+
} else {
|
|
642
|
+
const b = bounds;
|
|
643
|
+
sw = b.southwest;
|
|
644
|
+
ne = b.northeast;
|
|
645
|
+
}
|
|
646
|
+
return `SW: ${formatCoordinates(sw, 4)}, NE: ${formatCoordinates(ne, 4)}`;
|
|
647
|
+
}
|
|
648
|
+
function formatZoom(zoom) {
|
|
649
|
+
return `Zoom: ${zoom.toFixed(1)}`;
|
|
650
|
+
}
|
|
651
|
+
function formatBearing(bearing) {
|
|
652
|
+
const normalized = (bearing % 360 + 360) % 360;
|
|
653
|
+
let direction;
|
|
654
|
+
if (normalized >= 337.5 || normalized < 22.5) {
|
|
655
|
+
direction = "N";
|
|
656
|
+
} else if (normalized >= 22.5 && normalized < 67.5) {
|
|
657
|
+
direction = "NE";
|
|
658
|
+
} else if (normalized >= 67.5 && normalized < 112.5) {
|
|
659
|
+
direction = "E";
|
|
660
|
+
} else if (normalized >= 112.5 && normalized < 157.5) {
|
|
661
|
+
direction = "SE";
|
|
662
|
+
} else if (normalized >= 157.5 && normalized < 202.5) {
|
|
663
|
+
direction = "S";
|
|
664
|
+
} else if (normalized >= 202.5 && normalized < 247.5) {
|
|
665
|
+
direction = "SW";
|
|
666
|
+
} else if (normalized >= 247.5 && normalized < 292.5) {
|
|
667
|
+
direction = "W";
|
|
668
|
+
} else {
|
|
669
|
+
direction = "NW";
|
|
670
|
+
}
|
|
671
|
+
return `${Math.round(normalized)}\xB0 ${direction}`;
|
|
672
|
+
}
|
|
673
|
+
function formatPitch(pitch) {
|
|
674
|
+
return `${Math.round(pitch)}\xB0 tilt`;
|
|
675
|
+
}
|
|
676
|
+
function formatScale(scale) {
|
|
677
|
+
if (scale >= 1e6) {
|
|
678
|
+
return `1:${(scale / 1e6).toFixed(1)}M`;
|
|
679
|
+
}
|
|
680
|
+
if (scale >= 1e3) {
|
|
681
|
+
return `1:${Math.round(scale / 1e3)}K`;
|
|
682
|
+
}
|
|
683
|
+
return `1:${Math.round(scale)}`;
|
|
684
|
+
}
|
|
685
|
+
function zoomToScale(zoom, latitude = 0) {
|
|
686
|
+
const metersPerPixel = 40075e3 * Math.cos(latitude * Math.PI / 180) / (256 * Math.pow(2, zoom));
|
|
687
|
+
const screenMetersPerPixel = 264583e-9;
|
|
688
|
+
return Math.round(metersPerPixel / screenMetersPerPixel);
|
|
689
|
+
}
|
|
690
|
+
function formatPropertyValue(value) {
|
|
691
|
+
if (value === null || value === void 0) {
|
|
692
|
+
return "-";
|
|
693
|
+
}
|
|
694
|
+
if (typeof value === "number") {
|
|
695
|
+
if (Math.abs(value) <= 180 && value !== Math.floor(value)) {
|
|
696
|
+
return value.toFixed(6);
|
|
697
|
+
}
|
|
698
|
+
if (Math.abs(value) >= 1e3) {
|
|
699
|
+
return value.toLocaleString();
|
|
700
|
+
}
|
|
701
|
+
if (value !== Math.floor(value)) {
|
|
702
|
+
return value.toFixed(2);
|
|
703
|
+
}
|
|
704
|
+
return String(value);
|
|
705
|
+
}
|
|
706
|
+
if (typeof value === "boolean") {
|
|
707
|
+
return value ? "Yes" : "No";
|
|
708
|
+
}
|
|
709
|
+
if (Array.isArray(value)) {
|
|
710
|
+
return value.map(formatPropertyValue).join(", ");
|
|
711
|
+
}
|
|
712
|
+
if (typeof value === "object") {
|
|
713
|
+
return JSON.stringify(value);
|
|
714
|
+
}
|
|
715
|
+
return String(value);
|
|
716
|
+
}
|
|
717
|
+
function formatFeatureProperties(properties, options) {
|
|
718
|
+
const exclude = options?.exclude || ["id", "_id", "fid", "ogc_fid"];
|
|
719
|
+
const include = options?.include;
|
|
720
|
+
const labelMap = options?.labelMap || {};
|
|
721
|
+
const entries = Object.entries(properties).filter(([key]) => {
|
|
722
|
+
if (include) {
|
|
723
|
+
return include.includes(key);
|
|
724
|
+
}
|
|
725
|
+
return !exclude.includes(key) && !key.startsWith("_");
|
|
726
|
+
}).map(([key, value]) => {
|
|
727
|
+
const label = labelMap[key] || formatLabel(key);
|
|
728
|
+
return `<strong>${label}:</strong> ${formatPropertyValue(value)}`;
|
|
729
|
+
});
|
|
730
|
+
return entries.join("<br>");
|
|
731
|
+
}
|
|
732
|
+
function formatLabel(key) {
|
|
733
|
+
return key.replace(/_/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2").replace(/\b\w/g, (char) => char.toUpperCase());
|
|
734
|
+
}
|
|
735
|
+
function isValidLongitude(lng) {
|
|
736
|
+
return typeof lng === "number" && isFinite(lng) && lng >= -180 && lng <= 180;
|
|
737
|
+
}
|
|
738
|
+
function isValidLatitude(lat) {
|
|
739
|
+
return typeof lat === "number" && isFinite(lat) && lat >= -90 && lat <= 90;
|
|
740
|
+
}
|
|
741
|
+
function validateCoordinates(coordinates) {
|
|
742
|
+
if (!Array.isArray(coordinates)) {
|
|
743
|
+
return { valid: false, error: "Coordinates must be an array" };
|
|
744
|
+
}
|
|
745
|
+
if (coordinates.length < 2) {
|
|
746
|
+
return { valid: false, error: "Coordinates must have at least 2 elements [lng, lat]" };
|
|
747
|
+
}
|
|
748
|
+
const [lng, lat] = coordinates;
|
|
749
|
+
if (typeof lng !== "number" || typeof lat !== "number") {
|
|
750
|
+
return { valid: false, error: "Longitude and latitude must be numbers" };
|
|
751
|
+
}
|
|
752
|
+
if (!isFinite(lng) || !isFinite(lat)) {
|
|
753
|
+
return { valid: false, error: "Coordinates must be finite numbers" };
|
|
754
|
+
}
|
|
755
|
+
if (lng < -180 || lng > 180) {
|
|
756
|
+
return { valid: false, error: `Longitude ${lng} out of range [-180, 180]` };
|
|
757
|
+
}
|
|
758
|
+
if (lat < -90 || lat > 90) {
|
|
759
|
+
return { valid: false, error: `Latitude ${lat} out of range [-90, 90]` };
|
|
760
|
+
}
|
|
761
|
+
return {
|
|
762
|
+
valid: true,
|
|
763
|
+
normalized: [lng, lat]
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
function ensureValidCoordinates(coordinates) {
|
|
767
|
+
const result = validateCoordinates(coordinates);
|
|
768
|
+
if (!result.valid) {
|
|
769
|
+
throw new Error(`Invalid coordinates: ${result.error}`);
|
|
770
|
+
}
|
|
771
|
+
return result.normalized;
|
|
772
|
+
}
|
|
773
|
+
function normalizeLongitude(lng) {
|
|
774
|
+
if (!isFinite(lng)) return NaN;
|
|
775
|
+
let normalized = lng % 360;
|
|
776
|
+
if (normalized > 180) {
|
|
777
|
+
normalized -= 360;
|
|
778
|
+
} else if (normalized < -180) {
|
|
779
|
+
normalized += 360;
|
|
780
|
+
}
|
|
781
|
+
return normalized;
|
|
782
|
+
}
|
|
783
|
+
function clampLatitude(lat) {
|
|
784
|
+
if (!isFinite(lat)) return NaN;
|
|
785
|
+
return Math.max(-90, Math.min(90, lat));
|
|
786
|
+
}
|
|
787
|
+
function validateBoundsArray(bounds) {
|
|
788
|
+
if (!Array.isArray(bounds)) {
|
|
789
|
+
return { valid: false, error: "Bounds must be an array" };
|
|
790
|
+
}
|
|
791
|
+
if (bounds.length !== 2) {
|
|
792
|
+
return { valid: false, error: "Bounds must have exactly 2 elements [southwest, northeast]" };
|
|
793
|
+
}
|
|
794
|
+
const swResult = validateCoordinates(bounds[0]);
|
|
795
|
+
if (!swResult.valid) {
|
|
796
|
+
return { valid: false, error: `Invalid southwest corner: ${swResult.error}` };
|
|
797
|
+
}
|
|
798
|
+
const neResult = validateCoordinates(bounds[1]);
|
|
799
|
+
if (!neResult.valid) {
|
|
800
|
+
return { valid: false, error: `Invalid northeast corner: ${neResult.error}` };
|
|
801
|
+
}
|
|
802
|
+
const [, swLat] = swResult.normalized;
|
|
803
|
+
const [, neLat] = neResult.normalized;
|
|
804
|
+
if (swLat > neLat) {
|
|
805
|
+
return {
|
|
806
|
+
valid: false,
|
|
807
|
+
error: `Southwest latitude (${swLat}) must be less than northeast latitude (${neLat})`
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
return {
|
|
811
|
+
valid: true,
|
|
812
|
+
normalized: [swResult.normalized, neResult.normalized]
|
|
813
|
+
};
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
// src/utils/bounds.ts
|
|
817
|
+
function calculateBounds(geojson) {
|
|
818
|
+
let minLng = Infinity;
|
|
819
|
+
let maxLng = -Infinity;
|
|
820
|
+
let minLat = Infinity;
|
|
821
|
+
let maxLat = -Infinity;
|
|
822
|
+
let hasCoordinates = false;
|
|
823
|
+
function processCoordinate(coord) {
|
|
824
|
+
const [lng, lat] = coord;
|
|
825
|
+
if (typeof lng === "number" && typeof lat === "number" && isFinite(lng) && isFinite(lat)) {
|
|
826
|
+
minLng = Math.min(minLng, lng);
|
|
827
|
+
maxLng = Math.max(maxLng, lng);
|
|
828
|
+
minLat = Math.min(minLat, lat);
|
|
829
|
+
maxLat = Math.max(maxLat, lat);
|
|
830
|
+
hasCoordinates = true;
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
function processGeometry(geometry) {
|
|
834
|
+
if (!geometry) return;
|
|
835
|
+
switch (geometry.type) {
|
|
836
|
+
case "Point":
|
|
837
|
+
processCoordinate(geometry.coordinates);
|
|
838
|
+
break;
|
|
839
|
+
case "MultiPoint":
|
|
840
|
+
case "LineString":
|
|
841
|
+
geometry.coordinates.forEach(processCoordinate);
|
|
842
|
+
break;
|
|
843
|
+
case "MultiLineString":
|
|
844
|
+
case "Polygon":
|
|
845
|
+
geometry.coordinates.forEach((ring) => ring.forEach(processCoordinate));
|
|
846
|
+
break;
|
|
847
|
+
case "MultiPolygon":
|
|
848
|
+
geometry.coordinates.forEach(
|
|
849
|
+
(polygon) => polygon.forEach((ring) => ring.forEach(processCoordinate))
|
|
850
|
+
);
|
|
851
|
+
break;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
if (geojson.type === "FeatureCollection") {
|
|
855
|
+
geojson.features.forEach((feature) => processGeometry(feature.geometry));
|
|
856
|
+
} else if (geojson.type === "Feature") {
|
|
857
|
+
processGeometry(geojson.geometry);
|
|
858
|
+
}
|
|
859
|
+
if (!hasCoordinates) {
|
|
860
|
+
return null;
|
|
861
|
+
}
|
|
862
|
+
return [
|
|
863
|
+
[minLng, minLat],
|
|
864
|
+
// Southwest
|
|
865
|
+
[maxLng, maxLat]
|
|
866
|
+
// Northeast
|
|
867
|
+
];
|
|
868
|
+
}
|
|
869
|
+
function extendBounds(bounds, point) {
|
|
870
|
+
const [[swLng, swLat], [neLng, neLat]] = bounds;
|
|
871
|
+
const [lng, lat] = point;
|
|
872
|
+
return [
|
|
873
|
+
[Math.min(swLng, lng), Math.min(swLat, lat)],
|
|
874
|
+
[Math.max(neLng, lng), Math.max(neLat, lat)]
|
|
875
|
+
];
|
|
876
|
+
}
|
|
877
|
+
function combineBounds(bounds1, bounds2) {
|
|
878
|
+
const [[sw1Lng, sw1Lat], [ne1Lng, ne1Lat]] = bounds1;
|
|
879
|
+
const [[sw2Lng, sw2Lat], [ne2Lng, ne2Lat]] = bounds2;
|
|
880
|
+
return [
|
|
881
|
+
[Math.min(sw1Lng, sw2Lng), Math.min(sw1Lat, sw2Lat)],
|
|
882
|
+
[Math.max(ne1Lng, ne2Lng), Math.max(ne1Lat, ne2Lat)]
|
|
883
|
+
];
|
|
884
|
+
}
|
|
885
|
+
function isValidBounds(bounds) {
|
|
886
|
+
if (!Array.isArray(bounds) || bounds.length !== 2) {
|
|
887
|
+
return false;
|
|
888
|
+
}
|
|
889
|
+
const [sw, ne] = bounds;
|
|
890
|
+
if (!Array.isArray(sw) || sw.length !== 2 || !Array.isArray(ne) || ne.length !== 2) {
|
|
891
|
+
return false;
|
|
892
|
+
}
|
|
893
|
+
const [swLng, swLat] = sw;
|
|
894
|
+
const [neLng, neLat] = ne;
|
|
895
|
+
if (typeof swLng !== "number" || typeof swLat !== "number" || typeof neLng !== "number" || typeof neLat !== "number" || !isFinite(swLng) || !isFinite(swLat) || !isFinite(neLng) || !isFinite(neLat)) {
|
|
896
|
+
return false;
|
|
897
|
+
}
|
|
898
|
+
if (swLat > neLat) {
|
|
899
|
+
return false;
|
|
900
|
+
}
|
|
901
|
+
if (swLat < -90 || swLat > 90 || neLat < -90 || neLat > 90) {
|
|
902
|
+
return false;
|
|
903
|
+
}
|
|
904
|
+
if (swLng < -180 || swLng > 180 || neLng < -180 || neLng > 180) {
|
|
905
|
+
return false;
|
|
906
|
+
}
|
|
907
|
+
return true;
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
// src/utils/data.ts
|
|
911
|
+
async function loadGeoJSON(url, options = {}) {
|
|
912
|
+
const { timeout = 3e4, fetchOptions = {}, validate = true } = options;
|
|
913
|
+
try {
|
|
914
|
+
const controller = new AbortController();
|
|
915
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
916
|
+
const response = await fetch(url, {
|
|
917
|
+
...fetchOptions,
|
|
918
|
+
signal: controller.signal,
|
|
919
|
+
headers: {
|
|
920
|
+
Accept: "application/geo+json, application/json",
|
|
921
|
+
...fetchOptions.headers
|
|
922
|
+
}
|
|
923
|
+
});
|
|
924
|
+
clearTimeout(timeoutId);
|
|
925
|
+
if (!response.ok) {
|
|
926
|
+
return {
|
|
927
|
+
data: null,
|
|
928
|
+
error: `HTTP ${response.status}: ${response.statusText}`,
|
|
929
|
+
success: false
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
const data = await response.json();
|
|
933
|
+
if (validate) {
|
|
934
|
+
const validation = validateGeoJSON(data);
|
|
935
|
+
if (!validation.valid) {
|
|
936
|
+
return {
|
|
937
|
+
data: null,
|
|
938
|
+
error: `Invalid GeoJSON: ${validation.errors.join(", ")}`,
|
|
939
|
+
success: false
|
|
940
|
+
};
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
return {
|
|
944
|
+
data,
|
|
945
|
+
error: null,
|
|
946
|
+
success: true
|
|
947
|
+
};
|
|
948
|
+
} catch (err) {
|
|
949
|
+
if (err instanceof Error) {
|
|
950
|
+
if (err.name === "AbortError") {
|
|
951
|
+
return {
|
|
952
|
+
data: null,
|
|
953
|
+
error: `Request timeout after ${timeout}ms`,
|
|
954
|
+
success: false
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
return {
|
|
958
|
+
data: null,
|
|
959
|
+
error: err.message,
|
|
960
|
+
success: false
|
|
961
|
+
};
|
|
962
|
+
}
|
|
963
|
+
return {
|
|
964
|
+
data: null,
|
|
965
|
+
error: "Unknown error loading GeoJSON",
|
|
966
|
+
success: false
|
|
967
|
+
};
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
function validateGeoJSON(data) {
|
|
971
|
+
const errors = [];
|
|
972
|
+
const geometryTypes = /* @__PURE__ */ new Set();
|
|
973
|
+
let featureCount = 0;
|
|
974
|
+
if (!data || typeof data !== "object") {
|
|
975
|
+
return {
|
|
976
|
+
valid: false,
|
|
977
|
+
errors: ["Data must be an object"]
|
|
978
|
+
};
|
|
979
|
+
}
|
|
980
|
+
const obj = data;
|
|
981
|
+
if (!obj.type) {
|
|
982
|
+
errors.push('Missing "type" property');
|
|
983
|
+
return { valid: false, errors };
|
|
984
|
+
}
|
|
985
|
+
if (obj.type === "FeatureCollection") {
|
|
986
|
+
if (!Array.isArray(obj.features)) {
|
|
987
|
+
errors.push('"features" must be an array');
|
|
988
|
+
return { valid: false, errors };
|
|
989
|
+
}
|
|
990
|
+
featureCount = obj.features.length;
|
|
991
|
+
for (let i = 0; i < obj.features.length; i++) {
|
|
992
|
+
const feature = obj.features[i];
|
|
993
|
+
const featureErrors = validateFeature(feature, i);
|
|
994
|
+
errors.push(...featureErrors.errors);
|
|
995
|
+
if (feature && typeof feature === "object" && feature.geometry) {
|
|
996
|
+
const geom = feature.geometry;
|
|
997
|
+
if (geom && geom.type) {
|
|
998
|
+
geometryTypes.add(geom.type);
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
} else if (obj.type === "Feature") {
|
|
1003
|
+
const featureErrors = validateFeature(obj, 0);
|
|
1004
|
+
errors.push(...featureErrors.errors);
|
|
1005
|
+
featureCount = 1;
|
|
1006
|
+
if (obj.geometry && typeof obj.geometry === "object") {
|
|
1007
|
+
const geom = obj.geometry;
|
|
1008
|
+
if (geom.type) {
|
|
1009
|
+
geometryTypes.add(geom.type);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
} else if (isGeometryType(obj.type)) {
|
|
1013
|
+
const geomErrors = validateGeometry(obj);
|
|
1014
|
+
errors.push(...geomErrors);
|
|
1015
|
+
geometryTypes.add(obj.type);
|
|
1016
|
+
} else {
|
|
1017
|
+
errors.push(`Unknown GeoJSON type: "${obj.type}"`);
|
|
1018
|
+
}
|
|
1019
|
+
return {
|
|
1020
|
+
valid: errors.length === 0,
|
|
1021
|
+
errors,
|
|
1022
|
+
featureCount,
|
|
1023
|
+
geometryTypes: Array.from(geometryTypes)
|
|
1024
|
+
};
|
|
1025
|
+
}
|
|
1026
|
+
function validateFeature(feature, index) {
|
|
1027
|
+
const errors = [];
|
|
1028
|
+
const prefix = `Feature[${index}]`;
|
|
1029
|
+
if (!feature || typeof feature !== "object") {
|
|
1030
|
+
errors.push(`${prefix}: must be an object`);
|
|
1031
|
+
return { valid: false, errors };
|
|
1032
|
+
}
|
|
1033
|
+
const f = feature;
|
|
1034
|
+
if (f.type !== "Feature") {
|
|
1035
|
+
errors.push(`${prefix}: type must be "Feature"`);
|
|
1036
|
+
}
|
|
1037
|
+
if (f.geometry !== null && f.geometry !== void 0) {
|
|
1038
|
+
if (typeof f.geometry !== "object") {
|
|
1039
|
+
errors.push(`${prefix}: geometry must be an object or null`);
|
|
1040
|
+
} else {
|
|
1041
|
+
const geomErrors = validateGeometry(f.geometry, prefix);
|
|
1042
|
+
errors.push(...geomErrors);
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
if (f.properties !== null && f.properties !== void 0) {
|
|
1046
|
+
if (typeof f.properties !== "object") {
|
|
1047
|
+
errors.push(`${prefix}: properties must be an object or null`);
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
return { valid: errors.length === 0, errors };
|
|
1051
|
+
}
|
|
1052
|
+
function validateGeometry(geometry, prefix = "") {
|
|
1053
|
+
const errors = [];
|
|
1054
|
+
const p = prefix ? `${prefix}.geometry` : "Geometry";
|
|
1055
|
+
if (!geometry || typeof geometry !== "object") {
|
|
1056
|
+
errors.push(`${p}: must be an object`);
|
|
1057
|
+
return errors;
|
|
1058
|
+
}
|
|
1059
|
+
if (!geometry.type) {
|
|
1060
|
+
errors.push(`${p}: missing type`);
|
|
1061
|
+
return errors;
|
|
1062
|
+
}
|
|
1063
|
+
if (!isGeometryType(geometry.type)) {
|
|
1064
|
+
errors.push(`${p}: unknown geometry type "${geometry.type}"`);
|
|
1065
|
+
return errors;
|
|
1066
|
+
}
|
|
1067
|
+
if (geometry.type !== "GeometryCollection") {
|
|
1068
|
+
if (!("coordinates" in geometry) || geometry.coordinates === void 0) {
|
|
1069
|
+
errors.push(`${p}: missing coordinates`);
|
|
1070
|
+
return errors;
|
|
1071
|
+
}
|
|
1072
|
+
if (!Array.isArray(geometry.coordinates)) {
|
|
1073
|
+
errors.push(`${p}: coordinates must be an array`);
|
|
1074
|
+
return errors;
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
switch (geometry.type) {
|
|
1078
|
+
case "Point":
|
|
1079
|
+
if (!isValidPosition(geometry.coordinates)) {
|
|
1080
|
+
errors.push(`${p}: invalid Point coordinates`);
|
|
1081
|
+
}
|
|
1082
|
+
break;
|
|
1083
|
+
case "MultiPoint":
|
|
1084
|
+
case "LineString":
|
|
1085
|
+
if (!Array.isArray(geometry.coordinates) || geometry.coordinates.length === 0) {
|
|
1086
|
+
errors.push(`${p}: ${geometry.type} must have at least one position`);
|
|
1087
|
+
}
|
|
1088
|
+
break;
|
|
1089
|
+
case "Polygon":
|
|
1090
|
+
case "MultiLineString":
|
|
1091
|
+
if (!Array.isArray(geometry.coordinates) || geometry.coordinates.length === 0) {
|
|
1092
|
+
errors.push(`${p}: ${geometry.type} must have at least one ring/line`);
|
|
1093
|
+
}
|
|
1094
|
+
break;
|
|
1095
|
+
case "MultiPolygon":
|
|
1096
|
+
if (!Array.isArray(geometry.coordinates) || geometry.coordinates.length === 0) {
|
|
1097
|
+
errors.push(`${p}: MultiPolygon must have at least one polygon`);
|
|
1098
|
+
}
|
|
1099
|
+
break;
|
|
1100
|
+
case "GeometryCollection": {
|
|
1101
|
+
const geomCollection = geometry;
|
|
1102
|
+
if (!("geometries" in geometry)) {
|
|
1103
|
+
errors.push(`${p}: GeometryCollection must have "geometries" array`);
|
|
1104
|
+
} else if (!Array.isArray(geomCollection.geometries)) {
|
|
1105
|
+
errors.push(`${p}: GeometryCollection "geometries" must be an array`);
|
|
1106
|
+
} else {
|
|
1107
|
+
geomCollection.geometries.forEach((geom, idx) => {
|
|
1108
|
+
const nestedErrors = validateGeometry(geom, `${p}.geometries[${idx}]`);
|
|
1109
|
+
errors.push(...nestedErrors);
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
break;
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
return errors;
|
|
1116
|
+
}
|
|
1117
|
+
function isGeometryType(type) {
|
|
1118
|
+
return [
|
|
1119
|
+
"Point",
|
|
1120
|
+
"MultiPoint",
|
|
1121
|
+
"LineString",
|
|
1122
|
+
"MultiLineString",
|
|
1123
|
+
"Polygon",
|
|
1124
|
+
"MultiPolygon",
|
|
1125
|
+
"GeometryCollection"
|
|
1126
|
+
].includes(type);
|
|
1127
|
+
}
|
|
1128
|
+
function isValidPosition(position) {
|
|
1129
|
+
if (!Array.isArray(position)) return false;
|
|
1130
|
+
if (position.length < 2 || position.length > 3) return false;
|
|
1131
|
+
return position.every((coord) => typeof coord === "number" && isFinite(coord));
|
|
1132
|
+
}
|
|
1133
|
+
function calculateCentroid(geojson) {
|
|
1134
|
+
const coords = [];
|
|
1135
|
+
function collectCoordinates(geometry) {
|
|
1136
|
+
if (!geometry) return;
|
|
1137
|
+
switch (geometry.type) {
|
|
1138
|
+
case "Point":
|
|
1139
|
+
coords.push(geometry.coordinates);
|
|
1140
|
+
break;
|
|
1141
|
+
case "MultiPoint":
|
|
1142
|
+
case "LineString":
|
|
1143
|
+
geometry.coordinates.forEach((c) => coords.push(c));
|
|
1144
|
+
break;
|
|
1145
|
+
case "MultiLineString":
|
|
1146
|
+
case "Polygon":
|
|
1147
|
+
geometry.coordinates.forEach(
|
|
1148
|
+
(ring) => ring.forEach((c) => coords.push(c))
|
|
1149
|
+
);
|
|
1150
|
+
break;
|
|
1151
|
+
case "MultiPolygon":
|
|
1152
|
+
geometry.coordinates.forEach(
|
|
1153
|
+
(polygon) => polygon.forEach((ring) => ring.forEach((c) => coords.push(c)))
|
|
1154
|
+
);
|
|
1155
|
+
break;
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
if (geojson.type === "FeatureCollection") {
|
|
1159
|
+
geojson.features.forEach((f) => collectCoordinates(f.geometry));
|
|
1160
|
+
} else if (geojson.type === "Feature") {
|
|
1161
|
+
collectCoordinates(geojson.geometry);
|
|
1162
|
+
}
|
|
1163
|
+
if (coords.length === 0) return null;
|
|
1164
|
+
const sum = coords.reduce((acc, [lng, lat]) => [acc[0] + lng, acc[1] + lat], [0, 0]);
|
|
1165
|
+
return [sum[0] / coords.length, sum[1] / coords.length];
|
|
1166
|
+
}
|
|
1167
|
+
function countFeaturesByType(geojson) {
|
|
1168
|
+
const counts = {};
|
|
1169
|
+
geojson.features.forEach((feature) => {
|
|
1170
|
+
const type = feature.geometry?.type || "null";
|
|
1171
|
+
counts[type] = (counts[type] || 0) + 1;
|
|
1172
|
+
});
|
|
1173
|
+
return counts;
|
|
1174
|
+
}
|
|
1175
|
+
function filterByGeometryType(geojson, types) {
|
|
1176
|
+
return {
|
|
1177
|
+
type: "FeatureCollection",
|
|
1178
|
+
features: geojson.features.filter((f) => f.geometry && types.includes(f.geometry.type))
|
|
1179
|
+
};
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
// src/utils/cluster.ts
|
|
1183
|
+
function isClusterFeature(feature) {
|
|
1184
|
+
return feature.properties !== null && feature.properties !== void 0 && typeof feature.properties === "object" && "cluster_id" in feature.properties && "point_count" in feature.properties;
|
|
1185
|
+
}
|
|
1186
|
+
async function getClusterExpansionZoom(map, sourceId, clusterId) {
|
|
1187
|
+
const source = map.getSource(sourceId);
|
|
1188
|
+
if (!source) {
|
|
1189
|
+
throw new Error(`Source "${sourceId}" not found`);
|
|
1190
|
+
}
|
|
1191
|
+
if (typeof source.getClusterExpansionZoom !== "function") {
|
|
1192
|
+
throw new Error(`Source "${sourceId}" does not support clustering`);
|
|
1193
|
+
}
|
|
1194
|
+
return source.getClusterExpansionZoom(clusterId);
|
|
1195
|
+
}
|
|
1196
|
+
async function getClusterChildren(map, sourceId, clusterId) {
|
|
1197
|
+
const source = map.getSource(sourceId);
|
|
1198
|
+
if (!source) {
|
|
1199
|
+
throw new Error(`Source "${sourceId}" not found`);
|
|
1200
|
+
}
|
|
1201
|
+
if (typeof source.getClusterChildren !== "function") {
|
|
1202
|
+
throw new Error(`Source "${sourceId}" does not support clustering`);
|
|
1203
|
+
}
|
|
1204
|
+
return source.getClusterChildren(clusterId);
|
|
1205
|
+
}
|
|
1206
|
+
async function getClusterLeaves(map, sourceId, clusterId, limit = 100, offset = 0) {
|
|
1207
|
+
const source = map.getSource(sourceId);
|
|
1208
|
+
if (!source) {
|
|
1209
|
+
throw new Error(`Source "${sourceId}" not found`);
|
|
1210
|
+
}
|
|
1211
|
+
if (typeof source.getClusterLeaves !== "function") {
|
|
1212
|
+
throw new Error(`Source "${sourceId}" does not support clustering`);
|
|
1213
|
+
}
|
|
1214
|
+
return source.getClusterLeaves(clusterId, limit, offset);
|
|
1215
|
+
}
|
|
1216
|
+
async function expandCluster(map, sourceId, clusterId, center, options = {}) {
|
|
1217
|
+
const { duration = 500, animate = true, padding, maxZoom } = options;
|
|
1218
|
+
const expansionZoom = await getClusterExpansionZoom(map, sourceId, clusterId);
|
|
1219
|
+
const targetZoom = maxZoom !== void 0 ? Math.min(expansionZoom, maxZoom) : expansionZoom;
|
|
1220
|
+
if (map.getZoom() < targetZoom) {
|
|
1221
|
+
map.easeTo({
|
|
1222
|
+
center,
|
|
1223
|
+
zoom: targetZoom,
|
|
1224
|
+
duration: animate ? duration : 0,
|
|
1225
|
+
animate,
|
|
1226
|
+
...padding !== void 0 && { padding }
|
|
1227
|
+
});
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
async function getClusterBounds(map, sourceId, clusterId, limit = 1e3) {
|
|
1231
|
+
const leaves = await getClusterLeaves(map, sourceId, clusterId, limit);
|
|
1232
|
+
if (leaves.length === 0) {
|
|
1233
|
+
throw new Error("Cluster has no leaves");
|
|
1234
|
+
}
|
|
1235
|
+
let minLng = Infinity;
|
|
1236
|
+
let minLat = Infinity;
|
|
1237
|
+
let maxLng = -Infinity;
|
|
1238
|
+
let maxLat = -Infinity;
|
|
1239
|
+
for (const leaf of leaves) {
|
|
1240
|
+
if (leaf.geometry.type === "Point") {
|
|
1241
|
+
const [lng, lat] = leaf.geometry.coordinates;
|
|
1242
|
+
minLng = Math.min(minLng, lng);
|
|
1243
|
+
minLat = Math.min(minLat, lat);
|
|
1244
|
+
maxLng = Math.max(maxLng, lng);
|
|
1245
|
+
maxLat = Math.max(maxLat, lat);
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
return [
|
|
1249
|
+
[minLng, minLat],
|
|
1250
|
+
[maxLng, maxLat]
|
|
1251
|
+
];
|
|
1252
|
+
}
|
|
1253
|
+
async function expandClusterToBounds(map, sourceId, clusterId, options = {}) {
|
|
1254
|
+
const { duration = 500, animate = true, padding = 50, maxZoom } = options;
|
|
1255
|
+
const bounds = await getClusterBounds(map, sourceId, clusterId);
|
|
1256
|
+
map.fitBounds(bounds, {
|
|
1257
|
+
padding,
|
|
1258
|
+
duration: animate ? duration : 0,
|
|
1259
|
+
animate,
|
|
1260
|
+
...maxZoom !== void 0 && { maxZoom }
|
|
1261
|
+
});
|
|
1262
|
+
}
|
|
1263
|
+
function createClusterStyles(options = {}) {
|
|
1264
|
+
const {
|
|
1265
|
+
smallColor = "#51bbd6",
|
|
1266
|
+
mediumColor = "#f1f075",
|
|
1267
|
+
largeColor = "#f28cb1",
|
|
1268
|
+
mediumThreshold = 100,
|
|
1269
|
+
largeThreshold = 750,
|
|
1270
|
+
smallRadius = 20,
|
|
1271
|
+
mediumRadius = 30,
|
|
1272
|
+
largeRadius = 40,
|
|
1273
|
+
strokeColor = "#fff",
|
|
1274
|
+
strokeWidth = 2,
|
|
1275
|
+
opacity = 0.85
|
|
1276
|
+
} = options.circle ?? {};
|
|
1277
|
+
const {
|
|
1278
|
+
textColor = "#333",
|
|
1279
|
+
textSize = 12,
|
|
1280
|
+
fontStack = ["Open Sans Bold", "Arial Unicode MS Bold"],
|
|
1281
|
+
abbreviated = false
|
|
1282
|
+
} = options.text ?? {};
|
|
1283
|
+
const {
|
|
1284
|
+
color: pointColor = "#11b4da",
|
|
1285
|
+
radius: pointRadius = 8,
|
|
1286
|
+
strokeColor: pointStrokeColor = "#fff",
|
|
1287
|
+
strokeWidth: pointStrokeWidth = 1
|
|
1288
|
+
} = options.unclusteredPoint ?? {};
|
|
1289
|
+
return {
|
|
1290
|
+
clusterCirclePaint: {
|
|
1291
|
+
"circle-color": [
|
|
1292
|
+
"step",
|
|
1293
|
+
["get", "point_count"],
|
|
1294
|
+
smallColor,
|
|
1295
|
+
mediumThreshold,
|
|
1296
|
+
mediumColor,
|
|
1297
|
+
largeThreshold,
|
|
1298
|
+
largeColor
|
|
1299
|
+
],
|
|
1300
|
+
"circle-radius": [
|
|
1301
|
+
"step",
|
|
1302
|
+
["get", "point_count"],
|
|
1303
|
+
smallRadius,
|
|
1304
|
+
mediumThreshold,
|
|
1305
|
+
mediumRadius,
|
|
1306
|
+
largeThreshold,
|
|
1307
|
+
largeRadius
|
|
1308
|
+
],
|
|
1309
|
+
"circle-stroke-color": strokeColor,
|
|
1310
|
+
"circle-stroke-width": strokeWidth,
|
|
1311
|
+
"circle-opacity": opacity
|
|
1312
|
+
},
|
|
1313
|
+
clusterTextPaint: {
|
|
1314
|
+
"text-color": textColor
|
|
1315
|
+
},
|
|
1316
|
+
clusterTextLayout: {
|
|
1317
|
+
"text-field": abbreviated ? ["get", "point_count_abbreviated"] : ["to-string", ["get", "point_count"]],
|
|
1318
|
+
"text-font": fontStack,
|
|
1319
|
+
"text-size": textSize,
|
|
1320
|
+
"text-allow-overlap": true
|
|
1321
|
+
},
|
|
1322
|
+
unclusteredPointPaint: {
|
|
1323
|
+
"circle-color": pointColor,
|
|
1324
|
+
"circle-radius": pointRadius,
|
|
1325
|
+
"circle-stroke-color": pointStrokeColor,
|
|
1326
|
+
"circle-stroke-width": pointStrokeWidth
|
|
1327
|
+
},
|
|
1328
|
+
clusterFilter: ["has", "point_count"],
|
|
1329
|
+
unclusteredFilter: ["!", ["has", "point_count"]]
|
|
1330
|
+
};
|
|
1331
|
+
}
|
|
1332
|
+
function createClusterCirclePaint(options = {}) {
|
|
1333
|
+
const styles = createClusterStyles({ circle: options });
|
|
1334
|
+
return styles.clusterCirclePaint;
|
|
1335
|
+
}
|
|
1336
|
+
function createClusterTextLayout(options = {}) {
|
|
1337
|
+
const styles = createClusterStyles({ text: options });
|
|
1338
|
+
return styles.clusterTextLayout;
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
// src/utils/lod.ts
|
|
1342
|
+
function groupFeaturesByProperty(geojson, options) {
|
|
1343
|
+
const { groupBy, subGroupBy } = options;
|
|
1344
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1345
|
+
for (const feature of geojson.features) {
|
|
1346
|
+
const groupValue = String(feature.properties?.[groupBy] ?? "unknown");
|
|
1347
|
+
if (!groups.has(groupValue)) {
|
|
1348
|
+
groups.set(groupValue, {
|
|
1349
|
+
id: groupValue,
|
|
1350
|
+
features: [],
|
|
1351
|
+
bounds: null,
|
|
1352
|
+
centroid: null,
|
|
1353
|
+
count: 0,
|
|
1354
|
+
subGroups: subGroupBy ? /* @__PURE__ */ new Map() : void 0
|
|
1355
|
+
});
|
|
1356
|
+
}
|
|
1357
|
+
const group = groups.get(groupValue);
|
|
1358
|
+
group.features.push(feature);
|
|
1359
|
+
group.count++;
|
|
1360
|
+
if (subGroupBy && group.subGroups) {
|
|
1361
|
+
const subGroupValue = String(feature.properties?.[subGroupBy] ?? "unknown");
|
|
1362
|
+
if (!group.subGroups.has(subGroupValue)) {
|
|
1363
|
+
group.subGroups.set(subGroupValue, {
|
|
1364
|
+
id: subGroupValue,
|
|
1365
|
+
features: [],
|
|
1366
|
+
bounds: null,
|
|
1367
|
+
centroid: null,
|
|
1368
|
+
count: 0
|
|
1369
|
+
});
|
|
1370
|
+
}
|
|
1371
|
+
const subGroup = group.subGroups.get(subGroupValue);
|
|
1372
|
+
subGroup.features.push(feature);
|
|
1373
|
+
subGroup.count++;
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
for (const group of groups.values()) {
|
|
1377
|
+
const groupCollection = {
|
|
1378
|
+
type: "FeatureCollection",
|
|
1379
|
+
features: group.features
|
|
1380
|
+
};
|
|
1381
|
+
group.bounds = calculateBounds(groupCollection);
|
|
1382
|
+
group.centroid = group.bounds ? calculateCentroidFromBounds(group.bounds) : null;
|
|
1383
|
+
if (group.subGroups) {
|
|
1384
|
+
for (const subGroup of group.subGroups.values()) {
|
|
1385
|
+
const subGroupCollection = {
|
|
1386
|
+
type: "FeatureCollection",
|
|
1387
|
+
features: subGroup.features
|
|
1388
|
+
};
|
|
1389
|
+
subGroup.bounds = calculateBounds(subGroupCollection);
|
|
1390
|
+
subGroup.centroid = subGroup.bounds ? calculateCentroidFromBounds(subGroup.bounds) : null;
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
return groups;
|
|
1395
|
+
}
|
|
1396
|
+
function calculateCentroidFromBounds(bounds) {
|
|
1397
|
+
const [[swLng, swLat], [neLng, neLat]] = bounds;
|
|
1398
|
+
return [(swLng + neLng) / 2, (swLat + neLat) / 2];
|
|
1399
|
+
}
|
|
1400
|
+
function generateConvexHull(features) {
|
|
1401
|
+
const points = [];
|
|
1402
|
+
for (const feature of features) {
|
|
1403
|
+
if (feature.geometry?.type === "Polygon") {
|
|
1404
|
+
const exteriorRing = feature.geometry.coordinates[0];
|
|
1405
|
+
points.push(...exteriorRing);
|
|
1406
|
+
} else if (feature.geometry?.type === "MultiPolygon") {
|
|
1407
|
+
for (const polygon of feature.geometry.coordinates) {
|
|
1408
|
+
points.push(...polygon[0]);
|
|
1409
|
+
}
|
|
1410
|
+
} else if (feature.geometry?.type === "Point") {
|
|
1411
|
+
points.push(feature.geometry.coordinates);
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
if (points.length < 3) {
|
|
1415
|
+
return null;
|
|
1416
|
+
}
|
|
1417
|
+
const hull = convexHull(points);
|
|
1418
|
+
if (hull.length < 3) {
|
|
1419
|
+
return null;
|
|
1420
|
+
}
|
|
1421
|
+
const closedHull = [...hull, hull[0]];
|
|
1422
|
+
return {
|
|
1423
|
+
type: "Polygon",
|
|
1424
|
+
coordinates: [closedHull]
|
|
1425
|
+
};
|
|
1426
|
+
}
|
|
1427
|
+
function convexHull(points) {
|
|
1428
|
+
if (points.length < 3) return points;
|
|
1429
|
+
let leftmost = 0;
|
|
1430
|
+
for (let i = 1; i < points.length; i++) {
|
|
1431
|
+
if (points[i][0] < points[leftmost][0]) {
|
|
1432
|
+
leftmost = i;
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
const hull = [];
|
|
1436
|
+
let current = leftmost;
|
|
1437
|
+
let iterations = 0;
|
|
1438
|
+
const maxIterations = points.length * 2;
|
|
1439
|
+
do {
|
|
1440
|
+
hull.push(points[current]);
|
|
1441
|
+
let next = 0;
|
|
1442
|
+
for (let i = 1; i < points.length; i++) {
|
|
1443
|
+
if (next === current || crossProduct(points[current], points[next], points[i]) < 0) {
|
|
1444
|
+
next = i;
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
current = next;
|
|
1448
|
+
iterations++;
|
|
1449
|
+
} while (current !== leftmost && iterations < maxIterations);
|
|
1450
|
+
return hull;
|
|
1451
|
+
}
|
|
1452
|
+
function crossProduct(o, a, b) {
|
|
1453
|
+
return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);
|
|
1454
|
+
}
|
|
1455
|
+
function generateBoundingPolygon(features, padding = 0) {
|
|
1456
|
+
const collection = {
|
|
1457
|
+
type: "FeatureCollection",
|
|
1458
|
+
features
|
|
1459
|
+
};
|
|
1460
|
+
const bounds = calculateBounds(collection);
|
|
1461
|
+
if (!bounds) return null;
|
|
1462
|
+
return boundsToPolygon(bounds, padding);
|
|
1463
|
+
}
|
|
1464
|
+
function boundsToPolygon(bounds, padding = 0) {
|
|
1465
|
+
const [[swLng, swLat], [neLng, neLat]] = bounds;
|
|
1466
|
+
const minLng = swLng - padding;
|
|
1467
|
+
const minLat = swLat - padding;
|
|
1468
|
+
const maxLng = neLng + padding;
|
|
1469
|
+
const maxLat = neLat + padding;
|
|
1470
|
+
return {
|
|
1471
|
+
type: "Polygon",
|
|
1472
|
+
coordinates: [
|
|
1473
|
+
[
|
|
1474
|
+
[minLng, minLat],
|
|
1475
|
+
// SW
|
|
1476
|
+
[maxLng, minLat],
|
|
1477
|
+
// SE
|
|
1478
|
+
[maxLng, maxLat],
|
|
1479
|
+
// NE
|
|
1480
|
+
[minLng, maxLat],
|
|
1481
|
+
// NW
|
|
1482
|
+
[minLng, minLat]
|
|
1483
|
+
// Close
|
|
1484
|
+
]
|
|
1485
|
+
]
|
|
1486
|
+
};
|
|
1487
|
+
}
|
|
1488
|
+
function perpendicularDistance(point, lineStart, lineEnd) {
|
|
1489
|
+
const dx = lineEnd[0] - lineStart[0];
|
|
1490
|
+
const dy = lineEnd[1] - lineStart[1];
|
|
1491
|
+
const lineLengthSquared = dx * dx + dy * dy;
|
|
1492
|
+
if (lineLengthSquared === 0) {
|
|
1493
|
+
const pdx = point[0] - lineStart[0];
|
|
1494
|
+
const pdy = point[1] - lineStart[1];
|
|
1495
|
+
return Math.sqrt(pdx * pdx + pdy * pdy);
|
|
1496
|
+
}
|
|
1497
|
+
const numerator = Math.abs(
|
|
1498
|
+
dy * point[0] - dx * point[1] + lineEnd[0] * lineStart[1] - lineEnd[1] * lineStart[0]
|
|
1499
|
+
);
|
|
1500
|
+
const denominator = Math.sqrt(lineLengthSquared);
|
|
1501
|
+
return numerator / denominator;
|
|
1502
|
+
}
|
|
1503
|
+
function douglasPeuckerSimplify(points, tolerance) {
|
|
1504
|
+
if (points.length <= 2) {
|
|
1505
|
+
return points;
|
|
1506
|
+
}
|
|
1507
|
+
let maxDistance = 0;
|
|
1508
|
+
let maxIndex = 0;
|
|
1509
|
+
const first = points[0];
|
|
1510
|
+
const last = points[points.length - 1];
|
|
1511
|
+
for (let i = 1; i < points.length - 1; i++) {
|
|
1512
|
+
const distance = perpendicularDistance(points[i], first, last);
|
|
1513
|
+
if (distance > maxDistance) {
|
|
1514
|
+
maxDistance = distance;
|
|
1515
|
+
maxIndex = i;
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
if (maxDistance > tolerance) {
|
|
1519
|
+
const leftPoints = douglasPeuckerSimplify(points.slice(0, maxIndex + 1), tolerance);
|
|
1520
|
+
const rightPoints = douglasPeuckerSimplify(points.slice(maxIndex), tolerance);
|
|
1521
|
+
return leftPoints.slice(0, -1).concat(rightPoints);
|
|
1522
|
+
} else {
|
|
1523
|
+
return [first, last];
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
function simplifyRing(ring, tolerance) {
|
|
1527
|
+
if (ring.length < 4) {
|
|
1528
|
+
return ring;
|
|
1529
|
+
}
|
|
1530
|
+
const openRing = ring.slice(0, -1);
|
|
1531
|
+
const simplified = douglasPeuckerSimplify(openRing, tolerance);
|
|
1532
|
+
if (simplified.length < 3) {
|
|
1533
|
+
return ring;
|
|
1534
|
+
}
|
|
1535
|
+
return [...simplified, simplified[0]];
|
|
1536
|
+
}
|
|
1537
|
+
function simplifyPolygon(polygon, tolerance) {
|
|
1538
|
+
const simplifiedCoords = polygon.coordinates.map((ring) => simplifyRing(ring, tolerance));
|
|
1539
|
+
return {
|
|
1540
|
+
type: "Polygon",
|
|
1541
|
+
coordinates: simplifiedCoords
|
|
1542
|
+
};
|
|
1543
|
+
}
|
|
1544
|
+
function simplifyFeature(feature, tolerance) {
|
|
1545
|
+
if (!feature.geometry) {
|
|
1546
|
+
return feature;
|
|
1547
|
+
}
|
|
1548
|
+
switch (feature.geometry.type) {
|
|
1549
|
+
case "Point":
|
|
1550
|
+
case "MultiPoint":
|
|
1551
|
+
case "LineString":
|
|
1552
|
+
case "MultiLineString":
|
|
1553
|
+
return feature;
|
|
1554
|
+
case "Polygon":
|
|
1555
|
+
return {
|
|
1556
|
+
...feature,
|
|
1557
|
+
geometry: simplifyPolygon(feature.geometry, tolerance)
|
|
1558
|
+
};
|
|
1559
|
+
case "MultiPolygon": {
|
|
1560
|
+
const multiPolygon = feature.geometry;
|
|
1561
|
+
const simplifiedPolygons = multiPolygon.coordinates.map((polygonCoords) => {
|
|
1562
|
+
return polygonCoords.map((ring) => simplifyRing(ring, tolerance));
|
|
1563
|
+
});
|
|
1564
|
+
return {
|
|
1565
|
+
...feature,
|
|
1566
|
+
geometry: {
|
|
1567
|
+
type: "MultiPolygon",
|
|
1568
|
+
coordinates: simplifiedPolygons
|
|
1569
|
+
}
|
|
1570
|
+
};
|
|
1571
|
+
}
|
|
1572
|
+
default:
|
|
1573
|
+
return feature;
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
function simplifyFeatureCollection(collection, tolerance) {
|
|
1577
|
+
return {
|
|
1578
|
+
type: "FeatureCollection",
|
|
1579
|
+
features: collection.features.map((f) => simplifyFeature(f, tolerance))
|
|
1580
|
+
};
|
|
1581
|
+
}
|
|
1582
|
+
function countVertices(collection) {
|
|
1583
|
+
let count = 0;
|
|
1584
|
+
for (const feature of collection.features) {
|
|
1585
|
+
if (!feature.geometry) continue;
|
|
1586
|
+
switch (feature.geometry.type) {
|
|
1587
|
+
case "Point":
|
|
1588
|
+
count += 1;
|
|
1589
|
+
break;
|
|
1590
|
+
case "MultiPoint":
|
|
1591
|
+
case "LineString":
|
|
1592
|
+
count += feature.geometry.coordinates.length;
|
|
1593
|
+
break;
|
|
1594
|
+
case "MultiLineString":
|
|
1595
|
+
case "Polygon":
|
|
1596
|
+
for (const ring of feature.geometry.coordinates) {
|
|
1597
|
+
count += ring.length;
|
|
1598
|
+
}
|
|
1599
|
+
break;
|
|
1600
|
+
case "MultiPolygon":
|
|
1601
|
+
for (const polygon of feature.geometry.coordinates) {
|
|
1602
|
+
for (const ring of polygon) {
|
|
1603
|
+
count += ring.length;
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
break;
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
return count;
|
|
1610
|
+
}
|
|
1611
|
+
function simplifyFeatureCollectionWithStats(collection, tolerance) {
|
|
1612
|
+
const originalVertices = countVertices(collection);
|
|
1613
|
+
const simplified = simplifyFeatureCollection(collection, tolerance);
|
|
1614
|
+
const simplifiedVertices = countVertices(simplified);
|
|
1615
|
+
const reductionPercent = originalVertices > 0 ? (originalVertices - simplifiedVertices) / originalVertices * 100 : 0;
|
|
1616
|
+
return {
|
|
1617
|
+
data: simplified,
|
|
1618
|
+
stats: {
|
|
1619
|
+
originalVertices,
|
|
1620
|
+
simplifiedVertices,
|
|
1621
|
+
reductionPercent,
|
|
1622
|
+
featureCount: collection.features.length
|
|
1623
|
+
}
|
|
1624
|
+
};
|
|
1625
|
+
}
|
|
1626
|
+
function generateLODData(geojson, options) {
|
|
1627
|
+
const {
|
|
1628
|
+
groupBy,
|
|
1629
|
+
subGroupBy,
|
|
1630
|
+
groupBoundaries: providedGroupBoundaries,
|
|
1631
|
+
subGroupBoundaries: providedSubGroupBoundaries,
|
|
1632
|
+
useConvexHull = true,
|
|
1633
|
+
boundaryPadding = 1e-4,
|
|
1634
|
+
aggregateProperties = []
|
|
1635
|
+
} = options;
|
|
1636
|
+
const groups = groupFeaturesByProperty(geojson, { groupBy, subGroupBy });
|
|
1637
|
+
const groupBoundaryFeatures = [];
|
|
1638
|
+
for (const [groupId, group] of groups) {
|
|
1639
|
+
let geometry = providedGroupBoundaries?.get(groupId) ?? null;
|
|
1640
|
+
if (!geometry) {
|
|
1641
|
+
geometry = useConvexHull ? generateConvexHull(group.features) : generateBoundingPolygon(group.features, boundaryPadding);
|
|
1642
|
+
}
|
|
1643
|
+
if (geometry) {
|
|
1644
|
+
const aggregated = {};
|
|
1645
|
+
for (const prop of aggregateProperties) {
|
|
1646
|
+
const values = group.features.map((f) => f.properties?.[prop]).filter((v) => v !== void 0);
|
|
1647
|
+
if (values.length > 0) {
|
|
1648
|
+
if (typeof values[0] === "number") {
|
|
1649
|
+
aggregated[prop] = values.reduce((a, b) => a + b, 0);
|
|
1650
|
+
} else {
|
|
1651
|
+
aggregated[`${prop}Count`] = new Set(values).size;
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
groupBoundaryFeatures.push({
|
|
1656
|
+
type: "Feature",
|
|
1657
|
+
properties: {
|
|
1658
|
+
[groupBy]: groupId,
|
|
1659
|
+
lotCount: group.count,
|
|
1660
|
+
...aggregated
|
|
1661
|
+
},
|
|
1662
|
+
geometry
|
|
1663
|
+
});
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
let subGroupBoundaryFeatures = null;
|
|
1667
|
+
if (subGroupBy) {
|
|
1668
|
+
subGroupBoundaryFeatures = [];
|
|
1669
|
+
for (const [groupId, group] of groups) {
|
|
1670
|
+
if (group.subGroups) {
|
|
1671
|
+
for (const [subGroupId, subGroup] of group.subGroups) {
|
|
1672
|
+
const boundaryKey = `${groupId}:${subGroupId}`;
|
|
1673
|
+
let geometry = providedSubGroupBoundaries?.get(boundaryKey) ?? null;
|
|
1674
|
+
if (!geometry) {
|
|
1675
|
+
geometry = useConvexHull ? generateConvexHull(subGroup.features) : generateBoundingPolygon(subGroup.features, boundaryPadding);
|
|
1676
|
+
}
|
|
1677
|
+
if (geometry) {
|
|
1678
|
+
const aggregated = {};
|
|
1679
|
+
for (const prop of aggregateProperties) {
|
|
1680
|
+
const values = subGroup.features.map((f) => f.properties?.[prop]).filter((v) => v !== void 0);
|
|
1681
|
+
if (values.length > 0) {
|
|
1682
|
+
if (typeof values[0] === "number") {
|
|
1683
|
+
aggregated[prop] = values.reduce((a, b) => a + b, 0);
|
|
1684
|
+
} else {
|
|
1685
|
+
aggregated[`${prop}Count`] = new Set(values).size;
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
subGroupBoundaryFeatures.push({
|
|
1690
|
+
type: "Feature",
|
|
1691
|
+
properties: {
|
|
1692
|
+
[groupBy]: groupId,
|
|
1693
|
+
[subGroupBy]: subGroupId,
|
|
1694
|
+
lotCount: subGroup.count,
|
|
1695
|
+
...aggregated
|
|
1696
|
+
},
|
|
1697
|
+
geometry
|
|
1698
|
+
});
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
return {
|
|
1705
|
+
groupBoundaries: {
|
|
1706
|
+
type: "FeatureCollection",
|
|
1707
|
+
features: groupBoundaryFeatures
|
|
1708
|
+
},
|
|
1709
|
+
subGroupBoundaries: subGroupBoundaryFeatures ? {
|
|
1710
|
+
type: "FeatureCollection",
|
|
1711
|
+
features: subGroupBoundaryFeatures
|
|
1712
|
+
} : null,
|
|
1713
|
+
features: geojson,
|
|
1714
|
+
zoomThresholds: {
|
|
1715
|
+
groupMaxZoom: 12,
|
|
1716
|
+
subGroupMaxZoom: 14
|
|
1717
|
+
}
|
|
1718
|
+
};
|
|
1719
|
+
}
|
|
1720
|
+
function generateLODDataWithSimplification(geojson, options) {
|
|
1721
|
+
const baseLOD = generateLODData(geojson, options);
|
|
1722
|
+
const { simplificationThresholds } = options;
|
|
1723
|
+
if (!simplificationThresholds || simplificationThresholds.length === 0) {
|
|
1724
|
+
return baseLOD;
|
|
1725
|
+
}
|
|
1726
|
+
const sortedThresholds = [...simplificationThresholds].sort((a, b) => b.maxZoom - a.maxZoom);
|
|
1727
|
+
const simplifiedFeatures = /* @__PURE__ */ new Map();
|
|
1728
|
+
const simplificationStats = /* @__PURE__ */ new Map();
|
|
1729
|
+
for (const threshold of sortedThresholds) {
|
|
1730
|
+
const { data, stats } = simplifyFeatureCollectionWithStats(geojson, threshold.tolerance);
|
|
1731
|
+
simplifiedFeatures.set(threshold.maxZoom, data);
|
|
1732
|
+
simplificationStats.set(threshold.maxZoom, stats);
|
|
1733
|
+
}
|
|
1734
|
+
return {
|
|
1735
|
+
...baseLOD,
|
|
1736
|
+
simplifiedFeatures,
|
|
1737
|
+
simplificationStats
|
|
1738
|
+
};
|
|
1739
|
+
}
|
|
1740
|
+
function getSimplifiedFeaturesForZoom(lodData, zoom) {
|
|
1741
|
+
if (!lodData.simplifiedFeatures || lodData.simplifiedFeatures.size === 0) {
|
|
1742
|
+
return lodData.features;
|
|
1743
|
+
}
|
|
1744
|
+
let bestMatch = null;
|
|
1745
|
+
for (const [maxZoom, features] of lodData.simplifiedFeatures) {
|
|
1746
|
+
if (zoom < maxZoom) {
|
|
1747
|
+
if (!bestMatch) {
|
|
1748
|
+
bestMatch = features;
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
return bestMatch ?? lodData.features;
|
|
1753
|
+
}
|
|
1754
|
+
function calculateZoomThresholds(groups, options = {}) {
|
|
1755
|
+
const { minZoomGap = 2 } = options;
|
|
1756
|
+
const groupCount = groups.size;
|
|
1757
|
+
let subGroupCount = 0;
|
|
1758
|
+
for (const group of groups.values()) {
|
|
1759
|
+
if (group.subGroups) {
|
|
1760
|
+
subGroupCount += group.subGroups.size;
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
const groupMaxZoom = Math.max(10, Math.min(14, 10 + Math.log2(groupCount)));
|
|
1764
|
+
const subGroupMaxZoom = Math.max(
|
|
1765
|
+
groupMaxZoom + minZoomGap,
|
|
1766
|
+
Math.min(16, groupMaxZoom + Math.log2(Math.max(1, subGroupCount / groupCount)))
|
|
1767
|
+
);
|
|
1768
|
+
return {
|
|
1769
|
+
groupMaxZoom: Math.round(groupMaxZoom),
|
|
1770
|
+
subGroupMaxZoom: Math.round(subGroupMaxZoom)
|
|
1771
|
+
};
|
|
1772
|
+
}
|
|
1773
|
+
function createDynamicLODManager(options) {
|
|
1774
|
+
const {
|
|
1775
|
+
baseThresholds,
|
|
1776
|
+
targetFps = 50,
|
|
1777
|
+
adjustBelowFps = 40,
|
|
1778
|
+
maxAdjustment = 3,
|
|
1779
|
+
adjustmentStep = 0.5,
|
|
1780
|
+
smoothingFactor = 0.3,
|
|
1781
|
+
adjustmentCooldown = 1e3
|
|
1782
|
+
} = options;
|
|
1783
|
+
let averageFps = targetFps;
|
|
1784
|
+
let adjustment = 0;
|
|
1785
|
+
let lastAdjustmentTime = 0;
|
|
1786
|
+
function getState() {
|
|
1787
|
+
return {
|
|
1788
|
+
thresholds: {
|
|
1789
|
+
groupMaxZoom: baseThresholds.groupMaxZoom + adjustment,
|
|
1790
|
+
subGroupMaxZoom: baseThresholds.subGroupMaxZoom + adjustment
|
|
1791
|
+
},
|
|
1792
|
+
averageFps,
|
|
1793
|
+
adjustment,
|
|
1794
|
+
isAdjusted: adjustment > 0
|
|
1795
|
+
};
|
|
1796
|
+
}
|
|
1797
|
+
return {
|
|
1798
|
+
update(currentFps) {
|
|
1799
|
+
const now = performance.now();
|
|
1800
|
+
averageFps = smoothingFactor * currentFps + (1 - smoothingFactor) * averageFps;
|
|
1801
|
+
if (now - lastAdjustmentTime < adjustmentCooldown) {
|
|
1802
|
+
return getState();
|
|
1803
|
+
}
|
|
1804
|
+
if (averageFps < adjustBelowFps && adjustment < maxAdjustment) {
|
|
1805
|
+
const deficit = adjustBelowFps - averageFps;
|
|
1806
|
+
const newAdjustment = Math.min(
|
|
1807
|
+
maxAdjustment,
|
|
1808
|
+
adjustment + adjustmentStep * Math.ceil(deficit / 10)
|
|
1809
|
+
);
|
|
1810
|
+
if (newAdjustment !== adjustment) {
|
|
1811
|
+
adjustment = newAdjustment;
|
|
1812
|
+
lastAdjustmentTime = now;
|
|
1813
|
+
}
|
|
1814
|
+
} else if (averageFps >= targetFps && adjustment > 0) {
|
|
1815
|
+
const newAdjustment = Math.max(0, adjustment - adjustmentStep);
|
|
1816
|
+
if (newAdjustment !== adjustment) {
|
|
1817
|
+
adjustment = newAdjustment;
|
|
1818
|
+
lastAdjustmentTime = now;
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
return getState();
|
|
1822
|
+
},
|
|
1823
|
+
reset() {
|
|
1824
|
+
averageFps = targetFps;
|
|
1825
|
+
adjustment = 0;
|
|
1826
|
+
lastAdjustmentTime = 0;
|
|
1827
|
+
return getState();
|
|
1828
|
+
},
|
|
1829
|
+
getState
|
|
1830
|
+
};
|
|
1831
|
+
}
|
|
1832
|
+
function getSimplificationToleranceForZoom(zoom, baseToleranceAtZoom14 = 2e-5) {
|
|
1833
|
+
const zoomDiff = Math.max(0, 14 - zoom);
|
|
1834
|
+
const multiplier = Math.pow(2, zoomDiff / 2);
|
|
1835
|
+
return baseToleranceAtZoom14 * multiplier;
|
|
1836
|
+
}
|
|
1837
|
+
var DEFAULT_SIMPLIFICATION_THRESHOLDS = [
|
|
1838
|
+
{ maxZoom: 14, tolerance: 2e-5 },
|
|
1839
|
+
// Light: ~2m
|
|
1840
|
+
{ maxZoom: 13, tolerance: 5e-5 },
|
|
1841
|
+
// Medium-light: ~5m
|
|
1842
|
+
{ maxZoom: 12, tolerance: 1e-4 },
|
|
1843
|
+
// Medium: ~11m
|
|
1844
|
+
{ maxZoom: 11, tolerance: 2e-4 },
|
|
1845
|
+
// Medium-heavy: ~22m
|
|
1846
|
+
{ maxZoom: 10, tolerance: 5e-4 }
|
|
1847
|
+
// Heavy: ~55m
|
|
1848
|
+
];
|
|
1849
|
+
function buildSpatialIndex(geojson, options = {}) {
|
|
1850
|
+
const { targetCells = 100, minCellSize = 1e-3 } = options;
|
|
1851
|
+
const bounds = calculateBounds(geojson);
|
|
1852
|
+
if (!bounds) {
|
|
1853
|
+
return {
|
|
1854
|
+
grid: /* @__PURE__ */ new Map(),
|
|
1855
|
+
cols: 0,
|
|
1856
|
+
rows: 0,
|
|
1857
|
+
bounds: [
|
|
1858
|
+
[0, 0],
|
|
1859
|
+
[0, 0]
|
|
1860
|
+
],
|
|
1861
|
+
cellWidth: 0,
|
|
1862
|
+
cellHeight: 0,
|
|
1863
|
+
featureCount: 0
|
|
1864
|
+
};
|
|
1865
|
+
}
|
|
1866
|
+
const [[minLng, minLat], [maxLng, maxLat]] = bounds;
|
|
1867
|
+
const width = maxLng - minLng;
|
|
1868
|
+
const height = maxLat - minLat;
|
|
1869
|
+
const aspectRatio = width / height;
|
|
1870
|
+
let cols = Math.ceil(Math.sqrt(targetCells * aspectRatio));
|
|
1871
|
+
let rows = Math.ceil(targetCells / cols);
|
|
1872
|
+
const cellWidth = Math.max(width / cols, minCellSize);
|
|
1873
|
+
const cellHeight = Math.max(height / rows, minCellSize);
|
|
1874
|
+
cols = Math.ceil(width / cellWidth);
|
|
1875
|
+
rows = Math.ceil(height / cellHeight);
|
|
1876
|
+
const grid = /* @__PURE__ */ new Map();
|
|
1877
|
+
for (const feature of geojson.features) {
|
|
1878
|
+
const featureBounds = getFeatureBounds(feature);
|
|
1879
|
+
if (!featureBounds) continue;
|
|
1880
|
+
const [[fMinLng, fMinLat], [fMaxLng, fMaxLat]] = featureBounds;
|
|
1881
|
+
const minCol = Math.max(0, Math.floor((fMinLng - minLng) / cellWidth));
|
|
1882
|
+
const maxCol = Math.min(cols - 1, Math.floor((fMaxLng - minLng) / cellWidth));
|
|
1883
|
+
const minRow = Math.max(0, Math.floor((fMinLat - minLat) / cellHeight));
|
|
1884
|
+
const maxRow = Math.min(rows - 1, Math.floor((fMaxLat - minLat) / cellHeight));
|
|
1885
|
+
for (let col = minCol; col <= maxCol; col++) {
|
|
1886
|
+
for (let row = minRow; row <= maxRow; row++) {
|
|
1887
|
+
const key = `${col},${row}`;
|
|
1888
|
+
if (!grid.has(key)) {
|
|
1889
|
+
grid.set(key, { features: [] });
|
|
1890
|
+
}
|
|
1891
|
+
grid.get(key).features.push(feature);
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
return {
|
|
1896
|
+
grid,
|
|
1897
|
+
cols,
|
|
1898
|
+
rows,
|
|
1899
|
+
bounds,
|
|
1900
|
+
cellWidth,
|
|
1901
|
+
cellHeight,
|
|
1902
|
+
featureCount: geojson.features.length
|
|
1903
|
+
};
|
|
1904
|
+
}
|
|
1905
|
+
function getFeatureBounds(feature) {
|
|
1906
|
+
const geometry = feature.geometry;
|
|
1907
|
+
if (!geometry) return null;
|
|
1908
|
+
let minLng = Infinity;
|
|
1909
|
+
let minLat = Infinity;
|
|
1910
|
+
let maxLng = -Infinity;
|
|
1911
|
+
let maxLat = -Infinity;
|
|
1912
|
+
function processCoord(coord) {
|
|
1913
|
+
minLng = Math.min(minLng, coord[0]);
|
|
1914
|
+
minLat = Math.min(minLat, coord[1]);
|
|
1915
|
+
maxLng = Math.max(maxLng, coord[0]);
|
|
1916
|
+
maxLat = Math.max(maxLat, coord[1]);
|
|
1917
|
+
}
|
|
1918
|
+
function processRing(ring) {
|
|
1919
|
+
ring.forEach(processCoord);
|
|
1920
|
+
}
|
|
1921
|
+
switch (geometry.type) {
|
|
1922
|
+
case "Point":
|
|
1923
|
+
processCoord(geometry.coordinates);
|
|
1924
|
+
break;
|
|
1925
|
+
case "MultiPoint":
|
|
1926
|
+
case "LineString":
|
|
1927
|
+
geometry.coordinates.forEach(processCoord);
|
|
1928
|
+
break;
|
|
1929
|
+
case "MultiLineString":
|
|
1930
|
+
case "Polygon":
|
|
1931
|
+
geometry.coordinates.forEach(processRing);
|
|
1932
|
+
break;
|
|
1933
|
+
case "MultiPolygon":
|
|
1934
|
+
geometry.coordinates.forEach(
|
|
1935
|
+
(polygon) => polygon.forEach(processRing)
|
|
1936
|
+
);
|
|
1937
|
+
break;
|
|
1938
|
+
}
|
|
1939
|
+
if (minLng === Infinity) return null;
|
|
1940
|
+
return [
|
|
1941
|
+
[minLng, minLat],
|
|
1942
|
+
[maxLng, maxLat]
|
|
1943
|
+
];
|
|
1944
|
+
}
|
|
1945
|
+
function queryByBounds(index, queryBounds, options = {}) {
|
|
1946
|
+
const { buffer = 0.01, bufferFraction } = options;
|
|
1947
|
+
if (index.featureCount === 0) {
|
|
1948
|
+
return { type: "FeatureCollection", features: [] };
|
|
1949
|
+
}
|
|
1950
|
+
let [[minLng, minLat], [maxLng, maxLat]] = normalizeBounds(queryBounds);
|
|
1951
|
+
const viewWidth = maxLng - minLng;
|
|
1952
|
+
const viewHeight = maxLat - minLat;
|
|
1953
|
+
const actualBuffer = bufferFraction ? Math.max(viewWidth, viewHeight) * bufferFraction : buffer;
|
|
1954
|
+
minLng -= actualBuffer;
|
|
1955
|
+
minLat -= actualBuffer;
|
|
1956
|
+
maxLng += actualBuffer;
|
|
1957
|
+
maxLat += actualBuffer;
|
|
1958
|
+
const [[idxMinLng, idxMinLat]] = index.bounds;
|
|
1959
|
+
const minCol = Math.max(0, Math.floor((minLng - idxMinLng) / index.cellWidth));
|
|
1960
|
+
const maxCol = Math.min(index.cols - 1, Math.floor((maxLng - idxMinLng) / index.cellWidth));
|
|
1961
|
+
const minRow = Math.max(0, Math.floor((minLat - idxMinLat) / index.cellHeight));
|
|
1962
|
+
const maxRow = Math.min(index.rows - 1, Math.floor((maxLat - idxMinLat) / index.cellHeight));
|
|
1963
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1964
|
+
const features = [];
|
|
1965
|
+
for (let col = minCol; col <= maxCol; col++) {
|
|
1966
|
+
for (let row = minRow; row <= maxRow; row++) {
|
|
1967
|
+
const cell = index.grid.get(`${col},${row}`);
|
|
1968
|
+
if (cell) {
|
|
1969
|
+
for (const feature of cell.features) {
|
|
1970
|
+
if (!seen.has(feature)) {
|
|
1971
|
+
const featureBounds = getFeatureBounds(feature);
|
|
1972
|
+
if (featureBounds && boundsIntersect(featureBounds, [
|
|
1973
|
+
[minLng, minLat],
|
|
1974
|
+
[maxLng, maxLat]
|
|
1975
|
+
])) {
|
|
1976
|
+
seen.add(feature);
|
|
1977
|
+
features.push(feature);
|
|
1978
|
+
}
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1984
|
+
return { type: "FeatureCollection", features };
|
|
1985
|
+
}
|
|
1986
|
+
function boundsIntersect(a, b) {
|
|
1987
|
+
return !(a[1][0] < b[0][0] || // a is left of b
|
|
1988
|
+
a[0][0] > b[1][0] || // a is right of b
|
|
1989
|
+
a[1][1] < b[0][1] || // a is below b
|
|
1990
|
+
a[0][1] > b[1][1]);
|
|
1991
|
+
}
|
|
1992
|
+
function normalizeBounds(bounds) {
|
|
1993
|
+
if (Array.isArray(bounds) && Array.isArray(bounds[0])) {
|
|
1994
|
+
return bounds;
|
|
1995
|
+
}
|
|
1996
|
+
const mapBounds = bounds;
|
|
1997
|
+
return [mapBounds.southwest, mapBounds.northeast];
|
|
1998
|
+
}
|
|
1999
|
+
function queryByBoundsWithStats(index, queryBounds, options = {}) {
|
|
2000
|
+
const { buffer = 0.01, bufferFraction } = options;
|
|
2001
|
+
if (index.featureCount === 0) {
|
|
2002
|
+
return {
|
|
2003
|
+
data: { type: "FeatureCollection", features: [] },
|
|
2004
|
+
stats: {
|
|
2005
|
+
totalFeatures: 0,
|
|
2006
|
+
visibleFeatures: 0,
|
|
2007
|
+
culledPercent: 0,
|
|
2008
|
+
cellsChecked: 0,
|
|
2009
|
+
totalCells: 0
|
|
2010
|
+
}
|
|
2011
|
+
};
|
|
2012
|
+
}
|
|
2013
|
+
let [[minLng, minLat], [maxLng, maxLat]] = normalizeBounds(queryBounds);
|
|
2014
|
+
const viewWidth = maxLng - minLng;
|
|
2015
|
+
const viewHeight = maxLat - minLat;
|
|
2016
|
+
const actualBuffer = bufferFraction ? Math.max(viewWidth, viewHeight) * bufferFraction : buffer;
|
|
2017
|
+
minLng -= actualBuffer;
|
|
2018
|
+
minLat -= actualBuffer;
|
|
2019
|
+
maxLng += actualBuffer;
|
|
2020
|
+
maxLat += actualBuffer;
|
|
2021
|
+
const [[idxMinLng, idxMinLat]] = index.bounds;
|
|
2022
|
+
const minCol = Math.max(0, Math.floor((minLng - idxMinLng) / index.cellWidth));
|
|
2023
|
+
const maxCol = Math.min(index.cols - 1, Math.floor((maxLng - idxMinLng) / index.cellWidth));
|
|
2024
|
+
const minRow = Math.max(0, Math.floor((minLat - idxMinLat) / index.cellHeight));
|
|
2025
|
+
const maxRow = Math.min(index.rows - 1, Math.floor((maxLat - idxMinLat) / index.cellHeight));
|
|
2026
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2027
|
+
const features = [];
|
|
2028
|
+
let cellsChecked = 0;
|
|
2029
|
+
for (let col = minCol; col <= maxCol; col++) {
|
|
2030
|
+
for (let row = minRow; row <= maxRow; row++) {
|
|
2031
|
+
cellsChecked++;
|
|
2032
|
+
const cell = index.grid.get(`${col},${row}`);
|
|
2033
|
+
if (cell) {
|
|
2034
|
+
for (const feature of cell.features) {
|
|
2035
|
+
if (!seen.has(feature)) {
|
|
2036
|
+
const featureBounds = getFeatureBounds(feature);
|
|
2037
|
+
if (featureBounds && boundsIntersect(featureBounds, [
|
|
2038
|
+
[minLng, minLat],
|
|
2039
|
+
[maxLng, maxLat]
|
|
2040
|
+
])) {
|
|
2041
|
+
seen.add(feature);
|
|
2042
|
+
features.push(feature);
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
const visibleFeatures = features.length;
|
|
2050
|
+
const culledPercent = index.featureCount > 0 ? (index.featureCount - visibleFeatures) / index.featureCount * 100 : 0;
|
|
2051
|
+
return {
|
|
2052
|
+
data: { type: "FeatureCollection", features },
|
|
2053
|
+
stats: {
|
|
2054
|
+
totalFeatures: index.featureCount,
|
|
2055
|
+
visibleFeatures,
|
|
2056
|
+
culledPercent,
|
|
2057
|
+
cellsChecked,
|
|
2058
|
+
totalCells: index.cols * index.rows
|
|
2059
|
+
}
|
|
2060
|
+
};
|
|
2061
|
+
}
|
|
2062
|
+
function createViewportQuery(index, options) {
|
|
2063
|
+
const { debounceMs = 50, bufferFraction = 0.2, onUpdate } = options;
|
|
2064
|
+
let timeoutId = null;
|
|
2065
|
+
let lastBounds = null;
|
|
2066
|
+
return (bounds) => {
|
|
2067
|
+
lastBounds = bounds;
|
|
2068
|
+
if (timeoutId) {
|
|
2069
|
+
clearTimeout(timeoutId);
|
|
2070
|
+
}
|
|
2071
|
+
timeoutId = setTimeout(() => {
|
|
2072
|
+
if (lastBounds) {
|
|
2073
|
+
const { data, stats } = queryByBoundsWithStats(index, lastBounds, {
|
|
2074
|
+
bufferFraction
|
|
2075
|
+
});
|
|
2076
|
+
onUpdate(data, stats);
|
|
2077
|
+
}
|
|
2078
|
+
timeoutId = null;
|
|
2079
|
+
}, debounceMs);
|
|
2080
|
+
};
|
|
2081
|
+
}
|
|
2082
|
+
function createViewportManager(index, options = {}) {
|
|
2083
|
+
const { bufferFraction = 0.25, minMovement = 0.1 } = options;
|
|
2084
|
+
let lastBounds = null;
|
|
2085
|
+
let lastData = null;
|
|
2086
|
+
let lastStats = null;
|
|
2087
|
+
function shouldUpdate(newBounds) {
|
|
2088
|
+
if (!lastBounds) return true;
|
|
2089
|
+
const lastWidth = lastBounds[1][0] - lastBounds[0][0];
|
|
2090
|
+
const lastHeight = lastBounds[1][1] - lastBounds[0][1];
|
|
2091
|
+
const movementLng = Math.abs(
|
|
2092
|
+
(newBounds[0][0] + newBounds[1][0]) / 2 - (lastBounds[0][0] + lastBounds[1][0]) / 2
|
|
2093
|
+
);
|
|
2094
|
+
const movementLat = Math.abs(
|
|
2095
|
+
(newBounds[0][1] + newBounds[1][1]) / 2 - (lastBounds[0][1] + lastBounds[1][1]) / 2
|
|
2096
|
+
);
|
|
2097
|
+
const movement = Math.max(movementLng / lastWidth, movementLat / lastHeight);
|
|
2098
|
+
const newWidth = newBounds[1][0] - newBounds[0][0];
|
|
2099
|
+
const zoomChange = Math.abs(newWidth / lastWidth - 1);
|
|
2100
|
+
return movement > minMovement || zoomChange > 0.2;
|
|
2101
|
+
}
|
|
2102
|
+
return {
|
|
2103
|
+
update(bounds) {
|
|
2104
|
+
const normalizedBounds = normalizeBounds(bounds);
|
|
2105
|
+
if (lastData && !shouldUpdate(normalizedBounds)) {
|
|
2106
|
+
return {
|
|
2107
|
+
data: lastData,
|
|
2108
|
+
stats: lastStats,
|
|
2109
|
+
updated: false
|
|
2110
|
+
};
|
|
2111
|
+
}
|
|
2112
|
+
const { data, stats } = queryByBoundsWithStats(index, normalizedBounds, {
|
|
2113
|
+
bufferFraction
|
|
2114
|
+
});
|
|
2115
|
+
lastBounds = normalizedBounds;
|
|
2116
|
+
lastData = data;
|
|
2117
|
+
lastStats = stats;
|
|
2118
|
+
return {
|
|
2119
|
+
data,
|
|
2120
|
+
stats,
|
|
2121
|
+
updated: true
|
|
2122
|
+
};
|
|
2123
|
+
},
|
|
2124
|
+
reset() {
|
|
2125
|
+
lastBounds = null;
|
|
2126
|
+
lastData = null;
|
|
2127
|
+
lastStats = null;
|
|
2128
|
+
},
|
|
2129
|
+
getStats() {
|
|
2130
|
+
return lastStats;
|
|
2131
|
+
}
|
|
2132
|
+
};
|
|
2133
|
+
}
|
|
2134
|
+
var requestIdleCallbackPolyfill = typeof requestIdleCallback !== "undefined" ? requestIdleCallback : (cb, options) => {
|
|
2135
|
+
const start = Date.now();
|
|
2136
|
+
return setTimeout(() => {
|
|
2137
|
+
cb({
|
|
2138
|
+
didTimeout: true,
|
|
2139
|
+
timeRemaining: () => Math.max(0, 50 - (Date.now() - start))
|
|
2140
|
+
});
|
|
2141
|
+
}, options?.timeout ?? 1);
|
|
2142
|
+
};
|
|
2143
|
+
var cancelIdleCallbackPolyfill = typeof cancelIdleCallback !== "undefined" ? cancelIdleCallback : (id) => clearTimeout(id);
|
|
2144
|
+
function createIdleViewportManager(index, options = {}) {
|
|
2145
|
+
const {
|
|
2146
|
+
bufferFraction = 0.25,
|
|
2147
|
+
minMovement = 0.1,
|
|
2148
|
+
maxUpdatesPerSecond = 12,
|
|
2149
|
+
idleDelay = 100,
|
|
2150
|
+
predictivePan = true,
|
|
2151
|
+
predictiveMultiplier = 2,
|
|
2152
|
+
velocitySamples = 5,
|
|
2153
|
+
maxPanDistance = 0.5
|
|
2154
|
+
} = options;
|
|
2155
|
+
const minUpdateInterval = 1e3 / maxUpdatesPerSecond;
|
|
2156
|
+
let lastBounds = null;
|
|
2157
|
+
let lastDataFetchBounds = null;
|
|
2158
|
+
let lastData = null;
|
|
2159
|
+
let lastStats = null;
|
|
2160
|
+
let pendingIdleId = null;
|
|
2161
|
+
let pendingBounds = null;
|
|
2162
|
+
let lastUpdateTime = 0;
|
|
2163
|
+
let viewportSamples = [];
|
|
2164
|
+
let currentVelocity = { lngPerSec: 0, latPerSec: 0, magnitude: 0 };
|
|
2165
|
+
let dataReadyCallback = null;
|
|
2166
|
+
const isRTree = "tree" in index;
|
|
2167
|
+
function getCumulativeDistance(newBounds) {
|
|
2168
|
+
if (!lastDataFetchBounds) return Infinity;
|
|
2169
|
+
const viewWidth = newBounds[1][0] - newBounds[0][0];
|
|
2170
|
+
const viewHeight = newBounds[1][1] - newBounds[0][1];
|
|
2171
|
+
const fetchCenterLng = (lastDataFetchBounds[0][0] + lastDataFetchBounds[1][0]) / 2;
|
|
2172
|
+
const fetchCenterLat = (lastDataFetchBounds[0][1] + lastDataFetchBounds[1][1]) / 2;
|
|
2173
|
+
const newCenterLng = (newBounds[0][0] + newBounds[1][0]) / 2;
|
|
2174
|
+
const newCenterLat = (newBounds[0][1] + newBounds[1][1]) / 2;
|
|
2175
|
+
const distLng = Math.abs(newCenterLng - fetchCenterLng) / viewWidth;
|
|
2176
|
+
const distLat = Math.abs(newCenterLat - fetchCenterLat) / viewHeight;
|
|
2177
|
+
return Math.max(distLng, distLat);
|
|
2178
|
+
}
|
|
2179
|
+
function shouldUpdate(newBounds) {
|
|
2180
|
+
if (!lastBounds) return true;
|
|
2181
|
+
const lastWidth = lastBounds[1][0] - lastBounds[0][0];
|
|
2182
|
+
const lastHeight = lastBounds[1][1] - lastBounds[0][1];
|
|
2183
|
+
const movementLng = Math.abs(
|
|
2184
|
+
(newBounds[0][0] + newBounds[1][0]) / 2 - (lastBounds[0][0] + lastBounds[1][0]) / 2
|
|
2185
|
+
);
|
|
2186
|
+
const movementLat = Math.abs(
|
|
2187
|
+
(newBounds[0][1] + newBounds[1][1]) / 2 - (lastBounds[0][1] + lastBounds[1][1]) / 2
|
|
2188
|
+
);
|
|
2189
|
+
const movement = Math.max(movementLng / lastWidth, movementLat / lastHeight);
|
|
2190
|
+
const newWidth = newBounds[1][0] - newBounds[0][0];
|
|
2191
|
+
const zoomChange = Math.abs(newWidth / lastWidth - 1);
|
|
2192
|
+
const cumulativeDistance = getCumulativeDistance(newBounds);
|
|
2193
|
+
return movement > minMovement || zoomChange > 0.2 || cumulativeDistance > maxPanDistance;
|
|
2194
|
+
}
|
|
2195
|
+
function trackVelocity(normalizedBounds) {
|
|
2196
|
+
const now = performance.now();
|
|
2197
|
+
const center = [
|
|
2198
|
+
(normalizedBounds[0][0] + normalizedBounds[1][0]) / 2,
|
|
2199
|
+
(normalizedBounds[0][1] + normalizedBounds[1][1]) / 2
|
|
2200
|
+
];
|
|
2201
|
+
viewportSamples.push({ center, timestamp: now });
|
|
2202
|
+
while (viewportSamples.length > velocitySamples) {
|
|
2203
|
+
viewportSamples.shift();
|
|
2204
|
+
}
|
|
2205
|
+
currentVelocity = calculatePanVelocityInternal(viewportSamples);
|
|
2206
|
+
}
|
|
2207
|
+
function executeQuery(normalizedBounds) {
|
|
2208
|
+
const viewWidth = normalizedBounds[1][0] - normalizedBounds[0][0];
|
|
2209
|
+
const viewHeight = normalizedBounds[1][1] - normalizedBounds[0][1];
|
|
2210
|
+
const baseBuffer = Math.max(viewWidth, viewHeight) * bufferFraction;
|
|
2211
|
+
let queryBounds = normalizedBounds;
|
|
2212
|
+
if (predictivePan && currentVelocity.magnitude > 1e-5) {
|
|
2213
|
+
queryBounds = applyPredictiveBufferInternal(
|
|
2214
|
+
normalizedBounds,
|
|
2215
|
+
currentVelocity,
|
|
2216
|
+
baseBuffer,
|
|
2217
|
+
predictiveMultiplier
|
|
2218
|
+
);
|
|
2219
|
+
} else {
|
|
2220
|
+
queryBounds = [
|
|
2221
|
+
[normalizedBounds[0][0] - baseBuffer, normalizedBounds[0][1] - baseBuffer],
|
|
2222
|
+
[normalizedBounds[1][0] + baseBuffer, normalizedBounds[1][1] + baseBuffer]
|
|
2223
|
+
];
|
|
2224
|
+
}
|
|
2225
|
+
let data;
|
|
2226
|
+
let stats;
|
|
2227
|
+
if (isRTree) {
|
|
2228
|
+
const rtreeIndex = index;
|
|
2229
|
+
const result = queryRTreeByBoundsWithStats(rtreeIndex, queryBounds, {
|
|
2230
|
+
buffer: 0
|
|
2231
|
+
// Buffer already applied
|
|
2232
|
+
});
|
|
2233
|
+
data = result.data;
|
|
2234
|
+
stats = {
|
|
2235
|
+
totalFeatures: result.stats.totalFeatures,
|
|
2236
|
+
visibleFeatures: result.stats.visibleFeatures,
|
|
2237
|
+
culledPercent: result.stats.culledPercent,
|
|
2238
|
+
cellsChecked: 0,
|
|
2239
|
+
totalCells: 0
|
|
2240
|
+
};
|
|
2241
|
+
} else {
|
|
2242
|
+
const gridIndex = index;
|
|
2243
|
+
const result = queryByBoundsWithStats(gridIndex, queryBounds, {
|
|
2244
|
+
buffer: 0
|
|
2245
|
+
// Buffer already applied
|
|
2246
|
+
});
|
|
2247
|
+
data = result.data;
|
|
2248
|
+
stats = result.stats;
|
|
2249
|
+
}
|
|
2250
|
+
lastBounds = normalizedBounds;
|
|
2251
|
+
lastDataFetchBounds = normalizedBounds;
|
|
2252
|
+
lastData = data;
|
|
2253
|
+
lastStats = stats;
|
|
2254
|
+
lastUpdateTime = performance.now();
|
|
2255
|
+
return {
|
|
2256
|
+
data,
|
|
2257
|
+
stats,
|
|
2258
|
+
updated: true,
|
|
2259
|
+
velocity: currentVelocity
|
|
2260
|
+
};
|
|
2261
|
+
}
|
|
2262
|
+
function cancelPending() {
|
|
2263
|
+
if (pendingIdleId !== null) {
|
|
2264
|
+
cancelIdleCallbackPolyfill(pendingIdleId);
|
|
2265
|
+
pendingIdleId = null;
|
|
2266
|
+
}
|
|
2267
|
+
pendingBounds = null;
|
|
2268
|
+
}
|
|
2269
|
+
return {
|
|
2270
|
+
queueUpdate(bounds, trackOnly = false) {
|
|
2271
|
+
const normalizedBounds = normalizeBoundsInternal(bounds);
|
|
2272
|
+
trackVelocity(normalizedBounds);
|
|
2273
|
+
const cumulativeDistance = getCumulativeDistance(normalizedBounds);
|
|
2274
|
+
const mustUpdate = cumulativeDistance > maxPanDistance;
|
|
2275
|
+
if (trackOnly) {
|
|
2276
|
+
if (mustUpdate) {
|
|
2277
|
+
const result = executeQuery(normalizedBounds);
|
|
2278
|
+
result.chunkLoadTriggered = true;
|
|
2279
|
+
if (dataReadyCallback) {
|
|
2280
|
+
dataReadyCallback(result);
|
|
2281
|
+
}
|
|
2282
|
+
}
|
|
2283
|
+
return;
|
|
2284
|
+
}
|
|
2285
|
+
if (lastData && !shouldUpdate(normalizedBounds) && !mustUpdate) {
|
|
2286
|
+
return;
|
|
2287
|
+
}
|
|
2288
|
+
const now = performance.now();
|
|
2289
|
+
if (!mustUpdate && now - lastUpdateTime < minUpdateInterval) {
|
|
2290
|
+
pendingBounds = normalizedBounds;
|
|
2291
|
+
if (pendingIdleId === null) {
|
|
2292
|
+
pendingIdleId = requestIdleCallbackPolyfill(
|
|
2293
|
+
() => {
|
|
2294
|
+
pendingIdleId = null;
|
|
2295
|
+
if (pendingBounds) {
|
|
2296
|
+
const result = executeQuery(pendingBounds);
|
|
2297
|
+
pendingBounds = null;
|
|
2298
|
+
if (dataReadyCallback) {
|
|
2299
|
+
dataReadyCallback(result);
|
|
2300
|
+
}
|
|
2301
|
+
}
|
|
2302
|
+
},
|
|
2303
|
+
{ timeout: idleDelay }
|
|
2304
|
+
);
|
|
2305
|
+
}
|
|
2306
|
+
return;
|
|
2307
|
+
}
|
|
2308
|
+
cancelPending();
|
|
2309
|
+
if (mustUpdate) {
|
|
2310
|
+
const result = executeQuery(normalizedBounds);
|
|
2311
|
+
result.chunkLoadTriggered = true;
|
|
2312
|
+
if (dataReadyCallback) {
|
|
2313
|
+
dataReadyCallback(result);
|
|
2314
|
+
}
|
|
2315
|
+
return;
|
|
2316
|
+
}
|
|
2317
|
+
pendingBounds = normalizedBounds;
|
|
2318
|
+
pendingIdleId = requestIdleCallbackPolyfill(
|
|
2319
|
+
() => {
|
|
2320
|
+
pendingIdleId = null;
|
|
2321
|
+
if (pendingBounds) {
|
|
2322
|
+
const result = executeQuery(pendingBounds);
|
|
2323
|
+
pendingBounds = null;
|
|
2324
|
+
if (dataReadyCallback) {
|
|
2325
|
+
dataReadyCallback(result);
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
},
|
|
2329
|
+
{ timeout: idleDelay }
|
|
2330
|
+
);
|
|
2331
|
+
},
|
|
2332
|
+
forceUpdate(bounds) {
|
|
2333
|
+
const normalizedBounds = normalizeBoundsInternal(bounds);
|
|
2334
|
+
cancelPending();
|
|
2335
|
+
trackVelocity(normalizedBounds);
|
|
2336
|
+
if (lastData && !shouldUpdate(normalizedBounds)) {
|
|
2337
|
+
return {
|
|
2338
|
+
data: lastData,
|
|
2339
|
+
stats: lastStats,
|
|
2340
|
+
updated: false,
|
|
2341
|
+
velocity: currentVelocity
|
|
2342
|
+
};
|
|
2343
|
+
}
|
|
2344
|
+
return executeQuery(normalizedBounds);
|
|
2345
|
+
},
|
|
2346
|
+
onDataReady(callback) {
|
|
2347
|
+
dataReadyCallback = callback;
|
|
2348
|
+
},
|
|
2349
|
+
reset() {
|
|
2350
|
+
cancelPending();
|
|
2351
|
+
lastBounds = null;
|
|
2352
|
+
lastDataFetchBounds = null;
|
|
2353
|
+
lastData = null;
|
|
2354
|
+
lastStats = null;
|
|
2355
|
+
lastUpdateTime = 0;
|
|
2356
|
+
viewportSamples = [];
|
|
2357
|
+
currentVelocity = { lngPerSec: 0, latPerSec: 0, magnitude: 0 };
|
|
2358
|
+
},
|
|
2359
|
+
getStats() {
|
|
2360
|
+
return lastStats;
|
|
2361
|
+
},
|
|
2362
|
+
getVelocity() {
|
|
2363
|
+
return currentVelocity;
|
|
2364
|
+
},
|
|
2365
|
+
getCumulativeDistance(bounds) {
|
|
2366
|
+
return getCumulativeDistance(normalizeBoundsInternal(bounds));
|
|
2367
|
+
}
|
|
2368
|
+
};
|
|
2369
|
+
}
|
|
2370
|
+
function calculatePanVelocityInternal(samples) {
|
|
2371
|
+
if (samples.length < 2) {
|
|
2372
|
+
return { lngPerSec: 0, latPerSec: 0, magnitude: 0 };
|
|
2373
|
+
}
|
|
2374
|
+
let totalLngDelta = 0;
|
|
2375
|
+
let totalLatDelta = 0;
|
|
2376
|
+
let totalTime = 0;
|
|
2377
|
+
let weight = 1;
|
|
2378
|
+
for (let i = samples.length - 1; i > 0; i--) {
|
|
2379
|
+
const current = samples[i];
|
|
2380
|
+
const previous = samples[i - 1];
|
|
2381
|
+
const dt = (current.timestamp - previous.timestamp) / 1e3;
|
|
2382
|
+
if (dt > 0 && dt < 1) {
|
|
2383
|
+
totalLngDelta += (current.center[0] - previous.center[0]) * weight;
|
|
2384
|
+
totalLatDelta += (current.center[1] - previous.center[1]) * weight;
|
|
2385
|
+
totalTime += dt * weight;
|
|
2386
|
+
}
|
|
2387
|
+
weight *= 0.7;
|
|
2388
|
+
}
|
|
2389
|
+
if (totalTime === 0) {
|
|
2390
|
+
return { lngPerSec: 0, latPerSec: 0, magnitude: 0 };
|
|
2391
|
+
}
|
|
2392
|
+
const lngPerSec = totalLngDelta / totalTime;
|
|
2393
|
+
const latPerSec = totalLatDelta / totalTime;
|
|
2394
|
+
const magnitude = Math.sqrt(lngPerSec * lngPerSec + latPerSec * latPerSec);
|
|
2395
|
+
return { lngPerSec, latPerSec, magnitude };
|
|
2396
|
+
}
|
|
2397
|
+
function applyPredictiveBufferInternal(bounds, velocity, baseBuffer, multiplier) {
|
|
2398
|
+
const [[minLng, minLat], [maxLng, maxLat]] = bounds;
|
|
2399
|
+
let bufferMinLng = baseBuffer;
|
|
2400
|
+
let bufferMaxLng = baseBuffer;
|
|
2401
|
+
let bufferMinLat = baseBuffer;
|
|
2402
|
+
let bufferMaxLat = baseBuffer;
|
|
2403
|
+
if (velocity.magnitude > 1e-5) {
|
|
2404
|
+
const extraBuffer = baseBuffer * (multiplier - 1);
|
|
2405
|
+
if (velocity.lngPerSec > 0) {
|
|
2406
|
+
bufferMaxLng += extraBuffer * Math.min(1, velocity.lngPerSec / velocity.magnitude);
|
|
2407
|
+
} else if (velocity.lngPerSec < 0) {
|
|
2408
|
+
bufferMinLng += extraBuffer * Math.min(1, -velocity.lngPerSec / velocity.magnitude);
|
|
2409
|
+
}
|
|
2410
|
+
if (velocity.latPerSec > 0) {
|
|
2411
|
+
bufferMaxLat += extraBuffer * Math.min(1, velocity.latPerSec / velocity.magnitude);
|
|
2412
|
+
} else if (velocity.latPerSec < 0) {
|
|
2413
|
+
bufferMinLat += extraBuffer * Math.min(1, -velocity.latPerSec / velocity.magnitude);
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
return [
|
|
2417
|
+
[minLng - bufferMinLng, minLat - bufferMinLat],
|
|
2418
|
+
[maxLng + bufferMaxLng, maxLat + bufferMaxLat]
|
|
2419
|
+
];
|
|
2420
|
+
}
|
|
2421
|
+
function calculatePanVelocity(samples) {
|
|
2422
|
+
if (samples.length < 2) {
|
|
2423
|
+
return { lngPerSec: 0, latPerSec: 0, magnitude: 0 };
|
|
2424
|
+
}
|
|
2425
|
+
let totalLngDelta = 0;
|
|
2426
|
+
let totalLatDelta = 0;
|
|
2427
|
+
let totalTime = 0;
|
|
2428
|
+
let weight = 1;
|
|
2429
|
+
for (let i = samples.length - 1; i > 0; i--) {
|
|
2430
|
+
const current = samples[i];
|
|
2431
|
+
const previous = samples[i - 1];
|
|
2432
|
+
const dt = (current.timestamp - previous.timestamp) / 1e3;
|
|
2433
|
+
if (dt > 0 && dt < 1) {
|
|
2434
|
+
totalLngDelta += (current.center[0] - previous.center[0]) * weight;
|
|
2435
|
+
totalLatDelta += (current.center[1] - previous.center[1]) * weight;
|
|
2436
|
+
totalTime += dt * weight;
|
|
2437
|
+
}
|
|
2438
|
+
weight *= 0.7;
|
|
2439
|
+
}
|
|
2440
|
+
if (totalTime === 0) {
|
|
2441
|
+
return { lngPerSec: 0, latPerSec: 0, magnitude: 0 };
|
|
2442
|
+
}
|
|
2443
|
+
const lngPerSec = totalLngDelta / totalTime;
|
|
2444
|
+
const latPerSec = totalLatDelta / totalTime;
|
|
2445
|
+
const magnitude = Math.sqrt(lngPerSec * lngPerSec + latPerSec * latPerSec);
|
|
2446
|
+
return { lngPerSec, latPerSec, magnitude };
|
|
2447
|
+
}
|
|
2448
|
+
function applyPredictiveBuffer(bounds, velocity, baseBuffer, multiplier) {
|
|
2449
|
+
const [[minLng, minLat], [maxLng, maxLat]] = bounds;
|
|
2450
|
+
let bufferMinLng = baseBuffer;
|
|
2451
|
+
let bufferMaxLng = baseBuffer;
|
|
2452
|
+
let bufferMinLat = baseBuffer;
|
|
2453
|
+
let bufferMaxLat = baseBuffer;
|
|
2454
|
+
if (velocity.magnitude > 1e-5) {
|
|
2455
|
+
const extraBuffer = baseBuffer * (multiplier - 1);
|
|
2456
|
+
if (velocity.lngPerSec > 0) {
|
|
2457
|
+
bufferMaxLng += extraBuffer * Math.min(1, velocity.lngPerSec / velocity.magnitude);
|
|
2458
|
+
} else if (velocity.lngPerSec < 0) {
|
|
2459
|
+
bufferMinLng += extraBuffer * Math.min(1, -velocity.lngPerSec / velocity.magnitude);
|
|
2460
|
+
}
|
|
2461
|
+
if (velocity.latPerSec > 0) {
|
|
2462
|
+
bufferMaxLat += extraBuffer * Math.min(1, velocity.latPerSec / velocity.magnitude);
|
|
2463
|
+
} else if (velocity.latPerSec < 0) {
|
|
2464
|
+
bufferMinLat += extraBuffer * Math.min(1, -velocity.latPerSec / velocity.magnitude);
|
|
2465
|
+
}
|
|
2466
|
+
}
|
|
2467
|
+
return [
|
|
2468
|
+
[minLng - bufferMinLng, minLat - bufferMinLat],
|
|
2469
|
+
[maxLng + bufferMaxLng, maxLat + bufferMaxLat]
|
|
2470
|
+
];
|
|
2471
|
+
}
|
|
2472
|
+
function createPredictiveViewportManager(index, options = {}) {
|
|
2473
|
+
const {
|
|
2474
|
+
bufferFraction = 0.25,
|
|
2475
|
+
minMovement = 0.1,
|
|
2476
|
+
predictiveMultiplier = 2,
|
|
2477
|
+
velocitySamples = 5
|
|
2478
|
+
} = options;
|
|
2479
|
+
let lastBounds = null;
|
|
2480
|
+
let lastData = null;
|
|
2481
|
+
let lastStats = null;
|
|
2482
|
+
let viewportSamples = [];
|
|
2483
|
+
let currentVelocity = { lngPerSec: 0, latPerSec: 0, magnitude: 0 };
|
|
2484
|
+
const isRTree = "tree" in index;
|
|
2485
|
+
function shouldUpdate(newBounds) {
|
|
2486
|
+
if (!lastBounds) return true;
|
|
2487
|
+
const lastWidth = lastBounds[1][0] - lastBounds[0][0];
|
|
2488
|
+
const lastHeight = lastBounds[1][1] - lastBounds[0][1];
|
|
2489
|
+
const movementLng = Math.abs(
|
|
2490
|
+
(newBounds[0][0] + newBounds[1][0]) / 2 - (lastBounds[0][0] + lastBounds[1][0]) / 2
|
|
2491
|
+
);
|
|
2492
|
+
const movementLat = Math.abs(
|
|
2493
|
+
(newBounds[0][1] + newBounds[1][1]) / 2 - (lastBounds[0][1] + lastBounds[1][1]) / 2
|
|
2494
|
+
);
|
|
2495
|
+
const movement = Math.max(movementLng / lastWidth, movementLat / lastHeight);
|
|
2496
|
+
const newWidth = newBounds[1][0] - newBounds[0][0];
|
|
2497
|
+
const zoomChange = Math.abs(newWidth / lastWidth - 1);
|
|
2498
|
+
return movement > minMovement || zoomChange > 0.2;
|
|
2499
|
+
}
|
|
2500
|
+
return {
|
|
2501
|
+
update(bounds) {
|
|
2502
|
+
const normalizedBounds = normalizeBounds(bounds);
|
|
2503
|
+
const now = performance.now();
|
|
2504
|
+
const center = [
|
|
2505
|
+
(normalizedBounds[0][0] + normalizedBounds[1][0]) / 2,
|
|
2506
|
+
(normalizedBounds[0][1] + normalizedBounds[1][1]) / 2
|
|
2507
|
+
];
|
|
2508
|
+
viewportSamples.push({ center, timestamp: now });
|
|
2509
|
+
while (viewportSamples.length > velocitySamples) {
|
|
2510
|
+
viewportSamples.shift();
|
|
2511
|
+
}
|
|
2512
|
+
currentVelocity = calculatePanVelocity(viewportSamples);
|
|
2513
|
+
if (lastData && !shouldUpdate(normalizedBounds)) {
|
|
2514
|
+
return {
|
|
2515
|
+
data: lastData,
|
|
2516
|
+
stats: lastStats,
|
|
2517
|
+
updated: false,
|
|
2518
|
+
velocity: currentVelocity
|
|
2519
|
+
};
|
|
2520
|
+
}
|
|
2521
|
+
const viewWidth = normalizedBounds[1][0] - normalizedBounds[0][0];
|
|
2522
|
+
const viewHeight = normalizedBounds[1][1] - normalizedBounds[0][1];
|
|
2523
|
+
const baseBuffer = Math.max(viewWidth, viewHeight) * bufferFraction;
|
|
2524
|
+
const predictiveBounds = applyPredictiveBuffer(
|
|
2525
|
+
normalizedBounds,
|
|
2526
|
+
currentVelocity,
|
|
2527
|
+
baseBuffer,
|
|
2528
|
+
predictiveMultiplier
|
|
2529
|
+
);
|
|
2530
|
+
let data;
|
|
2531
|
+
let stats;
|
|
2532
|
+
if (isRTree) {
|
|
2533
|
+
const rtreeIndex = index;
|
|
2534
|
+
const result = queryRTreeByBoundsWithStats(rtreeIndex, predictiveBounds, {
|
|
2535
|
+
buffer: 0
|
|
2536
|
+
// Buffer already applied
|
|
2537
|
+
});
|
|
2538
|
+
data = result.data;
|
|
2539
|
+
stats = {
|
|
2540
|
+
totalFeatures: result.stats.totalFeatures,
|
|
2541
|
+
visibleFeatures: result.stats.visibleFeatures,
|
|
2542
|
+
culledPercent: result.stats.culledPercent,
|
|
2543
|
+
cellsChecked: 0,
|
|
2544
|
+
totalCells: 0
|
|
2545
|
+
};
|
|
2546
|
+
} else {
|
|
2547
|
+
const gridIndex = index;
|
|
2548
|
+
const result = queryByBoundsWithStats(gridIndex, predictiveBounds, {
|
|
2549
|
+
buffer: 0
|
|
2550
|
+
// Buffer already applied
|
|
2551
|
+
});
|
|
2552
|
+
data = result.data;
|
|
2553
|
+
stats = result.stats;
|
|
2554
|
+
}
|
|
2555
|
+
lastBounds = normalizedBounds;
|
|
2556
|
+
lastData = data;
|
|
2557
|
+
lastStats = stats;
|
|
2558
|
+
return {
|
|
2559
|
+
data,
|
|
2560
|
+
stats,
|
|
2561
|
+
updated: true,
|
|
2562
|
+
velocity: currentVelocity
|
|
2563
|
+
};
|
|
2564
|
+
},
|
|
2565
|
+
reset() {
|
|
2566
|
+
lastBounds = null;
|
|
2567
|
+
lastData = null;
|
|
2568
|
+
lastStats = null;
|
|
2569
|
+
viewportSamples = [];
|
|
2570
|
+
currentVelocity = { lngPerSec: 0, latPerSec: 0, magnitude: 0 };
|
|
2571
|
+
},
|
|
2572
|
+
getStats() {
|
|
2573
|
+
return lastStats;
|
|
2574
|
+
},
|
|
2575
|
+
getVelocity() {
|
|
2576
|
+
return currentVelocity;
|
|
2577
|
+
}
|
|
2578
|
+
};
|
|
2579
|
+
}
|
|
2580
|
+
function buildRTreeIndex(geojson, options = {}) {
|
|
2581
|
+
const { maxEntries = 9 } = options;
|
|
2582
|
+
const tree = new RBush__default.default(maxEntries);
|
|
2583
|
+
const items = [];
|
|
2584
|
+
let minLngAll = Infinity;
|
|
2585
|
+
let minLatAll = Infinity;
|
|
2586
|
+
let maxLngAll = -Infinity;
|
|
2587
|
+
let maxLatAll = -Infinity;
|
|
2588
|
+
for (const feature of geojson.features) {
|
|
2589
|
+
const featureBounds = getFeatureBoundsInternal(feature);
|
|
2590
|
+
if (!featureBounds) continue;
|
|
2591
|
+
const [[minLng, minLat], [maxLng, maxLat]] = featureBounds;
|
|
2592
|
+
items.push({
|
|
2593
|
+
minX: minLng,
|
|
2594
|
+
minY: minLat,
|
|
2595
|
+
maxX: maxLng,
|
|
2596
|
+
maxY: maxLat,
|
|
2597
|
+
feature
|
|
2598
|
+
});
|
|
2599
|
+
minLngAll = Math.min(minLngAll, minLng);
|
|
2600
|
+
minLatAll = Math.min(minLatAll, minLat);
|
|
2601
|
+
maxLngAll = Math.max(maxLngAll, maxLng);
|
|
2602
|
+
maxLatAll = Math.max(maxLatAll, maxLat);
|
|
2603
|
+
}
|
|
2604
|
+
tree.load(items);
|
|
2605
|
+
const bounds = minLngAll === Infinity ? [
|
|
2606
|
+
[0, 0],
|
|
2607
|
+
[0, 0]
|
|
2608
|
+
] : [
|
|
2609
|
+
[minLngAll, minLatAll],
|
|
2610
|
+
[maxLngAll, maxLatAll]
|
|
2611
|
+
];
|
|
2612
|
+
return {
|
|
2613
|
+
tree,
|
|
2614
|
+
bounds,
|
|
2615
|
+
featureCount: items.length
|
|
2616
|
+
};
|
|
2617
|
+
}
|
|
2618
|
+
function getFeatureBoundsInternal(feature) {
|
|
2619
|
+
const geometry = feature.geometry;
|
|
2620
|
+
if (!geometry) return null;
|
|
2621
|
+
let minLng = Infinity;
|
|
2622
|
+
let minLat = Infinity;
|
|
2623
|
+
let maxLng = -Infinity;
|
|
2624
|
+
let maxLat = -Infinity;
|
|
2625
|
+
function processCoord(coord) {
|
|
2626
|
+
minLng = Math.min(minLng, coord[0]);
|
|
2627
|
+
minLat = Math.min(minLat, coord[1]);
|
|
2628
|
+
maxLng = Math.max(maxLng, coord[0]);
|
|
2629
|
+
maxLat = Math.max(maxLat, coord[1]);
|
|
2630
|
+
}
|
|
2631
|
+
function processRing(ring) {
|
|
2632
|
+
ring.forEach(processCoord);
|
|
2633
|
+
}
|
|
2634
|
+
switch (geometry.type) {
|
|
2635
|
+
case "Point":
|
|
2636
|
+
processCoord(geometry.coordinates);
|
|
2637
|
+
break;
|
|
2638
|
+
case "MultiPoint":
|
|
2639
|
+
case "LineString":
|
|
2640
|
+
geometry.coordinates.forEach(processCoord);
|
|
2641
|
+
break;
|
|
2642
|
+
case "MultiLineString":
|
|
2643
|
+
case "Polygon":
|
|
2644
|
+
geometry.coordinates.forEach(processRing);
|
|
2645
|
+
break;
|
|
2646
|
+
case "MultiPolygon":
|
|
2647
|
+
geometry.coordinates.forEach(
|
|
2648
|
+
(polygon) => polygon.forEach(processRing)
|
|
2649
|
+
);
|
|
2650
|
+
break;
|
|
2651
|
+
}
|
|
2652
|
+
if (minLng === Infinity) return null;
|
|
2653
|
+
return [
|
|
2654
|
+
[minLng, minLat],
|
|
2655
|
+
[maxLng, maxLat]
|
|
2656
|
+
];
|
|
2657
|
+
}
|
|
2658
|
+
function queryRTreeByBounds(index, queryBounds, options = {}) {
|
|
2659
|
+
const { buffer = 0.01, bufferFraction } = options;
|
|
2660
|
+
if (index.featureCount === 0) {
|
|
2661
|
+
return { type: "FeatureCollection", features: [] };
|
|
2662
|
+
}
|
|
2663
|
+
let [[minLng, minLat], [maxLng, maxLat]] = normalizeBoundsInternal(queryBounds);
|
|
2664
|
+
const viewWidth = maxLng - minLng;
|
|
2665
|
+
const viewHeight = maxLat - minLat;
|
|
2666
|
+
const actualBuffer = bufferFraction ? Math.max(viewWidth, viewHeight) * bufferFraction : buffer;
|
|
2667
|
+
minLng -= actualBuffer;
|
|
2668
|
+
minLat -= actualBuffer;
|
|
2669
|
+
maxLng += actualBuffer;
|
|
2670
|
+
maxLat += actualBuffer;
|
|
2671
|
+
const results = index.tree.search({
|
|
2672
|
+
minX: minLng,
|
|
2673
|
+
minY: minLat,
|
|
2674
|
+
maxX: maxLng,
|
|
2675
|
+
maxY: maxLat
|
|
2676
|
+
});
|
|
2677
|
+
return {
|
|
2678
|
+
type: "FeatureCollection",
|
|
2679
|
+
features: results.map((item) => item.feature)
|
|
2680
|
+
};
|
|
2681
|
+
}
|
|
2682
|
+
function queryRTreeByBoundsWithStats(index, queryBounds, options = {}) {
|
|
2683
|
+
const { buffer = 0.01, bufferFraction } = options;
|
|
2684
|
+
if (index.featureCount === 0) {
|
|
2685
|
+
return {
|
|
2686
|
+
data: { type: "FeatureCollection", features: [] },
|
|
2687
|
+
stats: {
|
|
2688
|
+
totalFeatures: 0,
|
|
2689
|
+
visibleFeatures: 0,
|
|
2690
|
+
culledPercent: 0,
|
|
2691
|
+
queryTimeMs: 0
|
|
2692
|
+
}
|
|
2693
|
+
};
|
|
2694
|
+
}
|
|
2695
|
+
const startTime = performance.now();
|
|
2696
|
+
let [[minLng, minLat], [maxLng, maxLat]] = normalizeBoundsInternal(queryBounds);
|
|
2697
|
+
const viewWidth = maxLng - minLng;
|
|
2698
|
+
const viewHeight = maxLat - minLat;
|
|
2699
|
+
const actualBuffer = bufferFraction ? Math.max(viewWidth, viewHeight) * bufferFraction : buffer;
|
|
2700
|
+
minLng -= actualBuffer;
|
|
2701
|
+
minLat -= actualBuffer;
|
|
2702
|
+
maxLng += actualBuffer;
|
|
2703
|
+
maxLat += actualBuffer;
|
|
2704
|
+
const results = index.tree.search({
|
|
2705
|
+
minX: minLng,
|
|
2706
|
+
minY: minLat,
|
|
2707
|
+
maxX: maxLng,
|
|
2708
|
+
maxY: maxLat
|
|
2709
|
+
});
|
|
2710
|
+
const queryTimeMs = performance.now() - startTime;
|
|
2711
|
+
const visibleFeatures = results.length;
|
|
2712
|
+
const culledPercent = index.featureCount > 0 ? (index.featureCount - visibleFeatures) / index.featureCount * 100 : 0;
|
|
2713
|
+
return {
|
|
2714
|
+
data: {
|
|
2715
|
+
type: "FeatureCollection",
|
|
2716
|
+
features: results.map((item) => item.feature)
|
|
2717
|
+
},
|
|
2718
|
+
stats: {
|
|
2719
|
+
totalFeatures: index.featureCount,
|
|
2720
|
+
visibleFeatures,
|
|
2721
|
+
culledPercent,
|
|
2722
|
+
queryTimeMs
|
|
2723
|
+
}
|
|
2724
|
+
};
|
|
2725
|
+
}
|
|
2726
|
+
function normalizeBoundsInternal(bounds) {
|
|
2727
|
+
if (Array.isArray(bounds) && Array.isArray(bounds[0])) {
|
|
2728
|
+
return bounds;
|
|
2729
|
+
}
|
|
2730
|
+
const mapBounds = bounds;
|
|
2731
|
+
return [mapBounds.southwest, mapBounds.northeast];
|
|
2732
|
+
}
|
|
2733
|
+
function createRTreeViewportManager(index, options = {}) {
|
|
2734
|
+
const { bufferFraction = 0.25, minMovement = 0.1 } = options;
|
|
2735
|
+
let lastBounds = null;
|
|
2736
|
+
let lastData = null;
|
|
2737
|
+
let lastStats = null;
|
|
2738
|
+
function shouldUpdate(newBounds) {
|
|
2739
|
+
if (!lastBounds) return true;
|
|
2740
|
+
const lastWidth = lastBounds[1][0] - lastBounds[0][0];
|
|
2741
|
+
const lastHeight = lastBounds[1][1] - lastBounds[0][1];
|
|
2742
|
+
const movementLng = Math.abs(
|
|
2743
|
+
(newBounds[0][0] + newBounds[1][0]) / 2 - (lastBounds[0][0] + lastBounds[1][0]) / 2
|
|
2744
|
+
);
|
|
2745
|
+
const movementLat = Math.abs(
|
|
2746
|
+
(newBounds[0][1] + newBounds[1][1]) / 2 - (lastBounds[0][1] + lastBounds[1][1]) / 2
|
|
2747
|
+
);
|
|
2748
|
+
const movement = Math.max(movementLng / lastWidth, movementLat / lastHeight);
|
|
2749
|
+
const newWidth = newBounds[1][0] - newBounds[0][0];
|
|
2750
|
+
const zoomChange = Math.abs(newWidth / lastWidth - 1);
|
|
2751
|
+
return movement > minMovement || zoomChange > 0.2;
|
|
2752
|
+
}
|
|
2753
|
+
return {
|
|
2754
|
+
update(bounds) {
|
|
2755
|
+
const normalizedBounds = normalizeBoundsInternal(bounds);
|
|
2756
|
+
if (lastData && !shouldUpdate(normalizedBounds)) {
|
|
2757
|
+
return {
|
|
2758
|
+
data: lastData,
|
|
2759
|
+
stats: lastStats,
|
|
2760
|
+
updated: false,
|
|
2761
|
+
queryTimeMs: lastStats?.queryTimeMs
|
|
2762
|
+
};
|
|
2763
|
+
}
|
|
2764
|
+
const { data, stats } = queryRTreeByBoundsWithStats(index, normalizedBounds, {
|
|
2765
|
+
bufferFraction
|
|
2766
|
+
});
|
|
2767
|
+
lastBounds = normalizedBounds;
|
|
2768
|
+
lastData = data;
|
|
2769
|
+
lastStats = {
|
|
2770
|
+
totalFeatures: stats.totalFeatures,
|
|
2771
|
+
visibleFeatures: stats.visibleFeatures,
|
|
2772
|
+
culledPercent: stats.culledPercent,
|
|
2773
|
+
cellsChecked: 0,
|
|
2774
|
+
// R-tree doesn't use cells
|
|
2775
|
+
totalCells: 0,
|
|
2776
|
+
queryTimeMs: stats.queryTimeMs
|
|
2777
|
+
};
|
|
2778
|
+
return {
|
|
2779
|
+
data,
|
|
2780
|
+
stats: lastStats,
|
|
2781
|
+
updated: true,
|
|
2782
|
+
queryTimeMs: stats.queryTimeMs
|
|
2783
|
+
};
|
|
2784
|
+
},
|
|
2785
|
+
reset() {
|
|
2786
|
+
lastBounds = null;
|
|
2787
|
+
lastData = null;
|
|
2788
|
+
lastStats = null;
|
|
2789
|
+
},
|
|
2790
|
+
getStats() {
|
|
2791
|
+
return lastStats;
|
|
2792
|
+
}
|
|
2793
|
+
};
|
|
2794
|
+
}
|
|
2795
|
+
|
|
2796
|
+
// src/utils/fingerprint.ts
|
|
2797
|
+
function createGeoJSONFingerprint(data) {
|
|
2798
|
+
if (!data) return null;
|
|
2799
|
+
if (typeof data === "string") return null;
|
|
2800
|
+
if (data.type !== "FeatureCollection") return null;
|
|
2801
|
+
const features = data.features;
|
|
2802
|
+
if (!features || !Array.isArray(features)) {
|
|
2803
|
+
return { count: 0, firstId: void 0, lastId: void 0 };
|
|
2804
|
+
}
|
|
2805
|
+
const count = features.length;
|
|
2806
|
+
if (count === 0) {
|
|
2807
|
+
return { count: 0, firstId: void 0, lastId: void 0 };
|
|
2808
|
+
}
|
|
2809
|
+
const firstFeature = features[0];
|
|
2810
|
+
const lastFeature = features[count - 1];
|
|
2811
|
+
return {
|
|
2812
|
+
count,
|
|
2813
|
+
firstId: firstFeature?.id,
|
|
2814
|
+
lastId: lastFeature?.id
|
|
2815
|
+
};
|
|
2816
|
+
}
|
|
2817
|
+
function fingerprintEqual(a, b) {
|
|
2818
|
+
if (a === null && b === null) return true;
|
|
2819
|
+
if (a === null || b === null) return false;
|
|
2820
|
+
return a.count === b.count && a.firstId === b.firstId && a.lastId === b.lastId;
|
|
2821
|
+
}
|
|
2822
|
+
function geoJSONEqual(a, b) {
|
|
2823
|
+
if (typeof a === "string" || typeof b === "string") {
|
|
2824
|
+
return a === b;
|
|
2825
|
+
}
|
|
2826
|
+
if (!a && !b) return true;
|
|
2827
|
+
if (!a || !b) return false;
|
|
2828
|
+
const fpA = createGeoJSONFingerprint(a);
|
|
2829
|
+
const fpB = createGeoJSONFingerprint(b);
|
|
2830
|
+
return fingerprintEqual(fpA, fpB);
|
|
2831
|
+
}
|
|
2832
|
+
|
|
2833
|
+
// src/utils/equality.ts
|
|
2834
|
+
function deepEqual(a, b) {
|
|
2835
|
+
if (a === b) return true;
|
|
2836
|
+
if (a == null || b == null) return a === b;
|
|
2837
|
+
if (typeof a !== typeof b) return false;
|
|
2838
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
2839
|
+
if (a.length !== b.length) return false;
|
|
2840
|
+
for (let i = 0; i < a.length; i++) {
|
|
2841
|
+
if (!deepEqual(a[i], b[i])) return false;
|
|
2842
|
+
}
|
|
2843
|
+
return true;
|
|
2844
|
+
}
|
|
2845
|
+
if (typeof a === "object" && typeof b === "object") {
|
|
2846
|
+
const aKeys = Object.keys(a);
|
|
2847
|
+
const bKeys = Object.keys(b);
|
|
2848
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
2849
|
+
for (const key of aKeys) {
|
|
2850
|
+
if (!Object.prototype.hasOwnProperty.call(b, key) || !deepEqual(a[key], b[key])) {
|
|
2851
|
+
return false;
|
|
2852
|
+
}
|
|
2853
|
+
}
|
|
2854
|
+
return true;
|
|
2855
|
+
}
|
|
2856
|
+
return false;
|
|
2857
|
+
}
|
|
2858
|
+
function paintPropsEqual(prev, next) {
|
|
2859
|
+
if (prev === next) return true;
|
|
2860
|
+
if (!prev && !next) return true;
|
|
2861
|
+
if (!prev || !next) return false;
|
|
2862
|
+
const prevKeys = Object.keys(prev);
|
|
2863
|
+
const nextKeys = Object.keys(next);
|
|
2864
|
+
if (prevKeys.length !== nextKeys.length) return false;
|
|
2865
|
+
for (const key of prevKeys) {
|
|
2866
|
+
if (!Object.prototype.hasOwnProperty.call(next, key)) return false;
|
|
2867
|
+
if (!deepEqual(prev[key], next[key])) return false;
|
|
2868
|
+
}
|
|
2869
|
+
return true;
|
|
2870
|
+
}
|
|
2871
|
+
function getChangedPaintProps(prev, next) {
|
|
2872
|
+
const changed = {};
|
|
2873
|
+
const removed = [];
|
|
2874
|
+
if (!prev) {
|
|
2875
|
+
return {
|
|
2876
|
+
changed: next || {},
|
|
2877
|
+
removed: [],
|
|
2878
|
+
hasChanges: !!next && Object.keys(next).length > 0
|
|
2879
|
+
};
|
|
2880
|
+
}
|
|
2881
|
+
if (!next) {
|
|
2882
|
+
return {
|
|
2883
|
+
changed: {},
|
|
2884
|
+
removed: Object.keys(prev),
|
|
2885
|
+
hasChanges: Object.keys(prev).length > 0
|
|
2886
|
+
};
|
|
2887
|
+
}
|
|
2888
|
+
for (const key of Object.keys(next)) {
|
|
2889
|
+
if (!deepEqual(prev[key], next[key])) {
|
|
2890
|
+
changed[key] = next[key];
|
|
2891
|
+
}
|
|
2892
|
+
}
|
|
2893
|
+
for (const key of Object.keys(prev)) {
|
|
2894
|
+
if (!Object.prototype.hasOwnProperty.call(next, key)) {
|
|
2895
|
+
removed.push(key);
|
|
2896
|
+
}
|
|
2897
|
+
}
|
|
2898
|
+
return {
|
|
2899
|
+
changed,
|
|
2900
|
+
removed,
|
|
2901
|
+
hasChanges: Object.keys(changed).length > 0 || removed.length > 0
|
|
2902
|
+
};
|
|
2903
|
+
}
|
|
2904
|
+
function filterEqual(prev, next) {
|
|
2905
|
+
if (!prev && !next) return true;
|
|
2906
|
+
if (!prev || !next) return false;
|
|
2907
|
+
return deepEqual(prev, next);
|
|
2908
|
+
}
|
|
2909
|
+
function serializeFilter(filter) {
|
|
2910
|
+
if (!filter) return "";
|
|
2911
|
+
try {
|
|
2912
|
+
return JSON.stringify(filter);
|
|
2913
|
+
} catch {
|
|
2914
|
+
return "";
|
|
2915
|
+
}
|
|
2916
|
+
}
|
|
2917
|
+
|
|
2918
|
+
// src/utils/marker.ts
|
|
2919
|
+
var MARKER_PROTECTION_CLASS = "ct-marker-protected";
|
|
2920
|
+
function applyMarkerProtection(element) {
|
|
2921
|
+
element.classList.add(MARKER_PROTECTION_CLASS);
|
|
2922
|
+
const style = element.style;
|
|
2923
|
+
style.setProperty("transition", "none", "important");
|
|
2924
|
+
style.setProperty("transition-property", "none", "important");
|
|
2925
|
+
style.setProperty("animation", "none", "important");
|
|
2926
|
+
style.setProperty("will-change", "transform", "important");
|
|
2927
|
+
}
|
|
2928
|
+
function removeMarkerProtection(element) {
|
|
2929
|
+
element.classList.remove(MARKER_PROTECTION_CLASS);
|
|
2930
|
+
}
|
|
2931
|
+
function applyMarkerChildProtection(element) {
|
|
2932
|
+
const style = element.style;
|
|
2933
|
+
style.setProperty("transition", "none", "important");
|
|
2934
|
+
style.setProperty("animation", "none", "important");
|
|
2935
|
+
}
|
|
2936
|
+
|
|
2937
|
+
// src/utils/popup.ts
|
|
2938
|
+
function normalizePadding(padding) {
|
|
2939
|
+
if (typeof padding === "number") {
|
|
2940
|
+
return { top: padding, right: padding, bottom: padding, left: padding };
|
|
2941
|
+
}
|
|
2942
|
+
return padding;
|
|
2943
|
+
}
|
|
2944
|
+
function prefersReducedMotion() {
|
|
2945
|
+
if (typeof window === "undefined") return false;
|
|
2946
|
+
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
2947
|
+
}
|
|
2948
|
+
function panToFitPopup(map, popup, padding) {
|
|
2949
|
+
const popupEl = popup.getElement();
|
|
2950
|
+
if (!popupEl) return;
|
|
2951
|
+
const mapContainer = map.getContainer();
|
|
2952
|
+
const mapRect = mapContainer.getBoundingClientRect();
|
|
2953
|
+
const popupRect = popupEl.getBoundingClientRect();
|
|
2954
|
+
let dx = 0;
|
|
2955
|
+
let dy = 0;
|
|
2956
|
+
if (popupRect.left < mapRect.left + padding.left) {
|
|
2957
|
+
dx = popupRect.left - mapRect.left - padding.left;
|
|
2958
|
+
} else if (popupRect.right > mapRect.right - padding.right) {
|
|
2959
|
+
dx = popupRect.right - mapRect.right + padding.right;
|
|
2960
|
+
}
|
|
2961
|
+
if (popupRect.top < mapRect.top + padding.top) {
|
|
2962
|
+
dy = popupRect.top - mapRect.top - padding.top;
|
|
2963
|
+
} else if (popupRect.bottom > mapRect.bottom - padding.bottom) {
|
|
2964
|
+
dy = popupRect.bottom - mapRect.bottom + padding.bottom;
|
|
2965
|
+
}
|
|
2966
|
+
if (dx !== 0 || dy !== 0) {
|
|
2967
|
+
map.panBy([dx, dy], {
|
|
2968
|
+
animate: !prefersReducedMotion()
|
|
2969
|
+
});
|
|
2970
|
+
}
|
|
2971
|
+
}
|
|
2972
|
+
|
|
2973
|
+
exports.DEFAULT_SIMPLIFICATION_THRESHOLDS = DEFAULT_SIMPLIFICATION_THRESHOLDS;
|
|
2974
|
+
exports.KEYBOARD_CONTROLS = KEYBOARD_CONTROLS;
|
|
2975
|
+
exports.MARKER_PROTECTION_CLASS = MARKER_PROTECTION_CLASS;
|
|
2976
|
+
exports.applyMarkerChildProtection = applyMarkerChildProtection;
|
|
2977
|
+
exports.applyMarkerProtection = applyMarkerProtection;
|
|
2978
|
+
exports.boundsToPolygon = boundsToPolygon;
|
|
2979
|
+
exports.buildRTreeIndex = buildRTreeIndex;
|
|
2980
|
+
exports.buildSpatialIndex = buildSpatialIndex;
|
|
2981
|
+
exports.calculateBounds = calculateBounds;
|
|
2982
|
+
exports.calculateCentroid = calculateCentroid;
|
|
2983
|
+
exports.calculateZoomThresholds = calculateZoomThresholds;
|
|
2984
|
+
exports.clampLatitude = clampLatitude;
|
|
2985
|
+
exports.combineBounds = combineBounds;
|
|
2986
|
+
exports.countFeaturesByType = countFeaturesByType;
|
|
2987
|
+
exports.createCategoricalColorExpression = createCategoricalColorExpression;
|
|
2988
|
+
exports.createCircleStyle = createCircleStyle;
|
|
2989
|
+
exports.createClusterCirclePaint = createClusterCirclePaint;
|
|
2990
|
+
exports.createClusterStyles = createClusterStyles;
|
|
2991
|
+
exports.createClusterTextLayout = createClusterTextLayout;
|
|
2992
|
+
exports.createContinuousColorExpression = createContinuousColorExpression;
|
|
2993
|
+
exports.createDynamicLODManager = createDynamicLODManager;
|
|
2994
|
+
exports.createExtrusionHeightExpression = createExtrusionHeightExpression;
|
|
2995
|
+
exports.createExtrusionStyle = createExtrusionStyle;
|
|
2996
|
+
exports.createFillStyle = createFillStyle;
|
|
2997
|
+
exports.createGeoJSONFingerprint = createGeoJSONFingerprint;
|
|
2998
|
+
exports.createHeatmapStyle = createHeatmapStyle;
|
|
2999
|
+
exports.createHoverExpression = createHoverExpression;
|
|
3000
|
+
exports.createIdleViewportManager = createIdleViewportManager;
|
|
3001
|
+
exports.createInteractiveExpression = createInteractiveExpression;
|
|
3002
|
+
exports.createInteractiveStatusColorExpression = createInteractiveStatusColorExpression;
|
|
3003
|
+
exports.createLineStyle = createLineStyle;
|
|
3004
|
+
exports.createLotFillStyle = createLotFillStyle;
|
|
3005
|
+
exports.createLotOutlineStyle = createLotOutlineStyle;
|
|
3006
|
+
exports.createPredictiveViewportManager = createPredictiveViewportManager;
|
|
3007
|
+
exports.createRTreeViewportManager = createRTreeViewportManager;
|
|
3008
|
+
exports.createSelectionExpression = createSelectionExpression;
|
|
3009
|
+
exports.createStatusColorExpression = createStatusColorExpression;
|
|
3010
|
+
exports.createViewportManager = createViewportManager;
|
|
3011
|
+
exports.createViewportQuery = createViewportQuery;
|
|
3012
|
+
exports.createZoomExpression = createZoomExpression;
|
|
3013
|
+
exports.decimalToDMS = decimalToDMS;
|
|
3014
|
+
exports.deepEqual = deepEqual;
|
|
3015
|
+
exports.ensureValidCoordinates = ensureValidCoordinates;
|
|
3016
|
+
exports.expandCluster = expandCluster;
|
|
3017
|
+
exports.expandClusterToBounds = expandClusterToBounds;
|
|
3018
|
+
exports.extendBounds = extendBounds;
|
|
3019
|
+
exports.filterByGeometryType = filterByGeometryType;
|
|
3020
|
+
exports.filterEqual = filterEqual;
|
|
3021
|
+
exports.fingerprintEqual = fingerprintEqual;
|
|
3022
|
+
exports.formatArea = formatArea;
|
|
3023
|
+
exports.formatBearing = formatBearing;
|
|
3024
|
+
exports.formatBounds = formatBounds;
|
|
3025
|
+
exports.formatCoordinates = formatCoordinates;
|
|
3026
|
+
exports.formatDistance = formatDistance;
|
|
3027
|
+
exports.formatFeatureProperties = formatFeatureProperties;
|
|
3028
|
+
exports.formatLabel = formatLabel;
|
|
3029
|
+
exports.formatPitch = formatPitch;
|
|
3030
|
+
exports.formatPropertyValue = formatPropertyValue;
|
|
3031
|
+
exports.formatScale = formatScale;
|
|
3032
|
+
exports.formatZoom = formatZoom;
|
|
3033
|
+
exports.generateBoundingPolygon = generateBoundingPolygon;
|
|
3034
|
+
exports.generateConvexHull = generateConvexHull;
|
|
3035
|
+
exports.generateFeatureCollectionDescription = generateFeatureCollectionDescription;
|
|
3036
|
+
exports.generateFeatureTable = generateFeatureTable;
|
|
3037
|
+
exports.generateKeyboardControlsDescription = generateKeyboardControlsDescription;
|
|
3038
|
+
exports.generateLODData = generateLODData;
|
|
3039
|
+
exports.generateLODDataWithSimplification = generateLODDataWithSimplification;
|
|
3040
|
+
exports.generateMapDescription = generateMapDescription;
|
|
3041
|
+
exports.generateMarkerList = generateMarkerList;
|
|
3042
|
+
exports.generateMarkersDescription = generateMarkersDescription;
|
|
3043
|
+
exports.generateMoveAnnouncement = generateMoveAnnouncement;
|
|
3044
|
+
exports.geoJSONEqual = geoJSONEqual;
|
|
3045
|
+
exports.getChangedPaintProps = getChangedPaintProps;
|
|
3046
|
+
exports.getClusterBounds = getClusterBounds;
|
|
3047
|
+
exports.getClusterChildren = getClusterChildren;
|
|
3048
|
+
exports.getClusterExpansionZoom = getClusterExpansionZoom;
|
|
3049
|
+
exports.getClusterLeaves = getClusterLeaves;
|
|
3050
|
+
exports.getHighlightStyle = getHighlightStyle;
|
|
3051
|
+
exports.getSelectionStyle = getSelectionStyle;
|
|
3052
|
+
exports.getSimplificationToleranceForZoom = getSimplificationToleranceForZoom;
|
|
3053
|
+
exports.getSimplifiedFeaturesForZoom = getSimplifiedFeaturesForZoom;
|
|
3054
|
+
exports.groupFeaturesByProperty = groupFeaturesByProperty;
|
|
3055
|
+
exports.isClusterFeature = isClusterFeature;
|
|
3056
|
+
exports.isValidBounds = isValidBounds;
|
|
3057
|
+
exports.isValidLatitude = isValidLatitude;
|
|
3058
|
+
exports.isValidLongitude = isValidLongitude;
|
|
3059
|
+
exports.loadGeoJSON = loadGeoJSON;
|
|
3060
|
+
exports.normalizeLongitude = normalizeLongitude;
|
|
3061
|
+
exports.normalizePadding = normalizePadding;
|
|
3062
|
+
exports.paintPropsEqual = paintPropsEqual;
|
|
3063
|
+
exports.panToFitPopup = panToFitPopup;
|
|
3064
|
+
exports.prefersReducedMotion = prefersReducedMotion;
|
|
3065
|
+
exports.queryByBounds = queryByBounds;
|
|
3066
|
+
exports.queryByBoundsWithStats = queryByBoundsWithStats;
|
|
3067
|
+
exports.queryRTreeByBounds = queryRTreeByBounds;
|
|
3068
|
+
exports.queryRTreeByBoundsWithStats = queryRTreeByBoundsWithStats;
|
|
3069
|
+
exports.removeMarkerProtection = removeMarkerProtection;
|
|
3070
|
+
exports.serializeFilter = serializeFilter;
|
|
3071
|
+
exports.simplifyFeature = simplifyFeature;
|
|
3072
|
+
exports.simplifyFeatureCollection = simplifyFeatureCollection;
|
|
3073
|
+
exports.simplifyFeatureCollectionWithStats = simplifyFeatureCollectionWithStats;
|
|
3074
|
+
exports.simplifyPolygon = simplifyPolygon;
|
|
3075
|
+
exports.validateBoundsArray = validateBoundsArray;
|
|
3076
|
+
exports.validateCoordinates = validateCoordinates;
|
|
3077
|
+
exports.validateGeoJSON = validateGeoJSON;
|
|
3078
|
+
exports.zoomToScale = zoomToScale;
|