@classic-homes/maps-core 0.2.6 → 0.2.8

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.
@@ -53,7 +53,7 @@ interface GeoJSONFeatureCollection<G extends GeoJSONGeometry = GeoJSONGeometry,
53
53
  /**
54
54
  * GeoJSON Geometry types
55
55
  */
56
- type GeoJSONGeometry = GeoJSONPoint | GeoJSONMultiPoint | GeoJSONLineString | GeoJSONMultiLineString | GeoJSONPolygon | GeoJSONMultiPolygon;
56
+ type GeoJSONGeometry = GeoJSONPoint | GeoJSONMultiPoint | GeoJSONLineString | GeoJSONMultiLineString | GeoJSONPolygon | GeoJSONMultiPolygon | GeoJSONGeometryCollection;
57
57
  interface GeoJSONPoint {
58
58
  type: 'Point';
59
59
  coordinates: LngLat;
@@ -78,6 +78,10 @@ interface GeoJSONMultiPolygon {
78
78
  type: 'MultiPolygon';
79
79
  coordinates: LngLat[][][];
80
80
  }
81
+ interface GeoJSONGeometryCollection {
82
+ type: 'GeometryCollection';
83
+ geometries: GeoJSONGeometry[];
84
+ }
81
85
  /**
82
86
  * Marker data for displaying points of interest
83
87
  */
@@ -138,4 +142,4 @@ interface ExtrusionData {
138
142
  */
139
143
  type MapSourceData = GeoJSONFeatureCollection | GeoJSONFeature | string | MarkerData[];
140
144
 
141
- export type { BoundsArray as B, ClusterConfig as C, ExtrusionData as E, GeoJSONFeatureCollection as G, HeatmapPoint as H, LngLat as L, MapBounds as M, GeoJSONFeature as a, MarkerData as b, GeoJSONPolygon as c, MapViewport as d, GeoJSONGeometry as e, GeoJSONPoint as f, GeoJSONMultiPoint as g, GeoJSONLineString as h, GeoJSONMultiLineString as i, GeoJSONMultiPolygon as j, MapSourceData as k };
145
+ export type { BoundsArray as B, ClusterConfig as C, ExtrusionData as E, GeoJSONFeatureCollection as G, HeatmapPoint as H, LngLat as L, MapBounds as M, GeoJSONFeature as a, MarkerData as b, GeoJSONPolygon as c, MapViewport as d, GeoJSONGeometry as e, GeoJSONPoint as f, GeoJSONMultiPoint as g, GeoJSONLineString as h, GeoJSONMultiLineString as i, GeoJSONMultiPolygon as j, MapSourceData as k, GeoJSONGeometryCollection as l };
@@ -53,7 +53,7 @@ interface GeoJSONFeatureCollection<G extends GeoJSONGeometry = GeoJSONGeometry,
53
53
  /**
54
54
  * GeoJSON Geometry types
55
55
  */
56
- type GeoJSONGeometry = GeoJSONPoint | GeoJSONMultiPoint | GeoJSONLineString | GeoJSONMultiLineString | GeoJSONPolygon | GeoJSONMultiPolygon;
56
+ type GeoJSONGeometry = GeoJSONPoint | GeoJSONMultiPoint | GeoJSONLineString | GeoJSONMultiLineString | GeoJSONPolygon | GeoJSONMultiPolygon | GeoJSONGeometryCollection;
57
57
  interface GeoJSONPoint {
58
58
  type: 'Point';
59
59
  coordinates: LngLat;
@@ -78,6 +78,10 @@ interface GeoJSONMultiPolygon {
78
78
  type: 'MultiPolygon';
79
79
  coordinates: LngLat[][][];
80
80
  }
81
+ interface GeoJSONGeometryCollection {
82
+ type: 'GeometryCollection';
83
+ geometries: GeoJSONGeometry[];
84
+ }
81
85
  /**
82
86
  * Marker data for displaying points of interest
83
87
  */
@@ -138,4 +142,4 @@ interface ExtrusionData {
138
142
  */
139
143
  type MapSourceData = GeoJSONFeatureCollection | GeoJSONFeature | string | MarkerData[];
140
144
 
141
- export type { BoundsArray as B, ClusterConfig as C, ExtrusionData as E, GeoJSONFeatureCollection as G, HeatmapPoint as H, LngLat as L, MapBounds as M, GeoJSONFeature as a, MarkerData as b, GeoJSONPolygon as c, MapViewport as d, GeoJSONGeometry as e, GeoJSONPoint as f, GeoJSONMultiPoint as g, GeoJSONLineString as h, GeoJSONMultiLineString as i, GeoJSONMultiPolygon as j, MapSourceData as k };
145
+ export type { BoundsArray as B, ClusterConfig as C, ExtrusionData as E, GeoJSONFeatureCollection as G, HeatmapPoint as H, LngLat as L, MapBounds as M, GeoJSONFeature as a, MarkerData as b, GeoJSONPolygon as c, MapViewport as d, GeoJSONGeometry as e, GeoJSONPoint as f, GeoJSONMultiPoint as g, GeoJSONLineString as h, GeoJSONMultiLineString as i, GeoJSONMultiPolygon as j, MapSourceData as k, GeoJSONGeometryCollection as l };
package/dist/index.cjs CHANGED
@@ -1118,6 +1118,86 @@ function formatFeatureProperties(properties, options) {
1118
1118
  function formatLabel(key) {
1119
1119
  return key.replace(/_/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2").replace(/\b\w/g, (char) => char.toUpperCase());
1120
1120
  }
1121
+ function isValidLongitude(lng) {
1122
+ return typeof lng === "number" && isFinite(lng) && lng >= -180 && lng <= 180;
1123
+ }
1124
+ function isValidLatitude(lat) {
1125
+ return typeof lat === "number" && isFinite(lat) && lat >= -90 && lat <= 90;
1126
+ }
1127
+ function validateCoordinates(coordinates) {
1128
+ if (!Array.isArray(coordinates)) {
1129
+ return { valid: false, error: "Coordinates must be an array" };
1130
+ }
1131
+ if (coordinates.length < 2) {
1132
+ return { valid: false, error: "Coordinates must have at least 2 elements [lng, lat]" };
1133
+ }
1134
+ const [lng, lat] = coordinates;
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]` };
1146
+ }
1147
+ return {
1148
+ valid: true,
1149
+ normalized: [lng, lat]
1150
+ };
1151
+ }
1152
+ function ensureValidCoordinates(coordinates) {
1153
+ const result = validateCoordinates(coordinates);
1154
+ if (!result.valid) {
1155
+ throw new Error(`Invalid coordinates: ${result.error}`);
1156
+ }
1157
+ return result.normalized;
1158
+ }
1159
+ function normalizeLongitude(lng) {
1160
+ if (!isFinite(lng)) return NaN;
1161
+ let normalized = lng % 360;
1162
+ if (normalized > 180) {
1163
+ normalized -= 360;
1164
+ } else if (normalized < -180) {
1165
+ normalized += 360;
1166
+ }
1167
+ return normalized;
1168
+ }
1169
+ function clampLatitude(lat) {
1170
+ if (!isFinite(lat)) return NaN;
1171
+ return Math.max(-90, Math.min(90, lat));
1172
+ }
1173
+ function validateBoundsArray(bounds) {
1174
+ if (!Array.isArray(bounds)) {
1175
+ return { valid: false, error: "Bounds must be an array" };
1176
+ }
1177
+ if (bounds.length !== 2) {
1178
+ return { valid: false, error: "Bounds must have exactly 2 elements [southwest, northeast]" };
1179
+ }
1180
+ const swResult = validateCoordinates(bounds[0]);
1181
+ if (!swResult.valid) {
1182
+ return { valid: false, error: `Invalid southwest corner: ${swResult.error}` };
1183
+ }
1184
+ const neResult = validateCoordinates(bounds[1]);
1185
+ if (!neResult.valid) {
1186
+ return { valid: false, error: `Invalid northeast corner: ${neResult.error}` };
1187
+ }
1188
+ const [, swLat] = swResult.normalized;
1189
+ const [, neLat] = neResult.normalized;
1190
+ if (swLat > neLat) {
1191
+ return {
1192
+ valid: false,
1193
+ error: `Southwest latitude (${swLat}) must be less than northeast latitude (${neLat})`
1194
+ };
1195
+ }
1196
+ return {
1197
+ valid: true,
1198
+ normalized: [swResult.normalized, neResult.normalized]
1199
+ };
1200
+ }
1121
1201
 
1122
1202
  // src/utils/bounds.ts
1123
1203
  function calculateBounds(geojson) {
@@ -1370,13 +1450,15 @@ function validateGeometry(geometry, prefix = "") {
1370
1450
  errors.push(`${p}: unknown geometry type "${geometry.type}"`);
1371
1451
  return errors;
1372
1452
  }
1373
- if (!geometry.coordinates) {
1374
- errors.push(`${p}: missing coordinates`);
1375
- return errors;
1376
- }
1377
- if (!Array.isArray(geometry.coordinates)) {
1378
- errors.push(`${p}: coordinates must be an array`);
1379
- return errors;
1453
+ if (geometry.type !== "GeometryCollection") {
1454
+ if (!("coordinates" in geometry) || geometry.coordinates === void 0) {
1455
+ errors.push(`${p}: missing coordinates`);
1456
+ return errors;
1457
+ }
1458
+ if (!Array.isArray(geometry.coordinates)) {
1459
+ errors.push(`${p}: coordinates must be an array`);
1460
+ return errors;
1461
+ }
1380
1462
  }
1381
1463
  switch (geometry.type) {
1382
1464
  case "Point":
@@ -1401,6 +1483,20 @@ function validateGeometry(geometry, prefix = "") {
1401
1483
  errors.push(`${p}: MultiPolygon must have at least one polygon`);
1402
1484
  }
1403
1485
  break;
1486
+ case "GeometryCollection": {
1487
+ const geomCollection = geometry;
1488
+ if (!("geometries" in geometry)) {
1489
+ errors.push(`${p}: GeometryCollection must have "geometries" array`);
1490
+ } else if (!Array.isArray(geomCollection.geometries)) {
1491
+ errors.push(`${p}: GeometryCollection "geometries" must be an array`);
1492
+ } else {
1493
+ geomCollection.geometries.forEach((geom, idx) => {
1494
+ const nestedErrors = validateGeometry(geom, `${p}.geometries[${idx}]`);
1495
+ errors.push(...nestedErrors);
1496
+ });
1497
+ }
1498
+ break;
1499
+ }
1404
1500
  }
1405
1501
  return errors;
1406
1502
  }
@@ -1550,6 +1646,83 @@ async function expandClusterToBounds(map, sourceId, clusterId, options = {}) {
1550
1646
  ...maxZoom !== void 0 && { maxZoom }
1551
1647
  });
1552
1648
  }
1649
+ function createClusterStyles(options = {}) {
1650
+ const {
1651
+ smallColor = "#51bbd6",
1652
+ mediumColor = "#f1f075",
1653
+ largeColor = "#f28cb1",
1654
+ mediumThreshold = 100,
1655
+ largeThreshold = 750,
1656
+ smallRadius = 20,
1657
+ mediumRadius = 30,
1658
+ largeRadius = 40,
1659
+ strokeColor = "#fff",
1660
+ strokeWidth = 2,
1661
+ opacity = 0.85
1662
+ } = options.circle ?? {};
1663
+ const {
1664
+ textColor = "#333",
1665
+ textSize = 12,
1666
+ fontStack = ["Open Sans Bold", "Arial Unicode MS Bold"],
1667
+ abbreviated = false
1668
+ } = options.text ?? {};
1669
+ const {
1670
+ color: pointColor = "#11b4da",
1671
+ radius: pointRadius = 8,
1672
+ strokeColor: pointStrokeColor = "#fff",
1673
+ strokeWidth: pointStrokeWidth = 1
1674
+ } = options.unclusteredPoint ?? {};
1675
+ return {
1676
+ clusterCirclePaint: {
1677
+ "circle-color": [
1678
+ "step",
1679
+ ["get", "point_count"],
1680
+ smallColor,
1681
+ mediumThreshold,
1682
+ mediumColor,
1683
+ largeThreshold,
1684
+ largeColor
1685
+ ],
1686
+ "circle-radius": [
1687
+ "step",
1688
+ ["get", "point_count"],
1689
+ smallRadius,
1690
+ mediumThreshold,
1691
+ mediumRadius,
1692
+ largeThreshold,
1693
+ largeRadius
1694
+ ],
1695
+ "circle-stroke-color": strokeColor,
1696
+ "circle-stroke-width": strokeWidth,
1697
+ "circle-opacity": opacity
1698
+ },
1699
+ clusterTextPaint: {
1700
+ "text-color": textColor
1701
+ },
1702
+ clusterTextLayout: {
1703
+ "text-field": abbreviated ? ["get", "point_count_abbreviated"] : ["to-string", ["get", "point_count"]],
1704
+ "text-font": fontStack,
1705
+ "text-size": textSize,
1706
+ "text-allow-overlap": true
1707
+ },
1708
+ unclusteredPointPaint: {
1709
+ "circle-color": pointColor,
1710
+ "circle-radius": pointRadius,
1711
+ "circle-stroke-color": pointStrokeColor,
1712
+ "circle-stroke-width": pointStrokeWidth
1713
+ },
1714
+ clusterFilter: ["has", "point_count"],
1715
+ unclusteredFilter: ["!", ["has", "point_count"]]
1716
+ };
1717
+ }
1718
+ function createClusterCirclePaint(options = {}) {
1719
+ const styles = createClusterStyles({ circle: options });
1720
+ return styles.clusterCirclePaint;
1721
+ }
1722
+ function createClusterTextLayout(options = {}) {
1723
+ const styles = createClusterStyles({ text: options });
1724
+ return styles.clusterTextLayout;
1725
+ }
1553
1726
 
1554
1727
  // src/utils/lod.ts
1555
1728
  function groupFeaturesByProperty(geojson, options) {
@@ -4421,12 +4594,16 @@ exports.buildSpatialIndex = buildSpatialIndex;
4421
4594
  exports.calculateBounds = calculateBounds;
4422
4595
  exports.calculateCentroid = calculateCentroid;
4423
4596
  exports.calculateZoomThresholds = calculateZoomThresholds;
4597
+ exports.clampLatitude = clampLatitude;
4424
4598
  exports.clusterColorExpression = clusterColorExpression;
4425
4599
  exports.clusterColors = clusterColors;
4426
4600
  exports.combineBounds = combineBounds;
4427
4601
  exports.countFeaturesByType = countFeaturesByType;
4428
4602
  exports.createCategoricalColorExpression = createCategoricalColorExpression;
4429
4603
  exports.createCircleStyle = createCircleStyle;
4604
+ exports.createClusterCirclePaint = createClusterCirclePaint;
4605
+ exports.createClusterStyles = createClusterStyles;
4606
+ exports.createClusterTextLayout = createClusterTextLayout;
4430
4607
  exports.createContinuousColorExpression = createContinuousColorExpression;
4431
4608
  exports.createDynamicLODManager = createDynamicLODManager;
4432
4609
  exports.createExtrusionHeightExpression = createExtrusionHeightExpression;
@@ -4455,6 +4632,7 @@ exports.darkBasicStyle = darkBasicStyle;
4455
4632
  exports.darkTheme = darkTheme;
4456
4633
  exports.decimalToDMS = decimalToDMS;
4457
4634
  exports.deepEqual = deepEqual;
4635
+ exports.ensureValidCoordinates = ensureValidCoordinates;
4458
4636
  exports.expandCluster = expandCluster;
4459
4637
  exports.expandClusterToBounds = expandClusterToBounds;
4460
4638
  exports.extendBounds = extendBounds;
@@ -4522,6 +4700,8 @@ exports.inventoryStatusColors = inventoryStatusColors;
4522
4700
  exports.isAnyLayerLoading = isAnyLayerLoading;
4523
4701
  exports.isClusterFeature = isClusterFeature;
4524
4702
  exports.isValidBounds = isValidBounds;
4703
+ exports.isValidLatitude = isValidLatitude;
4704
+ exports.isValidLongitude = isValidLongitude;
4525
4705
  exports.lightBasicStyle = lightBasicStyle;
4526
4706
  exports.lightTheme = lightTheme;
4527
4707
  exports.loadGeoJSON = loadGeoJSON;
@@ -4530,6 +4710,7 @@ exports.lotAvailabilityColors = lotAvailabilityColors;
4530
4710
  exports.lotSizeColorExpression = lotSizeColorExpression;
4531
4711
  exports.lotSizeColors = lotSizeColors;
4532
4712
  exports.nonMatchedColor = nonMatchedColor;
4713
+ exports.normalizeLongitude = normalizeLongitude;
4533
4714
  exports.paintPropsEqual = paintPropsEqual;
4534
4715
  exports.queryByBounds = queryByBounds;
4535
4716
  exports.queryByBoundsWithStats = queryByBoundsWithStats;
@@ -4553,5 +4734,7 @@ exports.simplifyFeatureCollectionWithStats = simplifyFeatureCollectionWithStats;
4553
4734
  exports.simplifyPolygon = simplifyPolygon;
4554
4735
  exports.toggleLayerVisibility = toggleLayerVisibility;
4555
4736
  exports.updateLayerState = updateLayerState;
4737
+ exports.validateBoundsArray = validateBoundsArray;
4738
+ exports.validateCoordinates = validateCoordinates;
4556
4739
  exports.validateGeoJSON = validateGeoJSON;
4557
4740
  exports.zoomToScale = zoomToScale;