@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/index.cjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var themeTokens = require('@classic-homes/theme-tokens');
|
|
4
4
|
var RBush = require('rbush');
|
|
5
|
+
var contrast = require('@classic-homes/theme-tokens/contrast');
|
|
5
6
|
|
|
6
7
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
8
|
|
|
@@ -538,162 +539,173 @@ function getBasicStyle(themeName) {
|
|
|
538
539
|
return lightBasicStyle;
|
|
539
540
|
}
|
|
540
541
|
|
|
541
|
-
// src/utils/
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
},
|
|
553
|
-
rotate: {
|
|
554
|
-
left: "Shift + Arrow Left",
|
|
555
|
-
right: "Shift + Arrow Right"
|
|
556
|
-
},
|
|
557
|
-
pitch: {
|
|
558
|
-
increase: "Shift + Arrow Up",
|
|
559
|
-
decrease: "Shift + Arrow Down"
|
|
560
|
-
},
|
|
561
|
-
reset: {
|
|
562
|
-
bearing: "N key (reset north)",
|
|
563
|
-
view: "R key (reset view)"
|
|
542
|
+
// src/utils/format.ts
|
|
543
|
+
function formatCoordinates(coordinates, precision = 6, format = "decimal") {
|
|
544
|
+
const [lng, lat] = coordinates;
|
|
545
|
+
switch (format) {
|
|
546
|
+
case "dms":
|
|
547
|
+
return `${decimalToDMS(lat, "lat")}, ${decimalToDMS(lng, "lng")}`;
|
|
548
|
+
case "dd":
|
|
549
|
+
return `${lat.toFixed(precision)}, ${lng.toFixed(precision)}`;
|
|
550
|
+
case "decimal":
|
|
551
|
+
default:
|
|
552
|
+
return `${lng.toFixed(precision)}, ${lat.toFixed(precision)}`;
|
|
564
553
|
}
|
|
565
|
-
};
|
|
566
|
-
function generateKeyboardControlsDescription() {
|
|
567
|
-
return `
|
|
568
|
-
Map keyboard controls:
|
|
569
|
-
Pan: Use arrow keys to move the map.
|
|
570
|
-
Zoom: Press plus to zoom in, minus to zoom out.
|
|
571
|
-
Rotate: Hold Shift and press left or right arrows.
|
|
572
|
-
Tilt: Hold Shift and press up or down arrows.
|
|
573
|
-
Press N to reset north orientation.
|
|
574
|
-
`.trim().replace(/\s+/g, " ");
|
|
575
554
|
}
|
|
576
|
-
function
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
555
|
+
function decimalToDMS(decimal, type) {
|
|
556
|
+
const tenths = Math.round(Math.abs(decimal) * 36e3);
|
|
557
|
+
const degrees = Math.floor(tenths / 36e3);
|
|
558
|
+
const minutes = Math.floor(tenths % 36e3 / 600);
|
|
559
|
+
const seconds = (tenths % 600 / 10).toFixed(1);
|
|
560
|
+
let direction;
|
|
561
|
+
if (type === "lat") {
|
|
562
|
+
direction = decimal >= 0 ? "N" : "S";
|
|
563
|
+
} else {
|
|
564
|
+
direction = decimal >= 0 ? "E" : "W";
|
|
583
565
|
}
|
|
584
|
-
|
|
585
|
-
|
|
566
|
+
return `${degrees}\xB0 ${minutes}' ${seconds}" ${direction}`;
|
|
567
|
+
}
|
|
568
|
+
function formatDistance(meters, unit = "metric") {
|
|
569
|
+
if (unit === "imperial") {
|
|
570
|
+
const feet = meters * 3.28084;
|
|
571
|
+
if (feet < 1e3) {
|
|
572
|
+
return `${Math.round(feet)} ft`;
|
|
573
|
+
}
|
|
574
|
+
const miles = feet / 5280;
|
|
575
|
+
if (miles < 10) {
|
|
576
|
+
return `${miles.toFixed(1)} mi`;
|
|
577
|
+
}
|
|
578
|
+
return `${Math.round(miles)} mi`;
|
|
586
579
|
}
|
|
587
|
-
if (
|
|
588
|
-
|
|
580
|
+
if (meters < 1e3) {
|
|
581
|
+
return `${Math.round(meters)} m`;
|
|
589
582
|
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
583
|
+
const km = meters / 1e3;
|
|
584
|
+
if (km < 10) {
|
|
585
|
+
return `${km.toFixed(1)} km`;
|
|
593
586
|
}
|
|
594
|
-
|
|
595
|
-
|
|
587
|
+
return `${Math.round(km)} km`;
|
|
588
|
+
}
|
|
589
|
+
function formatArea(sqMeters, unit = "metric") {
|
|
590
|
+
if (unit === "imperial") {
|
|
591
|
+
const sqFeet = sqMeters * 10.7639;
|
|
592
|
+
if (sqFeet < 43560) {
|
|
593
|
+
return `${Math.round(sqFeet).toLocaleString()} sq ft`;
|
|
594
|
+
}
|
|
595
|
+
const acres = sqFeet / 43560;
|
|
596
|
+
if (acres < 640) {
|
|
597
|
+
return `${acres.toFixed(2)} acres`;
|
|
598
|
+
}
|
|
599
|
+
const sqMiles = acres / 640;
|
|
600
|
+
return `${sqMiles.toFixed(2)} sq mi`;
|
|
596
601
|
}
|
|
597
|
-
|
|
598
|
-
|
|
602
|
+
if (sqMeters < 1e4) {
|
|
603
|
+
return `${Math.round(sqMeters).toLocaleString()} m\xB2`;
|
|
604
|
+
}
|
|
605
|
+
const hectares = sqMeters / 1e4;
|
|
606
|
+
if (hectares < 100) {
|
|
607
|
+
return `${hectares.toFixed(2)} ha`;
|
|
608
|
+
}
|
|
609
|
+
const sqKm = sqMeters / 1e6;
|
|
610
|
+
return `${sqKm.toFixed(2)} km\xB2`;
|
|
599
611
|
}
|
|
600
|
-
function
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
612
|
+
function formatBounds(bounds) {
|
|
613
|
+
let sw;
|
|
614
|
+
let ne;
|
|
615
|
+
if (Array.isArray(bounds) && Array.isArray(bounds[0])) {
|
|
616
|
+
const arr = bounds;
|
|
617
|
+
sw = arr[0];
|
|
618
|
+
ne = arr[1];
|
|
619
|
+
} else {
|
|
620
|
+
const b = bounds;
|
|
621
|
+
sw = b.southwest;
|
|
622
|
+
ne = b.northeast;
|
|
604
623
|
}
|
|
605
|
-
|
|
606
|
-
data.features.forEach((feature) => {
|
|
607
|
-
const type = feature.geometry.type;
|
|
608
|
-
geometryTypes[type] = (geometryTypes[type] || 0) + 1;
|
|
609
|
-
});
|
|
610
|
-
const typeDescriptions = Object.entries(geometryTypes).map(([type, count]) => `${count} ${formatGeometryType(type, count)}`).join(", ");
|
|
611
|
-
return `${title}. Map layer with ${featureCount} features: ${typeDescriptions}.`;
|
|
624
|
+
return `SW: ${formatCoordinates(sw, 4)}, NE: ${formatCoordinates(ne, 4)}`;
|
|
612
625
|
}
|
|
613
|
-
function
|
|
614
|
-
|
|
615
|
-
Point: "point",
|
|
616
|
-
MultiPoint: "multi-point",
|
|
617
|
-
LineString: "line",
|
|
618
|
-
MultiLineString: "multi-line",
|
|
619
|
-
Polygon: "polygon",
|
|
620
|
-
MultiPolygon: "multi-polygon"
|
|
621
|
-
};
|
|
622
|
-
const plural = {
|
|
623
|
-
Point: "points",
|
|
624
|
-
MultiPoint: "multi-points",
|
|
625
|
-
LineString: "lines",
|
|
626
|
-
MultiLineString: "multi-lines",
|
|
627
|
-
Polygon: "polygons",
|
|
628
|
-
MultiPolygon: "multi-polygons"
|
|
629
|
-
};
|
|
630
|
-
return count === 1 ? singular[type] || type.toLowerCase() : plural[type] || `${type.toLowerCase()}s`;
|
|
626
|
+
function formatZoom(zoom) {
|
|
627
|
+
return `Zoom: ${zoom.toFixed(1)}`;
|
|
631
628
|
}
|
|
632
|
-
function
|
|
633
|
-
const
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
if (
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
629
|
+
function formatBearing(bearing) {
|
|
630
|
+
const normalized = (bearing % 360 + 360) % 360;
|
|
631
|
+
let direction;
|
|
632
|
+
if (normalized >= 337.5 || normalized < 22.5) {
|
|
633
|
+
direction = "N";
|
|
634
|
+
} else if (normalized >= 22.5 && normalized < 67.5) {
|
|
635
|
+
direction = "NE";
|
|
636
|
+
} else if (normalized >= 67.5 && normalized < 112.5) {
|
|
637
|
+
direction = "E";
|
|
638
|
+
} else if (normalized >= 112.5 && normalized < 157.5) {
|
|
639
|
+
direction = "SE";
|
|
640
|
+
} else if (normalized >= 157.5 && normalized < 202.5) {
|
|
641
|
+
direction = "S";
|
|
642
|
+
} else if (normalized >= 202.5 && normalized < 247.5) {
|
|
643
|
+
direction = "SW";
|
|
644
|
+
} else if (normalized >= 247.5 && normalized < 292.5) {
|
|
645
|
+
direction = "W";
|
|
646
|
+
} else {
|
|
647
|
+
direction = "NW";
|
|
645
648
|
}
|
|
646
|
-
return
|
|
649
|
+
return `${Math.round(normalized)}\xB0 ${direction}`;
|
|
647
650
|
}
|
|
648
|
-
function
|
|
649
|
-
|
|
650
|
-
return "";
|
|
651
|
-
}
|
|
652
|
-
const headers = ["Type", ...propertyKeys];
|
|
653
|
-
const headerRow = headers.map((h) => `<th scope="col">${escapeHtml(h)}</th>`).join("");
|
|
654
|
-
const bodyRows = features.features.slice(0, 100).map((feature) => {
|
|
655
|
-
const type = feature.geometry.type;
|
|
656
|
-
const cells = propertyKeys.map((key) => {
|
|
657
|
-
const value = feature.properties?.[key];
|
|
658
|
-
return `<td>${escapeHtml(String(value ?? ""))}</td>`;
|
|
659
|
-
});
|
|
660
|
-
return `<tr><td>${escapeHtml(type)}</td>${cells.join("")}</tr>`;
|
|
661
|
-
}).join("");
|
|
662
|
-
return `
|
|
663
|
-
<table class="sr-only" role="table" aria-label="Map feature data">
|
|
664
|
-
<thead><tr>${headerRow}</tr></thead>
|
|
665
|
-
<tbody>${bodyRows}</tbody>
|
|
666
|
-
</table>
|
|
667
|
-
`.trim();
|
|
651
|
+
function formatPitch(pitch) {
|
|
652
|
+
return `${Math.round(pitch)}\xB0 tilt`;
|
|
668
653
|
}
|
|
669
|
-
function
|
|
670
|
-
if (
|
|
671
|
-
return
|
|
654
|
+
function formatScale(scale) {
|
|
655
|
+
if (scale >= 1e6) {
|
|
656
|
+
return `1:${(scale / 1e6).toFixed(1)}M`;
|
|
672
657
|
}
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
}).join("");
|
|
678
|
-
return `
|
|
679
|
-
<ul class="sr-only" role="list" aria-label="Map markers">
|
|
680
|
-
${items}
|
|
681
|
-
</ul>
|
|
682
|
-
`.trim();
|
|
658
|
+
if (scale >= 1e3) {
|
|
659
|
+
return `1:${Math.round(scale / 1e3)}K`;
|
|
660
|
+
}
|
|
661
|
+
return `1:${Math.round(scale)}`;
|
|
683
662
|
}
|
|
684
|
-
function
|
|
685
|
-
const
|
|
686
|
-
const
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
return
|
|
663
|
+
function zoomToScale(zoom, latitude = 0) {
|
|
664
|
+
const metersPerPixel = 40075e3 * Math.cos(latitude * Math.PI / 180) / (256 * Math.pow(2, zoom));
|
|
665
|
+
const screenMetersPerPixel = 264583e-9;
|
|
666
|
+
return Math.round(metersPerPixel / screenMetersPerPixel);
|
|
667
|
+
}
|
|
668
|
+
function formatPropertyValue(value) {
|
|
669
|
+
if (value === null || value === void 0) {
|
|
670
|
+
return "-";
|
|
671
|
+
}
|
|
672
|
+
if (typeof value === "number") {
|
|
673
|
+
if (Math.abs(value) <= 180 && value !== Math.floor(value)) {
|
|
674
|
+
return value.toFixed(6);
|
|
675
|
+
}
|
|
676
|
+
if (Math.abs(value) >= 1e3) {
|
|
677
|
+
return value.toLocaleString();
|
|
678
|
+
}
|
|
679
|
+
if (value !== Math.floor(value)) {
|
|
680
|
+
return value.toFixed(2);
|
|
681
|
+
}
|
|
682
|
+
return String(value);
|
|
696
683
|
}
|
|
684
|
+
if (typeof value === "boolean") {
|
|
685
|
+
return value ? "Yes" : "No";
|
|
686
|
+
}
|
|
687
|
+
if (Array.isArray(value)) {
|
|
688
|
+
return value.map(formatPropertyValue).join(", ");
|
|
689
|
+
}
|
|
690
|
+
if (typeof value === "object") {
|
|
691
|
+
return JSON.stringify(value);
|
|
692
|
+
}
|
|
693
|
+
return String(value);
|
|
694
|
+
}
|
|
695
|
+
function formatFeatureProperties(properties, options) {
|
|
696
|
+
const exclude = options?.exclude || ["id", "_id", "fid", "ogc_fid"];
|
|
697
|
+
const include = options?.include;
|
|
698
|
+
const labelMap = options?.labelMap || {};
|
|
699
|
+
const entries = Object.entries(properties).filter(([key]) => {
|
|
700
|
+
if (include) {
|
|
701
|
+
return include.includes(key);
|
|
702
|
+
}
|
|
703
|
+
return !exclude.includes(key) && !key.startsWith("_");
|
|
704
|
+
}).map(([key, value]) => {
|
|
705
|
+
const label = labelMap[key] || formatLabel(key);
|
|
706
|
+
return `<strong>${escapeHtml(label)}:</strong> ${escapeHtml(formatPropertyValue(value))}`;
|
|
707
|
+
});
|
|
708
|
+
return entries.join("<br>");
|
|
697
709
|
}
|
|
698
710
|
function escapeHtml(str) {
|
|
699
711
|
const htmlEntities = {
|
|
@@ -705,498 +717,486 @@ function escapeHtml(str) {
|
|
|
705
717
|
};
|
|
706
718
|
return str.replace(/[&<>"']/g, (char) => htmlEntities[char] || char);
|
|
707
719
|
}
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
720
|
+
function formatLabel(key) {
|
|
721
|
+
return key.replace(/_/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2").replace(/\b\w/g, (char) => char.toUpperCase());
|
|
722
|
+
}
|
|
723
|
+
function isValidLongitude(lng) {
|
|
724
|
+
return typeof lng === "number" && isFinite(lng) && lng >= -180 && lng <= 180;
|
|
725
|
+
}
|
|
726
|
+
function isValidLatitude(lat) {
|
|
727
|
+
return typeof lat === "number" && isFinite(lat) && lat >= -90 && lat <= 90;
|
|
728
|
+
}
|
|
729
|
+
function validateCoordinates(coordinates) {
|
|
730
|
+
if (!Array.isArray(coordinates)) {
|
|
731
|
+
return { valid: false, error: "Coordinates must be an array" };
|
|
716
732
|
}
|
|
717
|
-
if (
|
|
718
|
-
|
|
733
|
+
if (coordinates.length < 2) {
|
|
734
|
+
return { valid: false, error: "Coordinates must have at least 2 elements [lng, lat]" };
|
|
719
735
|
}
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
const paint = {
|
|
724
|
-
"line-color": options.color,
|
|
725
|
-
"line-width": options.width
|
|
726
|
-
};
|
|
727
|
-
const layout = {};
|
|
728
|
-
if (options.opacity !== void 0) {
|
|
729
|
-
paint["line-opacity"] = options.opacity;
|
|
736
|
+
const [lng, lat] = coordinates;
|
|
737
|
+
if (typeof lng !== "number" || typeof lat !== "number") {
|
|
738
|
+
return { valid: false, error: "Longitude and latitude must be numbers" };
|
|
730
739
|
}
|
|
731
|
-
if (
|
|
732
|
-
|
|
740
|
+
if (!isFinite(lng) || !isFinite(lat)) {
|
|
741
|
+
return { valid: false, error: "Coordinates must be finite numbers" };
|
|
733
742
|
}
|
|
734
|
-
if (
|
|
735
|
-
|
|
743
|
+
if (lng < -180 || lng > 180) {
|
|
744
|
+
return { valid: false, error: `Longitude ${lng} out of range [-180, 180]` };
|
|
736
745
|
}
|
|
737
|
-
if (
|
|
738
|
-
|
|
746
|
+
if (lat < -90 || lat > 90) {
|
|
747
|
+
return { valid: false, error: `Latitude ${lat} out of range [-90, 90]` };
|
|
748
|
+
}
|
|
749
|
+
return {
|
|
750
|
+
valid: true,
|
|
751
|
+
normalized: [lng, lat]
|
|
752
|
+
};
|
|
753
|
+
}
|
|
754
|
+
function ensureValidCoordinates(coordinates) {
|
|
755
|
+
const result = validateCoordinates(coordinates);
|
|
756
|
+
if (!result.valid) {
|
|
757
|
+
throw new Error(`Invalid coordinates: ${result.error}`);
|
|
758
|
+
}
|
|
759
|
+
return result.normalized;
|
|
760
|
+
}
|
|
761
|
+
function normalizeLongitude(lng) {
|
|
762
|
+
if (!isFinite(lng)) return NaN;
|
|
763
|
+
let normalized = lng % 360;
|
|
764
|
+
if (normalized > 180) {
|
|
765
|
+
normalized -= 360;
|
|
766
|
+
} else if (normalized < -180) {
|
|
767
|
+
normalized += 360;
|
|
739
768
|
}
|
|
740
|
-
return
|
|
769
|
+
return normalized;
|
|
741
770
|
}
|
|
742
|
-
function
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
if (
|
|
748
|
-
|
|
749
|
-
}
|
|
750
|
-
if (options.strokeWidth !== void 0) {
|
|
751
|
-
paint["circle-stroke-width"] = options.strokeWidth;
|
|
771
|
+
function clampLatitude(lat) {
|
|
772
|
+
if (!isFinite(lat)) return NaN;
|
|
773
|
+
return Math.max(-90, Math.min(90, lat));
|
|
774
|
+
}
|
|
775
|
+
function validateBoundsArray(bounds) {
|
|
776
|
+
if (!Array.isArray(bounds)) {
|
|
777
|
+
return { valid: false, error: "Bounds must be an array" };
|
|
752
778
|
}
|
|
753
|
-
if (
|
|
754
|
-
|
|
779
|
+
if (bounds.length !== 2) {
|
|
780
|
+
return { valid: false, error: "Bounds must have exactly 2 elements [southwest, northeast]" };
|
|
755
781
|
}
|
|
756
|
-
|
|
757
|
-
|
|
782
|
+
const swResult = validateCoordinates(bounds[0]);
|
|
783
|
+
if (!swResult.valid) {
|
|
784
|
+
return { valid: false, error: `Invalid southwest corner: ${swResult.error}` };
|
|
758
785
|
}
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
const paint = {
|
|
763
|
-
"fill-extrusion-height": options.height,
|
|
764
|
-
"fill-extrusion-color": options.color
|
|
765
|
-
};
|
|
766
|
-
if (options.baseHeight !== void 0) {
|
|
767
|
-
paint["fill-extrusion-base"] = options.baseHeight;
|
|
786
|
+
const neResult = validateCoordinates(bounds[1]);
|
|
787
|
+
if (!neResult.valid) {
|
|
788
|
+
return { valid: false, error: `Invalid northeast corner: ${neResult.error}` };
|
|
768
789
|
}
|
|
769
|
-
|
|
770
|
-
|
|
790
|
+
const [, swLat] = swResult.normalized;
|
|
791
|
+
const [, neLat] = neResult.normalized;
|
|
792
|
+
if (swLat > neLat) {
|
|
793
|
+
return {
|
|
794
|
+
valid: false,
|
|
795
|
+
error: `Southwest latitude (${swLat}) must be less than northeast latitude (${neLat})`
|
|
796
|
+
};
|
|
771
797
|
}
|
|
772
|
-
|
|
773
|
-
|
|
798
|
+
return {
|
|
799
|
+
valid: true,
|
|
800
|
+
normalized: [swResult.normalized, neResult.normalized]
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
// src/utils/accessibility.ts
|
|
805
|
+
var KEYBOARD_CONTROLS = {
|
|
806
|
+
pan: {
|
|
807
|
+
up: "Arrow Up",
|
|
808
|
+
down: "Arrow Down",
|
|
809
|
+
left: "Arrow Left",
|
|
810
|
+
right: "Arrow Right"
|
|
811
|
+
},
|
|
812
|
+
zoom: {
|
|
813
|
+
in: "Plus (+) or Equals (=)",
|
|
814
|
+
out: "Minus (-)"
|
|
815
|
+
},
|
|
816
|
+
rotate: {
|
|
817
|
+
left: "Shift + Arrow Left",
|
|
818
|
+
right: "Shift + Arrow Right"
|
|
819
|
+
},
|
|
820
|
+
pitch: {
|
|
821
|
+
increase: "Shift + Arrow Up",
|
|
822
|
+
decrease: "Shift + Arrow Down"
|
|
823
|
+
},
|
|
824
|
+
reset: {
|
|
825
|
+
bearing: "N key (reset north)",
|
|
826
|
+
view: "R key (reset view)"
|
|
774
827
|
}
|
|
775
|
-
|
|
828
|
+
};
|
|
829
|
+
function generateKeyboardControlsDescription() {
|
|
830
|
+
return `
|
|
831
|
+
Map keyboard controls:
|
|
832
|
+
Pan: Use arrow keys to move the map.
|
|
833
|
+
Zoom: Press plus to zoom in, minus to zoom out.
|
|
834
|
+
Rotate: Hold Shift and press left or right arrows.
|
|
835
|
+
Tilt: Hold Shift and press up or down arrows.
|
|
836
|
+
Press N to reset north orientation.
|
|
837
|
+
`.trim().replace(/\s+/g, " ");
|
|
776
838
|
}
|
|
777
|
-
function
|
|
778
|
-
|
|
779
|
-
if (options
|
|
780
|
-
|
|
839
|
+
function generateMapDescription(title, options) {
|
|
840
|
+
let description = `${title}. Interactive map`;
|
|
841
|
+
if (options?.center) {
|
|
842
|
+
const [lng, lat] = options.center;
|
|
843
|
+
const latDir = lat >= 0 ? "N" : "S";
|
|
844
|
+
const lngDir = lng >= 0 ? "E" : "W";
|
|
845
|
+
description += ` centered at ${Math.abs(lat).toFixed(2)} degrees ${latDir}, ${Math.abs(lng).toFixed(2)} degrees ${lngDir}`;
|
|
781
846
|
}
|
|
782
|
-
if (options
|
|
783
|
-
|
|
847
|
+
if (options?.zoom !== void 0) {
|
|
848
|
+
description += ` at zoom level ${options.zoom}`;
|
|
784
849
|
}
|
|
785
|
-
if (options
|
|
786
|
-
|
|
850
|
+
if (options?.featureCount !== void 0 && options.featureCount > 0) {
|
|
851
|
+
description += `. Contains ${options.featureCount} ${options.featureCount === 1 ? "feature" : "features"}`;
|
|
787
852
|
}
|
|
788
|
-
if (options
|
|
789
|
-
|
|
853
|
+
if (options?.markerCount !== void 0 && options.markerCount > 0) {
|
|
854
|
+
description += options.featureCount ? ` and ` : `. Contains `;
|
|
855
|
+
description += `${options.markerCount} ${options.markerCount === 1 ? "marker" : "markers"}`;
|
|
790
856
|
}
|
|
791
|
-
if (options.
|
|
792
|
-
|
|
793
|
-
options.colorRamp.forEach((color, index) => {
|
|
794
|
-
stops.push(index / (options.colorRamp.length - 1));
|
|
795
|
-
stops.push(color);
|
|
796
|
-
});
|
|
797
|
-
paint["heatmap-color"] = stops;
|
|
857
|
+
if (options?.layerTypes && options.layerTypes.length > 0) {
|
|
858
|
+
description += `. Showing ${options.layerTypes.join(", ")} layers`;
|
|
798
859
|
}
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
function createHoverExpression(baseValue, hoverValue, featureStateName = "hover") {
|
|
802
|
-
return ["case", ["boolean", ["feature-state", featureStateName], false], hoverValue, baseValue];
|
|
803
|
-
}
|
|
804
|
-
function createSelectionExpression(baseValue, selectedValue, featureStateName = "selected") {
|
|
805
|
-
return [
|
|
806
|
-
"case",
|
|
807
|
-
["boolean", ["feature-state", featureStateName], false],
|
|
808
|
-
selectedValue,
|
|
809
|
-
baseValue
|
|
810
|
-
];
|
|
811
|
-
}
|
|
812
|
-
function createInteractiveExpression(baseValue, hoverValue, selectedValue) {
|
|
813
|
-
return [
|
|
814
|
-
"case",
|
|
815
|
-
["boolean", ["feature-state", "selected"], false],
|
|
816
|
-
selectedValue,
|
|
817
|
-
["boolean", ["feature-state", "hover"], false],
|
|
818
|
-
hoverValue,
|
|
819
|
-
baseValue
|
|
820
|
-
];
|
|
821
|
-
}
|
|
822
|
-
function createCategoricalColorExpression(property, colorMap, defaultColor) {
|
|
823
|
-
const expression = ["match", ["get", property]];
|
|
824
|
-
Object.entries(colorMap).forEach(([value, color]) => {
|
|
825
|
-
expression.push(value, color);
|
|
826
|
-
});
|
|
827
|
-
expression.push(defaultColor);
|
|
828
|
-
return expression;
|
|
860
|
+
description += ". Use keyboard to navigate.";
|
|
861
|
+
return description;
|
|
829
862
|
}
|
|
830
|
-
function
|
|
831
|
-
const
|
|
832
|
-
if (
|
|
833
|
-
|
|
834
|
-
} else if (interpolation === "exponential") {
|
|
835
|
-
expression.push(["exponential", 1]);
|
|
836
|
-
} else {
|
|
837
|
-
expression.push(interpolation);
|
|
863
|
+
function generateFeatureCollectionDescription(title, data) {
|
|
864
|
+
const featureCount = data.features.length;
|
|
865
|
+
if (featureCount === 0) {
|
|
866
|
+
return `${title}. Map layer with no features.`;
|
|
838
867
|
}
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
return expression;
|
|
844
|
-
}
|
|
845
|
-
function createZoomExpression(stops) {
|
|
846
|
-
const expression = ["interpolate", ["linear"], ["zoom"]];
|
|
847
|
-
stops.forEach(([zoom, value]) => {
|
|
848
|
-
expression.push(zoom, value);
|
|
868
|
+
const geometryTypes = {};
|
|
869
|
+
data.features.forEach((feature) => {
|
|
870
|
+
const type = feature.geometry.type;
|
|
871
|
+
geometryTypes[type] = (geometryTypes[type] || 0) + 1;
|
|
849
872
|
});
|
|
850
|
-
|
|
851
|
-
}
|
|
852
|
-
function getHighlightStyle(theme = lightTheme) {
|
|
853
|
-
const { highlight, highlightSecondary } = theme.colors;
|
|
854
|
-
return {
|
|
855
|
-
fill: {
|
|
856
|
-
"fill-color": createHoverExpression(highlightSecondary, highlight),
|
|
857
|
-
"fill-opacity": createHoverExpression(0.3, 0.5),
|
|
858
|
-
"fill-outline-color": highlight
|
|
859
|
-
},
|
|
860
|
-
line: {
|
|
861
|
-
"line-color": createHoverExpression(highlightSecondary, highlight),
|
|
862
|
-
"line-width": createHoverExpression(2, 3)
|
|
863
|
-
},
|
|
864
|
-
circle: {
|
|
865
|
-
"circle-color": createHoverExpression(highlightSecondary, highlight),
|
|
866
|
-
"circle-radius": createHoverExpression(6, 8),
|
|
867
|
-
"circle-stroke-color": highlight,
|
|
868
|
-
"circle-stroke-width": 2
|
|
869
|
-
}
|
|
870
|
-
};
|
|
871
|
-
}
|
|
872
|
-
function getSelectionStyle(theme = lightTheme) {
|
|
873
|
-
const { selection, highlight } = theme.colors;
|
|
874
|
-
return {
|
|
875
|
-
fill: {
|
|
876
|
-
"fill-color": createInteractiveExpression(highlight, highlight, selection),
|
|
877
|
-
"fill-opacity": createInteractiveExpression(0.2, 0.4, 0.6),
|
|
878
|
-
"fill-outline-color": createInteractiveExpression(highlight, highlight, selection)
|
|
879
|
-
},
|
|
880
|
-
line: {
|
|
881
|
-
"line-color": createInteractiveExpression(highlight, highlight, selection),
|
|
882
|
-
"line-width": createInteractiveExpression(2, 3, 4)
|
|
883
|
-
},
|
|
884
|
-
circle: {
|
|
885
|
-
"circle-color": createInteractiveExpression(highlight, highlight, selection),
|
|
886
|
-
"circle-radius": createInteractiveExpression(6, 8, 10),
|
|
887
|
-
"circle-stroke-color": createInteractiveExpression(highlight, highlight, selection),
|
|
888
|
-
"circle-stroke-width": 2
|
|
889
|
-
}
|
|
890
|
-
};
|
|
873
|
+
const typeDescriptions = Object.entries(geometryTypes).map(([type, count]) => `${count} ${formatGeometryType(type, count)}`).join(", ");
|
|
874
|
+
return `${title}. Map layer with ${featureCount} features: ${typeDescriptions}.`;
|
|
891
875
|
}
|
|
892
|
-
function
|
|
893
|
-
const
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
"
|
|
897
|
-
"
|
|
876
|
+
function formatGeometryType(type, count) {
|
|
877
|
+
const singular = {
|
|
878
|
+
Point: "point",
|
|
879
|
+
MultiPoint: "multi-point",
|
|
880
|
+
LineString: "line",
|
|
881
|
+
MultiLineString: "multi-line",
|
|
882
|
+
Polygon: "polygon",
|
|
883
|
+
MultiPolygon: "multi-polygon"
|
|
898
884
|
};
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
hoverWidth = 2,
|
|
907
|
-
selectedWidth = 3
|
|
908
|
-
} = options;
|
|
909
|
-
const lineColor = selectedColor ? createInteractiveExpression(defaultColor, hoverColor, selectedColor) : createHoverExpression(defaultColor, hoverColor);
|
|
910
|
-
const lineWidth = selectedColor ? createInteractiveExpression(defaultWidth, hoverWidth, selectedWidth) : createHoverExpression(defaultWidth, hoverWidth);
|
|
911
|
-
return {
|
|
912
|
-
"line-color": lineColor,
|
|
913
|
-
"line-width": lineWidth
|
|
885
|
+
const plural = {
|
|
886
|
+
Point: "points",
|
|
887
|
+
MultiPoint: "multi-points",
|
|
888
|
+
LineString: "lines",
|
|
889
|
+
MultiLineString: "multi-lines",
|
|
890
|
+
Polygon: "polygons",
|
|
891
|
+
MultiPolygon: "multi-polygons"
|
|
914
892
|
};
|
|
893
|
+
return count === 1 ? singular[type] || type.toLowerCase() : plural[type] || `${type.toLowerCase()}s`;
|
|
915
894
|
}
|
|
916
|
-
function
|
|
917
|
-
const
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
heightExpr = ["*", heightExpr, scale];
|
|
921
|
-
}
|
|
922
|
-
if (minHeight > 0) {
|
|
923
|
-
heightExpr = ["max", heightExpr, minHeight];
|
|
895
|
+
function generateMarkersDescription(title, markers) {
|
|
896
|
+
const count = markers.length;
|
|
897
|
+
if (count === 0) {
|
|
898
|
+
return `${title}. No markers on the map.`;
|
|
924
899
|
}
|
|
925
|
-
|
|
926
|
-
|
|
900
|
+
let description = `${title}. Map with ${count} ${count === 1 ? "marker" : "markers"}`;
|
|
901
|
+
const labeledMarkers = markers.filter((m) => m.label).slice(0, 3);
|
|
902
|
+
if (labeledMarkers.length > 0) {
|
|
903
|
+
const labels = labeledMarkers.map((m) => m.label).join(", ");
|
|
904
|
+
description += ` including ${labels}`;
|
|
905
|
+
if (count > labeledMarkers.length) {
|
|
906
|
+
description += ` and ${count - labeledMarkers.length} more`;
|
|
907
|
+
}
|
|
927
908
|
}
|
|
928
|
-
return
|
|
909
|
+
return description + ".";
|
|
929
910
|
}
|
|
930
|
-
function
|
|
931
|
-
|
|
911
|
+
function generateFeatureTable(features, propertyKeys) {
|
|
912
|
+
if (features.features.length === 0) {
|
|
913
|
+
return "";
|
|
914
|
+
}
|
|
915
|
+
const headers = ["Type", ...propertyKeys];
|
|
916
|
+
const headerRow = headers.map((h) => `<th scope="col">${escapeHtml(h)}</th>`).join("");
|
|
917
|
+
const bodyRows = features.features.slice(0, 100).map((feature) => {
|
|
918
|
+
const type = feature.geometry.type;
|
|
919
|
+
const cells = propertyKeys.map((key) => {
|
|
920
|
+
const value = feature.properties?.[key];
|
|
921
|
+
return `<td>${escapeHtml(String(value ?? ""))}</td>`;
|
|
922
|
+
});
|
|
923
|
+
return `<tr><td>${escapeHtml(type)}</td>${cells.join("")}</tr>`;
|
|
924
|
+
}).join("");
|
|
925
|
+
return `
|
|
926
|
+
<table class="sr-only" role="table" aria-label="Map feature data">
|
|
927
|
+
<thead><tr>${headerRow}</tr></thead>
|
|
928
|
+
<tbody>${bodyRows}</tbody>
|
|
929
|
+
</table>
|
|
930
|
+
`.trim();
|
|
932
931
|
}
|
|
933
|
-
function
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
if (selectedColor) {
|
|
937
|
-
return [
|
|
938
|
-
"case",
|
|
939
|
-
["boolean", ["feature-state", "selected"], false],
|
|
940
|
-
selectedColor,
|
|
941
|
-
["boolean", ["feature-state", "hover"], false],
|
|
942
|
-
hoverColor,
|
|
943
|
-
baseExpr
|
|
944
|
-
];
|
|
932
|
+
function generateMarkerList(markers) {
|
|
933
|
+
if (markers.length === 0) {
|
|
934
|
+
return "";
|
|
945
935
|
}
|
|
946
|
-
|
|
936
|
+
const items = markers.slice(0, 50).map((marker) => {
|
|
937
|
+
const label = marker.label || "Marker";
|
|
938
|
+
const [lng, lat] = marker.coordinates;
|
|
939
|
+
return `<li>${escapeHtml(label)} at ${lat.toFixed(4)}, ${lng.toFixed(4)}</li>`;
|
|
940
|
+
}).join("");
|
|
941
|
+
return `
|
|
942
|
+
<ul class="sr-only" role="list" aria-label="Map markers">
|
|
943
|
+
${items}
|
|
944
|
+
</ul>
|
|
945
|
+
`.trim();
|
|
947
946
|
}
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
const
|
|
952
|
-
switch (
|
|
953
|
-
case "
|
|
954
|
-
return
|
|
955
|
-
case "
|
|
956
|
-
return
|
|
957
|
-
case "
|
|
947
|
+
function generateMoveAnnouncement(center, zoom, action) {
|
|
948
|
+
const [lng, lat] = center;
|
|
949
|
+
const latDir = lat >= 0 ? "north" : "south";
|
|
950
|
+
const lngDir = lng >= 0 ? "east" : "west";
|
|
951
|
+
switch (action) {
|
|
952
|
+
case "pan":
|
|
953
|
+
return `Panned to ${Math.abs(lat).toFixed(2)} ${latDir}, ${Math.abs(lng).toFixed(2)} ${lngDir}`;
|
|
954
|
+
case "zoom":
|
|
955
|
+
return `Zoom level ${zoom.toFixed(1)}`;
|
|
956
|
+
case "move":
|
|
958
957
|
default:
|
|
959
|
-
return
|
|
958
|
+
return `Map moved to ${Math.abs(lat).toFixed(2)} ${latDir}, ${Math.abs(lng).toFixed(2)} ${lngDir} at zoom ${zoom.toFixed(1)}`;
|
|
960
959
|
}
|
|
961
960
|
}
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
const
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
direction = decimal >= 0 ? "N" : "S";
|
|
971
|
-
} else {
|
|
972
|
-
direction = decimal >= 0 ? "E" : "W";
|
|
961
|
+
|
|
962
|
+
// src/utils/styles.ts
|
|
963
|
+
function createFillStyle(options) {
|
|
964
|
+
const paint = {
|
|
965
|
+
"fill-color": options.color
|
|
966
|
+
};
|
|
967
|
+
if (options.opacity !== void 0) {
|
|
968
|
+
paint["fill-opacity"] = options.opacity;
|
|
973
969
|
}
|
|
974
|
-
|
|
970
|
+
if (options.outlineColor !== void 0) {
|
|
971
|
+
paint["fill-outline-color"] = options.outlineColor;
|
|
972
|
+
}
|
|
973
|
+
return { paint };
|
|
975
974
|
}
|
|
976
|
-
function
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
return `${miles.toFixed(1)} mi`;
|
|
985
|
-
}
|
|
986
|
-
return `${Math.round(miles)} mi`;
|
|
975
|
+
function createLineStyle(options) {
|
|
976
|
+
const paint = {
|
|
977
|
+
"line-color": options.color,
|
|
978
|
+
"line-width": options.width
|
|
979
|
+
};
|
|
980
|
+
const layout = {};
|
|
981
|
+
if (options.opacity !== void 0) {
|
|
982
|
+
paint["line-opacity"] = options.opacity;
|
|
987
983
|
}
|
|
988
|
-
if (
|
|
989
|
-
|
|
984
|
+
if (options.dashArray) {
|
|
985
|
+
paint["line-dasharray"] = options.dashArray;
|
|
990
986
|
}
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
return `${km.toFixed(1)} km`;
|
|
987
|
+
if (options.cap) {
|
|
988
|
+
layout["line-cap"] = options.cap;
|
|
994
989
|
}
|
|
995
|
-
|
|
990
|
+
if (options.join) {
|
|
991
|
+
layout["line-join"] = options.join;
|
|
992
|
+
}
|
|
993
|
+
return { paint, layout };
|
|
996
994
|
}
|
|
997
|
-
function
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
if (acres < 640) {
|
|
1005
|
-
return `${acres.toFixed(2)} acres`;
|
|
1006
|
-
}
|
|
1007
|
-
const sqMiles = acres / 640;
|
|
1008
|
-
return `${sqMiles.toFixed(2)} sq mi`;
|
|
995
|
+
function createCircleStyle(options) {
|
|
996
|
+
const paint = {
|
|
997
|
+
"circle-radius": options.radius,
|
|
998
|
+
"circle-color": options.color
|
|
999
|
+
};
|
|
1000
|
+
if (options.opacity !== void 0) {
|
|
1001
|
+
paint["circle-opacity"] = options.opacity;
|
|
1009
1002
|
}
|
|
1010
|
-
if (
|
|
1011
|
-
|
|
1003
|
+
if (options.strokeWidth !== void 0) {
|
|
1004
|
+
paint["circle-stroke-width"] = options.strokeWidth;
|
|
1012
1005
|
}
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
return `${hectares.toFixed(2)} ha`;
|
|
1006
|
+
if (options.strokeColor !== void 0) {
|
|
1007
|
+
paint["circle-stroke-color"] = options.strokeColor;
|
|
1016
1008
|
}
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
}
|
|
1020
|
-
function formatBounds(bounds) {
|
|
1021
|
-
let sw;
|
|
1022
|
-
let ne;
|
|
1023
|
-
if (Array.isArray(bounds) && Array.isArray(bounds[0])) {
|
|
1024
|
-
const arr = bounds;
|
|
1025
|
-
sw = arr[0];
|
|
1026
|
-
ne = arr[1];
|
|
1027
|
-
} else {
|
|
1028
|
-
const b = bounds;
|
|
1029
|
-
sw = b.southwest;
|
|
1030
|
-
ne = b.northeast;
|
|
1009
|
+
if (options.blur !== void 0) {
|
|
1010
|
+
paint["circle-blur"] = options.blur;
|
|
1031
1011
|
}
|
|
1032
|
-
return
|
|
1033
|
-
}
|
|
1034
|
-
function formatZoom(zoom) {
|
|
1035
|
-
return `Zoom: ${zoom.toFixed(1)}`;
|
|
1012
|
+
return { paint };
|
|
1036
1013
|
}
|
|
1037
|
-
function
|
|
1038
|
-
const
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
} else if (normalized >= 67.5 && normalized < 112.5) {
|
|
1045
|
-
direction = "E";
|
|
1046
|
-
} else if (normalized >= 112.5 && normalized < 157.5) {
|
|
1047
|
-
direction = "SE";
|
|
1048
|
-
} else if (normalized >= 157.5 && normalized < 202.5) {
|
|
1049
|
-
direction = "S";
|
|
1050
|
-
} else if (normalized >= 202.5 && normalized < 247.5) {
|
|
1051
|
-
direction = "SW";
|
|
1052
|
-
} else if (normalized >= 247.5 && normalized < 292.5) {
|
|
1053
|
-
direction = "W";
|
|
1054
|
-
} else {
|
|
1055
|
-
direction = "NW";
|
|
1014
|
+
function createExtrusionStyle(options) {
|
|
1015
|
+
const paint = {
|
|
1016
|
+
"fill-extrusion-height": options.height,
|
|
1017
|
+
"fill-extrusion-color": options.color
|
|
1018
|
+
};
|
|
1019
|
+
if (options.baseHeight !== void 0) {
|
|
1020
|
+
paint["fill-extrusion-base"] = options.baseHeight;
|
|
1056
1021
|
}
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
function formatPitch(pitch) {
|
|
1060
|
-
return `${Math.round(pitch)}\xB0 tilt`;
|
|
1061
|
-
}
|
|
1062
|
-
function formatScale(scale) {
|
|
1063
|
-
if (scale >= 1e6) {
|
|
1064
|
-
return `1:${(scale / 1e6).toFixed(1)}M`;
|
|
1022
|
+
if (options.opacity !== void 0) {
|
|
1023
|
+
paint["fill-extrusion-opacity"] = options.opacity;
|
|
1065
1024
|
}
|
|
1066
|
-
if (
|
|
1067
|
-
|
|
1025
|
+
if (options.verticalGradient !== void 0) {
|
|
1026
|
+
paint["fill-extrusion-vertical-gradient"] = options.verticalGradient;
|
|
1068
1027
|
}
|
|
1069
|
-
return
|
|
1070
|
-
}
|
|
1071
|
-
function zoomToScale(zoom, latitude = 0) {
|
|
1072
|
-
const metersPerPixel = 40075e3 * Math.cos(latitude * Math.PI / 180) / (256 * Math.pow(2, zoom));
|
|
1073
|
-
const screenMetersPerPixel = 264583e-9;
|
|
1074
|
-
return Math.round(metersPerPixel / screenMetersPerPixel);
|
|
1028
|
+
return { paint };
|
|
1075
1029
|
}
|
|
1076
|
-
function
|
|
1077
|
-
|
|
1078
|
-
|
|
1030
|
+
function createHeatmapStyle(options) {
|
|
1031
|
+
const paint = {};
|
|
1032
|
+
if (options.weight !== void 0) {
|
|
1033
|
+
paint["heatmap-weight"] = options.weight;
|
|
1079
1034
|
}
|
|
1080
|
-
if (
|
|
1081
|
-
|
|
1082
|
-
return value.toFixed(6);
|
|
1083
|
-
}
|
|
1084
|
-
if (Math.abs(value) >= 1e3) {
|
|
1085
|
-
return value.toLocaleString();
|
|
1086
|
-
}
|
|
1087
|
-
if (value !== Math.floor(value)) {
|
|
1088
|
-
return value.toFixed(2);
|
|
1089
|
-
}
|
|
1090
|
-
return String(value);
|
|
1035
|
+
if (options.intensity !== void 0) {
|
|
1036
|
+
paint["heatmap-intensity"] = options.intensity;
|
|
1091
1037
|
}
|
|
1092
|
-
if (
|
|
1093
|
-
|
|
1038
|
+
if (options.radius !== void 0) {
|
|
1039
|
+
paint["heatmap-radius"] = options.radius;
|
|
1094
1040
|
}
|
|
1095
|
-
if (
|
|
1096
|
-
|
|
1041
|
+
if (options.opacity !== void 0) {
|
|
1042
|
+
paint["heatmap-opacity"] = options.opacity;
|
|
1097
1043
|
}
|
|
1098
|
-
if (
|
|
1099
|
-
|
|
1044
|
+
if (options.colorRamp) {
|
|
1045
|
+
const stops = ["interpolate", ["linear"], ["heatmap-density"]];
|
|
1046
|
+
options.colorRamp.forEach((color, index) => {
|
|
1047
|
+
stops.push(index / (options.colorRamp.length - 1));
|
|
1048
|
+
stops.push(color);
|
|
1049
|
+
});
|
|
1050
|
+
paint["heatmap-color"] = stops;
|
|
1100
1051
|
}
|
|
1101
|
-
return
|
|
1052
|
+
return { paint };
|
|
1102
1053
|
}
|
|
1103
|
-
function
|
|
1104
|
-
|
|
1105
|
-
const include = options?.include;
|
|
1106
|
-
const labelMap = options?.labelMap || {};
|
|
1107
|
-
const entries = Object.entries(properties).filter(([key]) => {
|
|
1108
|
-
if (include) {
|
|
1109
|
-
return include.includes(key);
|
|
1110
|
-
}
|
|
1111
|
-
return !exclude.includes(key) && !key.startsWith("_");
|
|
1112
|
-
}).map(([key, value]) => {
|
|
1113
|
-
const label = labelMap[key] || formatLabel(key);
|
|
1114
|
-
return `<strong>${label}:</strong> ${formatPropertyValue(value)}`;
|
|
1115
|
-
});
|
|
1116
|
-
return entries.join("<br>");
|
|
1054
|
+
function createHoverExpression(baseValue, hoverValue, featureStateName = "hover") {
|
|
1055
|
+
return ["case", ["boolean", ["feature-state", featureStateName], false], hoverValue, baseValue];
|
|
1117
1056
|
}
|
|
1118
|
-
function
|
|
1119
|
-
return
|
|
1057
|
+
function createSelectionExpression(baseValue, selectedValue, featureStateName = "selected") {
|
|
1058
|
+
return [
|
|
1059
|
+
"case",
|
|
1060
|
+
["boolean", ["feature-state", featureStateName], false],
|
|
1061
|
+
selectedValue,
|
|
1062
|
+
baseValue
|
|
1063
|
+
];
|
|
1120
1064
|
}
|
|
1121
|
-
function
|
|
1122
|
-
return
|
|
1065
|
+
function createInteractiveExpression(baseValue, hoverValue, selectedValue) {
|
|
1066
|
+
return [
|
|
1067
|
+
"case",
|
|
1068
|
+
["boolean", ["feature-state", "selected"], false],
|
|
1069
|
+
selectedValue,
|
|
1070
|
+
["boolean", ["feature-state", "hover"], false],
|
|
1071
|
+
hoverValue,
|
|
1072
|
+
baseValue
|
|
1073
|
+
];
|
|
1123
1074
|
}
|
|
1124
|
-
function
|
|
1125
|
-
|
|
1075
|
+
function createCategoricalColorExpression(property, colorMap, defaultColor) {
|
|
1076
|
+
const expression = ["match", ["get", property]];
|
|
1077
|
+
Object.entries(colorMap).forEach(([value, color]) => {
|
|
1078
|
+
expression.push(value, color);
|
|
1079
|
+
});
|
|
1080
|
+
expression.push(defaultColor);
|
|
1081
|
+
return expression;
|
|
1126
1082
|
}
|
|
1127
|
-
function
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
if (
|
|
1132
|
-
|
|
1133
|
-
}
|
|
1134
|
-
|
|
1135
|
-
if (typeof lng !== "number" || typeof lat !== "number") {
|
|
1136
|
-
return { valid: false, error: "Longitude and latitude must be numbers" };
|
|
1137
|
-
}
|
|
1138
|
-
if (!isFinite(lng) || !isFinite(lat)) {
|
|
1139
|
-
return { valid: false, error: "Coordinates must be finite numbers" };
|
|
1140
|
-
}
|
|
1141
|
-
if (lng < -180 || lng > 180) {
|
|
1142
|
-
return { valid: false, error: `Longitude ${lng} out of range [-180, 180]` };
|
|
1143
|
-
}
|
|
1144
|
-
if (lat < -90 || lat > 90) {
|
|
1145
|
-
return { valid: false, error: `Latitude ${lat} out of range [-90, 90]` };
|
|
1083
|
+
function createContinuousColorExpression(property, stops, interpolation = "linear") {
|
|
1084
|
+
const expression = ["interpolate"];
|
|
1085
|
+
if (interpolation === "linear") {
|
|
1086
|
+
expression.push(["linear"]);
|
|
1087
|
+
} else if (interpolation === "exponential") {
|
|
1088
|
+
expression.push(["exponential", 1]);
|
|
1089
|
+
} else {
|
|
1090
|
+
expression.push(interpolation);
|
|
1146
1091
|
}
|
|
1092
|
+
expression.push(["get", property]);
|
|
1093
|
+
stops.forEach(([value, color]) => {
|
|
1094
|
+
expression.push(value, color);
|
|
1095
|
+
});
|
|
1096
|
+
return expression;
|
|
1097
|
+
}
|
|
1098
|
+
function createZoomExpression(stops) {
|
|
1099
|
+
const expression = ["interpolate", ["linear"], ["zoom"]];
|
|
1100
|
+
stops.forEach(([zoom, value]) => {
|
|
1101
|
+
expression.push(zoom, value);
|
|
1102
|
+
});
|
|
1103
|
+
return expression;
|
|
1104
|
+
}
|
|
1105
|
+
function getHighlightStyle(theme = lightTheme) {
|
|
1106
|
+
const { highlight, highlightSecondary } = theme.colors;
|
|
1147
1107
|
return {
|
|
1148
|
-
|
|
1149
|
-
|
|
1108
|
+
fill: {
|
|
1109
|
+
"fill-color": createHoverExpression(highlightSecondary, highlight),
|
|
1110
|
+
"fill-opacity": createHoverExpression(0.3, 0.5),
|
|
1111
|
+
"fill-outline-color": highlight
|
|
1112
|
+
},
|
|
1113
|
+
line: {
|
|
1114
|
+
"line-color": createHoverExpression(highlightSecondary, highlight),
|
|
1115
|
+
"line-width": createHoverExpression(2, 3)
|
|
1116
|
+
},
|
|
1117
|
+
circle: {
|
|
1118
|
+
"circle-color": createHoverExpression(highlightSecondary, highlight),
|
|
1119
|
+
"circle-radius": createHoverExpression(6, 8),
|
|
1120
|
+
"circle-stroke-color": highlight,
|
|
1121
|
+
"circle-stroke-width": 2
|
|
1122
|
+
}
|
|
1150
1123
|
};
|
|
1151
1124
|
}
|
|
1152
|
-
function
|
|
1153
|
-
const
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1125
|
+
function getSelectionStyle(theme = lightTheme) {
|
|
1126
|
+
const { selection, highlight } = theme.colors;
|
|
1127
|
+
return {
|
|
1128
|
+
fill: {
|
|
1129
|
+
"fill-color": createInteractiveExpression(highlight, highlight, selection),
|
|
1130
|
+
"fill-opacity": createInteractiveExpression(0.2, 0.4, 0.6),
|
|
1131
|
+
"fill-outline-color": createInteractiveExpression(highlight, highlight, selection)
|
|
1132
|
+
},
|
|
1133
|
+
line: {
|
|
1134
|
+
"line-color": createInteractiveExpression(highlight, highlight, selection),
|
|
1135
|
+
"line-width": createInteractiveExpression(2, 3, 4)
|
|
1136
|
+
},
|
|
1137
|
+
circle: {
|
|
1138
|
+
"circle-color": createInteractiveExpression(highlight, highlight, selection),
|
|
1139
|
+
"circle-radius": createInteractiveExpression(6, 8, 10),
|
|
1140
|
+
"circle-stroke-color": createInteractiveExpression(highlight, highlight, selection),
|
|
1141
|
+
"circle-stroke-width": 2
|
|
1142
|
+
}
|
|
1143
|
+
};
|
|
1158
1144
|
}
|
|
1159
|
-
function
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
}
|
|
1167
|
-
return normalized;
|
|
1145
|
+
function createLotFillStyle(options) {
|
|
1146
|
+
const { defaultColor, hoverColor, selectedColor, opacity = 0.7 } = options;
|
|
1147
|
+
const fillColor = selectedColor ? createInteractiveExpression(defaultColor, hoverColor, selectedColor) : createHoverExpression(defaultColor, hoverColor);
|
|
1148
|
+
return {
|
|
1149
|
+
"fill-color": fillColor,
|
|
1150
|
+
"fill-opacity": opacity
|
|
1151
|
+
};
|
|
1168
1152
|
}
|
|
1169
|
-
function
|
|
1170
|
-
|
|
1171
|
-
|
|
1153
|
+
function createLotOutlineStyle(options) {
|
|
1154
|
+
const {
|
|
1155
|
+
defaultColor,
|
|
1156
|
+
hoverColor,
|
|
1157
|
+
selectedColor,
|
|
1158
|
+
defaultWidth = 1,
|
|
1159
|
+
hoverWidth = 2,
|
|
1160
|
+
selectedWidth = 3
|
|
1161
|
+
} = options;
|
|
1162
|
+
const lineColor = selectedColor ? createInteractiveExpression(defaultColor, hoverColor, selectedColor) : createHoverExpression(defaultColor, hoverColor);
|
|
1163
|
+
const lineWidth = selectedColor ? createInteractiveExpression(defaultWidth, hoverWidth, selectedWidth) : createHoverExpression(defaultWidth, hoverWidth);
|
|
1164
|
+
return {
|
|
1165
|
+
"line-color": lineColor,
|
|
1166
|
+
"line-width": lineWidth
|
|
1167
|
+
};
|
|
1172
1168
|
}
|
|
1173
|
-
function
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
return { valid: false, error: "Bounds must have exactly 2 elements [southwest, northeast]" };
|
|
1169
|
+
function createExtrusionHeightExpression(property, options = {}) {
|
|
1170
|
+
const { scale = 1, minHeight = 0, maxHeight, defaultHeight = 0 } = options;
|
|
1171
|
+
let heightExpr = ["coalesce", ["get", property], defaultHeight];
|
|
1172
|
+
if (scale !== 1) {
|
|
1173
|
+
heightExpr = ["*", heightExpr, scale];
|
|
1179
1174
|
}
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
return { valid: false, error: `Invalid southwest corner: ${swResult.error}` };
|
|
1175
|
+
if (minHeight > 0) {
|
|
1176
|
+
heightExpr = ["max", heightExpr, minHeight];
|
|
1183
1177
|
}
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
return { valid: false, error: `Invalid northeast corner: ${neResult.error}` };
|
|
1178
|
+
if (maxHeight !== void 0) {
|
|
1179
|
+
heightExpr = ["min", heightExpr, maxHeight];
|
|
1187
1180
|
}
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1181
|
+
return heightExpr;
|
|
1182
|
+
}
|
|
1183
|
+
function createStatusColorExpression(statusColors, defaultColor = "#888888") {
|
|
1184
|
+
return createCategoricalColorExpression("status", statusColors, defaultColor);
|
|
1185
|
+
}
|
|
1186
|
+
function createInteractiveStatusColorExpression(statusColors, options) {
|
|
1187
|
+
const { hoverColor, selectedColor, defaultColor = "#888888" } = options;
|
|
1188
|
+
const baseExpr = createCategoricalColorExpression("status", statusColors, defaultColor);
|
|
1189
|
+
if (selectedColor) {
|
|
1190
|
+
return [
|
|
1191
|
+
"case",
|
|
1192
|
+
["boolean", ["feature-state", "selected"], false],
|
|
1193
|
+
selectedColor,
|
|
1194
|
+
["boolean", ["feature-state", "hover"], false],
|
|
1195
|
+
hoverColor,
|
|
1196
|
+
baseExpr
|
|
1197
|
+
];
|
|
1195
1198
|
}
|
|
1196
|
-
return
|
|
1197
|
-
valid: true,
|
|
1198
|
-
normalized: [swResult.normalized, neResult.normalized]
|
|
1199
|
-
};
|
|
1199
|
+
return ["case", ["boolean", ["feature-state", "hover"], false], hoverColor, baseExpr];
|
|
1200
1200
|
}
|
|
1201
1201
|
|
|
1202
1202
|
// src/utils/bounds.ts
|
|
@@ -1299,13 +1299,19 @@ async function loadGeoJSON(url, options = {}) {
|
|
|
1299
1299
|
try {
|
|
1300
1300
|
const controller = new AbortController();
|
|
1301
1301
|
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
1302
|
+
const callerSignal = fetchOptions.signal;
|
|
1303
|
+
if (callerSignal) {
|
|
1304
|
+
if (callerSignal.aborted) controller.abort();
|
|
1305
|
+
else callerSignal.addEventListener("abort", () => controller.abort(), { once: true });
|
|
1306
|
+
}
|
|
1307
|
+
const headers = new Headers(fetchOptions.headers);
|
|
1308
|
+
if (!headers.has("Accept")) {
|
|
1309
|
+
headers.set("Accept", "application/geo+json, application/json");
|
|
1310
|
+
}
|
|
1302
1311
|
const response = await fetch(url, {
|
|
1303
1312
|
...fetchOptions,
|
|
1304
1313
|
signal: controller.signal,
|
|
1305
|
-
headers
|
|
1306
|
-
Accept: "application/geo+json, application/json",
|
|
1307
|
-
...fetchOptions.headers
|
|
1308
|
-
}
|
|
1314
|
+
headers
|
|
1309
1315
|
});
|
|
1310
1316
|
clearTimeout(timeoutId);
|
|
1311
1317
|
if (!response.ok) {
|
|
@@ -1334,6 +1340,9 @@ async function loadGeoJSON(url, options = {}) {
|
|
|
1334
1340
|
} catch (err) {
|
|
1335
1341
|
if (err instanceof Error) {
|
|
1336
1342
|
if (err.name === "AbortError") {
|
|
1343
|
+
if (options.fetchOptions?.signal?.aborted) {
|
|
1344
|
+
return { data: null, error: "Request aborted", success: false };
|
|
1345
|
+
}
|
|
1337
1346
|
return {
|
|
1338
1347
|
data: null,
|
|
1339
1348
|
error: `Request timeout after ${timeout}ms`,
|
|
@@ -2128,11 +2137,11 @@ function getSimplifiedFeaturesForZoom(lodData, zoom) {
|
|
|
2128
2137
|
return lodData.features;
|
|
2129
2138
|
}
|
|
2130
2139
|
let bestMatch = null;
|
|
2140
|
+
let bestMaxZoom = Infinity;
|
|
2131
2141
|
for (const [maxZoom, features] of lodData.simplifiedFeatures) {
|
|
2132
|
-
if (zoom < maxZoom) {
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
}
|
|
2142
|
+
if (zoom < maxZoom && maxZoom < bestMaxZoom) {
|
|
2143
|
+
bestMatch = features;
|
|
2144
|
+
bestMaxZoom = maxZoom;
|
|
2136
2145
|
}
|
|
2137
2146
|
}
|
|
2138
2147
|
return bestMatch ?? lodData.features;
|
|
@@ -2149,7 +2158,7 @@ function calculateZoomThresholds(groups, options = {}) {
|
|
|
2149
2158
|
const groupMaxZoom = Math.max(10, Math.min(14, 10 + Math.log2(groupCount)));
|
|
2150
2159
|
const subGroupMaxZoom = Math.max(
|
|
2151
2160
|
groupMaxZoom + minZoomGap,
|
|
2152
|
-
Math.min(16, groupMaxZoom + Math.log2(Math.max(1, subGroupCount / groupCount)))
|
|
2161
|
+
Math.min(16, groupMaxZoom + Math.log2(Math.max(1, subGroupCount / Math.max(1, groupCount))))
|
|
2153
2162
|
);
|
|
2154
2163
|
return {
|
|
2155
2164
|
groupMaxZoom: Math.round(groupMaxZoom),
|
|
@@ -2250,8 +2259,8 @@ function buildSpatialIndex(geojson, options = {}) {
|
|
|
2250
2259
|
};
|
|
2251
2260
|
}
|
|
2252
2261
|
const [[minLng, minLat], [maxLng, maxLat]] = bounds;
|
|
2253
|
-
const width = maxLng - minLng;
|
|
2254
|
-
const height = maxLat - minLat;
|
|
2262
|
+
const width = Math.max(maxLng - minLng, minCellSize);
|
|
2263
|
+
const height = Math.max(maxLat - minLat, minCellSize);
|
|
2255
2264
|
const aspectRatio = width / height;
|
|
2256
2265
|
let cols = Math.ceil(Math.sqrt(targetCells * aspectRatio));
|
|
2257
2266
|
let rows = Math.ceil(targetCells / cols);
|
|
@@ -2264,10 +2273,10 @@ function buildSpatialIndex(geojson, options = {}) {
|
|
|
2264
2273
|
const featureBounds = getFeatureBounds(feature);
|
|
2265
2274
|
if (!featureBounds) continue;
|
|
2266
2275
|
const [[fMinLng, fMinLat], [fMaxLng, fMaxLat]] = featureBounds;
|
|
2267
|
-
const minCol =
|
|
2268
|
-
const maxCol =
|
|
2269
|
-
const minRow =
|
|
2270
|
-
const maxRow =
|
|
2276
|
+
const minCol = cellIndex(fMinLng, minLng, cellWidth, cols);
|
|
2277
|
+
const maxCol = cellIndex(fMaxLng, minLng, cellWidth, cols);
|
|
2278
|
+
const minRow = cellIndex(fMinLat, minLat, cellHeight, rows);
|
|
2279
|
+
const maxRow = cellIndex(fMaxLat, minLat, cellHeight, rows);
|
|
2271
2280
|
for (let col = minCol; col <= maxCol; col++) {
|
|
2272
2281
|
for (let row = minRow; row <= maxRow; row++) {
|
|
2273
2282
|
const key = `${col},${row}`;
|
|
@@ -2288,6 +2297,9 @@ function buildSpatialIndex(geojson, options = {}) {
|
|
|
2288
2297
|
featureCount: geojson.features.length
|
|
2289
2298
|
};
|
|
2290
2299
|
}
|
|
2300
|
+
function cellIndex(value, origin, size, count) {
|
|
2301
|
+
return Math.min(count - 1, Math.max(0, Math.floor((value - origin) / size)));
|
|
2302
|
+
}
|
|
2291
2303
|
function getFeatureBounds(feature) {
|
|
2292
2304
|
const geometry = feature.geometry;
|
|
2293
2305
|
if (!geometry) return null;
|
|
@@ -2342,10 +2354,10 @@ function queryByBounds(index, queryBounds, options = {}) {
|
|
|
2342
2354
|
maxLng += actualBuffer;
|
|
2343
2355
|
maxLat += actualBuffer;
|
|
2344
2356
|
const [[idxMinLng, idxMinLat]] = index.bounds;
|
|
2345
|
-
const minCol =
|
|
2346
|
-
const maxCol =
|
|
2347
|
-
const minRow =
|
|
2348
|
-
const maxRow =
|
|
2357
|
+
const minCol = cellIndex(minLng, idxMinLng, index.cellWidth, index.cols);
|
|
2358
|
+
const maxCol = cellIndex(maxLng, idxMinLng, index.cellWidth, index.cols);
|
|
2359
|
+
const minRow = cellIndex(minLat, idxMinLat, index.cellHeight, index.rows);
|
|
2360
|
+
const maxRow = cellIndex(maxLat, idxMinLat, index.cellHeight, index.rows);
|
|
2349
2361
|
const seen = /* @__PURE__ */ new Set();
|
|
2350
2362
|
const features = [];
|
|
2351
2363
|
for (let col = minCol; col <= maxCol; col++) {
|
|
@@ -2405,10 +2417,10 @@ function queryByBoundsWithStats(index, queryBounds, options = {}) {
|
|
|
2405
2417
|
maxLng += actualBuffer;
|
|
2406
2418
|
maxLat += actualBuffer;
|
|
2407
2419
|
const [[idxMinLng, idxMinLat]] = index.bounds;
|
|
2408
|
-
const minCol =
|
|
2409
|
-
const maxCol =
|
|
2410
|
-
const minRow =
|
|
2411
|
-
const maxRow =
|
|
2420
|
+
const minCol = cellIndex(minLng, idxMinLng, index.cellWidth, index.cols);
|
|
2421
|
+
const maxCol = cellIndex(maxLng, idxMinLng, index.cellWidth, index.cols);
|
|
2422
|
+
const minRow = cellIndex(minLat, idxMinLat, index.cellHeight, index.rows);
|
|
2423
|
+
const maxRow = cellIndex(maxLat, idxMinLat, index.cellHeight, index.rows);
|
|
2412
2424
|
const seen = /* @__PURE__ */ new Set();
|
|
2413
2425
|
const features = [];
|
|
2414
2426
|
let cellsChecked = 0;
|
|
@@ -4430,8 +4442,6 @@ var PositioningCoordinator = class {
|
|
|
4430
4442
|
function createPositioningCoordinator() {
|
|
4431
4443
|
return new PositioningCoordinator();
|
|
4432
4444
|
}
|
|
4433
|
-
|
|
4434
|
-
// src/colors/realEstate.ts
|
|
4435
4445
|
var lotAvailabilityColors = {
|
|
4436
4446
|
Available: "#4caf50",
|
|
4437
4447
|
// Green - ready for sale
|
|
@@ -4471,13 +4481,11 @@ var lotSizeColors = {
|
|
|
4471
4481
|
// Gray
|
|
4472
4482
|
};
|
|
4473
4483
|
function getContrastTextColor(backgroundColor) {
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
return
|
|
4478
|
-
}
|
|
4479
|
-
const luminance = 0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2];
|
|
4480
|
-
return luminance > 0.179 ? "rgba(0, 0, 0, 0.87)" : "#ffffff";
|
|
4484
|
+
try {
|
|
4485
|
+
return contrast.getContrastTextColor(backgroundColor) === "#000000" ? "rgba(0, 0, 0, 0.87)" : "#ffffff";
|
|
4486
|
+
} catch {
|
|
4487
|
+
return "#ffffff";
|
|
4488
|
+
}
|
|
4481
4489
|
}
|
|
4482
4490
|
function getAvailabilityColor(availability) {
|
|
4483
4491
|
return lotAvailabilityColors[availability] ?? lotAvailabilityColors.Unknown;
|