@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
package/dist/utils/index.cjs
CHANGED
|
@@ -7,6 +7,268 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
7
7
|
|
|
8
8
|
var RBush__default = /*#__PURE__*/_interopDefault(RBush);
|
|
9
9
|
|
|
10
|
+
// src/utils/format.ts
|
|
11
|
+
function formatCoordinates(coordinates, precision = 6, format = "decimal") {
|
|
12
|
+
const [lng, lat] = coordinates;
|
|
13
|
+
switch (format) {
|
|
14
|
+
case "dms":
|
|
15
|
+
return `${decimalToDMS(lat, "lat")}, ${decimalToDMS(lng, "lng")}`;
|
|
16
|
+
case "dd":
|
|
17
|
+
return `${lat.toFixed(precision)}, ${lng.toFixed(precision)}`;
|
|
18
|
+
case "decimal":
|
|
19
|
+
default:
|
|
20
|
+
return `${lng.toFixed(precision)}, ${lat.toFixed(precision)}`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function decimalToDMS(decimal, type) {
|
|
24
|
+
const tenths = Math.round(Math.abs(decimal) * 36e3);
|
|
25
|
+
const degrees = Math.floor(tenths / 36e3);
|
|
26
|
+
const minutes = Math.floor(tenths % 36e3 / 600);
|
|
27
|
+
const seconds = (tenths % 600 / 10).toFixed(1);
|
|
28
|
+
let direction;
|
|
29
|
+
if (type === "lat") {
|
|
30
|
+
direction = decimal >= 0 ? "N" : "S";
|
|
31
|
+
} else {
|
|
32
|
+
direction = decimal >= 0 ? "E" : "W";
|
|
33
|
+
}
|
|
34
|
+
return `${degrees}\xB0 ${minutes}' ${seconds}" ${direction}`;
|
|
35
|
+
}
|
|
36
|
+
function formatDistance(meters, unit = "metric") {
|
|
37
|
+
if (unit === "imperial") {
|
|
38
|
+
const feet = meters * 3.28084;
|
|
39
|
+
if (feet < 1e3) {
|
|
40
|
+
return `${Math.round(feet)} ft`;
|
|
41
|
+
}
|
|
42
|
+
const miles = feet / 5280;
|
|
43
|
+
if (miles < 10) {
|
|
44
|
+
return `${miles.toFixed(1)} mi`;
|
|
45
|
+
}
|
|
46
|
+
return `${Math.round(miles)} mi`;
|
|
47
|
+
}
|
|
48
|
+
if (meters < 1e3) {
|
|
49
|
+
return `${Math.round(meters)} m`;
|
|
50
|
+
}
|
|
51
|
+
const km = meters / 1e3;
|
|
52
|
+
if (km < 10) {
|
|
53
|
+
return `${km.toFixed(1)} km`;
|
|
54
|
+
}
|
|
55
|
+
return `${Math.round(km)} km`;
|
|
56
|
+
}
|
|
57
|
+
function formatArea(sqMeters, unit = "metric") {
|
|
58
|
+
if (unit === "imperial") {
|
|
59
|
+
const sqFeet = sqMeters * 10.7639;
|
|
60
|
+
if (sqFeet < 43560) {
|
|
61
|
+
return `${Math.round(sqFeet).toLocaleString()} sq ft`;
|
|
62
|
+
}
|
|
63
|
+
const acres = sqFeet / 43560;
|
|
64
|
+
if (acres < 640) {
|
|
65
|
+
return `${acres.toFixed(2)} acres`;
|
|
66
|
+
}
|
|
67
|
+
const sqMiles = acres / 640;
|
|
68
|
+
return `${sqMiles.toFixed(2)} sq mi`;
|
|
69
|
+
}
|
|
70
|
+
if (sqMeters < 1e4) {
|
|
71
|
+
return `${Math.round(sqMeters).toLocaleString()} m\xB2`;
|
|
72
|
+
}
|
|
73
|
+
const hectares = sqMeters / 1e4;
|
|
74
|
+
if (hectares < 100) {
|
|
75
|
+
return `${hectares.toFixed(2)} ha`;
|
|
76
|
+
}
|
|
77
|
+
const sqKm = sqMeters / 1e6;
|
|
78
|
+
return `${sqKm.toFixed(2)} km\xB2`;
|
|
79
|
+
}
|
|
80
|
+
function formatBounds(bounds) {
|
|
81
|
+
let sw;
|
|
82
|
+
let ne;
|
|
83
|
+
if (Array.isArray(bounds) && Array.isArray(bounds[0])) {
|
|
84
|
+
const arr = bounds;
|
|
85
|
+
sw = arr[0];
|
|
86
|
+
ne = arr[1];
|
|
87
|
+
} else {
|
|
88
|
+
const b = bounds;
|
|
89
|
+
sw = b.southwest;
|
|
90
|
+
ne = b.northeast;
|
|
91
|
+
}
|
|
92
|
+
return `SW: ${formatCoordinates(sw, 4)}, NE: ${formatCoordinates(ne, 4)}`;
|
|
93
|
+
}
|
|
94
|
+
function formatZoom(zoom) {
|
|
95
|
+
return `Zoom: ${zoom.toFixed(1)}`;
|
|
96
|
+
}
|
|
97
|
+
function formatBearing(bearing) {
|
|
98
|
+
const normalized = (bearing % 360 + 360) % 360;
|
|
99
|
+
let direction;
|
|
100
|
+
if (normalized >= 337.5 || normalized < 22.5) {
|
|
101
|
+
direction = "N";
|
|
102
|
+
} else if (normalized >= 22.5 && normalized < 67.5) {
|
|
103
|
+
direction = "NE";
|
|
104
|
+
} else if (normalized >= 67.5 && normalized < 112.5) {
|
|
105
|
+
direction = "E";
|
|
106
|
+
} else if (normalized >= 112.5 && normalized < 157.5) {
|
|
107
|
+
direction = "SE";
|
|
108
|
+
} else if (normalized >= 157.5 && normalized < 202.5) {
|
|
109
|
+
direction = "S";
|
|
110
|
+
} else if (normalized >= 202.5 && normalized < 247.5) {
|
|
111
|
+
direction = "SW";
|
|
112
|
+
} else if (normalized >= 247.5 && normalized < 292.5) {
|
|
113
|
+
direction = "W";
|
|
114
|
+
} else {
|
|
115
|
+
direction = "NW";
|
|
116
|
+
}
|
|
117
|
+
return `${Math.round(normalized)}\xB0 ${direction}`;
|
|
118
|
+
}
|
|
119
|
+
function formatPitch(pitch) {
|
|
120
|
+
return `${Math.round(pitch)}\xB0 tilt`;
|
|
121
|
+
}
|
|
122
|
+
function formatScale(scale) {
|
|
123
|
+
if (scale >= 1e6) {
|
|
124
|
+
return `1:${(scale / 1e6).toFixed(1)}M`;
|
|
125
|
+
}
|
|
126
|
+
if (scale >= 1e3) {
|
|
127
|
+
return `1:${Math.round(scale / 1e3)}K`;
|
|
128
|
+
}
|
|
129
|
+
return `1:${Math.round(scale)}`;
|
|
130
|
+
}
|
|
131
|
+
function zoomToScale(zoom, latitude = 0) {
|
|
132
|
+
const metersPerPixel = 40075e3 * Math.cos(latitude * Math.PI / 180) / (256 * Math.pow(2, zoom));
|
|
133
|
+
const screenMetersPerPixel = 264583e-9;
|
|
134
|
+
return Math.round(metersPerPixel / screenMetersPerPixel);
|
|
135
|
+
}
|
|
136
|
+
function formatPropertyValue(value) {
|
|
137
|
+
if (value === null || value === void 0) {
|
|
138
|
+
return "-";
|
|
139
|
+
}
|
|
140
|
+
if (typeof value === "number") {
|
|
141
|
+
if (Math.abs(value) <= 180 && value !== Math.floor(value)) {
|
|
142
|
+
return value.toFixed(6);
|
|
143
|
+
}
|
|
144
|
+
if (Math.abs(value) >= 1e3) {
|
|
145
|
+
return value.toLocaleString();
|
|
146
|
+
}
|
|
147
|
+
if (value !== Math.floor(value)) {
|
|
148
|
+
return value.toFixed(2);
|
|
149
|
+
}
|
|
150
|
+
return String(value);
|
|
151
|
+
}
|
|
152
|
+
if (typeof value === "boolean") {
|
|
153
|
+
return value ? "Yes" : "No";
|
|
154
|
+
}
|
|
155
|
+
if (Array.isArray(value)) {
|
|
156
|
+
return value.map(formatPropertyValue).join(", ");
|
|
157
|
+
}
|
|
158
|
+
if (typeof value === "object") {
|
|
159
|
+
return JSON.stringify(value);
|
|
160
|
+
}
|
|
161
|
+
return String(value);
|
|
162
|
+
}
|
|
163
|
+
function formatFeatureProperties(properties, options) {
|
|
164
|
+
const exclude = options?.exclude || ["id", "_id", "fid", "ogc_fid"];
|
|
165
|
+
const include = options?.include;
|
|
166
|
+
const labelMap = options?.labelMap || {};
|
|
167
|
+
const entries = Object.entries(properties).filter(([key]) => {
|
|
168
|
+
if (include) {
|
|
169
|
+
return include.includes(key);
|
|
170
|
+
}
|
|
171
|
+
return !exclude.includes(key) && !key.startsWith("_");
|
|
172
|
+
}).map(([key, value]) => {
|
|
173
|
+
const label = labelMap[key] || formatLabel(key);
|
|
174
|
+
return `<strong>${escapeHtml(label)}:</strong> ${escapeHtml(formatPropertyValue(value))}`;
|
|
175
|
+
});
|
|
176
|
+
return entries.join("<br>");
|
|
177
|
+
}
|
|
178
|
+
function escapeHtml(str) {
|
|
179
|
+
const htmlEntities = {
|
|
180
|
+
"&": "&",
|
|
181
|
+
"<": "<",
|
|
182
|
+
">": ">",
|
|
183
|
+
'"': """,
|
|
184
|
+
"'": "'"
|
|
185
|
+
};
|
|
186
|
+
return str.replace(/[&<>"']/g, (char) => htmlEntities[char] || char);
|
|
187
|
+
}
|
|
188
|
+
function formatLabel(key) {
|
|
189
|
+
return key.replace(/_/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2").replace(/\b\w/g, (char) => char.toUpperCase());
|
|
190
|
+
}
|
|
191
|
+
function isValidLongitude(lng) {
|
|
192
|
+
return typeof lng === "number" && isFinite(lng) && lng >= -180 && lng <= 180;
|
|
193
|
+
}
|
|
194
|
+
function isValidLatitude(lat) {
|
|
195
|
+
return typeof lat === "number" && isFinite(lat) && lat >= -90 && lat <= 90;
|
|
196
|
+
}
|
|
197
|
+
function validateCoordinates(coordinates) {
|
|
198
|
+
if (!Array.isArray(coordinates)) {
|
|
199
|
+
return { valid: false, error: "Coordinates must be an array" };
|
|
200
|
+
}
|
|
201
|
+
if (coordinates.length < 2) {
|
|
202
|
+
return { valid: false, error: "Coordinates must have at least 2 elements [lng, lat]" };
|
|
203
|
+
}
|
|
204
|
+
const [lng, lat] = coordinates;
|
|
205
|
+
if (typeof lng !== "number" || typeof lat !== "number") {
|
|
206
|
+
return { valid: false, error: "Longitude and latitude must be numbers" };
|
|
207
|
+
}
|
|
208
|
+
if (!isFinite(lng) || !isFinite(lat)) {
|
|
209
|
+
return { valid: false, error: "Coordinates must be finite numbers" };
|
|
210
|
+
}
|
|
211
|
+
if (lng < -180 || lng > 180) {
|
|
212
|
+
return { valid: false, error: `Longitude ${lng} out of range [-180, 180]` };
|
|
213
|
+
}
|
|
214
|
+
if (lat < -90 || lat > 90) {
|
|
215
|
+
return { valid: false, error: `Latitude ${lat} out of range [-90, 90]` };
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
valid: true,
|
|
219
|
+
normalized: [lng, lat]
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
function ensureValidCoordinates(coordinates) {
|
|
223
|
+
const result = validateCoordinates(coordinates);
|
|
224
|
+
if (!result.valid) {
|
|
225
|
+
throw new Error(`Invalid coordinates: ${result.error}`);
|
|
226
|
+
}
|
|
227
|
+
return result.normalized;
|
|
228
|
+
}
|
|
229
|
+
function normalizeLongitude(lng) {
|
|
230
|
+
if (!isFinite(lng)) return NaN;
|
|
231
|
+
let normalized = lng % 360;
|
|
232
|
+
if (normalized > 180) {
|
|
233
|
+
normalized -= 360;
|
|
234
|
+
} else if (normalized < -180) {
|
|
235
|
+
normalized += 360;
|
|
236
|
+
}
|
|
237
|
+
return normalized;
|
|
238
|
+
}
|
|
239
|
+
function clampLatitude(lat) {
|
|
240
|
+
if (!isFinite(lat)) return NaN;
|
|
241
|
+
return Math.max(-90, Math.min(90, lat));
|
|
242
|
+
}
|
|
243
|
+
function validateBoundsArray(bounds) {
|
|
244
|
+
if (!Array.isArray(bounds)) {
|
|
245
|
+
return { valid: false, error: "Bounds must be an array" };
|
|
246
|
+
}
|
|
247
|
+
if (bounds.length !== 2) {
|
|
248
|
+
return { valid: false, error: "Bounds must have exactly 2 elements [southwest, northeast]" };
|
|
249
|
+
}
|
|
250
|
+
const swResult = validateCoordinates(bounds[0]);
|
|
251
|
+
if (!swResult.valid) {
|
|
252
|
+
return { valid: false, error: `Invalid southwest corner: ${swResult.error}` };
|
|
253
|
+
}
|
|
254
|
+
const neResult = validateCoordinates(bounds[1]);
|
|
255
|
+
if (!neResult.valid) {
|
|
256
|
+
return { valid: false, error: `Invalid northeast corner: ${neResult.error}` };
|
|
257
|
+
}
|
|
258
|
+
const [, swLat] = swResult.normalized;
|
|
259
|
+
const [, neLat] = neResult.normalized;
|
|
260
|
+
if (swLat > neLat) {
|
|
261
|
+
return {
|
|
262
|
+
valid: false,
|
|
263
|
+
error: `Southwest latitude (${swLat}) must be less than northeast latitude (${neLat})`
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
valid: true,
|
|
268
|
+
normalized: [swResult.normalized, neResult.normalized]
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
|
|
10
272
|
// src/utils/accessibility.ts
|
|
11
273
|
var KEYBOARD_CONTROLS = {
|
|
12
274
|
pan: {
|
|
@@ -160,19 +422,9 @@ function generateMoveAnnouncement(center, zoom, action) {
|
|
|
160
422
|
case "zoom":
|
|
161
423
|
return `Zoom level ${zoom.toFixed(1)}`;
|
|
162
424
|
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);
|
|
425
|
+
default:
|
|
426
|
+
return `Map moved to ${Math.abs(lat).toFixed(2)} ${latDir}, ${Math.abs(lng).toFixed(2)} ${lngDir} at zoom ${zoom.toFixed(1)}`;
|
|
427
|
+
}
|
|
176
428
|
}
|
|
177
429
|
var THEME_LIGHT = "classic-light";
|
|
178
430
|
var THEME_DARK = "classic-dark";
|
|
@@ -560,259 +812,6 @@ function createInteractiveStatusColorExpression(statusColors, options) {
|
|
|
560
812
|
return ["case", ["boolean", ["feature-state", "hover"], false], hoverColor, baseExpr];
|
|
561
813
|
}
|
|
562
814
|
|
|
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
815
|
// src/utils/bounds.ts
|
|
817
816
|
function calculateBounds(geojson) {
|
|
818
817
|
let minLng = Infinity;
|
|
@@ -913,13 +912,19 @@ async function loadGeoJSON(url, options = {}) {
|
|
|
913
912
|
try {
|
|
914
913
|
const controller = new AbortController();
|
|
915
914
|
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
915
|
+
const callerSignal = fetchOptions.signal;
|
|
916
|
+
if (callerSignal) {
|
|
917
|
+
if (callerSignal.aborted) controller.abort();
|
|
918
|
+
else callerSignal.addEventListener("abort", () => controller.abort(), { once: true });
|
|
919
|
+
}
|
|
920
|
+
const headers = new Headers(fetchOptions.headers);
|
|
921
|
+
if (!headers.has("Accept")) {
|
|
922
|
+
headers.set("Accept", "application/geo+json, application/json");
|
|
923
|
+
}
|
|
916
924
|
const response = await fetch(url, {
|
|
917
925
|
...fetchOptions,
|
|
918
926
|
signal: controller.signal,
|
|
919
|
-
headers
|
|
920
|
-
Accept: "application/geo+json, application/json",
|
|
921
|
-
...fetchOptions.headers
|
|
922
|
-
}
|
|
927
|
+
headers
|
|
923
928
|
});
|
|
924
929
|
clearTimeout(timeoutId);
|
|
925
930
|
if (!response.ok) {
|
|
@@ -948,6 +953,9 @@ async function loadGeoJSON(url, options = {}) {
|
|
|
948
953
|
} catch (err) {
|
|
949
954
|
if (err instanceof Error) {
|
|
950
955
|
if (err.name === "AbortError") {
|
|
956
|
+
if (options.fetchOptions?.signal?.aborted) {
|
|
957
|
+
return { data: null, error: "Request aborted", success: false };
|
|
958
|
+
}
|
|
951
959
|
return {
|
|
952
960
|
data: null,
|
|
953
961
|
error: `Request timeout after ${timeout}ms`,
|
|
@@ -1742,11 +1750,11 @@ function getSimplifiedFeaturesForZoom(lodData, zoom) {
|
|
|
1742
1750
|
return lodData.features;
|
|
1743
1751
|
}
|
|
1744
1752
|
let bestMatch = null;
|
|
1753
|
+
let bestMaxZoom = Infinity;
|
|
1745
1754
|
for (const [maxZoom, features] of lodData.simplifiedFeatures) {
|
|
1746
|
-
if (zoom < maxZoom) {
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
}
|
|
1755
|
+
if (zoom < maxZoom && maxZoom < bestMaxZoom) {
|
|
1756
|
+
bestMatch = features;
|
|
1757
|
+
bestMaxZoom = maxZoom;
|
|
1750
1758
|
}
|
|
1751
1759
|
}
|
|
1752
1760
|
return bestMatch ?? lodData.features;
|
|
@@ -1763,7 +1771,7 @@ function calculateZoomThresholds(groups, options = {}) {
|
|
|
1763
1771
|
const groupMaxZoom = Math.max(10, Math.min(14, 10 + Math.log2(groupCount)));
|
|
1764
1772
|
const subGroupMaxZoom = Math.max(
|
|
1765
1773
|
groupMaxZoom + minZoomGap,
|
|
1766
|
-
Math.min(16, groupMaxZoom + Math.log2(Math.max(1, subGroupCount / groupCount)))
|
|
1774
|
+
Math.min(16, groupMaxZoom + Math.log2(Math.max(1, subGroupCount / Math.max(1, groupCount))))
|
|
1767
1775
|
);
|
|
1768
1776
|
return {
|
|
1769
1777
|
groupMaxZoom: Math.round(groupMaxZoom),
|
|
@@ -1864,8 +1872,8 @@ function buildSpatialIndex(geojson, options = {}) {
|
|
|
1864
1872
|
};
|
|
1865
1873
|
}
|
|
1866
1874
|
const [[minLng, minLat], [maxLng, maxLat]] = bounds;
|
|
1867
|
-
const width = maxLng - minLng;
|
|
1868
|
-
const height = maxLat - minLat;
|
|
1875
|
+
const width = Math.max(maxLng - minLng, minCellSize);
|
|
1876
|
+
const height = Math.max(maxLat - minLat, minCellSize);
|
|
1869
1877
|
const aspectRatio = width / height;
|
|
1870
1878
|
let cols = Math.ceil(Math.sqrt(targetCells * aspectRatio));
|
|
1871
1879
|
let rows = Math.ceil(targetCells / cols);
|
|
@@ -1878,10 +1886,10 @@ function buildSpatialIndex(geojson, options = {}) {
|
|
|
1878
1886
|
const featureBounds = getFeatureBounds(feature);
|
|
1879
1887
|
if (!featureBounds) continue;
|
|
1880
1888
|
const [[fMinLng, fMinLat], [fMaxLng, fMaxLat]] = featureBounds;
|
|
1881
|
-
const minCol =
|
|
1882
|
-
const maxCol =
|
|
1883
|
-
const minRow =
|
|
1884
|
-
const maxRow =
|
|
1889
|
+
const minCol = cellIndex(fMinLng, minLng, cellWidth, cols);
|
|
1890
|
+
const maxCol = cellIndex(fMaxLng, minLng, cellWidth, cols);
|
|
1891
|
+
const minRow = cellIndex(fMinLat, minLat, cellHeight, rows);
|
|
1892
|
+
const maxRow = cellIndex(fMaxLat, minLat, cellHeight, rows);
|
|
1885
1893
|
for (let col = minCol; col <= maxCol; col++) {
|
|
1886
1894
|
for (let row = minRow; row <= maxRow; row++) {
|
|
1887
1895
|
const key = `${col},${row}`;
|
|
@@ -1902,6 +1910,9 @@ function buildSpatialIndex(geojson, options = {}) {
|
|
|
1902
1910
|
featureCount: geojson.features.length
|
|
1903
1911
|
};
|
|
1904
1912
|
}
|
|
1913
|
+
function cellIndex(value, origin, size, count) {
|
|
1914
|
+
return Math.min(count - 1, Math.max(0, Math.floor((value - origin) / size)));
|
|
1915
|
+
}
|
|
1905
1916
|
function getFeatureBounds(feature) {
|
|
1906
1917
|
const geometry = feature.geometry;
|
|
1907
1918
|
if (!geometry) return null;
|
|
@@ -1956,10 +1967,10 @@ function queryByBounds(index, queryBounds, options = {}) {
|
|
|
1956
1967
|
maxLng += actualBuffer;
|
|
1957
1968
|
maxLat += actualBuffer;
|
|
1958
1969
|
const [[idxMinLng, idxMinLat]] = index.bounds;
|
|
1959
|
-
const minCol =
|
|
1960
|
-
const maxCol =
|
|
1961
|
-
const minRow =
|
|
1962
|
-
const maxRow =
|
|
1970
|
+
const minCol = cellIndex(minLng, idxMinLng, index.cellWidth, index.cols);
|
|
1971
|
+
const maxCol = cellIndex(maxLng, idxMinLng, index.cellWidth, index.cols);
|
|
1972
|
+
const minRow = cellIndex(minLat, idxMinLat, index.cellHeight, index.rows);
|
|
1973
|
+
const maxRow = cellIndex(maxLat, idxMinLat, index.cellHeight, index.rows);
|
|
1963
1974
|
const seen = /* @__PURE__ */ new Set();
|
|
1964
1975
|
const features = [];
|
|
1965
1976
|
for (let col = minCol; col <= maxCol; col++) {
|
|
@@ -2019,10 +2030,10 @@ function queryByBoundsWithStats(index, queryBounds, options = {}) {
|
|
|
2019
2030
|
maxLng += actualBuffer;
|
|
2020
2031
|
maxLat += actualBuffer;
|
|
2021
2032
|
const [[idxMinLng, idxMinLat]] = index.bounds;
|
|
2022
|
-
const minCol =
|
|
2023
|
-
const maxCol =
|
|
2024
|
-
const minRow =
|
|
2025
|
-
const maxRow =
|
|
2033
|
+
const minCol = cellIndex(minLng, idxMinLng, index.cellWidth, index.cols);
|
|
2034
|
+
const maxCol = cellIndex(maxLng, idxMinLng, index.cellWidth, index.cols);
|
|
2035
|
+
const minRow = cellIndex(minLat, idxMinLat, index.cellHeight, index.rows);
|
|
2036
|
+
const maxRow = cellIndex(maxLat, idxMinLat, index.cellHeight, index.rows);
|
|
2026
2037
|
const seen = /* @__PURE__ */ new Set();
|
|
2027
2038
|
const features = [];
|
|
2028
2039
|
let cellsChecked = 0;
|
package/dist/utils/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { DEFAULT_SIMPLIFICATION_THRESHOLDS, KEYBOARD_CONTROLS, MARKER_PROTECTION_CLASS, applyMarkerChildProtection, applyMarkerProtection, boundsToPolygon, buildRTreeIndex, buildSpatialIndex, calculateBounds, calculateCentroid, calculateZoomThresholds, clampLatitude, combineBounds, countFeaturesByType, createCategoricalColorExpression, createCircleStyle, createClusterCirclePaint, createClusterStyles, createClusterTextLayout, createContinuousColorExpression, createDynamicLODManager, createExtrusionHeightExpression, createExtrusionStyle, createFillStyle, createGeoJSONFingerprint, createHeatmapStyle, createHoverExpression, createIdleViewportManager, createInteractiveExpression, createInteractiveStatusColorExpression, createLineStyle, createLotFillStyle, createLotOutlineStyle, createPredictiveViewportManager, createRTreeViewportManager, createSelectionExpression, createStatusColorExpression, createViewportManager, createViewportQuery, createZoomExpression, decimalToDMS, deepEqual, ensureValidCoordinates, expandCluster, expandClusterToBounds, extendBounds, filterByGeometryType, filterEqual, fingerprintEqual, formatArea, formatBearing, formatBounds, formatCoordinates, formatDistance, formatFeatureProperties, formatLabel, formatPitch, formatPropertyValue, formatScale, formatZoom, generateBoundingPolygon, generateConvexHull, generateFeatureCollectionDescription, generateFeatureTable, generateKeyboardControlsDescription, generateLODData, generateLODDataWithSimplification, generateMapDescription, generateMarkerList, generateMarkersDescription, generateMoveAnnouncement, geoJSONEqual, getChangedPaintProps, getClusterBounds, getClusterChildren, getClusterExpansionZoom, getClusterLeaves, getHighlightStyle, getSelectionStyle, getSimplificationToleranceForZoom, getSimplifiedFeaturesForZoom, groupFeaturesByProperty, isClusterFeature, isValidBounds, isValidLatitude, isValidLongitude, loadGeoJSON, normalizeLongitude, normalizePadding, paintPropsEqual, panToFitPopup, prefersReducedMotion, queryByBounds, queryByBoundsWithStats, queryRTreeByBounds, queryRTreeByBoundsWithStats, removeMarkerProtection, serializeFilter, simplifyFeature, simplifyFeatureCollection, simplifyFeatureCollectionWithStats, simplifyPolygon, validateBoundsArray, validateCoordinates, validateGeoJSON, zoomToScale } from '../chunk-
|
|
1
|
+
export { DEFAULT_SIMPLIFICATION_THRESHOLDS, KEYBOARD_CONTROLS, MARKER_PROTECTION_CLASS, applyMarkerChildProtection, applyMarkerProtection, boundsToPolygon, buildRTreeIndex, buildSpatialIndex, calculateBounds, calculateCentroid, calculateZoomThresholds, clampLatitude, combineBounds, countFeaturesByType, createCategoricalColorExpression, createCircleStyle, createClusterCirclePaint, createClusterStyles, createClusterTextLayout, createContinuousColorExpression, createDynamicLODManager, createExtrusionHeightExpression, createExtrusionStyle, createFillStyle, createGeoJSONFingerprint, createHeatmapStyle, createHoverExpression, createIdleViewportManager, createInteractiveExpression, createInteractiveStatusColorExpression, createLineStyle, createLotFillStyle, createLotOutlineStyle, createPredictiveViewportManager, createRTreeViewportManager, createSelectionExpression, createStatusColorExpression, createViewportManager, createViewportQuery, createZoomExpression, decimalToDMS, deepEqual, ensureValidCoordinates, expandCluster, expandClusterToBounds, extendBounds, filterByGeometryType, filterEqual, fingerprintEqual, formatArea, formatBearing, formatBounds, formatCoordinates, formatDistance, formatFeatureProperties, formatLabel, formatPitch, formatPropertyValue, formatScale, formatZoom, generateBoundingPolygon, generateConvexHull, generateFeatureCollectionDescription, generateFeatureTable, generateKeyboardControlsDescription, generateLODData, generateLODDataWithSimplification, generateMapDescription, generateMarkerList, generateMarkersDescription, generateMoveAnnouncement, geoJSONEqual, getChangedPaintProps, getClusterBounds, getClusterChildren, getClusterExpansionZoom, getClusterLeaves, getHighlightStyle, getSelectionStyle, getSimplificationToleranceForZoom, getSimplifiedFeaturesForZoom, groupFeaturesByProperty, isClusterFeature, isValidBounds, isValidLatitude, isValidLongitude, loadGeoJSON, normalizeLongitude, normalizePadding, paintPropsEqual, panToFitPopup, prefersReducedMotion, queryByBounds, queryByBoundsWithStats, queryRTreeByBounds, queryRTreeByBoundsWithStats, removeMarkerProtection, serializeFilter, simplifyFeature, simplifyFeatureCollection, simplifyFeatureCollectionWithStats, simplifyPolygon, validateBoundsArray, validateCoordinates, validateGeoJSON, zoomToScale } from '../chunk-ASIFMIU7.js';
|
|
2
2
|
import '../chunk-ZGUACUEF.js';
|