@biodiv-platform/naksha-maplibre-layers 5.0.2 → 5.0.4
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/esm/index.js +257 -25
- package/dist/index.d.ts +1 -0
- package/dist/index.js +257 -25
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -251,27 +251,27 @@ var processRectangles = function(data, level) {
|
|
|
251
251
|
counts.forEach((count, hash) => {
|
|
252
252
|
const bboxStart = GeoHash.decodeGeoHash(hash);
|
|
253
253
|
const bboxEnd = GeoHash.decodeGeoHash(bins.get(hash));
|
|
254
|
-
const
|
|
254
|
+
const feature2 = new BoundingBox({
|
|
255
255
|
minlat: bboxStart.latitude[0],
|
|
256
256
|
minlon: bboxStart.longitude[0],
|
|
257
257
|
maxlat: bboxEnd.latitude[1],
|
|
258
258
|
maxlon: bboxEnd.longitude[1]
|
|
259
259
|
}).toGeoJSON();
|
|
260
|
-
features.push(__spreadProps(__spreadValues({},
|
|
260
|
+
features.push(__spreadProps(__spreadValues({}, feature2), { properties: { count, [PROPERTY_ID]: hash } }));
|
|
261
261
|
});
|
|
262
262
|
return features;
|
|
263
263
|
};
|
|
264
264
|
var processSquares = (data) => {
|
|
265
265
|
const features = [];
|
|
266
266
|
for (const [hash, count] of Object.entries(data)) {
|
|
267
|
-
const
|
|
268
|
-
const
|
|
269
|
-
minlat:
|
|
270
|
-
minlon:
|
|
271
|
-
maxlat:
|
|
272
|
-
maxlon:
|
|
267
|
+
const bbox2 = GeoHash.decodeGeoHash(hash);
|
|
268
|
+
const feature2 = new BoundingBox({
|
|
269
|
+
minlat: bbox2.latitude[0],
|
|
270
|
+
minlon: bbox2.longitude[0],
|
|
271
|
+
maxlat: bbox2.latitude[1],
|
|
272
|
+
maxlon: bbox2.longitude[1]
|
|
273
273
|
}).toGeoJSON();
|
|
274
|
-
features.push(__spreadProps(__spreadValues({},
|
|
274
|
+
features.push(__spreadProps(__spreadValues({}, feature2), { properties: { count, [PROPERTY_ID]: hash } }));
|
|
275
275
|
}
|
|
276
276
|
return features;
|
|
277
277
|
};
|
|
@@ -482,13 +482,18 @@ var LayersContext = createContext(
|
|
|
482
482
|
{}
|
|
483
483
|
);
|
|
484
484
|
var LayersProvider = ({ mp: _mp, children }) => {
|
|
485
|
-
var _a;
|
|
485
|
+
var _a, _b;
|
|
486
486
|
const [mp, setMP] = useState(_mp);
|
|
487
487
|
const { mapl } = useMap();
|
|
488
488
|
const [queryTerm, setQueryTerm] = useState("");
|
|
489
489
|
const queryTermDebounced = useDebounce(queryTerm, 500);
|
|
490
490
|
const styles = mp.mapStyles && mp.mapStyles.length > 0 ? mp.mapStyles : defaultMapStyles;
|
|
491
|
-
const [mapStyle, setMapStyle] = useState(
|
|
491
|
+
const [mapStyle, setMapStyle] = useState(
|
|
492
|
+
(_a = styles[(mp == null ? void 0 : mp.mapStyle) || 0]) == null ? void 0 : _a.style
|
|
493
|
+
);
|
|
494
|
+
const [maxZoom, setMaxZoom] = useState(
|
|
495
|
+
(_b = styles[(mp == null ? void 0 : mp.mapStyle) || 0]) == null ? void 0 : _b.maxZoom
|
|
496
|
+
);
|
|
492
497
|
const [selectionStyle, setSelectionStyle] = useState(
|
|
493
498
|
SELECTION_STYLE.TOP
|
|
494
499
|
);
|
|
@@ -549,7 +554,7 @@ var LayersProvider = ({ mp: _mp, children }) => {
|
|
|
549
554
|
toggleVectorLayer(layerIndex, styleIndex, false);
|
|
550
555
|
});
|
|
551
556
|
const onMapHover = (e) => __async(void 0, null, function* () {
|
|
552
|
-
var _a2,
|
|
557
|
+
var _a2, _b2, _c, _d;
|
|
553
558
|
if (!selectedLayerIds.length || !mapl)
|
|
554
559
|
return;
|
|
555
560
|
try {
|
|
@@ -558,14 +563,14 @@ var LayersProvider = ({ mp: _mp, children }) => {
|
|
|
558
563
|
layers: [lastLayerId]
|
|
559
564
|
});
|
|
560
565
|
if (feats.length) {
|
|
561
|
-
const fId = ((_a2 = feats[0]) == null ? void 0 : _a2.id) || ((_c = (
|
|
566
|
+
const fId = ((_a2 = feats[0]) == null ? void 0 : _a2.id) || ((_c = (_b2 = feats[0]) == null ? void 0 : _b2.properties) == null ? void 0 : _c[PROPERTY_ID]);
|
|
562
567
|
if (fId === (hoverFeatures == null ? void 0 : hoverFeatures.id))
|
|
563
568
|
return;
|
|
564
569
|
const layer = layers[getLayerIndexById(lastLayerId)];
|
|
565
570
|
const hoverProperties = (_d = layer == null ? void 0 : layer.data) == null ? void 0 : _d.summaryColumn.map((sc) => {
|
|
566
|
-
var _a3,
|
|
571
|
+
var _a3, _b3, _c2;
|
|
567
572
|
return [
|
|
568
|
-
((
|
|
573
|
+
((_b3 = (_a3 = layer.data) == null ? void 0 : _a3.propertyMap) == null ? void 0 : _b3[sc]) || sc,
|
|
569
574
|
(_c2 = feats[0].properties) == null ? void 0 : _c2[sc]
|
|
570
575
|
];
|
|
571
576
|
});
|
|
@@ -586,7 +591,7 @@ var LayersProvider = ({ mp: _mp, children }) => {
|
|
|
586
591
|
styleIndex = 0,
|
|
587
592
|
focus = true
|
|
588
593
|
}) {
|
|
589
|
-
var _a2;
|
|
594
|
+
var _a2, _b2;
|
|
590
595
|
if (!add) {
|
|
591
596
|
setSelectedLayerIds(
|
|
592
597
|
selectedLayerIds.filter((_lyrId) => layerId !== _lyrId)
|
|
@@ -595,11 +600,26 @@ var LayersProvider = ({ mp: _mp, children }) => {
|
|
|
595
600
|
}
|
|
596
601
|
const layerIndex = getLayerIndexById(layerId);
|
|
597
602
|
const sourceType = (_a2 = layers[layerIndex]) == null ? void 0 : _a2.source.type;
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
+
if (sourceType === "grid") {
|
|
604
|
+
setSelectedLayerIds((_slIds) => [
|
|
605
|
+
layerId,
|
|
606
|
+
..._slIds.filter((lid) => lid !== layerId)
|
|
607
|
+
]);
|
|
608
|
+
if (focus && ((_b2 = layers[layerIndex]) == null ? void 0 : _b2.bbox)) {
|
|
609
|
+
setTimeout(() => {
|
|
610
|
+
mapl == null ? void 0 : mapl.fitBounds(layers[layerIndex].bbox, {
|
|
611
|
+
padding: 40,
|
|
612
|
+
duration: 1e3
|
|
613
|
+
});
|
|
614
|
+
}, 100);
|
|
615
|
+
}
|
|
616
|
+
} else {
|
|
617
|
+
yield toggleVectorLayer(layerIndex, styleIndex, focus);
|
|
618
|
+
setSelectedLayerIds((_slIds) => [
|
|
619
|
+
layerId,
|
|
620
|
+
..._slIds.filter((lid) => lid !== layerId)
|
|
621
|
+
]);
|
|
622
|
+
}
|
|
603
623
|
});
|
|
604
624
|
const clearAllLayers = () => __async(void 0, null, function* () {
|
|
605
625
|
return setSelectedLayerIds([]);
|
|
@@ -689,6 +709,8 @@ var LayersProvider = ({ mp: _mp, children }) => {
|
|
|
689
709
|
mapStyle,
|
|
690
710
|
featuresAtLatLng,
|
|
691
711
|
setMapStyle,
|
|
712
|
+
maxZoom,
|
|
713
|
+
setMaxZoom,
|
|
692
714
|
mapStyles: styles,
|
|
693
715
|
all: layers,
|
|
694
716
|
setAll: setLayers,
|
|
@@ -1954,7 +1976,13 @@ import { jsx as jsx22, jsxs as jsxs14 } from "react/jsx-runtime";
|
|
|
1954
1976
|
function SettingsTabPanel() {
|
|
1955
1977
|
const { layer } = useLayers();
|
|
1956
1978
|
const { t } = useT9();
|
|
1957
|
-
const handleOnStyleChange = (e) =>
|
|
1979
|
+
const handleOnStyleChange = (e) => {
|
|
1980
|
+
var _a;
|
|
1981
|
+
layer.setMapStyle(e.target.value);
|
|
1982
|
+
layer.setMaxZoom(
|
|
1983
|
+
(_a = layer.mapStyles.find((ms) => ms.style === e.target.value)) == null ? void 0 : _a.maxZoom
|
|
1984
|
+
);
|
|
1985
|
+
};
|
|
1958
1986
|
return /* @__PURE__ */ jsxs14("div", {
|
|
1959
1987
|
className: tw17`w-full p-4 flex flex-col gap-4`,
|
|
1960
1988
|
children: [
|
|
@@ -2057,6 +2085,170 @@ function Sidebar() {
|
|
|
2057
2085
|
// src/components/map/layers/index.tsx
|
|
2058
2086
|
import { useMap as useMap4 } from "react-map-gl/maplibre";
|
|
2059
2087
|
|
|
2088
|
+
// ../../node_modules/@turf/helpers/dist/es/index.js
|
|
2089
|
+
var earthRadius = 63710088e-1;
|
|
2090
|
+
var factors = {
|
|
2091
|
+
centimeters: earthRadius * 100,
|
|
2092
|
+
centimetres: earthRadius * 100,
|
|
2093
|
+
degrees: earthRadius / 111325,
|
|
2094
|
+
feet: earthRadius * 3.28084,
|
|
2095
|
+
inches: earthRadius * 39.37,
|
|
2096
|
+
kilometers: earthRadius / 1e3,
|
|
2097
|
+
kilometres: earthRadius / 1e3,
|
|
2098
|
+
meters: earthRadius,
|
|
2099
|
+
metres: earthRadius,
|
|
2100
|
+
miles: earthRadius / 1609.344,
|
|
2101
|
+
millimeters: earthRadius * 1e3,
|
|
2102
|
+
millimetres: earthRadius * 1e3,
|
|
2103
|
+
nauticalmiles: earthRadius / 1852,
|
|
2104
|
+
radians: 1,
|
|
2105
|
+
yards: earthRadius * 1.0936
|
|
2106
|
+
};
|
|
2107
|
+
var unitsFactors = {
|
|
2108
|
+
centimeters: 100,
|
|
2109
|
+
centimetres: 100,
|
|
2110
|
+
degrees: 1 / 111325,
|
|
2111
|
+
feet: 3.28084,
|
|
2112
|
+
inches: 39.37,
|
|
2113
|
+
kilometers: 1 / 1e3,
|
|
2114
|
+
kilometres: 1 / 1e3,
|
|
2115
|
+
meters: 1,
|
|
2116
|
+
metres: 1,
|
|
2117
|
+
miles: 1 / 1609.344,
|
|
2118
|
+
millimeters: 1e3,
|
|
2119
|
+
millimetres: 1e3,
|
|
2120
|
+
nauticalmiles: 1 / 1852,
|
|
2121
|
+
radians: 1 / earthRadius,
|
|
2122
|
+
yards: 1.0936133
|
|
2123
|
+
};
|
|
2124
|
+
|
|
2125
|
+
// ../../node_modules/@turf/meta/dist/es/index.js
|
|
2126
|
+
function coordEach(geojson, callback, excludeWrapCoord) {
|
|
2127
|
+
if (geojson === null)
|
|
2128
|
+
return;
|
|
2129
|
+
var j, k, l, geometry, stopG, coords, geometryMaybeCollection, wrapShrink = 0, coordIndex = 0, isGeometryCollection, type = geojson.type, isFeatureCollection = type === "FeatureCollection", isFeature = type === "Feature", stop = isFeatureCollection ? geojson.features.length : 1;
|
|
2130
|
+
for (var featureIndex = 0; featureIndex < stop; featureIndex++) {
|
|
2131
|
+
geometryMaybeCollection = isFeatureCollection ? geojson.features[featureIndex].geometry : isFeature ? geojson.geometry : geojson;
|
|
2132
|
+
isGeometryCollection = geometryMaybeCollection ? geometryMaybeCollection.type === "GeometryCollection" : false;
|
|
2133
|
+
stopG = isGeometryCollection ? geometryMaybeCollection.geometries.length : 1;
|
|
2134
|
+
for (var geomIndex = 0; geomIndex < stopG; geomIndex++) {
|
|
2135
|
+
var multiFeatureIndex = 0;
|
|
2136
|
+
var geometryIndex = 0;
|
|
2137
|
+
geometry = isGeometryCollection ? geometryMaybeCollection.geometries[geomIndex] : geometryMaybeCollection;
|
|
2138
|
+
if (geometry === null)
|
|
2139
|
+
continue;
|
|
2140
|
+
coords = geometry.coordinates;
|
|
2141
|
+
var geomType = geometry.type;
|
|
2142
|
+
wrapShrink = excludeWrapCoord && (geomType === "Polygon" || geomType === "MultiPolygon") ? 1 : 0;
|
|
2143
|
+
switch (geomType) {
|
|
2144
|
+
case null:
|
|
2145
|
+
break;
|
|
2146
|
+
case "Point":
|
|
2147
|
+
if (callback(
|
|
2148
|
+
coords,
|
|
2149
|
+
coordIndex,
|
|
2150
|
+
featureIndex,
|
|
2151
|
+
multiFeatureIndex,
|
|
2152
|
+
geometryIndex
|
|
2153
|
+
) === false)
|
|
2154
|
+
return false;
|
|
2155
|
+
coordIndex++;
|
|
2156
|
+
multiFeatureIndex++;
|
|
2157
|
+
break;
|
|
2158
|
+
case "LineString":
|
|
2159
|
+
case "MultiPoint":
|
|
2160
|
+
for (j = 0; j < coords.length; j++) {
|
|
2161
|
+
if (callback(
|
|
2162
|
+
coords[j],
|
|
2163
|
+
coordIndex,
|
|
2164
|
+
featureIndex,
|
|
2165
|
+
multiFeatureIndex,
|
|
2166
|
+
geometryIndex
|
|
2167
|
+
) === false)
|
|
2168
|
+
return false;
|
|
2169
|
+
coordIndex++;
|
|
2170
|
+
if (geomType === "MultiPoint")
|
|
2171
|
+
multiFeatureIndex++;
|
|
2172
|
+
}
|
|
2173
|
+
if (geomType === "LineString")
|
|
2174
|
+
multiFeatureIndex++;
|
|
2175
|
+
break;
|
|
2176
|
+
case "Polygon":
|
|
2177
|
+
case "MultiLineString":
|
|
2178
|
+
for (j = 0; j < coords.length; j++) {
|
|
2179
|
+
for (k = 0; k < coords[j].length - wrapShrink; k++) {
|
|
2180
|
+
if (callback(
|
|
2181
|
+
coords[j][k],
|
|
2182
|
+
coordIndex,
|
|
2183
|
+
featureIndex,
|
|
2184
|
+
multiFeatureIndex,
|
|
2185
|
+
geometryIndex
|
|
2186
|
+
) === false)
|
|
2187
|
+
return false;
|
|
2188
|
+
coordIndex++;
|
|
2189
|
+
}
|
|
2190
|
+
if (geomType === "MultiLineString")
|
|
2191
|
+
multiFeatureIndex++;
|
|
2192
|
+
if (geomType === "Polygon")
|
|
2193
|
+
geometryIndex++;
|
|
2194
|
+
}
|
|
2195
|
+
if (geomType === "Polygon")
|
|
2196
|
+
multiFeatureIndex++;
|
|
2197
|
+
break;
|
|
2198
|
+
case "MultiPolygon":
|
|
2199
|
+
for (j = 0; j < coords.length; j++) {
|
|
2200
|
+
geometryIndex = 0;
|
|
2201
|
+
for (k = 0; k < coords[j].length; k++) {
|
|
2202
|
+
for (l = 0; l < coords[j][k].length - wrapShrink; l++) {
|
|
2203
|
+
if (callback(
|
|
2204
|
+
coords[j][k][l],
|
|
2205
|
+
coordIndex,
|
|
2206
|
+
featureIndex,
|
|
2207
|
+
multiFeatureIndex,
|
|
2208
|
+
geometryIndex
|
|
2209
|
+
) === false)
|
|
2210
|
+
return false;
|
|
2211
|
+
coordIndex++;
|
|
2212
|
+
}
|
|
2213
|
+
geometryIndex++;
|
|
2214
|
+
}
|
|
2215
|
+
multiFeatureIndex++;
|
|
2216
|
+
}
|
|
2217
|
+
break;
|
|
2218
|
+
case "GeometryCollection":
|
|
2219
|
+
for (j = 0; j < geometry.geometries.length; j++)
|
|
2220
|
+
if (coordEach(geometry.geometries[j], callback, excludeWrapCoord) === false)
|
|
2221
|
+
return false;
|
|
2222
|
+
break;
|
|
2223
|
+
default:
|
|
2224
|
+
throw new Error("Unknown Geometry Type");
|
|
2225
|
+
}
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
|
|
2230
|
+
// ../../node_modules/@turf/bbox/dist/es/index.js
|
|
2231
|
+
function bbox(geojson) {
|
|
2232
|
+
var result = [Infinity, Infinity, -Infinity, -Infinity];
|
|
2233
|
+
coordEach(geojson, function(coord) {
|
|
2234
|
+
if (result[0] > coord[0]) {
|
|
2235
|
+
result[0] = coord[0];
|
|
2236
|
+
}
|
|
2237
|
+
if (result[1] > coord[1]) {
|
|
2238
|
+
result[1] = coord[1];
|
|
2239
|
+
}
|
|
2240
|
+
if (result[2] < coord[0]) {
|
|
2241
|
+
result[2] = coord[0];
|
|
2242
|
+
}
|
|
2243
|
+
if (result[3] < coord[1]) {
|
|
2244
|
+
result[3] = coord[1];
|
|
2245
|
+
}
|
|
2246
|
+
});
|
|
2247
|
+
return result;
|
|
2248
|
+
}
|
|
2249
|
+
bbox["default"] = bbox;
|
|
2250
|
+
var es_default = bbox;
|
|
2251
|
+
|
|
2060
2252
|
// src/components/map/layers/grid/index.tsx
|
|
2061
2253
|
import { useEffect as useEffect4, useState as useState9 } from "react";
|
|
2062
2254
|
import { Layer, Source, useMap as useMap3 } from "react-map-gl/maplibre";
|
|
@@ -2068,7 +2260,9 @@ function GridLayer({
|
|
|
2068
2260
|
const { layer } = useLayers();
|
|
2069
2261
|
const { mapl } = useMap3();
|
|
2070
2262
|
const [layerData, setLayerData] = useState9({ geojson: {}, paint: {} });
|
|
2071
|
-
const
|
|
2263
|
+
const isSelected = layer.selectedIds.includes(data.id);
|
|
2264
|
+
const isLastSelected = layer.selectedIds[0] === data.id;
|
|
2265
|
+
const fetchGridData = (shouldFitBounds = false) => __async(this, null, function* () {
|
|
2072
2266
|
const { success, geojson, paint: paint2, stops, squareSize } = yield getGridLayerData(
|
|
2073
2267
|
data.source.fetcher,
|
|
2074
2268
|
mapl == null ? void 0 : mapl.getBounds(),
|
|
@@ -2076,14 +2270,50 @@ function GridLayer({
|
|
|
2076
2270
|
);
|
|
2077
2271
|
if (success) {
|
|
2078
2272
|
setLayerData({ geojson, paint: paint2 });
|
|
2273
|
+
if (shouldFitBounds && isLastSelected && data.zoomToFit) {
|
|
2274
|
+
try {
|
|
2275
|
+
const [minLon, minLat, maxLon, maxLat] = es_default(geojson);
|
|
2276
|
+
mapl == null ? void 0 : mapl.fitBounds(
|
|
2277
|
+
[
|
|
2278
|
+
[minLon, minLat],
|
|
2279
|
+
[maxLon, maxLat]
|
|
2280
|
+
],
|
|
2281
|
+
{ padding: 40, animate: true }
|
|
2282
|
+
);
|
|
2283
|
+
} catch (e) {
|
|
2284
|
+
console.warn("Failed to compute bbox", e);
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2079
2287
|
layer.setGridLegends({
|
|
2080
2288
|
[data.id]: { stops, squareSize }
|
|
2081
2289
|
});
|
|
2082
2290
|
}
|
|
2083
2291
|
});
|
|
2084
2292
|
useEffect4(() => {
|
|
2085
|
-
|
|
2086
|
-
|
|
2293
|
+
if (isSelected && isLastSelected) {
|
|
2294
|
+
fetchGridData(true);
|
|
2295
|
+
} else if (isSelected) {
|
|
2296
|
+
fetchGridData(false);
|
|
2297
|
+
}
|
|
2298
|
+
}, [isSelected, isLastSelected]);
|
|
2299
|
+
useEffect4(() => {
|
|
2300
|
+
if (!isSelected || !mapl)
|
|
2301
|
+
return;
|
|
2302
|
+
const handleIdle = () => fetchGridData(false);
|
|
2303
|
+
mapl.on("idle", handleIdle);
|
|
2304
|
+
return () => {
|
|
2305
|
+
mapl.off("idle", handleIdle);
|
|
2306
|
+
};
|
|
2307
|
+
}, [isSelected, mapl]);
|
|
2308
|
+
useEffect4(() => {
|
|
2309
|
+
return () => {
|
|
2310
|
+
layer.setGridLegends((prev) => {
|
|
2311
|
+
const newLegends = __spreadValues({}, prev);
|
|
2312
|
+
delete newLegends[data.id];
|
|
2313
|
+
return newLegends;
|
|
2314
|
+
});
|
|
2315
|
+
};
|
|
2316
|
+
}, [data.id]);
|
|
2087
2317
|
return /* @__PURE__ */ jsx25(Source, {
|
|
2088
2318
|
id: data.id,
|
|
2089
2319
|
type: "geojson",
|
|
@@ -2287,6 +2517,7 @@ function Map2() {
|
|
|
2287
2517
|
setCoordinates(event.lngLat);
|
|
2288
2518
|
hover.onHover(event);
|
|
2289
2519
|
};
|
|
2520
|
+
console.info("NakshaMaplibreLayers props");
|
|
2290
2521
|
return /* @__PURE__ */ jsxs18("div", {
|
|
2291
2522
|
className: tw20`h-full w-full relative bg-gray-100`,
|
|
2292
2523
|
children: [
|
|
@@ -2298,6 +2529,7 @@ function Map2() {
|
|
|
2298
2529
|
initialViewState: viewState,
|
|
2299
2530
|
style: { width: "100%", height: "100%" },
|
|
2300
2531
|
mapStyle: layer.mapStyle,
|
|
2532
|
+
maxZoom: layer.maxZoom,
|
|
2301
2533
|
onClick: onMapClick,
|
|
2302
2534
|
onMouseMove: handleOnMouseMove,
|
|
2303
2535
|
children: [
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -272,27 +272,27 @@ var processRectangles = function(data, level) {
|
|
|
272
272
|
counts.forEach((count, hash) => {
|
|
273
273
|
const bboxStart = import_geohash.GeoHash.decodeGeoHash(hash);
|
|
274
274
|
const bboxEnd = import_geohash.GeoHash.decodeGeoHash(bins.get(hash));
|
|
275
|
-
const
|
|
275
|
+
const feature2 = new import_boundingbox.default({
|
|
276
276
|
minlat: bboxStart.latitude[0],
|
|
277
277
|
minlon: bboxStart.longitude[0],
|
|
278
278
|
maxlat: bboxEnd.latitude[1],
|
|
279
279
|
maxlon: bboxEnd.longitude[1]
|
|
280
280
|
}).toGeoJSON();
|
|
281
|
-
features.push(__spreadProps(__spreadValues({},
|
|
281
|
+
features.push(__spreadProps(__spreadValues({}, feature2), { properties: { count, [PROPERTY_ID]: hash } }));
|
|
282
282
|
});
|
|
283
283
|
return features;
|
|
284
284
|
};
|
|
285
285
|
var processSquares = (data) => {
|
|
286
286
|
const features = [];
|
|
287
287
|
for (const [hash, count] of Object.entries(data)) {
|
|
288
|
-
const
|
|
289
|
-
const
|
|
290
|
-
minlat:
|
|
291
|
-
minlon:
|
|
292
|
-
maxlat:
|
|
293
|
-
maxlon:
|
|
288
|
+
const bbox2 = import_geohash.GeoHash.decodeGeoHash(hash);
|
|
289
|
+
const feature2 = new import_boundingbox.default({
|
|
290
|
+
minlat: bbox2.latitude[0],
|
|
291
|
+
minlon: bbox2.longitude[0],
|
|
292
|
+
maxlat: bbox2.latitude[1],
|
|
293
|
+
maxlon: bbox2.longitude[1]
|
|
294
294
|
}).toGeoJSON();
|
|
295
|
-
features.push(__spreadProps(__spreadValues({},
|
|
295
|
+
features.push(__spreadProps(__spreadValues({}, feature2), { properties: { count, [PROPERTY_ID]: hash } }));
|
|
296
296
|
}
|
|
297
297
|
return features;
|
|
298
298
|
};
|
|
@@ -503,13 +503,18 @@ var LayersContext = (0, import_react.createContext)(
|
|
|
503
503
|
{}
|
|
504
504
|
);
|
|
505
505
|
var LayersProvider = ({ mp: _mp, children }) => {
|
|
506
|
-
var _a;
|
|
506
|
+
var _a, _b;
|
|
507
507
|
const [mp, setMP] = (0, import_react.useState)(_mp);
|
|
508
508
|
const { mapl } = (0, import_maplibre.useMap)();
|
|
509
509
|
const [queryTerm, setQueryTerm] = (0, import_react.useState)("");
|
|
510
510
|
const queryTermDebounced = (0, import_naksha_commons2.useDebounce)(queryTerm, 500);
|
|
511
511
|
const styles = mp.mapStyles && mp.mapStyles.length > 0 ? mp.mapStyles : import_naksha_commons2.defaultMapStyles;
|
|
512
|
-
const [mapStyle, setMapStyle] = (0, import_react.useState)(
|
|
512
|
+
const [mapStyle, setMapStyle] = (0, import_react.useState)(
|
|
513
|
+
(_a = styles[(mp == null ? void 0 : mp.mapStyle) || 0]) == null ? void 0 : _a.style
|
|
514
|
+
);
|
|
515
|
+
const [maxZoom, setMaxZoom] = (0, import_react.useState)(
|
|
516
|
+
(_b = styles[(mp == null ? void 0 : mp.mapStyle) || 0]) == null ? void 0 : _b.maxZoom
|
|
517
|
+
);
|
|
513
518
|
const [selectionStyle, setSelectionStyle] = (0, import_react.useState)(
|
|
514
519
|
SELECTION_STYLE.TOP
|
|
515
520
|
);
|
|
@@ -570,7 +575,7 @@ var LayersProvider = ({ mp: _mp, children }) => {
|
|
|
570
575
|
toggleVectorLayer(layerIndex, styleIndex, false);
|
|
571
576
|
});
|
|
572
577
|
const onMapHover = (e) => __async(void 0, null, function* () {
|
|
573
|
-
var _a2,
|
|
578
|
+
var _a2, _b2, _c, _d;
|
|
574
579
|
if (!selectedLayerIds.length || !mapl)
|
|
575
580
|
return;
|
|
576
581
|
try {
|
|
@@ -579,14 +584,14 @@ var LayersProvider = ({ mp: _mp, children }) => {
|
|
|
579
584
|
layers: [lastLayerId]
|
|
580
585
|
});
|
|
581
586
|
if (feats.length) {
|
|
582
|
-
const fId = ((_a2 = feats[0]) == null ? void 0 : _a2.id) || ((_c = (
|
|
587
|
+
const fId = ((_a2 = feats[0]) == null ? void 0 : _a2.id) || ((_c = (_b2 = feats[0]) == null ? void 0 : _b2.properties) == null ? void 0 : _c[PROPERTY_ID]);
|
|
583
588
|
if (fId === (hoverFeatures == null ? void 0 : hoverFeatures.id))
|
|
584
589
|
return;
|
|
585
590
|
const layer = layers[getLayerIndexById(lastLayerId)];
|
|
586
591
|
const hoverProperties = (_d = layer == null ? void 0 : layer.data) == null ? void 0 : _d.summaryColumn.map((sc) => {
|
|
587
|
-
var _a3,
|
|
592
|
+
var _a3, _b3, _c2;
|
|
588
593
|
return [
|
|
589
|
-
((
|
|
594
|
+
((_b3 = (_a3 = layer.data) == null ? void 0 : _a3.propertyMap) == null ? void 0 : _b3[sc]) || sc,
|
|
590
595
|
(_c2 = feats[0].properties) == null ? void 0 : _c2[sc]
|
|
591
596
|
];
|
|
592
597
|
});
|
|
@@ -607,7 +612,7 @@ var LayersProvider = ({ mp: _mp, children }) => {
|
|
|
607
612
|
styleIndex = 0,
|
|
608
613
|
focus = true
|
|
609
614
|
}) {
|
|
610
|
-
var _a2;
|
|
615
|
+
var _a2, _b2;
|
|
611
616
|
if (!add) {
|
|
612
617
|
setSelectedLayerIds(
|
|
613
618
|
selectedLayerIds.filter((_lyrId) => layerId !== _lyrId)
|
|
@@ -616,11 +621,26 @@ var LayersProvider = ({ mp: _mp, children }) => {
|
|
|
616
621
|
}
|
|
617
622
|
const layerIndex = getLayerIndexById(layerId);
|
|
618
623
|
const sourceType = (_a2 = layers[layerIndex]) == null ? void 0 : _a2.source.type;
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
+
if (sourceType === "grid") {
|
|
625
|
+
setSelectedLayerIds((_slIds) => [
|
|
626
|
+
layerId,
|
|
627
|
+
..._slIds.filter((lid) => lid !== layerId)
|
|
628
|
+
]);
|
|
629
|
+
if (focus && ((_b2 = layers[layerIndex]) == null ? void 0 : _b2.bbox)) {
|
|
630
|
+
setTimeout(() => {
|
|
631
|
+
mapl == null ? void 0 : mapl.fitBounds(layers[layerIndex].bbox, {
|
|
632
|
+
padding: 40,
|
|
633
|
+
duration: 1e3
|
|
634
|
+
});
|
|
635
|
+
}, 100);
|
|
636
|
+
}
|
|
637
|
+
} else {
|
|
638
|
+
yield toggleVectorLayer(layerIndex, styleIndex, focus);
|
|
639
|
+
setSelectedLayerIds((_slIds) => [
|
|
640
|
+
layerId,
|
|
641
|
+
..._slIds.filter((lid) => lid !== layerId)
|
|
642
|
+
]);
|
|
643
|
+
}
|
|
624
644
|
});
|
|
625
645
|
const clearAllLayers = () => __async(void 0, null, function* () {
|
|
626
646
|
return setSelectedLayerIds([]);
|
|
@@ -710,6 +730,8 @@ var LayersProvider = ({ mp: _mp, children }) => {
|
|
|
710
730
|
mapStyle,
|
|
711
731
|
featuresAtLatLng,
|
|
712
732
|
setMapStyle,
|
|
733
|
+
maxZoom,
|
|
734
|
+
setMaxZoom,
|
|
713
735
|
mapStyles: styles,
|
|
714
736
|
all: layers,
|
|
715
737
|
setAll: setLayers,
|
|
@@ -1975,7 +1997,13 @@ var import_jsx_runtime22 = require("react/jsx-runtime");
|
|
|
1975
1997
|
function SettingsTabPanel() {
|
|
1976
1998
|
const { layer } = useLayers();
|
|
1977
1999
|
const { t } = (0, import_naksha_commons11.useT)();
|
|
1978
|
-
const handleOnStyleChange = (e) =>
|
|
2000
|
+
const handleOnStyleChange = (e) => {
|
|
2001
|
+
var _a;
|
|
2002
|
+
layer.setMapStyle(e.target.value);
|
|
2003
|
+
layer.setMaxZoom(
|
|
2004
|
+
(_a = layer.mapStyles.find((ms) => ms.style === e.target.value)) == null ? void 0 : _a.maxZoom
|
|
2005
|
+
);
|
|
2006
|
+
};
|
|
1979
2007
|
return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", {
|
|
1980
2008
|
className: import_twind17.tw`w-full p-4 flex flex-col gap-4`,
|
|
1981
2009
|
children: [
|
|
@@ -2078,6 +2106,170 @@ function Sidebar() {
|
|
|
2078
2106
|
// src/components/map/layers/index.tsx
|
|
2079
2107
|
var import_maplibre6 = require("react-map-gl/maplibre");
|
|
2080
2108
|
|
|
2109
|
+
// ../../node_modules/@turf/helpers/dist/es/index.js
|
|
2110
|
+
var earthRadius = 63710088e-1;
|
|
2111
|
+
var factors = {
|
|
2112
|
+
centimeters: earthRadius * 100,
|
|
2113
|
+
centimetres: earthRadius * 100,
|
|
2114
|
+
degrees: earthRadius / 111325,
|
|
2115
|
+
feet: earthRadius * 3.28084,
|
|
2116
|
+
inches: earthRadius * 39.37,
|
|
2117
|
+
kilometers: earthRadius / 1e3,
|
|
2118
|
+
kilometres: earthRadius / 1e3,
|
|
2119
|
+
meters: earthRadius,
|
|
2120
|
+
metres: earthRadius,
|
|
2121
|
+
miles: earthRadius / 1609.344,
|
|
2122
|
+
millimeters: earthRadius * 1e3,
|
|
2123
|
+
millimetres: earthRadius * 1e3,
|
|
2124
|
+
nauticalmiles: earthRadius / 1852,
|
|
2125
|
+
radians: 1,
|
|
2126
|
+
yards: earthRadius * 1.0936
|
|
2127
|
+
};
|
|
2128
|
+
var unitsFactors = {
|
|
2129
|
+
centimeters: 100,
|
|
2130
|
+
centimetres: 100,
|
|
2131
|
+
degrees: 1 / 111325,
|
|
2132
|
+
feet: 3.28084,
|
|
2133
|
+
inches: 39.37,
|
|
2134
|
+
kilometers: 1 / 1e3,
|
|
2135
|
+
kilometres: 1 / 1e3,
|
|
2136
|
+
meters: 1,
|
|
2137
|
+
metres: 1,
|
|
2138
|
+
miles: 1 / 1609.344,
|
|
2139
|
+
millimeters: 1e3,
|
|
2140
|
+
millimetres: 1e3,
|
|
2141
|
+
nauticalmiles: 1 / 1852,
|
|
2142
|
+
radians: 1 / earthRadius,
|
|
2143
|
+
yards: 1.0936133
|
|
2144
|
+
};
|
|
2145
|
+
|
|
2146
|
+
// ../../node_modules/@turf/meta/dist/es/index.js
|
|
2147
|
+
function coordEach(geojson, callback, excludeWrapCoord) {
|
|
2148
|
+
if (geojson === null)
|
|
2149
|
+
return;
|
|
2150
|
+
var j, k, l, geometry, stopG, coords, geometryMaybeCollection, wrapShrink = 0, coordIndex = 0, isGeometryCollection, type = geojson.type, isFeatureCollection = type === "FeatureCollection", isFeature = type === "Feature", stop = isFeatureCollection ? geojson.features.length : 1;
|
|
2151
|
+
for (var featureIndex = 0; featureIndex < stop; featureIndex++) {
|
|
2152
|
+
geometryMaybeCollection = isFeatureCollection ? geojson.features[featureIndex].geometry : isFeature ? geojson.geometry : geojson;
|
|
2153
|
+
isGeometryCollection = geometryMaybeCollection ? geometryMaybeCollection.type === "GeometryCollection" : false;
|
|
2154
|
+
stopG = isGeometryCollection ? geometryMaybeCollection.geometries.length : 1;
|
|
2155
|
+
for (var geomIndex = 0; geomIndex < stopG; geomIndex++) {
|
|
2156
|
+
var multiFeatureIndex = 0;
|
|
2157
|
+
var geometryIndex = 0;
|
|
2158
|
+
geometry = isGeometryCollection ? geometryMaybeCollection.geometries[geomIndex] : geometryMaybeCollection;
|
|
2159
|
+
if (geometry === null)
|
|
2160
|
+
continue;
|
|
2161
|
+
coords = geometry.coordinates;
|
|
2162
|
+
var geomType = geometry.type;
|
|
2163
|
+
wrapShrink = excludeWrapCoord && (geomType === "Polygon" || geomType === "MultiPolygon") ? 1 : 0;
|
|
2164
|
+
switch (geomType) {
|
|
2165
|
+
case null:
|
|
2166
|
+
break;
|
|
2167
|
+
case "Point":
|
|
2168
|
+
if (callback(
|
|
2169
|
+
coords,
|
|
2170
|
+
coordIndex,
|
|
2171
|
+
featureIndex,
|
|
2172
|
+
multiFeatureIndex,
|
|
2173
|
+
geometryIndex
|
|
2174
|
+
) === false)
|
|
2175
|
+
return false;
|
|
2176
|
+
coordIndex++;
|
|
2177
|
+
multiFeatureIndex++;
|
|
2178
|
+
break;
|
|
2179
|
+
case "LineString":
|
|
2180
|
+
case "MultiPoint":
|
|
2181
|
+
for (j = 0; j < coords.length; j++) {
|
|
2182
|
+
if (callback(
|
|
2183
|
+
coords[j],
|
|
2184
|
+
coordIndex,
|
|
2185
|
+
featureIndex,
|
|
2186
|
+
multiFeatureIndex,
|
|
2187
|
+
geometryIndex
|
|
2188
|
+
) === false)
|
|
2189
|
+
return false;
|
|
2190
|
+
coordIndex++;
|
|
2191
|
+
if (geomType === "MultiPoint")
|
|
2192
|
+
multiFeatureIndex++;
|
|
2193
|
+
}
|
|
2194
|
+
if (geomType === "LineString")
|
|
2195
|
+
multiFeatureIndex++;
|
|
2196
|
+
break;
|
|
2197
|
+
case "Polygon":
|
|
2198
|
+
case "MultiLineString":
|
|
2199
|
+
for (j = 0; j < coords.length; j++) {
|
|
2200
|
+
for (k = 0; k < coords[j].length - wrapShrink; k++) {
|
|
2201
|
+
if (callback(
|
|
2202
|
+
coords[j][k],
|
|
2203
|
+
coordIndex,
|
|
2204
|
+
featureIndex,
|
|
2205
|
+
multiFeatureIndex,
|
|
2206
|
+
geometryIndex
|
|
2207
|
+
) === false)
|
|
2208
|
+
return false;
|
|
2209
|
+
coordIndex++;
|
|
2210
|
+
}
|
|
2211
|
+
if (geomType === "MultiLineString")
|
|
2212
|
+
multiFeatureIndex++;
|
|
2213
|
+
if (geomType === "Polygon")
|
|
2214
|
+
geometryIndex++;
|
|
2215
|
+
}
|
|
2216
|
+
if (geomType === "Polygon")
|
|
2217
|
+
multiFeatureIndex++;
|
|
2218
|
+
break;
|
|
2219
|
+
case "MultiPolygon":
|
|
2220
|
+
for (j = 0; j < coords.length; j++) {
|
|
2221
|
+
geometryIndex = 0;
|
|
2222
|
+
for (k = 0; k < coords[j].length; k++) {
|
|
2223
|
+
for (l = 0; l < coords[j][k].length - wrapShrink; l++) {
|
|
2224
|
+
if (callback(
|
|
2225
|
+
coords[j][k][l],
|
|
2226
|
+
coordIndex,
|
|
2227
|
+
featureIndex,
|
|
2228
|
+
multiFeatureIndex,
|
|
2229
|
+
geometryIndex
|
|
2230
|
+
) === false)
|
|
2231
|
+
return false;
|
|
2232
|
+
coordIndex++;
|
|
2233
|
+
}
|
|
2234
|
+
geometryIndex++;
|
|
2235
|
+
}
|
|
2236
|
+
multiFeatureIndex++;
|
|
2237
|
+
}
|
|
2238
|
+
break;
|
|
2239
|
+
case "GeometryCollection":
|
|
2240
|
+
for (j = 0; j < geometry.geometries.length; j++)
|
|
2241
|
+
if (coordEach(geometry.geometries[j], callback, excludeWrapCoord) === false)
|
|
2242
|
+
return false;
|
|
2243
|
+
break;
|
|
2244
|
+
default:
|
|
2245
|
+
throw new Error("Unknown Geometry Type");
|
|
2246
|
+
}
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
}
|
|
2250
|
+
|
|
2251
|
+
// ../../node_modules/@turf/bbox/dist/es/index.js
|
|
2252
|
+
function bbox(geojson) {
|
|
2253
|
+
var result = [Infinity, Infinity, -Infinity, -Infinity];
|
|
2254
|
+
coordEach(geojson, function(coord) {
|
|
2255
|
+
if (result[0] > coord[0]) {
|
|
2256
|
+
result[0] = coord[0];
|
|
2257
|
+
}
|
|
2258
|
+
if (result[1] > coord[1]) {
|
|
2259
|
+
result[1] = coord[1];
|
|
2260
|
+
}
|
|
2261
|
+
if (result[2] < coord[0]) {
|
|
2262
|
+
result[2] = coord[0];
|
|
2263
|
+
}
|
|
2264
|
+
if (result[3] < coord[1]) {
|
|
2265
|
+
result[3] = coord[1];
|
|
2266
|
+
}
|
|
2267
|
+
});
|
|
2268
|
+
return result;
|
|
2269
|
+
}
|
|
2270
|
+
bbox["default"] = bbox;
|
|
2271
|
+
var es_default = bbox;
|
|
2272
|
+
|
|
2081
2273
|
// src/components/map/layers/grid/index.tsx
|
|
2082
2274
|
var import_react10 = require("react");
|
|
2083
2275
|
var import_maplibre3 = require("react-map-gl/maplibre");
|
|
@@ -2089,7 +2281,9 @@ function GridLayer({
|
|
|
2089
2281
|
const { layer } = useLayers();
|
|
2090
2282
|
const { mapl } = (0, import_maplibre3.useMap)();
|
|
2091
2283
|
const [layerData, setLayerData] = (0, import_react10.useState)({ geojson: {}, paint: {} });
|
|
2092
|
-
const
|
|
2284
|
+
const isSelected = layer.selectedIds.includes(data.id);
|
|
2285
|
+
const isLastSelected = layer.selectedIds[0] === data.id;
|
|
2286
|
+
const fetchGridData = (shouldFitBounds = false) => __async(this, null, function* () {
|
|
2093
2287
|
const { success, geojson, paint: paint2, stops, squareSize } = yield getGridLayerData(
|
|
2094
2288
|
data.source.fetcher,
|
|
2095
2289
|
mapl == null ? void 0 : mapl.getBounds(),
|
|
@@ -2097,14 +2291,50 @@ function GridLayer({
|
|
|
2097
2291
|
);
|
|
2098
2292
|
if (success) {
|
|
2099
2293
|
setLayerData({ geojson, paint: paint2 });
|
|
2294
|
+
if (shouldFitBounds && isLastSelected && data.zoomToFit) {
|
|
2295
|
+
try {
|
|
2296
|
+
const [minLon, minLat, maxLon, maxLat] = es_default(geojson);
|
|
2297
|
+
mapl == null ? void 0 : mapl.fitBounds(
|
|
2298
|
+
[
|
|
2299
|
+
[minLon, minLat],
|
|
2300
|
+
[maxLon, maxLat]
|
|
2301
|
+
],
|
|
2302
|
+
{ padding: 40, animate: true }
|
|
2303
|
+
);
|
|
2304
|
+
} catch (e) {
|
|
2305
|
+
console.warn("Failed to compute bbox", e);
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2100
2308
|
layer.setGridLegends({
|
|
2101
2309
|
[data.id]: { stops, squareSize }
|
|
2102
2310
|
});
|
|
2103
2311
|
}
|
|
2104
2312
|
});
|
|
2105
2313
|
(0, import_react10.useEffect)(() => {
|
|
2106
|
-
|
|
2107
|
-
|
|
2314
|
+
if (isSelected && isLastSelected) {
|
|
2315
|
+
fetchGridData(true);
|
|
2316
|
+
} else if (isSelected) {
|
|
2317
|
+
fetchGridData(false);
|
|
2318
|
+
}
|
|
2319
|
+
}, [isSelected, isLastSelected]);
|
|
2320
|
+
(0, import_react10.useEffect)(() => {
|
|
2321
|
+
if (!isSelected || !mapl)
|
|
2322
|
+
return;
|
|
2323
|
+
const handleIdle = () => fetchGridData(false);
|
|
2324
|
+
mapl.on("idle", handleIdle);
|
|
2325
|
+
return () => {
|
|
2326
|
+
mapl.off("idle", handleIdle);
|
|
2327
|
+
};
|
|
2328
|
+
}, [isSelected, mapl]);
|
|
2329
|
+
(0, import_react10.useEffect)(() => {
|
|
2330
|
+
return () => {
|
|
2331
|
+
layer.setGridLegends((prev) => {
|
|
2332
|
+
const newLegends = __spreadValues({}, prev);
|
|
2333
|
+
delete newLegends[data.id];
|
|
2334
|
+
return newLegends;
|
|
2335
|
+
});
|
|
2336
|
+
};
|
|
2337
|
+
}, [data.id]);
|
|
2108
2338
|
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_maplibre3.Source, {
|
|
2109
2339
|
id: data.id,
|
|
2110
2340
|
type: "geojson",
|
|
@@ -2308,6 +2538,7 @@ function Map2() {
|
|
|
2308
2538
|
setCoordinates(event.lngLat);
|
|
2309
2539
|
hover.onHover(event);
|
|
2310
2540
|
};
|
|
2541
|
+
console.info("NakshaMaplibreLayers props");
|
|
2311
2542
|
return /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)("div", {
|
|
2312
2543
|
className: import_twind20.tw`h-full w-full relative bg-gray-100`,
|
|
2313
2544
|
children: [
|
|
@@ -2319,6 +2550,7 @@ function Map2() {
|
|
|
2319
2550
|
initialViewState: viewState,
|
|
2320
2551
|
style: { width: "100%", height: "100%" },
|
|
2321
2552
|
mapStyle: layer.mapStyle,
|
|
2553
|
+
maxZoom: layer.maxZoom,
|
|
2322
2554
|
onClick: onMapClick,
|
|
2323
2555
|
onMouseMove: handleOnMouseMove,
|
|
2324
2556
|
children: [
|