@classic-homes/maps-core 0.4.1 → 0.5.2
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-EXGGK4H7.js → chunk-ASIFMIU7.js} +300 -289
- package/dist/index.cjs +600 -592
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +8 -11
- package/dist/route/index.cjs +15 -5
- package/dist/route/index.d.cts +10 -6
- package/dist/route/index.d.ts +10 -6
- package/dist/route/index.js +15 -5
- package/dist/utils/index.cjs +300 -289
- package/dist/utils/index.js +1 -1
- package/dist/workers/index.cjs +29 -6
- package/dist/workers/index.d.cts +6 -0
- package/dist/workers/index.d.ts +6 -0
- package/dist/workers/index.js +29 -6
- package/dist/workers/spatial.worker.js +13 -10
- package/package.json +3 -2
|
@@ -1,6 +1,268 @@
|
|
|
1
1
|
import { lightTheme } from './chunk-ZGUACUEF.js';
|
|
2
2
|
import RBush from 'rbush';
|
|
3
3
|
|
|
4
|
+
// src/utils/format.ts
|
|
5
|
+
function formatCoordinates(coordinates, precision = 6, format = "decimal") {
|
|
6
|
+
const [lng, lat] = coordinates;
|
|
7
|
+
switch (format) {
|
|
8
|
+
case "dms":
|
|
9
|
+
return `${decimalToDMS(lat, "lat")}, ${decimalToDMS(lng, "lng")}`;
|
|
10
|
+
case "dd":
|
|
11
|
+
return `${lat.toFixed(precision)}, ${lng.toFixed(precision)}`;
|
|
12
|
+
case "decimal":
|
|
13
|
+
default:
|
|
14
|
+
return `${lng.toFixed(precision)}, ${lat.toFixed(precision)}`;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function decimalToDMS(decimal, type) {
|
|
18
|
+
const tenths = Math.round(Math.abs(decimal) * 36e3);
|
|
19
|
+
const degrees = Math.floor(tenths / 36e3);
|
|
20
|
+
const minutes = Math.floor(tenths % 36e3 / 600);
|
|
21
|
+
const seconds = (tenths % 600 / 10).toFixed(1);
|
|
22
|
+
let direction;
|
|
23
|
+
if (type === "lat") {
|
|
24
|
+
direction = decimal >= 0 ? "N" : "S";
|
|
25
|
+
} else {
|
|
26
|
+
direction = decimal >= 0 ? "E" : "W";
|
|
27
|
+
}
|
|
28
|
+
return `${degrees}\xB0 ${minutes}' ${seconds}" ${direction}`;
|
|
29
|
+
}
|
|
30
|
+
function formatDistance(meters, unit = "metric") {
|
|
31
|
+
if (unit === "imperial") {
|
|
32
|
+
const feet = meters * 3.28084;
|
|
33
|
+
if (feet < 1e3) {
|
|
34
|
+
return `${Math.round(feet)} ft`;
|
|
35
|
+
}
|
|
36
|
+
const miles = feet / 5280;
|
|
37
|
+
if (miles < 10) {
|
|
38
|
+
return `${miles.toFixed(1)} mi`;
|
|
39
|
+
}
|
|
40
|
+
return `${Math.round(miles)} mi`;
|
|
41
|
+
}
|
|
42
|
+
if (meters < 1e3) {
|
|
43
|
+
return `${Math.round(meters)} m`;
|
|
44
|
+
}
|
|
45
|
+
const km = meters / 1e3;
|
|
46
|
+
if (km < 10) {
|
|
47
|
+
return `${km.toFixed(1)} km`;
|
|
48
|
+
}
|
|
49
|
+
return `${Math.round(km)} km`;
|
|
50
|
+
}
|
|
51
|
+
function formatArea(sqMeters, unit = "metric") {
|
|
52
|
+
if (unit === "imperial") {
|
|
53
|
+
const sqFeet = sqMeters * 10.7639;
|
|
54
|
+
if (sqFeet < 43560) {
|
|
55
|
+
return `${Math.round(sqFeet).toLocaleString()} sq ft`;
|
|
56
|
+
}
|
|
57
|
+
const acres = sqFeet / 43560;
|
|
58
|
+
if (acres < 640) {
|
|
59
|
+
return `${acres.toFixed(2)} acres`;
|
|
60
|
+
}
|
|
61
|
+
const sqMiles = acres / 640;
|
|
62
|
+
return `${sqMiles.toFixed(2)} sq mi`;
|
|
63
|
+
}
|
|
64
|
+
if (sqMeters < 1e4) {
|
|
65
|
+
return `${Math.round(sqMeters).toLocaleString()} m\xB2`;
|
|
66
|
+
}
|
|
67
|
+
const hectares = sqMeters / 1e4;
|
|
68
|
+
if (hectares < 100) {
|
|
69
|
+
return `${hectares.toFixed(2)} ha`;
|
|
70
|
+
}
|
|
71
|
+
const sqKm = sqMeters / 1e6;
|
|
72
|
+
return `${sqKm.toFixed(2)} km\xB2`;
|
|
73
|
+
}
|
|
74
|
+
function formatBounds(bounds) {
|
|
75
|
+
let sw;
|
|
76
|
+
let ne;
|
|
77
|
+
if (Array.isArray(bounds) && Array.isArray(bounds[0])) {
|
|
78
|
+
const arr = bounds;
|
|
79
|
+
sw = arr[0];
|
|
80
|
+
ne = arr[1];
|
|
81
|
+
} else {
|
|
82
|
+
const b = bounds;
|
|
83
|
+
sw = b.southwest;
|
|
84
|
+
ne = b.northeast;
|
|
85
|
+
}
|
|
86
|
+
return `SW: ${formatCoordinates(sw, 4)}, NE: ${formatCoordinates(ne, 4)}`;
|
|
87
|
+
}
|
|
88
|
+
function formatZoom(zoom) {
|
|
89
|
+
return `Zoom: ${zoom.toFixed(1)}`;
|
|
90
|
+
}
|
|
91
|
+
function formatBearing(bearing) {
|
|
92
|
+
const normalized = (bearing % 360 + 360) % 360;
|
|
93
|
+
let direction;
|
|
94
|
+
if (normalized >= 337.5 || normalized < 22.5) {
|
|
95
|
+
direction = "N";
|
|
96
|
+
} else if (normalized >= 22.5 && normalized < 67.5) {
|
|
97
|
+
direction = "NE";
|
|
98
|
+
} else if (normalized >= 67.5 && normalized < 112.5) {
|
|
99
|
+
direction = "E";
|
|
100
|
+
} else if (normalized >= 112.5 && normalized < 157.5) {
|
|
101
|
+
direction = "SE";
|
|
102
|
+
} else if (normalized >= 157.5 && normalized < 202.5) {
|
|
103
|
+
direction = "S";
|
|
104
|
+
} else if (normalized >= 202.5 && normalized < 247.5) {
|
|
105
|
+
direction = "SW";
|
|
106
|
+
} else if (normalized >= 247.5 && normalized < 292.5) {
|
|
107
|
+
direction = "W";
|
|
108
|
+
} else {
|
|
109
|
+
direction = "NW";
|
|
110
|
+
}
|
|
111
|
+
return `${Math.round(normalized)}\xB0 ${direction}`;
|
|
112
|
+
}
|
|
113
|
+
function formatPitch(pitch) {
|
|
114
|
+
return `${Math.round(pitch)}\xB0 tilt`;
|
|
115
|
+
}
|
|
116
|
+
function formatScale(scale) {
|
|
117
|
+
if (scale >= 1e6) {
|
|
118
|
+
return `1:${(scale / 1e6).toFixed(1)}M`;
|
|
119
|
+
}
|
|
120
|
+
if (scale >= 1e3) {
|
|
121
|
+
return `1:${Math.round(scale / 1e3)}K`;
|
|
122
|
+
}
|
|
123
|
+
return `1:${Math.round(scale)}`;
|
|
124
|
+
}
|
|
125
|
+
function zoomToScale(zoom, latitude = 0) {
|
|
126
|
+
const metersPerPixel = 40075e3 * Math.cos(latitude * Math.PI / 180) / (256 * Math.pow(2, zoom));
|
|
127
|
+
const screenMetersPerPixel = 264583e-9;
|
|
128
|
+
return Math.round(metersPerPixel / screenMetersPerPixel);
|
|
129
|
+
}
|
|
130
|
+
function formatPropertyValue(value) {
|
|
131
|
+
if (value === null || value === void 0) {
|
|
132
|
+
return "-";
|
|
133
|
+
}
|
|
134
|
+
if (typeof value === "number") {
|
|
135
|
+
if (Math.abs(value) <= 180 && value !== Math.floor(value)) {
|
|
136
|
+
return value.toFixed(6);
|
|
137
|
+
}
|
|
138
|
+
if (Math.abs(value) >= 1e3) {
|
|
139
|
+
return value.toLocaleString();
|
|
140
|
+
}
|
|
141
|
+
if (value !== Math.floor(value)) {
|
|
142
|
+
return value.toFixed(2);
|
|
143
|
+
}
|
|
144
|
+
return String(value);
|
|
145
|
+
}
|
|
146
|
+
if (typeof value === "boolean") {
|
|
147
|
+
return value ? "Yes" : "No";
|
|
148
|
+
}
|
|
149
|
+
if (Array.isArray(value)) {
|
|
150
|
+
return value.map(formatPropertyValue).join(", ");
|
|
151
|
+
}
|
|
152
|
+
if (typeof value === "object") {
|
|
153
|
+
return JSON.stringify(value);
|
|
154
|
+
}
|
|
155
|
+
return String(value);
|
|
156
|
+
}
|
|
157
|
+
function formatFeatureProperties(properties, options) {
|
|
158
|
+
const exclude = options?.exclude || ["id", "_id", "fid", "ogc_fid"];
|
|
159
|
+
const include = options?.include;
|
|
160
|
+
const labelMap = options?.labelMap || {};
|
|
161
|
+
const entries = Object.entries(properties).filter(([key]) => {
|
|
162
|
+
if (include) {
|
|
163
|
+
return include.includes(key);
|
|
164
|
+
}
|
|
165
|
+
return !exclude.includes(key) && !key.startsWith("_");
|
|
166
|
+
}).map(([key, value]) => {
|
|
167
|
+
const label = labelMap[key] || formatLabel(key);
|
|
168
|
+
return `<strong>${escapeHtml(label)}:</strong> ${escapeHtml(formatPropertyValue(value))}`;
|
|
169
|
+
});
|
|
170
|
+
return entries.join("<br>");
|
|
171
|
+
}
|
|
172
|
+
function escapeHtml(str) {
|
|
173
|
+
const htmlEntities = {
|
|
174
|
+
"&": "&",
|
|
175
|
+
"<": "<",
|
|
176
|
+
">": ">",
|
|
177
|
+
'"': """,
|
|
178
|
+
"'": "'"
|
|
179
|
+
};
|
|
180
|
+
return str.replace(/[&<>"']/g, (char) => htmlEntities[char] || char);
|
|
181
|
+
}
|
|
182
|
+
function formatLabel(key) {
|
|
183
|
+
return key.replace(/_/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2").replace(/\b\w/g, (char) => char.toUpperCase());
|
|
184
|
+
}
|
|
185
|
+
function isValidLongitude(lng) {
|
|
186
|
+
return typeof lng === "number" && isFinite(lng) && lng >= -180 && lng <= 180;
|
|
187
|
+
}
|
|
188
|
+
function isValidLatitude(lat) {
|
|
189
|
+
return typeof lat === "number" && isFinite(lat) && lat >= -90 && lat <= 90;
|
|
190
|
+
}
|
|
191
|
+
function validateCoordinates(coordinates) {
|
|
192
|
+
if (!Array.isArray(coordinates)) {
|
|
193
|
+
return { valid: false, error: "Coordinates must be an array" };
|
|
194
|
+
}
|
|
195
|
+
if (coordinates.length < 2) {
|
|
196
|
+
return { valid: false, error: "Coordinates must have at least 2 elements [lng, lat]" };
|
|
197
|
+
}
|
|
198
|
+
const [lng, lat] = coordinates;
|
|
199
|
+
if (typeof lng !== "number" || typeof lat !== "number") {
|
|
200
|
+
return { valid: false, error: "Longitude and latitude must be numbers" };
|
|
201
|
+
}
|
|
202
|
+
if (!isFinite(lng) || !isFinite(lat)) {
|
|
203
|
+
return { valid: false, error: "Coordinates must be finite numbers" };
|
|
204
|
+
}
|
|
205
|
+
if (lng < -180 || lng > 180) {
|
|
206
|
+
return { valid: false, error: `Longitude ${lng} out of range [-180, 180]` };
|
|
207
|
+
}
|
|
208
|
+
if (lat < -90 || lat > 90) {
|
|
209
|
+
return { valid: false, error: `Latitude ${lat} out of range [-90, 90]` };
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
valid: true,
|
|
213
|
+
normalized: [lng, lat]
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
function ensureValidCoordinates(coordinates) {
|
|
217
|
+
const result = validateCoordinates(coordinates);
|
|
218
|
+
if (!result.valid) {
|
|
219
|
+
throw new Error(`Invalid coordinates: ${result.error}`);
|
|
220
|
+
}
|
|
221
|
+
return result.normalized;
|
|
222
|
+
}
|
|
223
|
+
function normalizeLongitude(lng) {
|
|
224
|
+
if (!isFinite(lng)) return NaN;
|
|
225
|
+
let normalized = lng % 360;
|
|
226
|
+
if (normalized > 180) {
|
|
227
|
+
normalized -= 360;
|
|
228
|
+
} else if (normalized < -180) {
|
|
229
|
+
normalized += 360;
|
|
230
|
+
}
|
|
231
|
+
return normalized;
|
|
232
|
+
}
|
|
233
|
+
function clampLatitude(lat) {
|
|
234
|
+
if (!isFinite(lat)) return NaN;
|
|
235
|
+
return Math.max(-90, Math.min(90, lat));
|
|
236
|
+
}
|
|
237
|
+
function validateBoundsArray(bounds) {
|
|
238
|
+
if (!Array.isArray(bounds)) {
|
|
239
|
+
return { valid: false, error: "Bounds must be an array" };
|
|
240
|
+
}
|
|
241
|
+
if (bounds.length !== 2) {
|
|
242
|
+
return { valid: false, error: "Bounds must have exactly 2 elements [southwest, northeast]" };
|
|
243
|
+
}
|
|
244
|
+
const swResult = validateCoordinates(bounds[0]);
|
|
245
|
+
if (!swResult.valid) {
|
|
246
|
+
return { valid: false, error: `Invalid southwest corner: ${swResult.error}` };
|
|
247
|
+
}
|
|
248
|
+
const neResult = validateCoordinates(bounds[1]);
|
|
249
|
+
if (!neResult.valid) {
|
|
250
|
+
return { valid: false, error: `Invalid northeast corner: ${neResult.error}` };
|
|
251
|
+
}
|
|
252
|
+
const [, swLat] = swResult.normalized;
|
|
253
|
+
const [, neLat] = neResult.normalized;
|
|
254
|
+
if (swLat > neLat) {
|
|
255
|
+
return {
|
|
256
|
+
valid: false,
|
|
257
|
+
error: `Southwest latitude (${swLat}) must be less than northeast latitude (${neLat})`
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
return {
|
|
261
|
+
valid: true,
|
|
262
|
+
normalized: [swResult.normalized, neResult.normalized]
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
4
266
|
// src/utils/accessibility.ts
|
|
5
267
|
var KEYBOARD_CONTROLS = {
|
|
6
268
|
pan: {
|
|
@@ -154,19 +416,9 @@ function generateMoveAnnouncement(center, zoom, action) {
|
|
|
154
416
|
case "zoom":
|
|
155
417
|
return `Zoom level ${zoom.toFixed(1)}`;
|
|
156
418
|
case "move":
|
|
157
|
-
default:
|
|
158
|
-
return `Map moved to ${Math.abs(lat).toFixed(2)} ${latDir}, ${Math.abs(lng).toFixed(2)} ${lngDir} at zoom ${zoom.toFixed(1)}`;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
function escapeHtml(str) {
|
|
162
|
-
const htmlEntities = {
|
|
163
|
-
"&": "&",
|
|
164
|
-
"<": "<",
|
|
165
|
-
">": ">",
|
|
166
|
-
'"': """,
|
|
167
|
-
"'": "'"
|
|
168
|
-
};
|
|
169
|
-
return str.replace(/[&<>"']/g, (char) => htmlEntities[char] || char);
|
|
419
|
+
default:
|
|
420
|
+
return `Map moved to ${Math.abs(lat).toFixed(2)} ${latDir}, ${Math.abs(lng).toFixed(2)} ${lngDir} at zoom ${zoom.toFixed(1)}`;
|
|
421
|
+
}
|
|
170
422
|
}
|
|
171
423
|
|
|
172
424
|
// src/utils/styles.ts
|
|
@@ -409,259 +661,6 @@ function createInteractiveStatusColorExpression(statusColors, options) {
|
|
|
409
661
|
return ["case", ["boolean", ["feature-state", "hover"], false], hoverColor, baseExpr];
|
|
410
662
|
}
|
|
411
663
|
|
|
412
|
-
// src/utils/format.ts
|
|
413
|
-
function formatCoordinates(coordinates, precision = 6, format = "decimal") {
|
|
414
|
-
const [lng, lat] = coordinates;
|
|
415
|
-
switch (format) {
|
|
416
|
-
case "dms":
|
|
417
|
-
return `${decimalToDMS(lat, "lat")}, ${decimalToDMS(lng, "lng")}`;
|
|
418
|
-
case "dd":
|
|
419
|
-
return `${lat.toFixed(precision)}, ${lng.toFixed(precision)}`;
|
|
420
|
-
case "decimal":
|
|
421
|
-
default:
|
|
422
|
-
return `${lng.toFixed(precision)}, ${lat.toFixed(precision)}`;
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
function decimalToDMS(decimal, type) {
|
|
426
|
-
const absolute = Math.abs(decimal);
|
|
427
|
-
const degrees = Math.floor(absolute);
|
|
428
|
-
const minutesDecimal = (absolute - degrees) * 60;
|
|
429
|
-
const minutes = Math.floor(minutesDecimal);
|
|
430
|
-
const seconds = ((minutesDecimal - minutes) * 60).toFixed(1);
|
|
431
|
-
let direction;
|
|
432
|
-
if (type === "lat") {
|
|
433
|
-
direction = decimal >= 0 ? "N" : "S";
|
|
434
|
-
} else {
|
|
435
|
-
direction = decimal >= 0 ? "E" : "W";
|
|
436
|
-
}
|
|
437
|
-
return `${degrees}\xB0 ${minutes}' ${seconds}" ${direction}`;
|
|
438
|
-
}
|
|
439
|
-
function formatDistance(meters, unit = "metric") {
|
|
440
|
-
if (unit === "imperial") {
|
|
441
|
-
const feet = meters * 3.28084;
|
|
442
|
-
if (feet < 1e3) {
|
|
443
|
-
return `${Math.round(feet)} ft`;
|
|
444
|
-
}
|
|
445
|
-
const miles = feet / 5280;
|
|
446
|
-
if (miles < 10) {
|
|
447
|
-
return `${miles.toFixed(1)} mi`;
|
|
448
|
-
}
|
|
449
|
-
return `${Math.round(miles)} mi`;
|
|
450
|
-
}
|
|
451
|
-
if (meters < 1e3) {
|
|
452
|
-
return `${Math.round(meters)} m`;
|
|
453
|
-
}
|
|
454
|
-
const km = meters / 1e3;
|
|
455
|
-
if (km < 10) {
|
|
456
|
-
return `${km.toFixed(1)} km`;
|
|
457
|
-
}
|
|
458
|
-
return `${Math.round(km)} km`;
|
|
459
|
-
}
|
|
460
|
-
function formatArea(sqMeters, unit = "metric") {
|
|
461
|
-
if (unit === "imperial") {
|
|
462
|
-
const sqFeet = sqMeters * 10.7639;
|
|
463
|
-
if (sqFeet < 43560) {
|
|
464
|
-
return `${Math.round(sqFeet).toLocaleString()} sq ft`;
|
|
465
|
-
}
|
|
466
|
-
const acres = sqFeet / 43560;
|
|
467
|
-
if (acres < 640) {
|
|
468
|
-
return `${acres.toFixed(2)} acres`;
|
|
469
|
-
}
|
|
470
|
-
const sqMiles = acres / 640;
|
|
471
|
-
return `${sqMiles.toFixed(2)} sq mi`;
|
|
472
|
-
}
|
|
473
|
-
if (sqMeters < 1e4) {
|
|
474
|
-
return `${Math.round(sqMeters).toLocaleString()} m\xB2`;
|
|
475
|
-
}
|
|
476
|
-
const hectares = sqMeters / 1e4;
|
|
477
|
-
if (hectares < 100) {
|
|
478
|
-
return `${hectares.toFixed(2)} ha`;
|
|
479
|
-
}
|
|
480
|
-
const sqKm = sqMeters / 1e6;
|
|
481
|
-
return `${sqKm.toFixed(2)} km\xB2`;
|
|
482
|
-
}
|
|
483
|
-
function formatBounds(bounds) {
|
|
484
|
-
let sw;
|
|
485
|
-
let ne;
|
|
486
|
-
if (Array.isArray(bounds) && Array.isArray(bounds[0])) {
|
|
487
|
-
const arr = bounds;
|
|
488
|
-
sw = arr[0];
|
|
489
|
-
ne = arr[1];
|
|
490
|
-
} else {
|
|
491
|
-
const b = bounds;
|
|
492
|
-
sw = b.southwest;
|
|
493
|
-
ne = b.northeast;
|
|
494
|
-
}
|
|
495
|
-
return `SW: ${formatCoordinates(sw, 4)}, NE: ${formatCoordinates(ne, 4)}`;
|
|
496
|
-
}
|
|
497
|
-
function formatZoom(zoom) {
|
|
498
|
-
return `Zoom: ${zoom.toFixed(1)}`;
|
|
499
|
-
}
|
|
500
|
-
function formatBearing(bearing) {
|
|
501
|
-
const normalized = (bearing % 360 + 360) % 360;
|
|
502
|
-
let direction;
|
|
503
|
-
if (normalized >= 337.5 || normalized < 22.5) {
|
|
504
|
-
direction = "N";
|
|
505
|
-
} else if (normalized >= 22.5 && normalized < 67.5) {
|
|
506
|
-
direction = "NE";
|
|
507
|
-
} else if (normalized >= 67.5 && normalized < 112.5) {
|
|
508
|
-
direction = "E";
|
|
509
|
-
} else if (normalized >= 112.5 && normalized < 157.5) {
|
|
510
|
-
direction = "SE";
|
|
511
|
-
} else if (normalized >= 157.5 && normalized < 202.5) {
|
|
512
|
-
direction = "S";
|
|
513
|
-
} else if (normalized >= 202.5 && normalized < 247.5) {
|
|
514
|
-
direction = "SW";
|
|
515
|
-
} else if (normalized >= 247.5 && normalized < 292.5) {
|
|
516
|
-
direction = "W";
|
|
517
|
-
} else {
|
|
518
|
-
direction = "NW";
|
|
519
|
-
}
|
|
520
|
-
return `${Math.round(normalized)}\xB0 ${direction}`;
|
|
521
|
-
}
|
|
522
|
-
function formatPitch(pitch) {
|
|
523
|
-
return `${Math.round(pitch)}\xB0 tilt`;
|
|
524
|
-
}
|
|
525
|
-
function formatScale(scale) {
|
|
526
|
-
if (scale >= 1e6) {
|
|
527
|
-
return `1:${(scale / 1e6).toFixed(1)}M`;
|
|
528
|
-
}
|
|
529
|
-
if (scale >= 1e3) {
|
|
530
|
-
return `1:${Math.round(scale / 1e3)}K`;
|
|
531
|
-
}
|
|
532
|
-
return `1:${Math.round(scale)}`;
|
|
533
|
-
}
|
|
534
|
-
function zoomToScale(zoom, latitude = 0) {
|
|
535
|
-
const metersPerPixel = 40075e3 * Math.cos(latitude * Math.PI / 180) / (256 * Math.pow(2, zoom));
|
|
536
|
-
const screenMetersPerPixel = 264583e-9;
|
|
537
|
-
return Math.round(metersPerPixel / screenMetersPerPixel);
|
|
538
|
-
}
|
|
539
|
-
function formatPropertyValue(value) {
|
|
540
|
-
if (value === null || value === void 0) {
|
|
541
|
-
return "-";
|
|
542
|
-
}
|
|
543
|
-
if (typeof value === "number") {
|
|
544
|
-
if (Math.abs(value) <= 180 && value !== Math.floor(value)) {
|
|
545
|
-
return value.toFixed(6);
|
|
546
|
-
}
|
|
547
|
-
if (Math.abs(value) >= 1e3) {
|
|
548
|
-
return value.toLocaleString();
|
|
549
|
-
}
|
|
550
|
-
if (value !== Math.floor(value)) {
|
|
551
|
-
return value.toFixed(2);
|
|
552
|
-
}
|
|
553
|
-
return String(value);
|
|
554
|
-
}
|
|
555
|
-
if (typeof value === "boolean") {
|
|
556
|
-
return value ? "Yes" : "No";
|
|
557
|
-
}
|
|
558
|
-
if (Array.isArray(value)) {
|
|
559
|
-
return value.map(formatPropertyValue).join(", ");
|
|
560
|
-
}
|
|
561
|
-
if (typeof value === "object") {
|
|
562
|
-
return JSON.stringify(value);
|
|
563
|
-
}
|
|
564
|
-
return String(value);
|
|
565
|
-
}
|
|
566
|
-
function formatFeatureProperties(properties, options) {
|
|
567
|
-
const exclude = options?.exclude || ["id", "_id", "fid", "ogc_fid"];
|
|
568
|
-
const include = options?.include;
|
|
569
|
-
const labelMap = options?.labelMap || {};
|
|
570
|
-
const entries = Object.entries(properties).filter(([key]) => {
|
|
571
|
-
if (include) {
|
|
572
|
-
return include.includes(key);
|
|
573
|
-
}
|
|
574
|
-
return !exclude.includes(key) && !key.startsWith("_");
|
|
575
|
-
}).map(([key, value]) => {
|
|
576
|
-
const label = labelMap[key] || formatLabel(key);
|
|
577
|
-
return `<strong>${label}:</strong> ${formatPropertyValue(value)}`;
|
|
578
|
-
});
|
|
579
|
-
return entries.join("<br>");
|
|
580
|
-
}
|
|
581
|
-
function formatLabel(key) {
|
|
582
|
-
return key.replace(/_/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2").replace(/\b\w/g, (char) => char.toUpperCase());
|
|
583
|
-
}
|
|
584
|
-
function isValidLongitude(lng) {
|
|
585
|
-
return typeof lng === "number" && isFinite(lng) && lng >= -180 && lng <= 180;
|
|
586
|
-
}
|
|
587
|
-
function isValidLatitude(lat) {
|
|
588
|
-
return typeof lat === "number" && isFinite(lat) && lat >= -90 && lat <= 90;
|
|
589
|
-
}
|
|
590
|
-
function validateCoordinates(coordinates) {
|
|
591
|
-
if (!Array.isArray(coordinates)) {
|
|
592
|
-
return { valid: false, error: "Coordinates must be an array" };
|
|
593
|
-
}
|
|
594
|
-
if (coordinates.length < 2) {
|
|
595
|
-
return { valid: false, error: "Coordinates must have at least 2 elements [lng, lat]" };
|
|
596
|
-
}
|
|
597
|
-
const [lng, lat] = coordinates;
|
|
598
|
-
if (typeof lng !== "number" || typeof lat !== "number") {
|
|
599
|
-
return { valid: false, error: "Longitude and latitude must be numbers" };
|
|
600
|
-
}
|
|
601
|
-
if (!isFinite(lng) || !isFinite(lat)) {
|
|
602
|
-
return { valid: false, error: "Coordinates must be finite numbers" };
|
|
603
|
-
}
|
|
604
|
-
if (lng < -180 || lng > 180) {
|
|
605
|
-
return { valid: false, error: `Longitude ${lng} out of range [-180, 180]` };
|
|
606
|
-
}
|
|
607
|
-
if (lat < -90 || lat > 90) {
|
|
608
|
-
return { valid: false, error: `Latitude ${lat} out of range [-90, 90]` };
|
|
609
|
-
}
|
|
610
|
-
return {
|
|
611
|
-
valid: true,
|
|
612
|
-
normalized: [lng, lat]
|
|
613
|
-
};
|
|
614
|
-
}
|
|
615
|
-
function ensureValidCoordinates(coordinates) {
|
|
616
|
-
const result = validateCoordinates(coordinates);
|
|
617
|
-
if (!result.valid) {
|
|
618
|
-
throw new Error(`Invalid coordinates: ${result.error}`);
|
|
619
|
-
}
|
|
620
|
-
return result.normalized;
|
|
621
|
-
}
|
|
622
|
-
function normalizeLongitude(lng) {
|
|
623
|
-
if (!isFinite(lng)) return NaN;
|
|
624
|
-
let normalized = lng % 360;
|
|
625
|
-
if (normalized > 180) {
|
|
626
|
-
normalized -= 360;
|
|
627
|
-
} else if (normalized < -180) {
|
|
628
|
-
normalized += 360;
|
|
629
|
-
}
|
|
630
|
-
return normalized;
|
|
631
|
-
}
|
|
632
|
-
function clampLatitude(lat) {
|
|
633
|
-
if (!isFinite(lat)) return NaN;
|
|
634
|
-
return Math.max(-90, Math.min(90, lat));
|
|
635
|
-
}
|
|
636
|
-
function validateBoundsArray(bounds) {
|
|
637
|
-
if (!Array.isArray(bounds)) {
|
|
638
|
-
return { valid: false, error: "Bounds must be an array" };
|
|
639
|
-
}
|
|
640
|
-
if (bounds.length !== 2) {
|
|
641
|
-
return { valid: false, error: "Bounds must have exactly 2 elements [southwest, northeast]" };
|
|
642
|
-
}
|
|
643
|
-
const swResult = validateCoordinates(bounds[0]);
|
|
644
|
-
if (!swResult.valid) {
|
|
645
|
-
return { valid: false, error: `Invalid southwest corner: ${swResult.error}` };
|
|
646
|
-
}
|
|
647
|
-
const neResult = validateCoordinates(bounds[1]);
|
|
648
|
-
if (!neResult.valid) {
|
|
649
|
-
return { valid: false, error: `Invalid northeast corner: ${neResult.error}` };
|
|
650
|
-
}
|
|
651
|
-
const [, swLat] = swResult.normalized;
|
|
652
|
-
const [, neLat] = neResult.normalized;
|
|
653
|
-
if (swLat > neLat) {
|
|
654
|
-
return {
|
|
655
|
-
valid: false,
|
|
656
|
-
error: `Southwest latitude (${swLat}) must be less than northeast latitude (${neLat})`
|
|
657
|
-
};
|
|
658
|
-
}
|
|
659
|
-
return {
|
|
660
|
-
valid: true,
|
|
661
|
-
normalized: [swResult.normalized, neResult.normalized]
|
|
662
|
-
};
|
|
663
|
-
}
|
|
664
|
-
|
|
665
664
|
// src/utils/bounds.ts
|
|
666
665
|
function calculateBounds(geojson) {
|
|
667
666
|
let minLng = Infinity;
|
|
@@ -762,13 +761,19 @@ async function loadGeoJSON(url, options = {}) {
|
|
|
762
761
|
try {
|
|
763
762
|
const controller = new AbortController();
|
|
764
763
|
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
764
|
+
const callerSignal = fetchOptions.signal;
|
|
765
|
+
if (callerSignal) {
|
|
766
|
+
if (callerSignal.aborted) controller.abort();
|
|
767
|
+
else callerSignal.addEventListener("abort", () => controller.abort(), { once: true });
|
|
768
|
+
}
|
|
769
|
+
const headers = new Headers(fetchOptions.headers);
|
|
770
|
+
if (!headers.has("Accept")) {
|
|
771
|
+
headers.set("Accept", "application/geo+json, application/json");
|
|
772
|
+
}
|
|
765
773
|
const response = await fetch(url, {
|
|
766
774
|
...fetchOptions,
|
|
767
775
|
signal: controller.signal,
|
|
768
|
-
headers
|
|
769
|
-
Accept: "application/geo+json, application/json",
|
|
770
|
-
...fetchOptions.headers
|
|
771
|
-
}
|
|
776
|
+
headers
|
|
772
777
|
});
|
|
773
778
|
clearTimeout(timeoutId);
|
|
774
779
|
if (!response.ok) {
|
|
@@ -797,6 +802,9 @@ async function loadGeoJSON(url, options = {}) {
|
|
|
797
802
|
} catch (err) {
|
|
798
803
|
if (err instanceof Error) {
|
|
799
804
|
if (err.name === "AbortError") {
|
|
805
|
+
if (options.fetchOptions?.signal?.aborted) {
|
|
806
|
+
return { data: null, error: "Request aborted", success: false };
|
|
807
|
+
}
|
|
800
808
|
return {
|
|
801
809
|
data: null,
|
|
802
810
|
error: `Request timeout after ${timeout}ms`,
|
|
@@ -1591,11 +1599,11 @@ function getSimplifiedFeaturesForZoom(lodData, zoom) {
|
|
|
1591
1599
|
return lodData.features;
|
|
1592
1600
|
}
|
|
1593
1601
|
let bestMatch = null;
|
|
1602
|
+
let bestMaxZoom = Infinity;
|
|
1594
1603
|
for (const [maxZoom, features] of lodData.simplifiedFeatures) {
|
|
1595
|
-
if (zoom < maxZoom) {
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
}
|
|
1604
|
+
if (zoom < maxZoom && maxZoom < bestMaxZoom) {
|
|
1605
|
+
bestMatch = features;
|
|
1606
|
+
bestMaxZoom = maxZoom;
|
|
1599
1607
|
}
|
|
1600
1608
|
}
|
|
1601
1609
|
return bestMatch ?? lodData.features;
|
|
@@ -1612,7 +1620,7 @@ function calculateZoomThresholds(groups, options = {}) {
|
|
|
1612
1620
|
const groupMaxZoom = Math.max(10, Math.min(14, 10 + Math.log2(groupCount)));
|
|
1613
1621
|
const subGroupMaxZoom = Math.max(
|
|
1614
1622
|
groupMaxZoom + minZoomGap,
|
|
1615
|
-
Math.min(16, groupMaxZoom + Math.log2(Math.max(1, subGroupCount / groupCount)))
|
|
1623
|
+
Math.min(16, groupMaxZoom + Math.log2(Math.max(1, subGroupCount / Math.max(1, groupCount))))
|
|
1616
1624
|
);
|
|
1617
1625
|
return {
|
|
1618
1626
|
groupMaxZoom: Math.round(groupMaxZoom),
|
|
@@ -1713,8 +1721,8 @@ function buildSpatialIndex(geojson, options = {}) {
|
|
|
1713
1721
|
};
|
|
1714
1722
|
}
|
|
1715
1723
|
const [[minLng, minLat], [maxLng, maxLat]] = bounds;
|
|
1716
|
-
const width = maxLng - minLng;
|
|
1717
|
-
const height = maxLat - minLat;
|
|
1724
|
+
const width = Math.max(maxLng - minLng, minCellSize);
|
|
1725
|
+
const height = Math.max(maxLat - minLat, minCellSize);
|
|
1718
1726
|
const aspectRatio = width / height;
|
|
1719
1727
|
let cols = Math.ceil(Math.sqrt(targetCells * aspectRatio));
|
|
1720
1728
|
let rows = Math.ceil(targetCells / cols);
|
|
@@ -1727,10 +1735,10 @@ function buildSpatialIndex(geojson, options = {}) {
|
|
|
1727
1735
|
const featureBounds = getFeatureBounds(feature);
|
|
1728
1736
|
if (!featureBounds) continue;
|
|
1729
1737
|
const [[fMinLng, fMinLat], [fMaxLng, fMaxLat]] = featureBounds;
|
|
1730
|
-
const minCol =
|
|
1731
|
-
const maxCol =
|
|
1732
|
-
const minRow =
|
|
1733
|
-
const maxRow =
|
|
1738
|
+
const minCol = cellIndex(fMinLng, minLng, cellWidth, cols);
|
|
1739
|
+
const maxCol = cellIndex(fMaxLng, minLng, cellWidth, cols);
|
|
1740
|
+
const minRow = cellIndex(fMinLat, minLat, cellHeight, rows);
|
|
1741
|
+
const maxRow = cellIndex(fMaxLat, minLat, cellHeight, rows);
|
|
1734
1742
|
for (let col = minCol; col <= maxCol; col++) {
|
|
1735
1743
|
for (let row = minRow; row <= maxRow; row++) {
|
|
1736
1744
|
const key = `${col},${row}`;
|
|
@@ -1751,6 +1759,9 @@ function buildSpatialIndex(geojson, options = {}) {
|
|
|
1751
1759
|
featureCount: geojson.features.length
|
|
1752
1760
|
};
|
|
1753
1761
|
}
|
|
1762
|
+
function cellIndex(value, origin, size, count) {
|
|
1763
|
+
return Math.min(count - 1, Math.max(0, Math.floor((value - origin) / size)));
|
|
1764
|
+
}
|
|
1754
1765
|
function getFeatureBounds(feature) {
|
|
1755
1766
|
const geometry = feature.geometry;
|
|
1756
1767
|
if (!geometry) return null;
|
|
@@ -1805,10 +1816,10 @@ function queryByBounds(index, queryBounds, options = {}) {
|
|
|
1805
1816
|
maxLng += actualBuffer;
|
|
1806
1817
|
maxLat += actualBuffer;
|
|
1807
1818
|
const [[idxMinLng, idxMinLat]] = index.bounds;
|
|
1808
|
-
const minCol =
|
|
1809
|
-
const maxCol =
|
|
1810
|
-
const minRow =
|
|
1811
|
-
const maxRow =
|
|
1819
|
+
const minCol = cellIndex(minLng, idxMinLng, index.cellWidth, index.cols);
|
|
1820
|
+
const maxCol = cellIndex(maxLng, idxMinLng, index.cellWidth, index.cols);
|
|
1821
|
+
const minRow = cellIndex(minLat, idxMinLat, index.cellHeight, index.rows);
|
|
1822
|
+
const maxRow = cellIndex(maxLat, idxMinLat, index.cellHeight, index.rows);
|
|
1812
1823
|
const seen = /* @__PURE__ */ new Set();
|
|
1813
1824
|
const features = [];
|
|
1814
1825
|
for (let col = minCol; col <= maxCol; col++) {
|
|
@@ -1868,10 +1879,10 @@ function queryByBoundsWithStats(index, queryBounds, options = {}) {
|
|
|
1868
1879
|
maxLng += actualBuffer;
|
|
1869
1880
|
maxLat += actualBuffer;
|
|
1870
1881
|
const [[idxMinLng, idxMinLat]] = index.bounds;
|
|
1871
|
-
const minCol =
|
|
1872
|
-
const maxCol =
|
|
1873
|
-
const minRow =
|
|
1874
|
-
const maxRow =
|
|
1882
|
+
const minCol = cellIndex(minLng, idxMinLng, index.cellWidth, index.cols);
|
|
1883
|
+
const maxCol = cellIndex(maxLng, idxMinLng, index.cellWidth, index.cols);
|
|
1884
|
+
const minRow = cellIndex(minLat, idxMinLat, index.cellHeight, index.rows);
|
|
1885
|
+
const maxRow = cellIndex(maxLat, idxMinLat, index.cellHeight, index.rows);
|
|
1875
1886
|
const seen = /* @__PURE__ */ new Set();
|
|
1876
1887
|
const features = [];
|
|
1877
1888
|
let cellsChecked = 0;
|