@octostar/map-component 0.2.4 → 0.2.6
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/index.cjs +218 -151
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +218 -151
- package/dist/index.mjs.map +1 -1
- package/dist/types/components/map-editor-canvas.d.ts.map +1 -1
- package/dist/types/components/properties-panel.d.ts.map +1 -1
- package/dist/types/lib/history-diff.d.ts +52 -0
- package/dist/types/lib/history-diff.d.ts.map +1 -0
- package/dist/types/lib/read-only-feature-index.d.ts +26 -0
- package/dist/types/lib/read-only-feature-index.d.ts.map +1 -0
- package/dist/types/lib/visible-feature-count.d.ts +34 -0
- package/dist/types/lib/visible-feature-count.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2805,6 +2805,32 @@ function formatDateForState(value) {
|
|
|
2805
2805
|
}
|
|
2806
2806
|
return "";
|
|
2807
2807
|
}
|
|
2808
|
+
const ENTITY_CARDS_RENDER_CAP = 50;
|
|
2809
|
+
function EntityCardsList({
|
|
2810
|
+
selectedFeatures,
|
|
2811
|
+
entityCardProvider
|
|
2812
|
+
}) {
|
|
2813
|
+
const shown = selectedFeatures.slice(0, ENTITY_CARDS_RENDER_CAP);
|
|
2814
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "p-2 space-y-2", children: [
|
|
2815
|
+
shown.map((f) => {
|
|
2816
|
+
const geoFeature = {
|
|
2817
|
+
type: "Feature",
|
|
2818
|
+
id: f.id,
|
|
2819
|
+
geometry: f.geometry,
|
|
2820
|
+
properties: f.properties
|
|
2821
|
+
};
|
|
2822
|
+
const card = entityCardProvider(geoFeature);
|
|
2823
|
+
return card ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "border border-border rounded-md p-2 bg-card", children: card }, f.id) : null;
|
|
2824
|
+
}),
|
|
2825
|
+
selectedFeatures.length > shown.length && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-center py-2 text-muted-foreground text-sm", "data-testid": "entity-cards-cap-note", children: [
|
|
2826
|
+
"Showing the first ",
|
|
2827
|
+
shown.length,
|
|
2828
|
+
" of ",
|
|
2829
|
+
selectedFeatures.length.toLocaleString(),
|
|
2830
|
+
" selected features"
|
|
2831
|
+
] })
|
|
2832
|
+
] });
|
|
2833
|
+
}
|
|
2808
2834
|
function getFeatureTypeIcon(geometryType, kind, size = "sm") {
|
|
2809
2835
|
const cls = size === "lg" ? "w-5 h-5" : "w-4 h-4";
|
|
2810
2836
|
if (kind === "text") {
|
|
@@ -3406,16 +3432,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
|
|
|
3406
3432
|
const recordProperties = feature ? Object.entries(feature.properties).filter(
|
|
3407
3433
|
([key, value]) => !isExcludedRecordKey(key) && value !== void 0 && value !== null && !key.startsWith("_") && !key.startsWith("os_") && !key.startsWith("isHidden")
|
|
3408
3434
|
).map(([key, value]) => ({ key, value: formatFieldValue(String(value)) })) : [];
|
|
3409
|
-
const entityCardsContent = /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-2 space-y-2", children:
|
|
3410
|
-
const geoFeature = {
|
|
3411
|
-
type: "Feature",
|
|
3412
|
-
id: f.id,
|
|
3413
|
-
geometry: f.geometry,
|
|
3414
|
-
properties: f.properties
|
|
3415
|
-
};
|
|
3416
|
-
const card = entityCardProvider(geoFeature);
|
|
3417
|
-
return card ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "border border-border rounded-md p-2 bg-card", children: card }, f.id) : null;
|
|
3418
|
-
}) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-center py-4 text-muted-foreground text-sm", children: "No entity card provider registered" }) });
|
|
3435
|
+
const entityCardsContent = entityCardProvider ? /* @__PURE__ */ jsxRuntime.jsx(EntityCardsList, { selectedFeatures, entityCardProvider }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-2 space-y-2", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-center py-4 text-muted-foreground text-sm", children: "No entity card provider registered" }) });
|
|
3419
3436
|
const propertiesDisabledOverlay = /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute inset-0 bg-background/80 flex items-center justify-center z-10 rounded-md", children: /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground text-center px-4", children: "Select a single feature to see/set properties" }) });
|
|
3420
3437
|
if (hasMultipleSelection && !entityCardProvider) {
|
|
3421
3438
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
@@ -3478,7 +3495,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
|
|
|
3478
3495
|
/* @__PURE__ */ jsxRuntime.jsx(antd.Divider, { className: "!my-1.5" }),
|
|
3479
3496
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-0.5", children: [
|
|
3480
3497
|
/* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "feature-name", className: "text-xs text-muted-foreground", children: feature.properties.kind === "text" ? "Label" : "Name" }),
|
|
3481
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3498
|
+
isEditMode ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
3482
3499
|
antd.Input,
|
|
3483
3500
|
{
|
|
3484
3501
|
ref: nameInputRef,
|
|
@@ -3491,11 +3508,14 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
|
|
|
3491
3508
|
}
|
|
3492
3509
|
},
|
|
3493
3510
|
onBlur: () => handleSave(),
|
|
3494
|
-
placeholder:
|
|
3495
|
-
readOnly: !isEditMode,
|
|
3511
|
+
placeholder: feature.properties.kind === "text" ? "Enter label..." : "Feature name",
|
|
3496
3512
|
className: "!h-6 text-[13px]",
|
|
3497
3513
|
"data-testid": "input-feature-name"
|
|
3498
3514
|
}
|
|
3515
|
+
) : (
|
|
3516
|
+
// Static in view mode — a readOnly Input keeps the editable look
|
|
3517
|
+
// but swallows every keystroke (see LatLngFields).
|
|
3518
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-[13px] px-1 py-0.5 break-words", "data-testid": "text-feature-name", children: name || /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground", children: "No name" }) })
|
|
3499
3519
|
)
|
|
3500
3520
|
] }),
|
|
3501
3521
|
(typePickerProvider || feature.geometry.type === "Point" && feature.properties.kind !== "text" && pointIcon) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
@@ -3966,7 +3986,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
|
|
|
3966
3986
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1", children: [
|
|
3967
3987
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start gap-1", children: [
|
|
3968
3988
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-[13px] font-mono text-muted-foreground shrink-0 w-24 px-1 leading-6 select-none", children: "description" }),
|
|
3969
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3989
|
+
isEditMode ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
3970
3990
|
TextArea,
|
|
3971
3991
|
{
|
|
3972
3992
|
id: "feature-description",
|
|
@@ -3974,14 +3994,13 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
|
|
|
3974
3994
|
onChange: (e) => setDescription(e.target.value),
|
|
3975
3995
|
onBlur: () => handleSave(),
|
|
3976
3996
|
autoSize: { minRows: 1, maxRows: 5 },
|
|
3977
|
-
placeholder:
|
|
3978
|
-
readOnly: !isEditMode,
|
|
3997
|
+
placeholder: "—",
|
|
3979
3998
|
className: "flex-1 !text-[13px] !px-1.5 !py-0.5 resize-none",
|
|
3980
3999
|
"data-testid": "input-feature-description"
|
|
3981
4000
|
}
|
|
3982
|
-
)
|
|
4001
|
+
) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 text-[13px] px-1.5 leading-6 break-words", "data-testid": "text-feature-description", children: description || /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground", children: "—" }) })
|
|
3983
4002
|
] }),
|
|
3984
|
-
customProperties.map((prop, index) => /* @__PURE__ */ jsxRuntime.
|
|
4003
|
+
customProperties.map((prop, index) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: isEditMode ? "flex items-center gap-1" : "flex items-start gap-1", children: isEditMode ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3985
4004
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3986
4005
|
antd.Input,
|
|
3987
4006
|
{
|
|
@@ -3989,8 +4008,8 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
|
|
|
3989
4008
|
onChange: (e) => handlePropertyKeyChange(index, e.target.value),
|
|
3990
4009
|
onBlur: () => handleSave(),
|
|
3991
4010
|
placeholder: "Key",
|
|
4011
|
+
style: { width: "6rem", flex: "0 0 6rem" },
|
|
3992
4012
|
className: "shrink-0 w-24 text-[13px] font-mono !h-6 !px-1",
|
|
3993
|
-
readOnly: !isEditMode,
|
|
3994
4013
|
"data-testid": `input-property-key-${index}`
|
|
3995
4014
|
}
|
|
3996
4015
|
),
|
|
@@ -4002,11 +4021,10 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
|
|
|
4002
4021
|
onBlur: () => handleSave(),
|
|
4003
4022
|
placeholder: "Value",
|
|
4004
4023
|
className: "flex-1 text-[13px] !h-6 !px-1.5",
|
|
4005
|
-
readOnly: !isEditMode,
|
|
4006
4024
|
"data-testid": `input-property-value-${index}`
|
|
4007
4025
|
}
|
|
4008
4026
|
),
|
|
4009
|
-
|
|
4027
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4010
4028
|
"button",
|
|
4011
4029
|
{
|
|
4012
4030
|
type: "button",
|
|
@@ -4019,7 +4037,10 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
|
|
|
4019
4037
|
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Trash2, { className: "w-3 h-3" })
|
|
4020
4038
|
}
|
|
4021
4039
|
)
|
|
4022
|
-
] },
|
|
4040
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
4041
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-[13px] font-mono text-muted-foreground shrink-0 w-24 px-1 leading-6 select-none break-all", children: prop.key }),
|
|
4042
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 text-[13px] px-1.5 leading-6 break-words", "data-testid": `text-property-value-${index}`, children: prop.value || /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground", children: "—" }) })
|
|
4043
|
+
] }) }, index))
|
|
4023
4044
|
] }),
|
|
4024
4045
|
isEditMode && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1 pt-0.5", children: [
|
|
4025
4046
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -5293,6 +5314,86 @@ function useMapHistory(options) {
|
|
|
5293
5314
|
}, [history, rerender]);
|
|
5294
5315
|
return { push, undo, redo, clear, canUndo: history.canUndo, canRedo: history.canRedo };
|
|
5295
5316
|
}
|
|
5317
|
+
function historyLayersEqual(a, b) {
|
|
5318
|
+
if (a.featureIds.length !== b.featureIds.length) return false;
|
|
5319
|
+
for (let i = 0; i < a.featureIds.length; i += 1) {
|
|
5320
|
+
if (a.featureIds[i] !== b.featureIds[i]) return false;
|
|
5321
|
+
}
|
|
5322
|
+
const { featureIds: _aIds, ...aRest } = a;
|
|
5323
|
+
const { featureIds: _bIds, ...bRest } = b;
|
|
5324
|
+
return JSON.stringify(aRest) === JSON.stringify(bRest);
|
|
5325
|
+
}
|
|
5326
|
+
function diffHistorySnapshots(before, after, beforeLayers, afterLayers) {
|
|
5327
|
+
const allFeatureIds = /* @__PURE__ */ new Set();
|
|
5328
|
+
before.forEach((_v, k) => allFeatureIds.add(k));
|
|
5329
|
+
after.forEach((_v, k) => allFeatureIds.add(k));
|
|
5330
|
+
const featureIds = /* @__PURE__ */ new Set();
|
|
5331
|
+
allFeatureIds.forEach((id) => {
|
|
5332
|
+
const b = before.get(id);
|
|
5333
|
+
const a = after.get(id);
|
|
5334
|
+
if (!b || !a || b.layerId !== a.layerId || b.store !== a.store) {
|
|
5335
|
+
featureIds.add(id);
|
|
5336
|
+
return;
|
|
5337
|
+
}
|
|
5338
|
+
if (b.feature === a.feature) return;
|
|
5339
|
+
if (JSON.stringify(b.feature.geometry) !== JSON.stringify(a.feature.geometry) || JSON.stringify(b.feature.properties ?? {}) !== JSON.stringify(a.feature.properties ?? {})) {
|
|
5340
|
+
featureIds.add(id);
|
|
5341
|
+
}
|
|
5342
|
+
});
|
|
5343
|
+
const allLayerIds = /* @__PURE__ */ new Set();
|
|
5344
|
+
beforeLayers.forEach((_v, k) => allLayerIds.add(k));
|
|
5345
|
+
afterLayers.forEach((_v, k) => allLayerIds.add(k));
|
|
5346
|
+
const layerIds = /* @__PURE__ */ new Set();
|
|
5347
|
+
allLayerIds.forEach((id) => {
|
|
5348
|
+
const b = beforeLayers.get(id);
|
|
5349
|
+
const a = afterLayers.get(id);
|
|
5350
|
+
if (!b || !a || !historyLayersEqual(b, a)) layerIds.add(id);
|
|
5351
|
+
});
|
|
5352
|
+
return { featureIds, layerIds };
|
|
5353
|
+
}
|
|
5354
|
+
function isReadOnlyIndexCurrent(cached, store) {
|
|
5355
|
+
if (!cached || cached.sources.size !== store.size) return false;
|
|
5356
|
+
let stale = false;
|
|
5357
|
+
store.forEach((features, layerId) => {
|
|
5358
|
+
if (!stale && cached.sources.get(layerId) !== features) stale = true;
|
|
5359
|
+
});
|
|
5360
|
+
return !stale;
|
|
5361
|
+
}
|
|
5362
|
+
function buildReadOnlyFeatureIndex(store) {
|
|
5363
|
+
const byId = /* @__PURE__ */ new Map();
|
|
5364
|
+
store.forEach((features) => {
|
|
5365
|
+
for (const f of features) {
|
|
5366
|
+
if (f.id == null) continue;
|
|
5367
|
+
const fid = String(f.id);
|
|
5368
|
+
if (!byId.has(fid)) byId.set(fid, f);
|
|
5369
|
+
}
|
|
5370
|
+
});
|
|
5371
|
+
return { sources: new Map(store), byId };
|
|
5372
|
+
}
|
|
5373
|
+
function countFeaturesInBounds(featureGroups, bounds, options) {
|
|
5374
|
+
var _a;
|
|
5375
|
+
const { west, east, south, north } = bounds;
|
|
5376
|
+
const { threshold, visibleSet } = options;
|
|
5377
|
+
const fullWidth = east - west >= 360;
|
|
5378
|
+
const inView = (lng, lat) => {
|
|
5379
|
+
if (lat < south || lat > north) return false;
|
|
5380
|
+
if (fullWidth) return true;
|
|
5381
|
+
return lng >= west && lng <= east || lng + 360 >= west && lng + 360 <= east || lng - 360 >= west && lng - 360 <= east;
|
|
5382
|
+
};
|
|
5383
|
+
let count = 0;
|
|
5384
|
+
for (const features of featureGroups) {
|
|
5385
|
+
for (const f of features) {
|
|
5386
|
+
if (visibleSet && f.id != null && !visibleSet.has(String(f.id))) continue;
|
|
5387
|
+
if (((_a = f.geometry) == null ? void 0 : _a.type) === "Point") {
|
|
5388
|
+
const [lng, lat] = f.geometry.coordinates;
|
|
5389
|
+
if (!inView(lng, lat)) continue;
|
|
5390
|
+
}
|
|
5391
|
+
count += 1;
|
|
5392
|
+
if (count > threshold) return count;
|
|
5393
|
+
}
|
|
5394
|
+
}
|
|
5395
|
+
return count;
|
|
5396
|
+
}
|
|
5296
5397
|
const OTHER_BUCKET_KEY = "__other__";
|
|
5297
5398
|
const OTHER_BUCKET_LABEL = "Other";
|
|
5298
5399
|
const OTHER_BUCKET_COLOR = "#9ca3af";
|
|
@@ -6082,6 +6183,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
6082
6183
|
const filterPolygonRef = react.useRef(null);
|
|
6083
6184
|
const pendingFeatureKindRef = react.useRef(null);
|
|
6084
6185
|
const arrowFeatureIdsRef = react.useRef(/* @__PURE__ */ new Set());
|
|
6186
|
+
const hasArrowFeaturesRef = react.useRef(false);
|
|
6085
6187
|
const [circleDrawCenter, setCircleDrawCenter] = react.useState(null);
|
|
6086
6188
|
const [circleDrawPreview, setCircleDrawPreview] = react.useState(null);
|
|
6087
6189
|
const isDrawingCircle = react.useRef(false);
|
|
@@ -6199,19 +6301,28 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
6199
6301
|
return true;
|
|
6200
6302
|
});
|
|
6201
6303
|
}, [selectedFeatureIds]);
|
|
6202
|
-
const selectedFeatures =
|
|
6304
|
+
const selectedFeatures = react.useMemo(
|
|
6305
|
+
() => getSelectedFeatures(),
|
|
6306
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- featureUpdateCounter invalidates stale clones
|
|
6307
|
+
[getSelectedFeatures, featureUpdateCounter]
|
|
6308
|
+
);
|
|
6309
|
+
const readOnlyFeatureIndexRef = react.useRef(null);
|
|
6310
|
+
const getReadOnlyFeatureById = react.useCallback((id) => {
|
|
6311
|
+
const store = readOnlyFeatures.current;
|
|
6312
|
+
let cached = readOnlyFeatureIndexRef.current;
|
|
6313
|
+
if (!isReadOnlyIndexCurrent(cached, store)) {
|
|
6314
|
+
cached = buildReadOnlyFeatureIndex(store);
|
|
6315
|
+
readOnlyFeatureIndexRef.current = cached;
|
|
6316
|
+
}
|
|
6317
|
+
return cached.byId.get(id) ?? null;
|
|
6318
|
+
}, []);
|
|
6203
6319
|
const getFeatureById = react.useCallback((id) => {
|
|
6204
6320
|
if (draw.current) {
|
|
6205
6321
|
const feature = draw.current.get(id);
|
|
6206
6322
|
if (feature) return feature;
|
|
6207
6323
|
}
|
|
6208
|
-
|
|
6209
|
-
|
|
6210
|
-
const found = features.find((f) => String(f.id) === id);
|
|
6211
|
-
if (found) return found;
|
|
6212
|
-
}
|
|
6213
|
-
return null;
|
|
6214
|
-
}, []);
|
|
6324
|
+
return getReadOnlyFeatureById(id);
|
|
6325
|
+
}, [getReadOnlyFeatureById]);
|
|
6215
6326
|
const canDeleteSelected = react.useMemo(() => {
|
|
6216
6327
|
if (selectedFeatureIds.length === 0) return false;
|
|
6217
6328
|
return selectedFeatureIds.some((id) => {
|
|
@@ -6237,7 +6348,9 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
6237
6348
|
if (!isMapLoaded || !draw.current) {
|
|
6238
6349
|
setSelectedFeatureIds(nextIds);
|
|
6239
6350
|
if (options == null ? void 0 : options.focusProperties) setShowProperties(nextIds.length > 0);
|
|
6240
|
-
|
|
6351
|
+
if (onFeatureSelect) {
|
|
6352
|
+
onFeatureSelect(nextIds.length > 0 ? nextIds.map((id) => getFeatureById(id)).filter(Boolean) : []);
|
|
6353
|
+
}
|
|
6241
6354
|
return;
|
|
6242
6355
|
}
|
|
6243
6356
|
const editableIdSet = /* @__PURE__ */ new Set();
|
|
@@ -6264,8 +6377,9 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
6264
6377
|
setSelectedFeatureIds(nextIds);
|
|
6265
6378
|
selectedFeatureIdsRef.current = nextIds;
|
|
6266
6379
|
if (options == null ? void 0 : options.focusProperties) setShowProperties(nextIds.length > 0);
|
|
6267
|
-
|
|
6268
|
-
|
|
6380
|
+
if (onFeatureSelect) {
|
|
6381
|
+
onFeatureSelect(nextIds.map((id) => getFeatureById(id)).filter(Boolean));
|
|
6382
|
+
}
|
|
6269
6383
|
syncRef.current();
|
|
6270
6384
|
if (readOnlyIds.length > 0) {
|
|
6271
6385
|
queueMicrotask(() => {
|
|
@@ -6289,6 +6403,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
6289
6403
|
setFeatureCount(drawFeatureCount + hiddenCount + readOnlyCount);
|
|
6290
6404
|
}, []);
|
|
6291
6405
|
const timelineVisibleIdsRef = react.useRef(null);
|
|
6406
|
+
const timelineSyncRafRef = react.useRef(null);
|
|
6292
6407
|
const syncRef = react.useRef(() => {
|
|
6293
6408
|
});
|
|
6294
6409
|
const hashStringToColor$1 = react.useCallback((str) => hashStringToColor(str), []);
|
|
@@ -6359,6 +6474,22 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
6359
6474
|
});
|
|
6360
6475
|
return colorMap;
|
|
6361
6476
|
}, [selectedFeatureIds, layers, getAllFeatures, hashStringToColor$1]);
|
|
6477
|
+
const countVisibleFeatures = react.useCallback((threshold) => {
|
|
6478
|
+
const m = map.current;
|
|
6479
|
+
if (!m) return 0;
|
|
6480
|
+
const bounds = m.getBounds();
|
|
6481
|
+
const groups = [];
|
|
6482
|
+
if (draw.current) groups.push(draw.current.getAll().features);
|
|
6483
|
+
readOnlyFeatures.current.forEach((features, layerId) => {
|
|
6484
|
+
const layer = layersRef.current.find((l) => l.id === layerId);
|
|
6485
|
+
if (layer == null ? void 0 : layer.visible) groups.push(features);
|
|
6486
|
+
});
|
|
6487
|
+
return countFeaturesInBounds(
|
|
6488
|
+
groups,
|
|
6489
|
+
{ west: bounds.getWest(), east: bounds.getEast(), south: bounds.getSouth(), north: bounds.getNorth() },
|
|
6490
|
+
{ threshold, visibleSet: timelineVisibleIdsRef.current }
|
|
6491
|
+
);
|
|
6492
|
+
}, []);
|
|
6362
6493
|
const isSyncingRef = react.useRef(false);
|
|
6363
6494
|
const syncFeaturesToCustomLayers = react.useCallback(() => {
|
|
6364
6495
|
if (!map.current) return;
|
|
@@ -6711,11 +6842,13 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
6711
6842
|
if (arrowHeadSource && map.current) {
|
|
6712
6843
|
const arrowHeadTriangles = [];
|
|
6713
6844
|
const mapInstance = map.current;
|
|
6845
|
+
let sawArrowFeature = false;
|
|
6714
6846
|
const headLength = 16;
|
|
6715
6847
|
const headWidth = 10;
|
|
6716
6848
|
sourceData.features.forEach((f) => {
|
|
6717
6849
|
var _a;
|
|
6718
6850
|
const isArrow = ((_a = f.properties) == null ? void 0 : _a.kind) === "arrow" || arrowFeatureIdsRef.current.has(String(f.id));
|
|
6851
|
+
if (isArrow) sawArrowFeature = true;
|
|
6719
6852
|
if (f.geometry.type !== "LineString" || !isArrow) return;
|
|
6720
6853
|
const coords = f.geometry.coordinates;
|
|
6721
6854
|
if (coords.length < 2) return;
|
|
@@ -6761,6 +6894,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
6761
6894
|
});
|
|
6762
6895
|
});
|
|
6763
6896
|
arrowHeadSource.setData({ type: "FeatureCollection", features: arrowHeadTriangles });
|
|
6897
|
+
hasArrowFeaturesRef.current = sawArrowFeature;
|
|
6764
6898
|
}
|
|
6765
6899
|
const arrowLabelSource = map.current.getSource("arrow-labels");
|
|
6766
6900
|
if (arrowLabelSource) {
|
|
@@ -6806,37 +6940,15 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
6806
6940
|
if (update3DFlightPathsRef == null ? void 0 : update3DFlightPathsRef.current) {
|
|
6807
6941
|
update3DFlightPathsRef.current();
|
|
6808
6942
|
}
|
|
6809
|
-
|
|
6810
|
-
|
|
6811
|
-
|
|
6812
|
-
|
|
6813
|
-
const countLayers = ["custom-point", "custom-line", "custom-polygon-fill"];
|
|
6814
|
-
const existing = countLayers.filter((id) => m.getLayer(id));
|
|
6815
|
-
if (existing.length === 0) {
|
|
6816
|
-
setVisibleFeatureCount(0);
|
|
6817
|
-
setLabelsSuppressed(false);
|
|
6818
|
-
return;
|
|
6819
|
-
}
|
|
6820
|
-
const threshold = autoLabelConfig.enabled ? autoLabelConfig.threshold : 220;
|
|
6821
|
-
const rendered = m.queryRenderedFeatures(void 0, { layers: existing });
|
|
6822
|
-
const uniqueIds = /* @__PURE__ */ new Set();
|
|
6823
|
-
let count = 0;
|
|
6824
|
-
for (const f of rendered) {
|
|
6825
|
-
const fid = ((_a = f.properties) == null ? void 0 : _a.id) || f.id;
|
|
6826
|
-
if (fid && !uniqueIds.has(String(fid))) {
|
|
6827
|
-
uniqueIds.add(String(fid));
|
|
6828
|
-
count++;
|
|
6829
|
-
if (count > threshold) break;
|
|
6830
|
-
}
|
|
6831
|
-
}
|
|
6832
|
-
setVisibleFeatureCount(count);
|
|
6833
|
-
setLabelsSuppressed(false);
|
|
6834
|
-
});
|
|
6943
|
+
{
|
|
6944
|
+
const threshold = autoLabelConfig.enabled ? autoLabelConfig.threshold : 220;
|
|
6945
|
+
setVisibleFeatureCount(countVisibleFeatures(threshold));
|
|
6946
|
+
setLabelsSuppressed(false);
|
|
6835
6947
|
}
|
|
6836
6948
|
} finally {
|
|
6837
6949
|
isSyncingRef.current = false;
|
|
6838
6950
|
}
|
|
6839
|
-
}, [layers, hashStringToColor$1, autoLabelConfig]);
|
|
6951
|
+
}, [layers, hashStringToColor$1, autoLabelConfig, countVisibleFeatures]);
|
|
6840
6952
|
const update3DFlightPaths = react.useCallback(() => {
|
|
6841
6953
|
if (!map.current || !is3DTerrainEnabled) {
|
|
6842
6954
|
if (map.current && flightPath3DLayerId.current) {
|
|
@@ -7157,6 +7269,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
7157
7269
|
updateFeatureCount();
|
|
7158
7270
|
scheduleTimelineUpdate();
|
|
7159
7271
|
syncFeaturesToCustomLayers();
|
|
7272
|
+
setFeatureUpdateCounter((c) => c + 1);
|
|
7160
7273
|
queueMicrotask(() => {
|
|
7161
7274
|
isSelectingReadOnlyRef.current = false;
|
|
7162
7275
|
});
|
|
@@ -7165,25 +7278,8 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
7165
7278
|
);
|
|
7166
7279
|
const buildDiffCommand = react.useCallback(
|
|
7167
7280
|
(label, coalesceKey, before, after, beforeLayers, afterLayers, beforeSelectedIds, afterSelectedIds) => {
|
|
7168
|
-
const featureIds =
|
|
7169
|
-
|
|
7170
|
-
after.forEach((_v, k) => featureIds.add(k));
|
|
7171
|
-
const layerIds = /* @__PURE__ */ new Set();
|
|
7172
|
-
beforeLayers.forEach((_v, k) => layerIds.add(k));
|
|
7173
|
-
afterLayers.forEach((_v, k) => layerIds.add(k));
|
|
7174
|
-
const featuresChanged = Array.from(featureIds).some((id) => {
|
|
7175
|
-
const b = before.get(id);
|
|
7176
|
-
const a = after.get(id);
|
|
7177
|
-
if (!b || !a || b.layerId !== a.layerId) return true;
|
|
7178
|
-
if (JSON.stringify(b.feature.geometry) !== JSON.stringify(a.feature.geometry)) return true;
|
|
7179
|
-
return JSON.stringify(b.feature.properties ?? {}) !== JSON.stringify(a.feature.properties ?? {});
|
|
7180
|
-
});
|
|
7181
|
-
const layersChanged = featuresChanged || Array.from(layerIds).some((id) => {
|
|
7182
|
-
const b = beforeLayers.get(id);
|
|
7183
|
-
const a = afterLayers.get(id);
|
|
7184
|
-
return !b || !a || JSON.stringify(b) !== JSON.stringify(a);
|
|
7185
|
-
});
|
|
7186
|
-
if (!featuresChanged && !layersChanged) return null;
|
|
7281
|
+
const { featureIds, layerIds } = diffHistorySnapshots(before, after, beforeLayers, afterLayers);
|
|
7282
|
+
if (featureIds.size === 0 && layerIds.size === 0) return null;
|
|
7187
7283
|
const pick = (src, keys) => {
|
|
7188
7284
|
const out = /* @__PURE__ */ new Map();
|
|
7189
7285
|
keys.forEach((k) => {
|
|
@@ -8375,12 +8471,14 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
8375
8471
|
justCreatedRectangleRef.current = false;
|
|
8376
8472
|
return;
|
|
8377
8473
|
}
|
|
8378
|
-
|
|
8379
|
-
|
|
8380
|
-
|
|
8381
|
-
originalGeometriesRef.current.
|
|
8382
|
-
|
|
8383
|
-
|
|
8474
|
+
if (isEditModeRef.current) {
|
|
8475
|
+
e.features.forEach((feature) => {
|
|
8476
|
+
const fid = feature.id;
|
|
8477
|
+
if (!originalGeometriesRef.current.has(fid)) {
|
|
8478
|
+
originalGeometriesRef.current.set(fid, JSON.parse(JSON.stringify(feature.geometry)));
|
|
8479
|
+
}
|
|
8480
|
+
});
|
|
8481
|
+
}
|
|
8384
8482
|
const currentIds = new Set(ids);
|
|
8385
8483
|
originalGeometriesRef.current.forEach((_, key) => {
|
|
8386
8484
|
if (!currentIds.has(key)) {
|
|
@@ -9420,19 +9518,18 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
9420
9518
|
const handleDeleteSelected = react.useCallback(() => {
|
|
9421
9519
|
if (selectedFeatureIds.length === 0) return;
|
|
9422
9520
|
const idSet = new Set(selectedFeatureIds);
|
|
9521
|
+
const readOnlyIdSet = /* @__PURE__ */ new Set();
|
|
9522
|
+
for (const layer of layersRef.current) {
|
|
9523
|
+
if (!layer.readOnly) continue;
|
|
9524
|
+
for (const fid of layer.featureIds) readOnlyIdSet.add(fid);
|
|
9525
|
+
}
|
|
9423
9526
|
const editableIds = [];
|
|
9424
9527
|
const readOnlyIds = [];
|
|
9425
|
-
const currentLayers = layersRef.current;
|
|
9426
9528
|
for (const id of selectedFeatureIds) {
|
|
9427
|
-
|
|
9428
|
-
if (layer == null ? void 0 : layer.readOnly) {
|
|
9429
|
-
readOnlyIds.push(id);
|
|
9430
|
-
} else {
|
|
9431
|
-
editableIds.push(id);
|
|
9432
|
-
}
|
|
9529
|
+
(readOnlyIdSet.has(id) ? readOnlyIds : editableIds).push(id);
|
|
9433
9530
|
}
|
|
9531
|
+
saveStateForUndo("delete features");
|
|
9434
9532
|
if (editableIds.length > 0 && draw.current) {
|
|
9435
|
-
saveStateForUndo();
|
|
9436
9533
|
editableIds.forEach((id) => {
|
|
9437
9534
|
arrowFeatureIdsRef.current.delete(id);
|
|
9438
9535
|
try {
|
|
@@ -9767,7 +9864,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
9767
9864
|
const handleUpdateProperties = react.useCallback((featureId, properties, options) => {
|
|
9768
9865
|
var _a, _b, _c;
|
|
9769
9866
|
if (!map.current) return;
|
|
9770
|
-
saveStateForUndo();
|
|
9867
|
+
if (!(options == null ? void 0 : options.fromRefresh)) saveStateForUndo();
|
|
9771
9868
|
const { startDate, endDate } = normalizeTemporalProperties(properties);
|
|
9772
9869
|
const normalizedProperties = {
|
|
9773
9870
|
...properties,
|
|
@@ -9794,12 +9891,13 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
9794
9891
|
}
|
|
9795
9892
|
syncFeaturesToCustomLayers();
|
|
9796
9893
|
scheduleTimelineUpdate();
|
|
9894
|
+
setFeatureUpdateCounter((c) => c + 1);
|
|
9797
9895
|
const updated = draw.current.get(featureId);
|
|
9798
9896
|
if (updated) onFeatureUpdate == null ? void 0 : onFeatureUpdate(updated);
|
|
9799
9897
|
} else {
|
|
9800
9898
|
let updatedFeature;
|
|
9801
9899
|
readOnlyFeatures.current.forEach((features, layerId) => {
|
|
9802
|
-
var _a2
|
|
9900
|
+
var _a2;
|
|
9803
9901
|
const idx = features.findIndex((f) => String(f.id) === featureId);
|
|
9804
9902
|
if (idx !== -1) {
|
|
9805
9903
|
const f = features[idx];
|
|
@@ -9810,20 +9908,25 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
9810
9908
|
if (JSON.stringify(oldVal) !== JSON.stringify(value)) hasRealChange = true;
|
|
9811
9909
|
});
|
|
9812
9910
|
const currentUnsaved = (_a2 = f.properties) == null ? void 0 : _a2._unsaved;
|
|
9813
|
-
|
|
9911
|
+
const nextProperties = { ...f.properties, ...normalizedProperties };
|
|
9814
9912
|
if (!externalPersistence && hasRealChange && currentUnsaved !== false && !(options == null ? void 0 : options.fromRefresh)) {
|
|
9815
|
-
|
|
9913
|
+
nextProperties._unsaved = true;
|
|
9816
9914
|
}
|
|
9817
|
-
if (properties.kind === "text" ||
|
|
9818
|
-
delete
|
|
9915
|
+
if (properties.kind === "text" || nextProperties.kind === "text") {
|
|
9916
|
+
delete nextProperties.text;
|
|
9819
9917
|
}
|
|
9918
|
+
const replacement = { ...f, properties: nextProperties };
|
|
9919
|
+
const nextFeatures = features.slice();
|
|
9920
|
+
nextFeatures[idx] = replacement;
|
|
9921
|
+
readOnlyFeatures.current.set(layerId, nextFeatures);
|
|
9820
9922
|
layerTemporalCacheRef.current.delete(layerId);
|
|
9821
|
-
updatedFeature =
|
|
9923
|
+
updatedFeature = replacement;
|
|
9822
9924
|
}
|
|
9823
9925
|
});
|
|
9824
9926
|
if (updatedFeature) {
|
|
9825
9927
|
syncFeaturesToCustomLayers();
|
|
9826
9928
|
scheduleTimelineUpdate();
|
|
9929
|
+
setFeatureUpdateCounter((c) => c + 1);
|
|
9827
9930
|
onFeatureUpdate == null ? void 0 : onFeatureUpdate(updatedFeature);
|
|
9828
9931
|
}
|
|
9829
9932
|
}
|
|
@@ -9850,6 +9953,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
9850
9953
|
}
|
|
9851
9954
|
draw.current.changeMode("simple_select", { featureIds: [featureId] });
|
|
9852
9955
|
syncFeaturesToCustomLayers();
|
|
9956
|
+
setFeatureUpdateCounter((c) => c + 1);
|
|
9853
9957
|
const updated = draw.current.get(featureId);
|
|
9854
9958
|
if (updated) {
|
|
9855
9959
|
onFeatureUpdate == null ? void 0 : onFeatureUpdate(updated);
|
|
@@ -10017,16 +10121,8 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
10017
10121
|
}, [saveStateForUndo]);
|
|
10018
10122
|
const findFeatureById = react.useCallback((id) => {
|
|
10019
10123
|
var _a;
|
|
10020
|
-
|
|
10021
|
-
|
|
10022
|
-
readOnlyFeatures.current.forEach((features) => {
|
|
10023
|
-
if (!feature) {
|
|
10024
|
-
const found = features.find((f) => String(f.id) === id);
|
|
10025
|
-
if (found) feature = found;
|
|
10026
|
-
}
|
|
10027
|
-
});
|
|
10028
|
-
return feature;
|
|
10029
|
-
}, []);
|
|
10124
|
+
return ((_a = draw.current) == null ? void 0 : _a.get(id)) ?? getReadOnlyFeatureById(id) ?? void 0;
|
|
10125
|
+
}, [getReadOnlyFeatureById]);
|
|
10030
10126
|
const handleMoveFeaturesToLayer = react.useCallback((featureIds, targetLayerId) => {
|
|
10031
10127
|
if (!draw.current) return;
|
|
10032
10128
|
saveStateForUndo();
|
|
@@ -10386,22 +10482,10 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
10386
10482
|
setAutoLabelConfig(config);
|
|
10387
10483
|
}, []);
|
|
10388
10484
|
const countVisibleFeaturesInViewport = react.useCallback(() => {
|
|
10389
|
-
var _a;
|
|
10390
10485
|
if (!map.current || !isMapLoaded) return;
|
|
10391
|
-
const
|
|
10392
|
-
|
|
10393
|
-
|
|
10394
|
-
setVisibleFeatureCount(0);
|
|
10395
|
-
return;
|
|
10396
|
-
}
|
|
10397
|
-
const rendered = map.current.queryRenderedFeatures(void 0, { layers: existingLayers });
|
|
10398
|
-
const uniqueIds = /* @__PURE__ */ new Set();
|
|
10399
|
-
for (const f of rendered) {
|
|
10400
|
-
const fid = ((_a = f.properties) == null ? void 0 : _a.id) || f.id;
|
|
10401
|
-
if (fid) uniqueIds.add(String(fid));
|
|
10402
|
-
}
|
|
10403
|
-
setVisibleFeatureCount(uniqueIds.size);
|
|
10404
|
-
}, [isMapLoaded]);
|
|
10486
|
+
const threshold = autoLabelConfig.enabled ? autoLabelConfig.threshold : 220;
|
|
10487
|
+
setVisibleFeatureCount(countVisibleFeatures(threshold));
|
|
10488
|
+
}, [isMapLoaded, countVisibleFeatures, autoLabelConfig.enabled, autoLabelConfig.threshold]);
|
|
10405
10489
|
react.useEffect(() => {
|
|
10406
10490
|
if (!map.current || !isMapLoaded) return;
|
|
10407
10491
|
const mapInstance = map.current;
|
|
@@ -10431,6 +10515,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
10431
10515
|
if (!map.current || !isMapLoaded) return;
|
|
10432
10516
|
const mapInstance = map.current;
|
|
10433
10517
|
const handleMove = () => {
|
|
10518
|
+
if (!hasArrowFeaturesRef.current) return;
|
|
10434
10519
|
if (syncRef.current) {
|
|
10435
10520
|
syncRef.current();
|
|
10436
10521
|
}
|
|
@@ -10487,31 +10572,8 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
10487
10572
|
let lastCenter = mapInstance.getCenter();
|
|
10488
10573
|
let lastZoom = mapInstance.getZoom();
|
|
10489
10574
|
const updateViewportCount = () => {
|
|
10490
|
-
var _a;
|
|
10491
|
-
const layers2 = ["custom-point", "custom-line", "custom-polygon-fill"];
|
|
10492
|
-
const existing = layers2.filter((id) => mapInstance.getLayer(id));
|
|
10493
|
-
if (existing.length === 0) {
|
|
10494
|
-
setVisibleFeatureCount(0);
|
|
10495
|
-
setLabelsSuppressed(false);
|
|
10496
|
-
return;
|
|
10497
|
-
}
|
|
10498
10575
|
const threshold = autoLabelConfig.enabled ? autoLabelConfig.threshold : 220;
|
|
10499
|
-
|
|
10500
|
-
const uniqueIds = /* @__PURE__ */ new Set();
|
|
10501
|
-
let count = 0;
|
|
10502
|
-
for (const f of rendered) {
|
|
10503
|
-
const fid = ((_a = f.properties) == null ? void 0 : _a.id) || f.id;
|
|
10504
|
-
if (fid && !uniqueIds.has(String(fid))) {
|
|
10505
|
-
uniqueIds.add(String(fid));
|
|
10506
|
-
count++;
|
|
10507
|
-
if (count > threshold) {
|
|
10508
|
-
setVisibleFeatureCount(count);
|
|
10509
|
-
setLabelsSuppressed(false);
|
|
10510
|
-
return;
|
|
10511
|
-
}
|
|
10512
|
-
}
|
|
10513
|
-
}
|
|
10514
|
-
setVisibleFeatureCount(count);
|
|
10576
|
+
setVisibleFeatureCount(countVisibleFeatures(threshold));
|
|
10515
10577
|
setLabelsSuppressed(false);
|
|
10516
10578
|
};
|
|
10517
10579
|
const onMapMovement = () => {
|
|
@@ -10537,7 +10599,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
10537
10599
|
} catch {
|
|
10538
10600
|
}
|
|
10539
10601
|
};
|
|
10540
|
-
}, [isMapLoaded, autoLabelConfig.threshold, autoLabelConfig.enabled]);
|
|
10602
|
+
}, [isMapLoaded, autoLabelConfig.threshold, autoLabelConfig.enabled, countVisibleFeatures]);
|
|
10541
10603
|
const DEFAULT_LABEL_THRESHOLD = 220;
|
|
10542
10604
|
react.useEffect(() => {
|
|
10543
10605
|
if (!map.current || !isMapLoaded) return;
|
|
@@ -12242,7 +12304,12 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
12242
12304
|
const handleTimelineFilterChange = react.useCallback((visibleIds, hiddenIds, untimedIds) => {
|
|
12243
12305
|
if (!draw.current || !map.current) return;
|
|
12244
12306
|
timelineVisibleIdsRef.current = /* @__PURE__ */ new Set([...visibleIds, ...untimedIds]);
|
|
12245
|
-
|
|
12307
|
+
if (timelineSyncRafRef.current == null) {
|
|
12308
|
+
timelineSyncRafRef.current = requestAnimationFrame(() => {
|
|
12309
|
+
timelineSyncRafRef.current = null;
|
|
12310
|
+
syncFeaturesToCustomLayers();
|
|
12311
|
+
});
|
|
12312
|
+
}
|
|
12246
12313
|
}, [syncFeaturesToCustomLayers]);
|
|
12247
12314
|
const prevTimelineEnabledRef = react.useRef(timelineStore.isEnabled);
|
|
12248
12315
|
react.useEffect(() => {
|