@biodiv-platform/naksha-maplibre-layers 5.0.3 → 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 +241 -20
- package/dist/index.d.ts +1 -0
- package/dist/index.js +241 -20
- 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
|
};
|
|
@@ -488,8 +488,12 @@ var LayersProvider = ({ mp: _mp, children }) => {
|
|
|
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(
|
|
492
|
-
|
|
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
|
+
);
|
|
493
497
|
const [selectionStyle, setSelectionStyle] = useState(
|
|
494
498
|
SELECTION_STYLE.TOP
|
|
495
499
|
);
|
|
@@ -587,7 +591,7 @@ var LayersProvider = ({ mp: _mp, children }) => {
|
|
|
587
591
|
styleIndex = 0,
|
|
588
592
|
focus = true
|
|
589
593
|
}) {
|
|
590
|
-
var _a2;
|
|
594
|
+
var _a2, _b2;
|
|
591
595
|
if (!add) {
|
|
592
596
|
setSelectedLayerIds(
|
|
593
597
|
selectedLayerIds.filter((_lyrId) => layerId !== _lyrId)
|
|
@@ -596,11 +600,26 @@ var LayersProvider = ({ mp: _mp, children }) => {
|
|
|
596
600
|
}
|
|
597
601
|
const layerIndex = getLayerIndexById(layerId);
|
|
598
602
|
const sourceType = (_a2 = layers[layerIndex]) == null ? void 0 : _a2.source.type;
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
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
|
+
}
|
|
604
623
|
});
|
|
605
624
|
const clearAllLayers = () => __async(void 0, null, function* () {
|
|
606
625
|
return setSelectedLayerIds([]);
|
|
@@ -2066,6 +2085,170 @@ function Sidebar() {
|
|
|
2066
2085
|
// src/components/map/layers/index.tsx
|
|
2067
2086
|
import { useMap as useMap4 } from "react-map-gl/maplibre";
|
|
2068
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
|
+
|
|
2069
2252
|
// src/components/map/layers/grid/index.tsx
|
|
2070
2253
|
import { useEffect as useEffect4, useState as useState9 } from "react";
|
|
2071
2254
|
import { Layer, Source, useMap as useMap3 } from "react-map-gl/maplibre";
|
|
@@ -2077,7 +2260,9 @@ function GridLayer({
|
|
|
2077
2260
|
const { layer } = useLayers();
|
|
2078
2261
|
const { mapl } = useMap3();
|
|
2079
2262
|
const [layerData, setLayerData] = useState9({ geojson: {}, paint: {} });
|
|
2080
|
-
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* () {
|
|
2081
2266
|
const { success, geojson, paint: paint2, stops, squareSize } = yield getGridLayerData(
|
|
2082
2267
|
data.source.fetcher,
|
|
2083
2268
|
mapl == null ? void 0 : mapl.getBounds(),
|
|
@@ -2085,14 +2270,50 @@ function GridLayer({
|
|
|
2085
2270
|
);
|
|
2086
2271
|
if (success) {
|
|
2087
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
|
+
}
|
|
2088
2287
|
layer.setGridLegends({
|
|
2089
2288
|
[data.id]: { stops, squareSize }
|
|
2090
2289
|
});
|
|
2091
2290
|
}
|
|
2092
2291
|
});
|
|
2093
2292
|
useEffect4(() => {
|
|
2094
|
-
|
|
2095
|
-
|
|
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]);
|
|
2096
2317
|
return /* @__PURE__ */ jsx25(Source, {
|
|
2097
2318
|
id: data.id,
|
|
2098
2319
|
type: "geojson",
|
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
|
};
|
|
@@ -509,8 +509,12 @@ var LayersProvider = ({ mp: _mp, children }) => {
|
|
|
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)(
|
|
513
|
-
|
|
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
|
+
);
|
|
514
518
|
const [selectionStyle, setSelectionStyle] = (0, import_react.useState)(
|
|
515
519
|
SELECTION_STYLE.TOP
|
|
516
520
|
);
|
|
@@ -608,7 +612,7 @@ var LayersProvider = ({ mp: _mp, children }) => {
|
|
|
608
612
|
styleIndex = 0,
|
|
609
613
|
focus = true
|
|
610
614
|
}) {
|
|
611
|
-
var _a2;
|
|
615
|
+
var _a2, _b2;
|
|
612
616
|
if (!add) {
|
|
613
617
|
setSelectedLayerIds(
|
|
614
618
|
selectedLayerIds.filter((_lyrId) => layerId !== _lyrId)
|
|
@@ -617,11 +621,26 @@ var LayersProvider = ({ mp: _mp, children }) => {
|
|
|
617
621
|
}
|
|
618
622
|
const layerIndex = getLayerIndexById(layerId);
|
|
619
623
|
const sourceType = (_a2 = layers[layerIndex]) == null ? void 0 : _a2.source.type;
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
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
|
+
}
|
|
625
644
|
});
|
|
626
645
|
const clearAllLayers = () => __async(void 0, null, function* () {
|
|
627
646
|
return setSelectedLayerIds([]);
|
|
@@ -2087,6 +2106,170 @@ function Sidebar() {
|
|
|
2087
2106
|
// src/components/map/layers/index.tsx
|
|
2088
2107
|
var import_maplibre6 = require("react-map-gl/maplibre");
|
|
2089
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
|
+
|
|
2090
2273
|
// src/components/map/layers/grid/index.tsx
|
|
2091
2274
|
var import_react10 = require("react");
|
|
2092
2275
|
var import_maplibre3 = require("react-map-gl/maplibre");
|
|
@@ -2098,7 +2281,9 @@ function GridLayer({
|
|
|
2098
2281
|
const { layer } = useLayers();
|
|
2099
2282
|
const { mapl } = (0, import_maplibre3.useMap)();
|
|
2100
2283
|
const [layerData, setLayerData] = (0, import_react10.useState)({ geojson: {}, paint: {} });
|
|
2101
|
-
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* () {
|
|
2102
2287
|
const { success, geojson, paint: paint2, stops, squareSize } = yield getGridLayerData(
|
|
2103
2288
|
data.source.fetcher,
|
|
2104
2289
|
mapl == null ? void 0 : mapl.getBounds(),
|
|
@@ -2106,14 +2291,50 @@ function GridLayer({
|
|
|
2106
2291
|
);
|
|
2107
2292
|
if (success) {
|
|
2108
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
|
+
}
|
|
2109
2308
|
layer.setGridLegends({
|
|
2110
2309
|
[data.id]: { stops, squareSize }
|
|
2111
2310
|
});
|
|
2112
2311
|
}
|
|
2113
2312
|
});
|
|
2114
2313
|
(0, import_react10.useEffect)(() => {
|
|
2115
|
-
|
|
2116
|
-
|
|
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]);
|
|
2117
2338
|
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_maplibre3.Source, {
|
|
2118
2339
|
id: data.id,
|
|
2119
2340
|
type: "geojson",
|