@octostar/map-component 0.6.5 → 0.7.0

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.
Files changed (31) hide show
  1. package/dist/index.mjs +601 -78
  2. package/dist/index.mjs.map +1 -1
  3. package/dist/types/components/layers-panel.d.ts +8 -0
  4. package/dist/types/components/layers-panel.d.ts.map +1 -1
  5. package/dist/types/components/map-editor-canvas.d.ts.map +1 -1
  6. package/dist/types/index.d.ts +2 -0
  7. package/dist/types/index.d.ts.map +1 -1
  8. package/dist/types/lib/custom-layer-stack.d.ts +7 -1
  9. package/dist/types/lib/custom-layer-stack.d.ts.map +1 -1
  10. package/dist/types/lib/feature-stack.d.ts.map +1 -1
  11. package/dist/types/lib/host-icon-scale.d.ts +28 -0
  12. package/dist/types/lib/host-icon-scale.d.ts.map +1 -0
  13. package/dist/types/lib/host-line-decorations.d.ts +70 -0
  14. package/dist/types/lib/host-line-decorations.d.ts.map +1 -0
  15. package/dist/types/lib/host-owned-layers.d.ts +84 -0
  16. package/dist/types/lib/host-owned-layers.d.ts.map +1 -0
  17. package/dist/types/lib/label-pinning.d.ts +24 -0
  18. package/dist/types/lib/label-pinning.d.ts.map +1 -1
  19. package/dist/types/lib/map-editor-api.d.ts +37 -0
  20. package/dist/types/lib/map-editor-api.d.ts.map +1 -1
  21. package/dist/types/lib/paint-feature.d.ts +9 -2
  22. package/dist/types/lib/paint-feature.d.ts.map +1 -1
  23. package/dist/types/lib/property-utils.d.ts +1 -1
  24. package/dist/types/lib/property-utils.d.ts.map +1 -1
  25. package/dist/types/lib/selection-overlay.d.ts +2 -1
  26. package/dist/types/lib/selection-overlay.d.ts.map +1 -1
  27. package/dist/types/lib/shard-constants.d.ts +5 -1
  28. package/dist/types/lib/shard-constants.d.ts.map +1 -1
  29. package/dist/types/lib/shard-registry.d.ts +2 -0
  30. package/dist/types/lib/shard-registry.d.ts.map +1 -1
  31. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -776,6 +776,27 @@ function installInlinedMaplibreWorker() {
776
776
  }
777
777
  setWorkerUrl(URL.createObjectURL(new Blob([maplibreWorkerSource], { type: "text/javascript" })));
778
778
  }
779
+ const HOST_ICON_FULL_ZOOM_PROP = "iconFullZoom";
780
+ const HOST_ICON_MIN_ZOOM_PROP = "iconMinZoom";
781
+ const HOST_ICON_MIN_SCALE_PROP = "iconMinScale";
782
+ const ZOOM_STOPS = Array.from({ length: 23 }, (_, z) => z);
783
+ function hostIconScaleAt(z) {
784
+ const full = ["coalesce", ["get", HOST_ICON_FULL_ZOOM_PROP], 0];
785
+ const min = ["coalesce", ["get", HOST_ICON_MIN_ZOOM_PROP], -1];
786
+ const towardsMin = ["max", 0, ["min", 1, ["/", ["-", full, z], ["max", 1e-3, ["-", full, min]]]]];
787
+ return ["^", ["coalesce", ["get", HOST_ICON_MIN_SCALE_PROP], 1], towardsMin];
788
+ }
789
+ function zoomCurve(at) {
790
+ return ["interpolate", ["exponential", 2], ["zoom"], ...ZOOM_STOPS.flatMap((z) => [z, at(z)])];
791
+ }
792
+ const iconSizeAt = (z, canvasSize) => ["*", ["/", ["coalesce", ["get", "iconSize"], 24], canvasSize], hostIconScaleAt(z)];
793
+ function hostIconSizeMultiplier(size, fieldPosition) {
794
+ if ((size == null ? void 0 : size.mode) === "override" && size.overrideValue !== void 0) {
795
+ return 0.5 + Math.max(1, Math.min(10, size.overrideValue)) * 0.1;
796
+ }
797
+ if ((size == null ? void 0 : size.mode) === "field" && fieldPosition !== null) return 0.6 + fieldPosition * 0.9;
798
+ return 1;
799
+ }
779
800
  const SELECTED_STATE_KEY = "selected";
780
801
  const SELECTED = ["boolean", ["feature-state", SELECTED_STATE_KEY], false];
781
802
  const SELECTED_STATE = Object.freeze({ [SELECTED_STATE_KEY]: true });
@@ -787,6 +808,18 @@ const TRACE_ENDPOINT = ["boolean", ["feature-state", TRACE_ENDPOINT_KEY], false]
787
808
  const LABEL_NEVER_HIDE_PROP = "_labelNeverHide";
788
809
  const PINNED_LABEL_FILTER = ["==", ["get", LABEL_NEVER_HIDE_PROP], 1];
789
810
  const UNPINNED_LABEL_FILTER = ["!=", ["get", LABEL_NEVER_HIDE_PROP], 1];
811
+ const HOST_OWNED_PROP = "_hostOwned";
812
+ const HOST_FILTER = ["==", ["get", HOST_OWNED_PROP], 1];
813
+ const NOT_HOST_FILTER = ["!=", ["get", HOST_OWNED_PROP], 1];
814
+ const hostIconLabelOffsetAt = (z) => [
815
+ "interpolate",
816
+ ["linear"],
817
+ ["+", 0.2, ["/", ["*", ["coalesce", ["get", "iconSize"], 24], hostIconScaleAt(z)], ["*", 2, ["coalesce", ["get", "fontSize"], 12]]]],
818
+ 0,
819
+ ["literal", [0, 0]],
820
+ 1e3,
821
+ ["literal", [0, 1e3]]
822
+ ];
790
823
  function computeLabelNeverHide(label) {
791
824
  return (label == null ? void 0 : label.neverHide) && !label.hidden ? 1 : 0;
792
825
  }
@@ -852,6 +885,23 @@ function buildCustomLabelPaint(opts) {
852
885
  "text-opacity": (opts == null ? void 0 : opts.hideSelected) ? ["case", TIMELINE_HIDDEN, 0, SELECTED, 0, visibleOpacity] : visibleOpacity
853
886
  };
854
887
  }
888
+ function buildHostLabelLayout() {
889
+ const base = buildCustomLabelLayout();
890
+ return {
891
+ ...base,
892
+ "text-field": ["case", ["==", ["geometry-type"], "LineString"], "", base["text-field"]],
893
+ "text-size": ["coalesce", ["get", "fontSize"], 12],
894
+ "text-offset": zoomCurve((z) => [
895
+ "case",
896
+ ["!=", ["get", "icon"], ""],
897
+ hostIconLabelOffsetAt(z),
898
+ ["literal", [0, 0.8]]
899
+ ])
900
+ };
901
+ }
902
+ function buildHostLabelPaint() {
903
+ return { ...buildCustomLabelPaint(), "text-color": ["coalesce", ["get", "fontColor"], "#1f2937"] };
904
+ }
855
905
  const DEFAULT_FEATURE_COLOR = "#3b82f6";
856
906
  const LAYER_COLOR_PALETTE = [
857
907
  "#3FB37F",
@@ -912,8 +962,10 @@ const CUSTOM_LAYER_ROLES = [
912
962
  "point-shadow",
913
963
  "point",
914
964
  "point-icon",
965
+ "host-icon",
915
966
  "labels",
916
- "labels-pinned"
967
+ "labels-pinned",
968
+ "host-labels"
917
969
  ];
918
970
  const SHARED_SOURCE_ID = "custom-features";
919
971
  function customSourceSpec() {
@@ -970,6 +1022,11 @@ function shardInsertAnchor(role) {
970
1022
  return "custom-arrow-heads";
971
1023
  case "labels-pinned":
972
1024
  return "custom-arrow-heads";
1025
+ // Never in a shard stack: host-owned layers are not sharded.
1026
+ case "host-icon":
1027
+ return "custom-arrow-heads";
1028
+ case "host-labels":
1029
+ return "custom-arrow-heads";
973
1030
  }
974
1031
  }
975
1032
  const POINT_RADIUS = ["case", TRACE_ENDPOINT, ["get", "_endpointRadius"], ["coalesce", ["get", "pointRadius"], 5]];
@@ -978,6 +1035,7 @@ function unlessTimelineHidden(value) {
978
1035
  }
979
1036
  function buildLayer(role, sourceId, opts) {
980
1037
  const id = customLayerId(role, sourceId);
1038
+ const shared = sourceId === SHARED_SOURCE_ID;
981
1039
  switch (role) {
982
1040
  // Custom polygon fill layer - preserves original styling
983
1041
  case "polygon-fill":
@@ -1116,7 +1174,7 @@ function buildLayer(role, sourceId, opts) {
1116
1174
  id,
1117
1175
  type: "symbol",
1118
1176
  source: sourceId,
1119
- filter: ["all", ["==", "$type", "Point"], ["!=", "icon", ""]],
1177
+ filter: shared ? ["all", ["==", "$type", "Point"], ["!=", "icon", ""], ["!=", HOST_OWNED_PROP, 1]] : ["all", ["==", "$type", "Point"], ["!=", "icon", ""]],
1120
1178
  layout: {
1121
1179
  "icon-image": ["get", "icon"],
1122
1180
  "icon-size": ["/", ["coalesce", ["get", "iconSize"], 24], EMOJI_CANVAS_SIZE],
@@ -1146,7 +1204,7 @@ function buildLayer(role, sourceId, opts) {
1146
1204
  id,
1147
1205
  type: "symbol",
1148
1206
  source: sourceId,
1149
- filter: UNPINNED_LABEL_FILTER,
1207
+ filter: shared ? ["all", UNPINNED_LABEL_FILTER, NOT_HOST_FILTER] : UNPINNED_LABEL_FILTER,
1150
1208
  layout: {
1151
1209
  ...buildCustomLabelLayout(),
1152
1210
  "visibility": opts.labelsVisible ? "visible" : "none",
@@ -1198,7 +1256,7 @@ function buildLayer(role, sourceId, opts) {
1198
1256
  id,
1199
1257
  type: "symbol",
1200
1258
  source: sourceId,
1201
- filter: PINNED_LABEL_FILTER,
1259
+ filter: shared ? ["all", PINNED_LABEL_FILTER, NOT_HOST_FILTER] : PINNED_LABEL_FILTER,
1202
1260
  layout: {
1203
1261
  ...buildCustomLabelLayout(),
1204
1262
  "visibility": "visible",
@@ -1211,6 +1269,29 @@ function buildLayer(role, sourceId, opts) {
1211
1269
  },
1212
1270
  paint: buildCustomLabelPaint({ hideSelected: true })
1213
1271
  };
1272
+ // A host point's icon, scaled along the host's zoom curve. The only
1273
+ // icon layer a pointer can hit, while a host-owned layer exists.
1274
+ case "host-icon": {
1275
+ const icon = buildLayer("point-icon", sourceId, opts);
1276
+ return {
1277
+ ...icon,
1278
+ id,
1279
+ filter: ["all", ["==", "$type", "Point"], ["!=", "icon", ""], ["==", HOST_OWNED_PROP, 1]],
1280
+ layout: { ...icon.layout, "icon-size": zoomCurve((z) => iconSizeAt(z, EMOJI_CANVAS_SIZE)) }
1281
+ };
1282
+ }
1283
+ // Host labels: collision-culled and density-hidden like `labels`, styled
1284
+ // by the host (label-pinning.ts). A host layer's "never hide" is not honoured.
1285
+ case "host-labels": {
1286
+ const labels = buildLayer("labels", sourceId, opts);
1287
+ return {
1288
+ ...labels,
1289
+ id,
1290
+ filter: HOST_FILTER,
1291
+ layout: { ...labels.layout, ...buildHostLabelLayout() },
1292
+ paint: buildHostLabelPaint()
1293
+ };
1294
+ }
1214
1295
  }
1215
1296
  }
1216
1297
  function buildCustomLayerStack(sourceId, roles, opts) {
@@ -1221,6 +1302,7 @@ function isShardEligible(layer, featureCount, shardSize) {
1221
1302
  var _a;
1222
1303
  if (!layer.readOnly) return false;
1223
1304
  if ((_a = layer.traceConfig) == null ? void 0 : _a.enabled) return false;
1305
+ if (layer.hostOwned) return false;
1224
1306
  if (!isUsableShardSize(shardSize)) return false;
1225
1307
  return featureCount > shardSize;
1226
1308
  }
@@ -1276,6 +1358,7 @@ function shardFingerprintsEqual(a, b) {
1276
1358
  return Object.is(a.features, b.features) && Object.is(a.visualConfig, b.visualConfig) && Object.is(a.heatmapConfig, b.heatmapConfig) && Object.is(a.clusterConfig, b.clusterConfig) && Object.is(a.altitudeDisplayMode, b.altitudeDisplayMode) && Object.is(a.hasAltitudeData, b.hasAltitudeData) && Object.is(a.shardSize, b.shardSize);
1277
1359
  }
1278
1360
  const INTERACTIVE_ROLES = ["point", "line", "polygon-fill"];
1361
+ const HOST_INTERACTIVE_ROLES = [...INTERACTIVE_ROLES, "host-icon"];
1279
1362
  function createShardRegistry(host, hooks) {
1280
1363
  const states = /* @__PURE__ */ new Map();
1281
1364
  let sharedLayerIds = [];
@@ -1397,7 +1480,8 @@ function createShardRegistry(host, hooks) {
1397
1480
  },
1398
1481
  labelLayerIds(kind, opts) {
1399
1482
  const roles = kind === "unpinned" ? ["labels"] : kind === "pinned" ? ["labels-pinned"] : ["labels", "labels-pinned"];
1400
- const ids = sharedLayerIds.filter((id) => roles.some((role) => id === customLayerId(role, SHARED_SOURCE_ID)));
1483
+ const sharedRoles = kind === "pinned" ? roles : [...roles, "host-labels"];
1484
+ const ids = sharedLayerIds.filter((id) => sharedRoles.some((role) => id === customLayerId(role, SHARED_SOURCE_ID)));
1401
1485
  states.forEach((state) => {
1402
1486
  if ((opts == null ? void 0 : opts.visibleLayersOnly) && !state.visible) return;
1403
1487
  state.stacks.forEach((stack) => {
@@ -1410,8 +1494,10 @@ function createShardRegistry(host, hooks) {
1410
1494
  return ids;
1411
1495
  },
1412
1496
  interactiveLayerIds() {
1497
+ var _a;
1498
+ const sharedRoles = ((_a = hooks.hostIconInteractive) == null ? void 0 : _a.call(hooks)) ? HOST_INTERACTIVE_ROLES : INTERACTIVE_ROLES;
1413
1499
  const ids = sharedLayerIds.filter(
1414
- (id) => INTERACTIVE_ROLES.some((role) => id === customLayerId(role, SHARED_SOURCE_ID))
1500
+ (id) => sharedRoles.some((role) => id === customLayerId(role, SHARED_SOURCE_ID))
1415
1501
  );
1416
1502
  states.forEach((state) => {
1417
1503
  if (!state.visible) return;
@@ -1544,6 +1630,79 @@ function formatGradientStop(value) {
1544
1630
  }
1545
1631
  return new Intl.NumberFormat("en-US", { maximumFractionDigits: 2 }).format(value);
1546
1632
  }
1633
+ const HOST_IMAGE_PREFIX = "host:";
1634
+ function isHostOwnedLayer(layer) {
1635
+ return (layer == null ? void 0 : layer.hostOwned) === true;
1636
+ }
1637
+ function isHistoryExcludedLayer(layer) {
1638
+ var _a;
1639
+ return ((_a = layer == null ? void 0 : layer.metadata) == null ? void 0 : _a.dataViewing) === true || isHostOwnedLayer(layer);
1640
+ }
1641
+ function keepLayerAfterFeatureRemoval(layer) {
1642
+ return layer.featureIds.length > 0 || !layer.readOnly || isHostOwnedLayer(layer);
1643
+ }
1644
+ function showsPropertiesFor(ids, layers) {
1645
+ if (ids.length === 0) return false;
1646
+ const hostIds = new Set(layers.filter(isHostOwnedLayer).flatMap((l) => l.featureIds));
1647
+ return ids.some((id) => !hostIds.has(id));
1648
+ }
1649
+ function splitDeleteByOwner(layers, ids) {
1650
+ const hostLayerOf = /* @__PURE__ */ new Map();
1651
+ for (const layer of layers) {
1652
+ if (!isHostOwnedLayer(layer)) continue;
1653
+ for (const fid of layer.featureIds) hostLayerOf.set(fid, layer.id);
1654
+ }
1655
+ const deletableIds = [];
1656
+ const byLayer = /* @__PURE__ */ new Map();
1657
+ for (const id of ids) {
1658
+ const layerId = hostLayerOf.get(id);
1659
+ if (layerId === void 0) {
1660
+ deletableIds.push(id);
1661
+ continue;
1662
+ }
1663
+ const list = byLayer.get(layerId);
1664
+ if (list) list.push(id);
1665
+ else byLayer.set(layerId, [id]);
1666
+ }
1667
+ const hostRequests = [];
1668
+ for (const layer of layers) {
1669
+ const featureIds = byLayer.get(layer.id);
1670
+ if (featureIds) hostRequests.push({ layerId: layer.id, featureIds });
1671
+ }
1672
+ return { deletableIds, hostRequests };
1673
+ }
1674
+ function movableFeatureIds(layers, ids, targetLayerId) {
1675
+ if (targetLayerId !== void 0 && isHostOwnedLayer(layers.find((l) => l.id === targetLayerId))) return [];
1676
+ return splitDeleteByOwner(layers, ids).deletableIds;
1677
+ }
1678
+ function isHostDeleteUndo(value) {
1679
+ return typeof (value == null ? void 0 : value.undo) === "function" && typeof (value == null ? void 0 : value.redo) === "function";
1680
+ }
1681
+ function withHostDeleteUndos(base, label, hostUndos) {
1682
+ if (hostUndos.length === 0) return base;
1683
+ return {
1684
+ ...base,
1685
+ label: (base == null ? void 0 : base.label) ?? label,
1686
+ undo: () => {
1687
+ base == null ? void 0 : base.undo();
1688
+ hostUndos.forEach((h) => h.undo());
1689
+ },
1690
+ redo: () => {
1691
+ base == null ? void 0 : base.redo();
1692
+ hostUndos.forEach((h) => h.redo());
1693
+ }
1694
+ };
1695
+ }
1696
+ function resolveMissingImage(id, provider) {
1697
+ let image = null;
1698
+ try {
1699
+ image = provider == null ? void 0 : provider(id);
1700
+ } catch {
1701
+ image = null;
1702
+ }
1703
+ if (image == null ? void 0 : image.data) return { kind: "host", image };
1704
+ return id.startsWith(HOST_IMAGE_PREFIX) ? { kind: "none" } : { kind: "emoji" };
1705
+ }
1547
1706
  const ICONS = [
1548
1707
  // Location & Places
1549
1708
  { id: "map-pin", emoji: "📍", name: "Map Pin", category: "places" },
@@ -2165,6 +2324,11 @@ const DEFAULT_LABEL_PRIORITY = 100;
2165
2324
  const DEFAULT_VISIBLE_STROKE_OPACITY = 1;
2166
2325
  const DEFAULT_VISIBLE_FILL_OPACITY = 0.2;
2167
2326
  const RENDER_PASSTHROUGH_KEYS = ["_dvl_h3"];
2327
+ const HOST_PASSTHROUGH_KEYS = [
2328
+ HOST_ICON_FULL_ZOOM_PROP,
2329
+ HOST_ICON_MIN_ZOOM_PROP,
2330
+ HOST_ICON_MIN_SCALE_PROP
2331
+ ];
2168
2332
  const ANNOTATION_PASSTHROUGH_KEYS = [
2169
2333
  "kind",
2170
2334
  "text",
@@ -2193,7 +2357,7 @@ function resolveIcon(value) {
2193
2357
  if (typeof value !== "string" || value === "") return "";
2194
2358
  if (value !== lastIcon) {
2195
2359
  lastIcon = value;
2196
- lastResolvedIcon = isEmojiIcon(value) ? value : EMOJI_BY_ID.get(value) ?? "";
2360
+ lastResolvedIcon = value.startsWith(HOST_IMAGE_PREFIX) || isEmojiIcon(value) ? value : EMOJI_BY_ID.get(value) ?? "";
2197
2361
  }
2198
2362
  return lastResolvedIcon;
2199
2363
  }
@@ -2208,6 +2372,16 @@ const clusterHidesPoints = (layer) => {
2208
2372
  function layerHidesPoints(layer) {
2209
2373
  return heatmapHidesPoints(layer) || clusterHidesPoints(layer);
2210
2374
  }
2375
+ function sizeFieldPosition(f, layer, ctx) {
2376
+ var _a, _b;
2377
+ const size = (_a = layer == null ? void 0 : layer.visualConfig) == null ? void 0 : _a.size;
2378
+ if (!layer || (size == null ? void 0 : size.mode) !== "field" || !size.fieldName) return null;
2379
+ const range = ctx.sizeFieldRanges.get(layer.id);
2380
+ if (!range) return null;
2381
+ const val = coerceFiniteNumber((_b = f.properties) == null ? void 0 : _b[size.fieldName]);
2382
+ if (val === null) return null;
2383
+ return range.max > range.min ? (val - range.min) / (range.max - range.min) : 0.5;
2384
+ }
2211
2385
  function styleFeatureForPaint(f, layer, ctx, slim) {
2212
2386
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
2213
2387
  const featureId = String(f.id);
@@ -2226,20 +2400,18 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
2226
2400
  let strokeWidth = ((_c = f.properties) == null ? void 0 : _c["stroke-width"]) || 2;
2227
2401
  let pointRadius = Math.round(3 + strokeWidth);
2228
2402
  const sizeConfig = visualConfig == null ? void 0 : visualConfig.size;
2229
- if (sizeConfig) {
2403
+ const hostSizeMultiplier = (layer == null ? void 0 : layer.hostOwned) ? hostIconSizeMultiplier(sizeConfig, sizeFieldPosition(f, layer, ctx)) : null;
2404
+ if (hostSizeMultiplier !== null) {
2405
+ strokeWidth *= hostSizeMultiplier;
2406
+ } else if (sizeConfig) {
2230
2407
  if (sizeConfig.mode === "override" && sizeConfig.overrideValue !== void 0) {
2231
2408
  strokeWidth = Math.max(1, Math.min(10, sizeConfig.overrideValue));
2232
2409
  pointRadius = Math.round(3 + strokeWidth);
2233
- } else if (sizeConfig.mode === "field" && sizeConfig.fieldName && layer) {
2234
- const range = ctx.sizeFieldRanges.get(layer.id);
2235
- if (range && f.properties) {
2236
- const rawVal = f.properties[sizeConfig.fieldName];
2237
- const val = typeof rawVal === "number" ? rawVal : typeof rawVal === "string" && rawVal.trim() !== "" ? Number(rawVal) : NaN;
2238
- if (isFinite(val)) {
2239
- const normalized = range.max > range.min ? (val - range.min) / (range.max - range.min) : 0.5;
2240
- strokeWidth = 2 + normalized * 8;
2241
- pointRadius = Math.round(2 + normalized * 16);
2242
- }
2410
+ } else {
2411
+ const pos = sizeFieldPosition(f, layer, ctx);
2412
+ if (pos !== null) {
2413
+ strokeWidth = 2 + pos * 8;
2414
+ pointRadius = Math.round(2 + pos * 16);
2243
2415
  }
2244
2416
  }
2245
2417
  }
@@ -2263,7 +2435,9 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
2263
2435
  }
2264
2436
  }
2265
2437
  let featureIcon = resolveIcon(((_e = f.properties) == null ? void 0 : _e.pointIcon) || ((_f = f.properties) == null ? void 0 : _f.icon));
2438
+ if (featureIcon.startsWith(HOST_IMAGE_PREFIX) && !isHostOwnedLayer(layer)) featureIcon = "";
2266
2439
  let featureIconSize = ((_g = f.properties) == null ? void 0 : _g.pointIconSize) || ((_h = f.properties) == null ? void 0 : _h.iconSize) || 24;
2440
+ if (hostSizeMultiplier !== null) featureIconSize *= hostSizeMultiplier;
2267
2441
  const iconConfig = visualConfig == null ? void 0 : visualConfig.icon;
2268
2442
  const layerIcon = !featureIcon && (iconConfig == null ? void 0 : iconConfig.enabled) ? resolveIcon(iconConfig.icon) : "";
2269
2443
  if (layerIcon) {
@@ -2282,7 +2456,12 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
2282
2456
  RENDER_PASSTHROUGH_KEYS.forEach((key) => {
2283
2457
  if (key in props) sanitizedProps[key] = sanitizeValue(props[key]);
2284
2458
  });
2285
- if (typeof props.kind === "string") {
2459
+ if (layer == null ? void 0 : layer.hostOwned) {
2460
+ HOST_PASSTHROUGH_KEYS.forEach((key) => {
2461
+ if (key in props) sanitizedProps[key] = sanitizeValue(props[key]);
2462
+ });
2463
+ }
2464
+ if (typeof props.kind === "string" || (layer == null ? void 0 : layer.hostOwned)) {
2286
2465
  ANNOTATION_PASSTHROUGH_KEYS.forEach((key) => {
2287
2466
  if (key in props) sanitizedProps[key] = sanitizeValue(props[key]);
2288
2467
  });
@@ -2307,7 +2486,7 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
2307
2486
  }
2308
2487
  const visibleStrokeOpacity = hideFlatFor3DOnly ? 0 : baseOpacity;
2309
2488
  const visibleFillOpacity = hideFlatFor3DOnly ? 0 : ((_k = f.properties) == null ? void 0 : _k["fill-opacity"]) ?? DEFAULT_VISIBLE_FILL_OPACITY;
2310
- return {
2489
+ const styled = {
2311
2490
  feature: {
2312
2491
  type: "Feature",
2313
2492
  id: featureId,
@@ -2335,6 +2514,8 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
2335
2514
  }
2336
2515
  }
2337
2516
  };
2517
+ if (layer == null ? void 0 : layer.hostOwned) styled.feature.properties[HOST_OWNED_PROP] = 1;
2518
+ return styled;
2338
2519
  }
2339
2520
  function layerFieldRanges(visualConfig, forEachProperties) {
2340
2521
  const sizeConfig = visualConfig == null ? void 0 : visualConfig.size;
@@ -2432,6 +2613,224 @@ function frameYield(scheduler = defaultScheduler, fallbackMs = 50) {
2432
2613
  }, fallbackMs);
2433
2614
  });
2434
2615
  }
2616
+ const HOST_DECORATION_SOURCE_ID = "host-line-decorations";
2617
+ const HOST_DECORATION_LAYER_IDS = {
2618
+ arrowheads: "custom-host-arrowheads",
2619
+ labels: "custom-host-line-labels"
2620
+ };
2621
+ const ARROWHEAD_IMAGE_ID = "octostar:arrowhead";
2622
+ const ARROWHEAD_LENGTH = 12;
2623
+ const ARROWHEAD_WIDTH = 10;
2624
+ const ARROWHEAD_BUFFER = 3;
2625
+ function arrowheadScale(strokeWidth) {
2626
+ const width = typeof strokeWidth === "number" && isFinite(strokeWidth) ? strokeWidth : 2;
2627
+ return Math.max(1, width / 2);
2628
+ }
2629
+ const DEG = Math.PI / 180;
2630
+ function toMercator([lng, lat]) {
2631
+ const clamped = Math.max(-85.0511, Math.min(85.0511, lat));
2632
+ return [lng * DEG, Math.log(Math.tan(Math.PI / 4 + clamped * DEG / 2))];
2633
+ }
2634
+ function fromMercator([x, y]) {
2635
+ return [x / DEG, (2 * Math.atan(Math.exp(y)) - Math.PI / 2) / DEG];
2636
+ }
2637
+ function segmentBearing(from, to) {
2638
+ const [x0, y0] = toMercator(from);
2639
+ const [x1, y1] = toMercator(to);
2640
+ return Math.atan2(x1 - x0, y1 - y0) / DEG;
2641
+ }
2642
+ function labelRotationForBearing(bearing) {
2643
+ let r = bearing - 90;
2644
+ r = (r % 360 + 540) % 360 - 180;
2645
+ if (r > 90) r -= 180;
2646
+ else if (r < -90) r += 180;
2647
+ return r;
2648
+ }
2649
+ function lineMidpoint(coords) {
2650
+ if (coords.length < 2) return null;
2651
+ const projected = coords.map(toMercator);
2652
+ const lengths = [];
2653
+ let total = 0;
2654
+ for (let i = 1; i < projected.length; i++) {
2655
+ const len = Math.hypot(projected[i][0] - projected[i - 1][0], projected[i][1] - projected[i - 1][1]);
2656
+ lengths.push(len);
2657
+ total += len;
2658
+ }
2659
+ if (total === 0) return null;
2660
+ let remaining = total / 2;
2661
+ for (let i = 0; i < lengths.length; i++) {
2662
+ if (remaining <= lengths[i] || i === lengths.length - 1) {
2663
+ const t = lengths[i] === 0 ? 0 : Math.min(1, remaining / lengths[i]);
2664
+ const a = projected[i];
2665
+ const b = projected[i + 1];
2666
+ return {
2667
+ point: fromMercator([a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t]),
2668
+ bearing: segmentBearing(coords[i], coords[i + 1])
2669
+ };
2670
+ }
2671
+ remaining -= lengths[i];
2672
+ }
2673
+ return null;
2674
+ }
2675
+ function buildHostLineDecorations(lines) {
2676
+ var _a, _b, _c, _d;
2677
+ const out = [];
2678
+ for (const { styled, record } of lines) {
2679
+ if (((_a = styled.geometry) == null ? void 0 : _a.type) !== "LineString") continue;
2680
+ const coords = styled.geometry.coordinates;
2681
+ if (coords.length < 2) continue;
2682
+ const props = styled.properties ?? {};
2683
+ const opacity = props["stroke-opacity"] ?? 1;
2684
+ const name = props.name;
2685
+ if (typeof name === "string" && name !== "") {
2686
+ const mid = lineMidpoint(coords);
2687
+ if (mid) {
2688
+ out.push({
2689
+ type: "Feature",
2690
+ geometry: { type: "Point", coordinates: mid.point },
2691
+ properties: {
2692
+ role: "label",
2693
+ name,
2694
+ fontColor: props.fontColor ?? null,
2695
+ fontSize: props.fontSize ?? null,
2696
+ "stroke-opacity": opacity,
2697
+ labelRotate: labelRotationForBearing(mid.bearing)
2698
+ }
2699
+ });
2700
+ }
2701
+ }
2702
+ if (((_b = record.properties) == null ? void 0 : _b.kind) === "arrow") {
2703
+ const end = coords[coords.length - 1];
2704
+ let i = coords.length - 2;
2705
+ while (i > 0 && coords[i][0] === end[0] && coords[i][1] === end[1]) i--;
2706
+ const prev = coords[i];
2707
+ if (prev[0] === end[0] && prev[1] === end[1]) continue;
2708
+ const scale = arrowheadScale(props["stroke-width"]);
2709
+ const insetRaw = (_c = record.properties) == null ? void 0 : _c.arrowInset;
2710
+ const storedWidth = Number((_d = record.properties) == null ? void 0 : _d["stroke-width"]) || 2;
2711
+ const sizeFactor = typeof props["stroke-width"] === "number" ? props["stroke-width"] / storedWidth : 1;
2712
+ const inset = typeof insetRaw === "number" && isFinite(insetRaw) && insetRaw > 0 ? insetRaw * sizeFactor : 0;
2713
+ out.push({
2714
+ type: "Feature",
2715
+ geometry: { type: "Point", coordinates: [end[0], end[1]] },
2716
+ properties: {
2717
+ role: "arrow",
2718
+ stroke: props.stroke ?? null,
2719
+ "stroke-opacity": opacity,
2720
+ arrowBearing: segmentBearing(prev, end),
2721
+ arrowScale: scale,
2722
+ // `icon-offset` is in icon-size units: the head's own half length,
2723
+ // plus the inset in pixels divided back out of the scale. The inset is
2724
+ // the end node's radius, so it shrinks with that node's icon.
2725
+ arrowHeadOffset: ARROWHEAD_LENGTH / 2,
2726
+ arrowInsetOffset: inset / scale,
2727
+ ...hostIconScaleProps(record.properties)
2728
+ }
2729
+ });
2730
+ }
2731
+ }
2732
+ return out;
2733
+ }
2734
+ const offsetAlongYAt = (z) => [
2735
+ "interpolate",
2736
+ ["linear"],
2737
+ ["+", ["coalesce", ["get", "arrowHeadOffset"], 0], ["*", ["coalesce", ["get", "arrowInsetOffset"], 0], hostIconScaleAt(z)]],
2738
+ 0,
2739
+ ["literal", [0, 0]],
2740
+ 1e5,
2741
+ ["literal", [0, 1e5]]
2742
+ ];
2743
+ function hostIconScaleProps(props) {
2744
+ const out = {};
2745
+ for (const key of [HOST_ICON_FULL_ZOOM_PROP, HOST_ICON_MIN_ZOOM_PROP, HOST_ICON_MIN_SCALE_PROP]) {
2746
+ const value = props == null ? void 0 : props[key];
2747
+ if (typeof value === "number" && isFinite(value)) out[key] = value;
2748
+ }
2749
+ return out;
2750
+ }
2751
+ function buildHostDecorationLayers() {
2752
+ return [
2753
+ {
2754
+ id: HOST_DECORATION_LAYER_IDS.arrowheads,
2755
+ type: "symbol",
2756
+ source: HOST_DECORATION_SOURCE_ID,
2757
+ filter: ["==", ["get", "role"], "arrow"],
2758
+ layout: {
2759
+ "icon-image": ARROWHEAD_IMAGE_ID,
2760
+ "icon-size": ["coalesce", ["get", "arrowScale"], 1],
2761
+ "icon-rotate": ["coalesce", ["get", "arrowBearing"], 0],
2762
+ "icon-rotation-alignment": "map",
2763
+ "icon-pitch-alignment": "map",
2764
+ // The image points up; with `icon-rotate` the offset is in the rotated
2765
+ // frame, so +y pulls the head back along the line.
2766
+ "icon-offset": zoomCurve(offsetAlongYAt),
2767
+ "icon-allow-overlap": true,
2768
+ "icon-ignore-placement": true
2769
+ },
2770
+ paint: {
2771
+ "icon-color": ["coalesce", ["get", "stroke"], "#3b82f6"],
2772
+ "icon-opacity": ["coalesce", ["get", "stroke-opacity"], 1]
2773
+ }
2774
+ },
2775
+ {
2776
+ id: HOST_DECORATION_LAYER_IDS.labels,
2777
+ type: "symbol",
2778
+ source: HOST_DECORATION_SOURCE_ID,
2779
+ filter: ["==", ["get", "role"], "label"],
2780
+ layout: {
2781
+ "text-field": ["get", "name"],
2782
+ "text-size": ["coalesce", ["get", "fontSize"], 12],
2783
+ "text-font": ["literal", ["Montserrat Regular", "Noto Sans Regular"]],
2784
+ "text-rotate": ["coalesce", ["get", "labelRotate"], 0],
2785
+ "text-rotation-alignment": "map",
2786
+ "text-anchor": "center",
2787
+ "text-padding": 2,
2788
+ "text-allow-overlap": false,
2789
+ "text-ignore-placement": false
2790
+ },
2791
+ paint: {
2792
+ "text-color": ["coalesce", ["get", "fontColor"], "#1f2937"],
2793
+ "text-halo-color": "#ffffff",
2794
+ // Wide enough to close the gaps between words, where the line under
2795
+ // the label would otherwise show through.
2796
+ "text-halo-width": 2.5,
2797
+ "text-opacity": ["coalesce", ["get", "stroke-opacity"], 1]
2798
+ }
2799
+ }
2800
+ ];
2801
+ }
2802
+ function buildArrowheadImage(pixelRatio) {
2803
+ const ratio = pixelRatio > 0 && isFinite(pixelRatio) ? pixelRatio : 1;
2804
+ const cssW = ARROWHEAD_WIDTH + 2 * ARROWHEAD_BUFFER;
2805
+ const cssH = ARROWHEAD_LENGTH + 2 * ARROWHEAD_BUFFER;
2806
+ const width = Math.round(cssW * ratio);
2807
+ const height = Math.round(cssH * ratio);
2808
+ const tip = [cssW / 2, ARROWHEAD_BUFFER];
2809
+ const left = [ARROWHEAD_BUFFER, ARROWHEAD_BUFFER + ARROWHEAD_LENGTH];
2810
+ const right = [ARROWHEAD_BUFFER + ARROWHEAD_WIDTH, ARROWHEAD_BUFFER + ARROWHEAD_LENGTH];
2811
+ const edges = [[tip, right], [right, left], [left, tip]];
2812
+ const data = new Uint8Array(width * height * 4);
2813
+ for (let j = 0; j < height; j++) {
2814
+ for (let i = 0; i < width; i++) {
2815
+ const px = (i + 0.5) / ratio;
2816
+ const py = (j + 0.5) / ratio;
2817
+ let inside = Infinity;
2818
+ for (const [a, b] of edges) {
2819
+ const ex = b[0] - a[0];
2820
+ const ey = b[1] - a[1];
2821
+ const d = ((py - a[1]) * ex - (px - a[0]) * ey) / Math.hypot(ex, ey);
2822
+ if (d < inside) inside = d;
2823
+ }
2824
+ const alpha = Math.max(0, Math.min(1, 0.75 + inside * (0.75 / ARROWHEAD_BUFFER)));
2825
+ const o = (j * width + i) * 4;
2826
+ data[o] = 255;
2827
+ data[o + 1] = 255;
2828
+ data[o + 2] = 255;
2829
+ data[o + 3] = Math.round(alpha * 255);
2830
+ }
2831
+ }
2832
+ return { width, height, data };
2833
+ }
2435
2834
  function placeContextMenu(point2, parent, menu) {
2436
2835
  const scaleX = parent.offsetWidth > 0 ? parent.rect.width / parent.offsetWidth : 1;
2437
2836
  const scaleY = parent.offsetHeight > 0 ? parent.rect.height / parent.offsetHeight : 1;
@@ -4634,7 +5033,8 @@ function LayersPanel({
4634
5033
  onClick: () => onFitToLayerFeatures(layer.id)
4635
5034
  }
4636
5035
  ] : [],
4637
- ...layers.length > 1 ? [
5036
+ // A host-owned layer is removed by its host, never from here.
5037
+ ...layers.length > 1 && !layer.hostOwned ? [
4638
5038
  { type: "divider" },
4639
5039
  {
4640
5040
  key: "delete",
@@ -5694,6 +6094,7 @@ function resolveTooltipFeature(rendered, lookup) {
5694
6094
  };
5695
6095
  }
5696
6096
  const DEFAULT_POINT_RADIUS = 5;
6097
+ const DEFAULT_ICON_SIZE = 24;
5697
6098
  const MAX_POINT_RADIUS = 18;
5698
6099
  const SAME_SPOT_PX = 1;
5699
6100
  const CROWD = 16;
@@ -5703,8 +6104,12 @@ const distance = (a, b) => Math.hypot(a.x - b.x, a.y - b.y);
5703
6104
  function paintedRadius(f) {
5704
6105
  var _a, _b;
5705
6106
  const p = f.properties ?? {};
5706
- const hidden = ((_a = f.state) == null ? void 0 : _a[TIMELINE_HIDDEN_KEY]) === true || p.isHiddenByCluster === 1 || p.isHiddenByHeatmap === 1 || typeof p.icon === "string" && p.icon !== "";
6107
+ const hidden = ((_a = f.state) == null ? void 0 : _a[TIMELINE_HIDDEN_KEY]) === true || p.isHiddenByCluster === 1 || p.isHiddenByHeatmap === 1;
5707
6108
  if (hidden) return 0;
6109
+ if (typeof p.icon === "string" && p.icon !== "") {
6110
+ if (p[HOST_OWNED_PROP] !== 1) return 0;
6111
+ return typeof p.iconSize === "number" && Number.isFinite(p.iconSize) ? p.iconSize / 2 : DEFAULT_ICON_SIZE / 2;
6112
+ }
5708
6113
  const r = ((_b = f.state) == null ? void 0 : _b[TRACE_ENDPOINT_KEY]) === true ? p._endpointRadius : p.pointRadius;
5709
6114
  return typeof r === "number" && Number.isFinite(r) ? r : DEFAULT_POINT_RADIUS;
5710
6115
  }
@@ -9137,6 +9542,7 @@ function hitTestSelection(featureGroups, selectionPolygon, options) {
9137
9542
  const SELECTION_OVERLAY_SOURCE_ID = "selection-overlay";
9138
9543
  const SELECTION_OVERLAY_LAYER_IDS = {
9139
9544
  iconRing: "selection-overlay-icon-ring",
9545
+ hostIconRing: "selection-overlay-host-icon-ring",
9140
9546
  line: "selection-overlay-line",
9141
9547
  polygon: "selection-overlay-polygon",
9142
9548
  label: "selection-overlay-label"
@@ -9148,7 +9554,7 @@ function buildSelectionOverlayStack() {
9148
9554
  id: SELECTION_OVERLAY_LAYER_IDS.iconRing,
9149
9555
  type: "circle",
9150
9556
  source,
9151
- filter: ["all", ["==", "$type", "Point"], ["!=", "icon", ""], ["!=", "isHiddenByHeatmap", 1]],
9557
+ filter: ["all", ["==", "$type", "Point"], ["!=", "icon", ""], ["!=", "isHiddenByHeatmap", 1], ["!=", HOST_OWNED_PROP, 1]],
9152
9558
  paint: {
9153
9559
  "circle-color": "transparent",
9154
9560
  "circle-radius": ["/", ["coalesce", ["get", "iconSize"], 24], 1.6],
@@ -9157,6 +9563,20 @@ function buildSelectionOverlayStack() {
9157
9563
  "circle-stroke-opacity": 1
9158
9564
  }
9159
9565
  },
9566
+ {
9567
+ // A host icon shrinks along the host's zoom curve, and its ring with it.
9568
+ id: SELECTION_OVERLAY_LAYER_IDS.hostIconRing,
9569
+ type: "circle",
9570
+ source,
9571
+ filter: ["all", ["==", "$type", "Point"], ["!=", "icon", ""], ["==", HOST_OWNED_PROP, 1]],
9572
+ paint: {
9573
+ "circle-color": "transparent",
9574
+ "circle-radius": zoomCurve((z) => ["/", ["*", ["coalesce", ["get", "iconSize"], 24], hostIconScaleAt(z)], 1.6]),
9575
+ "circle-stroke-color": SELECTION_COLOR,
9576
+ "circle-stroke-width": 3,
9577
+ "circle-stroke-opacity": 1
9578
+ }
9579
+ },
9160
9580
  {
9161
9581
  id: SELECTION_OVERLAY_LAYER_IDS.line,
9162
9582
  type: "line",
@@ -9183,6 +9603,8 @@ function buildSelectionOverlayStack() {
9183
9603
  id: SELECTION_OVERLAY_LAYER_IDS.label,
9184
9604
  type: "symbol",
9185
9605
  source,
9606
+ // A selected host feature keeps its label in the shared `host-labels` layer.
9607
+ filter: NOT_HOST_FILTER,
9186
9608
  layout: {
9187
9609
  ...buildCustomLabelLayout(),
9188
9610
  // Never hidden by the auto-label density cap, which only flips the
@@ -9267,6 +9689,10 @@ const INTERNAL_PROPERTY_KEYS = /* @__PURE__ */ new Set([
9267
9689
  "fontColor",
9268
9690
  "fontWeight",
9269
9691
  "arrowSize",
9692
+ "arrowInset",
9693
+ "iconFullZoom",
9694
+ "iconMinZoom",
9695
+ "iconMinScale",
9270
9696
  "label",
9271
9697
  "entityType",
9272
9698
  "kind",
@@ -9293,7 +9719,11 @@ const STYLING_PROPERTY_KEYS = [
9293
9719
  "fontSize",
9294
9720
  "fontColor",
9295
9721
  "fontWeight",
9296
- "arrowSize"
9722
+ "arrowSize",
9723
+ "arrowInset",
9724
+ "iconFullZoom",
9725
+ "iconMinZoom",
9726
+ "iconMinScale"
9297
9727
  ];
9298
9728
  const INTERNAL_PROPERTY_PREFIXES = [
9299
9729
  "IsHiddenBy",
@@ -9713,7 +10143,6 @@ function ClusterPieManager(props) {
9713
10143
  }
9714
10144
  const EMPTY_ID_SET = /* @__PURE__ */ new Set();
9715
10145
  const EMPTY_SOURCES = [];
9716
- const TOOLTIP_EXCLUDED_KEYS = ["stroke", "stroke-width", "stroke-opacity", "fill", "fill-opacity", "pointRadius", "kind", "meta:type", "circleCenter", "circleRadius", "icon", "iconSize", "pointIcon", "pointIconSize", "fontSize", "fontColor", "fontWeight", "arrowSize", "label", "entityType"];
9717
10146
  const EMPTY_LABEL_MAP = /* @__PURE__ */ new Map();
9718
10147
  const TICK_COUNT_SETTLE_MS = 300;
9719
10148
  const SPATIAL_COUNT_MIN_FEATURES = 5e3;
@@ -9735,7 +10164,7 @@ function emojiCanvasToImageData(canvas) {
9735
10164
  const id = ctx.getImageData(0, 0, canvas.width, canvas.height);
9736
10165
  return { width: canvas.width, height: canvas.height, data: new Uint8Array(id.data.buffer) };
9737
10166
  }
9738
- function loadEmojiIconsIntoMap(mapInstance) {
10167
+ function loadEmojiIconsIntoMap(mapInstance, hostImages) {
9739
10168
  const ratio = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
9740
10169
  for (const { emoji } of ICONS) {
9741
10170
  if (!emoji || mapInstance.hasImage(emoji)) continue;
@@ -9746,10 +10175,19 @@ function loadEmojiIconsIntoMap(mapInstance) {
9746
10175
  }
9747
10176
  }
9748
10177
  mapInstance.setMissingStyleImageResolver((id) => {
9749
- if (mapInstance.hasImage(id) || !isEmojiIcon(id)) return;
10178
+ if (mapInstance.hasImage(id)) return;
9750
10179
  try {
9751
- const canvas = renderEmojiToCanvas(id);
9752
- mapInstance.addImage(id, emojiCanvasToImageData(canvas), { pixelRatio: ratio });
10180
+ if (id === ARROWHEAD_IMAGE_ID) {
10181
+ mapInstance.addImage(id, buildArrowheadImage(ratio), { pixelRatio: ratio, sdf: true });
10182
+ return;
10183
+ }
10184
+ const resolved = resolveMissingImage(id, hostImages());
10185
+ if (resolved.kind === "host") {
10186
+ mapInstance.addImage(id, resolved.image.data, { pixelRatio: resolved.image.pixelRatio ?? 1 });
10187
+ } else if (resolved.kind === "emoji" && isEmojiIcon(id)) {
10188
+ const canvas = renderEmojiToCanvas(id);
10189
+ mapInstance.addImage(id, emojiCanvasToImageData(canvas), { pixelRatio: ratio });
10190
+ }
9753
10191
  } catch {
9754
10192
  }
9755
10193
  });
@@ -9963,6 +10401,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9963
10401
  onFeatureCreate,
9964
10402
  onFeatureUpdate,
9965
10403
  onFeatureDelete,
10404
+ onDeleteRequest,
10405
+ iconImageProvider,
9966
10406
  onLayerChange,
9967
10407
  onActiveEditingLayerChange,
9968
10408
  onTimelineChange,
@@ -10062,6 +10502,12 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10062
10502
  const moveLabelsBeforeBasemapSymbolsRef = useRef(null);
10063
10503
  const tooltipProviderRef = useRef(tooltipProvider);
10064
10504
  tooltipProviderRef.current = tooltipProvider;
10505
+ const onFeatureSelectRef = useRef(onFeatureSelect);
10506
+ onFeatureSelectRef.current = onFeatureSelect;
10507
+ const onDeleteRequestRef = useRef(onDeleteRequest);
10508
+ onDeleteRequestRef.current = onDeleteRequest;
10509
+ const iconImageProviderRef = useRef(iconImageProvider);
10510
+ iconImageProviderRef.current = iconImageProvider;
10065
10511
  const onFeatureUpdateRef = useRef(onFeatureUpdate);
10066
10512
  onFeatureUpdateRef.current = onFeatureUpdate;
10067
10513
  const restoreEnrichedGeoJSONRef = useRef(null);
@@ -10102,6 +10548,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10102
10548
  const pendingFeatureKindRef = useRef(null);
10103
10549
  const arrowFeatureIdsRef = useRef(/* @__PURE__ */ new Set());
10104
10550
  const hasArrowFeaturesRef = useRef(false);
10551
+ const hadHostDecorationsRef = useRef(false);
10105
10552
  const [circleDrawCenter, setCircleDrawCenter] = useState(null);
10106
10553
  const [circleDrawPreview, setCircleDrawPreview] = useState(null);
10107
10554
  const isDrawingCircle = useRef(false);
@@ -10122,6 +10569,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10122
10569
  const ingestProgressStoreRef = useRef(null);
10123
10570
  const bindHoverHandlersRef = useRef(null);
10124
10571
  const unbindHoverHandlersRef = useRef(null);
10572
+ const hostIconBoundRef = useRef(false);
10125
10573
  const [labelsSuppressed, setLabelsSuppressed] = useState(true);
10126
10574
  const labelsSuppressedRef = useRef(labelsSuppressed);
10127
10575
  labelsSuppressedRef.current = labelsSuppressed;
@@ -10352,7 +10800,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10352
10800
  const applySelectionState$1 = useCallback((nextIds, options) => {
10353
10801
  if (!isMapLoaded || !draw.current) {
10354
10802
  setSelectedFeatureIds(nextIds);
10355
- if (options == null ? void 0 : options.focusProperties) setShowProperties(nextIds.length > 0);
10803
+ if (options == null ? void 0 : options.focusProperties) setShowProperties(showsPropertiesFor(nextIds, layersRef.current));
10356
10804
  if (onFeatureSelect) {
10357
10805
  onFeatureSelect(nextIds.length > 0 ? nextIds.map((id) => getFeatureById(id)).filter(Boolean) : []);
10358
10806
  }
@@ -10389,7 +10837,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10389
10837
  }
10390
10838
  setSelectedFeatureIds(nextIds);
10391
10839
  selectedFeatureIdsRef.current = nextIds;
10392
- if (options == null ? void 0 : options.focusProperties) setShowProperties(nextIds.length > 0);
10840
+ if (options == null ? void 0 : options.focusProperties) setShowProperties(showsPropertiesFor(nextIds, layersRef.current));
10393
10841
  if (onFeatureSelect) {
10394
10842
  onFeatureSelect(nextIds.map((id) => getFeatureById(id)).filter(Boolean));
10395
10843
  }
@@ -10557,7 +11005,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10557
11005
  }
10558
11006
  readOnlyFeatures.current.forEach((features, layerId) => {
10559
11007
  const layer = layersRef.current.find((l) => l.id === layerId);
10560
- if (layer == null ? void 0 : layer.visible) groups.push(groupOf(features));
11008
+ if (!(layer == null ? void 0 : layer.visible)) return;
11009
+ groups.push(isHostOwnedLayer(layer) ? { features } : groupOf(features));
10561
11010
  });
10562
11011
  return countFeaturesInBounds(
10563
11012
  groups,
@@ -10569,7 +11018,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10569
11018
  const tracePaintCacheRef = useRef(null);
10570
11019
  const traceEndpointsRef = useRef(/* @__PURE__ */ new Set());
10571
11020
  const paintedArrowLinesRef = useRef([]);
10572
- const renderArrowOverlays = useCallback((arrowLines) => {
11021
+ const renderArrowOverlays = useCallback((arrowLines, options) => {
10573
11022
  const mapInstance = map.current;
10574
11023
  if (!mapInstance) return;
10575
11024
  const arrowHeadSource = mapInstance.getSource("arrow-heads");
@@ -10624,7 +11073,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10624
11073
  arrowHeadSource.setData({ type: "FeatureCollection", features: arrowHeadTriangles });
10625
11074
  }
10626
11075
  const arrowLabelSource = mapInstance.getSource("arrow-labels");
10627
- if (arrowLabelSource) {
11076
+ if (arrowLabelSource && !(options == null ? void 0 : options.headsOnly)) {
10628
11077
  const arrowLabelPoints = [];
10629
11078
  arrowLines.forEach((f) => {
10630
11079
  var _a;
@@ -10697,7 +11146,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10697
11146
  const layer = currentLayers.find((l) => l.id === layerId);
10698
11147
  if (layer && isLayerVisible(layer)) {
10699
11148
  pushAll(allFeatures, features);
10700
- addSlice(features);
11149
+ if (!isHostOwnedLayer(layer)) addSlice(features);
10701
11150
  }
10702
11151
  });
10703
11152
  const featureById = /* @__PURE__ */ new Map();
@@ -10802,9 +11251,14 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10802
11251
  const { s, e } = record ? featureInterval(record, timelineFieldsNow) : { s: NaN, e: NaN };
10803
11252
  arrowLines.push(isIntervalVisible(s, e, timelineWindow) ? styled : { ...styled, properties: { ...styled.properties, "stroke-opacity": 0, "fill-opacity": 0 } });
10804
11253
  };
11254
+ const hostLines = [];
10805
11255
  sourceData.features.forEach((f, i) => {
10806
- var _a2;
10807
- const isArrow = ((_a2 = f.properties) == null ? void 0 : _a2.kind) === "arrow" || arrowFeatureIdsRef.current.has(String(f.id));
11256
+ var _a2, _b2;
11257
+ if (((_a2 = f.properties) == null ? void 0 : _a2[HOST_OWNED_PROP]) === 1) {
11258
+ if (f.geometry.type === "LineString") hostLines.push({ styled: f, record: allFeatures[i] });
11259
+ return;
11260
+ }
11261
+ const isArrow = ((_b2 = f.properties) == null ? void 0 : _b2.kind) === "arrow" || arrowFeatureIdsRef.current.has(String(f.id));
10808
11262
  if (!isArrow) return;
10809
11263
  sawArrowFeature = true;
10810
11264
  if (f.geometry.type === "LineString") pushArrow(f, allFeatures[i]);
@@ -10820,6 +11274,11 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10820
11274
  hasArrowFeaturesRef.current = sawArrowFeature;
10821
11275
  paintedArrowLinesRef.current = arrowLines;
10822
11276
  renderArrowOverlays(arrowLines);
11277
+ const hostDecorationSource = map.current.getSource(HOST_DECORATION_SOURCE_ID);
11278
+ if (hostDecorationSource && (hostLines.length > 0 || hadHostDecorationsRef.current)) {
11279
+ hostDecorationSource.setData({ type: "FeatureCollection", features: buildHostLineDecorations(hostLines) });
11280
+ hadHostDecorationsRef.current = hostLines.length > 0;
11281
+ }
10823
11282
  }
10824
11283
  if (update3DFlightPathsRef == null ? void 0 : update3DFlightPathsRef.current) {
10825
11284
  update3DFlightPathsRef.current();
@@ -11059,7 +11518,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11059
11518
  );
11060
11519
  readOnlyFeatures.current.forEach((features, layerId) => {
11061
11520
  const layer = currentLayers.find((l) => l.id === layerId);
11062
- if (!(layer == null ? void 0 : layer.visible)) return;
11521
+ if (!(layer == null ? void 0 : layer.visible) || isHostOwnedLayer(layer)) return;
11063
11522
  const cached = layerTemporalCacheRef.current.get(layerId);
11064
11523
  if (cached && (cached.fieldsKey ?? "") === fieldsKey && cached.featureCount === features.length && !cached.hasTemporal) {
11065
11524
  for (const f of features) scan.untimedIds.push(f.id);
@@ -11107,10 +11566,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11107
11566
  }, [updateTimelineStore]);
11108
11567
  const collectHistoryFeatures = useCallback(
11109
11568
  (overrides) => {
11110
- var _a;
11111
11569
  const featureToLayer = /* @__PURE__ */ new Map();
11112
11570
  for (const l of layersRef.current) {
11113
- if (((_a = l.metadata) == null ? void 0 : _a.dataViewing) === true) continue;
11571
+ if (isHistoryExcludedLayer(l)) continue;
11114
11572
  for (const fid of l.featureIds) featureToLayer.set(fid, l.id);
11115
11573
  }
11116
11574
  const result = /* @__PURE__ */ new Map();
@@ -11126,9 +11584,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11126
11584
  }
11127
11585
  }
11128
11586
  readOnlyFeatures.current.forEach((features, layerId) => {
11129
- var _a2;
11130
11587
  const layer = layersRef.current.find((l) => l.id === layerId);
11131
- if (((_a2 = layer == null ? void 0 : layer.metadata) == null ? void 0 : _a2.dataViewing) === true) return;
11588
+ if (isHistoryExcludedLayer(layer)) return;
11132
11589
  for (const f of features) {
11133
11590
  if (f.id == null) continue;
11134
11591
  result.set(String(f.id), { feature: f, layerId, store: "readOnly" });
@@ -11157,10 +11614,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11157
11614
  []
11158
11615
  );
11159
11616
  const collectHistoryLayers = useCallback(() => {
11160
- var _a;
11161
11617
  const result = /* @__PURE__ */ new Map();
11162
11618
  for (const l of layersRef.current) {
11163
- if (((_a = l.metadata) == null ? void 0 : _a.dataViewing) === true) continue;
11619
+ if (isHistoryExcludedLayer(l)) continue;
11164
11620
  const { importing: _importing, ...record } = l;
11165
11621
  result.set(l.id, { ...record, featureIds: [...l.featureIds] });
11166
11622
  }
@@ -11247,6 +11703,15 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11247
11703
  if (!isMapLoaded) return;
11248
11704
  cleanupOrphanLayerSources(new Set(layers.map((l) => l.id)));
11249
11705
  }, [layers, isMapLoaded, cleanupOrphanLayerSources]);
11706
+ useEffect(() => {
11707
+ if (!isMapLoaded) return;
11708
+ const wanted = layers.some(isHostOwnedLayer);
11709
+ if (wanted === hostIconBoundRef.current) return;
11710
+ const toggle = wanted ? bindHoverHandlersRef.current : unbindHoverHandlersRef.current;
11711
+ if (!toggle) return;
11712
+ toggle(customLayerId("host-icon", SHARED_SOURCE_ID));
11713
+ hostIconBoundRef.current = wanted;
11714
+ }, [layers, isMapLoaded]);
11250
11715
  const applyHistoryState = useCallback(
11251
11716
  (featureIds, layerIds, targetFeatures, targetLayers) => {
11252
11717
  const wasApiAdding = isApiAddingRef.current;
@@ -11389,8 +11854,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11389
11854
  pending.beforeSelectedIds,
11390
11855
  [...selectedFeatureIdsRef.current]
11391
11856
  );
11392
- if (command) {
11393
- history.push(command);
11857
+ const step = withHostDeleteUndos(command, pending.label, pending.hostUndos ?? []);
11858
+ if (step) {
11859
+ history.push(step);
11394
11860
  }
11395
11861
  }, [collectHistoryFeatures, collectHistoryLayers, buildDiffCommand, history]);
11396
11862
  const saveStateForUndo = useCallback(
@@ -11525,7 +11991,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11525
11991
  var _a2;
11526
11992
  return (_a2 = unbindHoverHandlersRef.current) == null ? void 0 : _a2.call(unbindHoverHandlersRef, id);
11527
11993
  }),
11528
- labelsVisible: () => lastLabelVisibility.current
11994
+ labelsVisible: () => lastLabelVisibility.current,
11995
+ hostIconInteractive: () => hostIconBoundRef.current
11529
11996
  });
11530
11997
  shardRegistryRef.current.registerShared(sharedStack.map((spec) => spec.id));
11531
11998
  mapInstance.addSource("arrow-heads", {
@@ -11572,6 +12039,14 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11572
12039
  "text-opacity": ["coalesce", ["get", "stroke-opacity"], 1]
11573
12040
  }
11574
12041
  });
12042
+ mapInstance.addSource(HOST_DECORATION_SOURCE_ID, {
12043
+ type: "geojson",
12044
+ data: { type: "FeatureCollection", features: [] },
12045
+ maxzoom: 22
12046
+ });
12047
+ const [hostArrowheads, hostLineLabels] = buildHostDecorationLayers();
12048
+ mapInstance.addLayer(hostArrowheads, "custom-point-shadow");
12049
+ mapInstance.addLayer(hostLineLabels);
11575
12050
  mapInstance.addSource(TRACE_SOURCE_ID, {
11576
12051
  type: "geojson",
11577
12052
  data: { type: "FeatureCollection", features: [] },
@@ -11715,7 +12190,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11715
12190
  const highlightFields = /* @__PURE__ */ new Set();
11716
12191
  if (((_a2 = visualConfig == null ? void 0 : visualConfig.size) == null ? void 0 : _a2.mode) === "field" && visualConfig.size.fieldName) highlightFields.add(visualConfig.size.fieldName);
11717
12192
  if (((_b2 = visualConfig == null ? void 0 : visualConfig.color) == null ? void 0 : _b2.mode) === "field" && visualConfig.color.fieldName) highlightFields.add(visualConfig.color.fieldName);
11718
- const displayProps = Object.entries(props).filter(([key, value]) => !TOOLTIP_EXCLUDED_KEYS.includes(key) && !key.startsWith("_") && !key.startsWith("isHidden") && !key.startsWith("isTrace") && !key.startsWith("isTimeline") && !key.startsWith("trace") && value != null && value !== "").slice(0, 5);
12193
+ const displayProps = Object.entries(props).filter(([key, value]) => !isInternalProperty(key) && !key.startsWith("_") && value != null && value !== "").slice(0, 5);
11719
12194
  const name = props.name;
11720
12195
  let html = '<div class="text-sm space-y-0.5">';
11721
12196
  if (name) html += `<div class="font-medium">${escapeHtml(name)}</div>`;
@@ -11978,7 +12453,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11978
12453
  tracePopupRef.current.remove();
11979
12454
  }
11980
12455
  });
11981
- loadEmojiIconsIntoMap(mapInstance);
12456
+ loadEmojiIconsIntoMap(mapInstance, () => iconImageProviderRef.current);
11982
12457
  setIsMapLoaded(true);
11983
12458
  isMapLoadedRef.current = true;
11984
12459
  updateFeatureCount();
@@ -12321,6 +12796,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12321
12796
  onFeatureDelete == null ? void 0 : onFeatureDelete(deletedIds);
12322
12797
  });
12323
12798
  onDrawEvent(mapInstance, "draw.selectionchange", (e) => {
12799
+ var _a;
12324
12800
  if (isSelectingReadOnlyRef.current) {
12325
12801
  return;
12326
12802
  }
@@ -12351,13 +12827,13 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12351
12827
  setShowProperties(ids.length > 0);
12352
12828
  }
12353
12829
  scheduleSync("selection");
12354
- onFeatureSelect == null ? void 0 : onFeatureSelect(e.features);
12830
+ (_a = onFeatureSelectRef.current) == null ? void 0 : _a.call(onFeatureSelectRef, e.features);
12355
12831
  });
12356
12832
  onDrawEvent(mapInstance, "draw.modechange", () => {
12357
12833
  scheduleSync();
12358
12834
  });
12359
12835
  mapInstance.on("click", (e) => {
12360
- var _a, _b;
12836
+ var _a, _b, _c;
12361
12837
  if (!enableSelectionRef.current) return;
12362
12838
  if (e.originalEvent.button !== 0) return;
12363
12839
  if (contextMenuFiredRef.current) return;
@@ -12418,7 +12894,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12418
12894
  }
12419
12895
  setSelectedFeatureIds(nextIds);
12420
12896
  selectedFeatureIdsRef.current = nextIds;
12421
- if (enableProperties) setShowProperties(nextIds.length > 0);
12897
+ if (enableProperties) setShowProperties(showsPropertiesFor(nextIds, layersRef.current));
12422
12898
  scheduleSync("selection");
12423
12899
  const selectedFeatures2 = [];
12424
12900
  for (const id of nextIds) {
@@ -12427,7 +12903,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12427
12903
  if (found) selectedFeatures2.push(found);
12428
12904
  });
12429
12905
  }
12430
- onFeatureSelect == null ? void 0 : onFeatureSelect(selectedFeatures2);
12906
+ (_c = onFeatureSelectRef.current) == null ? void 0 : _c.call(onFeatureSelectRef, selectedFeatures2);
12431
12907
  requestAnimationFrame(() => {
12432
12908
  isSelectingReadOnlyRef.current = false;
12433
12909
  });
@@ -12663,6 +13139,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12663
13139
  parseGeoJSONText: (label, text) => ingestWithProgress(label, text, { idStrategy: "preserve" }),
12664
13140
  addLayer: (name, geojson, options) => {
12665
13141
  if (!isMapLoadedRef.current) return "";
13142
+ const hostOwned = (options == null ? void 0 : options.hostOwned) === true;
13143
+ const readOnly = hostOwned ? true : options == null ? void 0 : options.readOnly;
12666
13144
  if (options == null ? void 0 : options.recordHistory) saveStateForUndo(`add layer "${name}"`);
12667
13145
  const layerId = `layer-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
12668
13146
  const newLayer = {
@@ -12675,7 +13153,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12675
13153
  // visibility toggle).
12676
13154
  visible: (options == null ? void 0 : options.visible) ?? true,
12677
13155
  featureIds: [],
12678
- readOnly: options == null ? void 0 : options.readOnly,
13156
+ readOnly,
13157
+ ...hostOwned ? { hostOwned: true } : {},
12679
13158
  group: options == null ? void 0 : options.group,
12680
13159
  metadata: options == null ? void 0 : options.metadata,
12681
13160
  // Per-layer visual configs are passed through verbatim so that hosts
@@ -12692,7 +13171,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12692
13171
  let capDropped = 0;
12693
13172
  if (geojson) {
12694
13173
  const max = featureCapRef.current;
12695
- if (options == null ? void 0 : options.readOnly) {
13174
+ if (readOnly) {
12696
13175
  const prepared = prepareFeaturesForLayer(geojson.features, "addLayer", { max });
12697
13176
  readOnlyFeatures.current.set(layerId, prepared.features);
12698
13177
  layerTemporalCacheRef.current.set(layerId, { featureCount: prepared.features.length, hasTemporal: prepared.hasTemporal });
@@ -12730,7 +13209,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12730
13209
  source: "api"
12731
13210
  });
12732
13211
  }
12733
- if (newLayer.visible === false && !(options == null ? void 0 : options.readOnly) && draw.current && newLayer.featureIds.length > 0) {
13212
+ if (newLayer.visible === false && !readOnly && draw.current && newLayer.featureIds.length > 0) {
12734
13213
  const features = newLayer.featureIds.map((id) => draw.current.get(id)).filter(Boolean);
12735
13214
  hiddenFeatures.current.set(layerId, features);
12736
13215
  newLayer.featureIds.forEach((id) => {
@@ -12964,7 +13443,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12964
13443
  ...l,
12965
13444
  featureIds: l.featureIds.filter((id) => !idSet.has(id))
12966
13445
  }));
12967
- return updated.filter((l) => l.featureIds.length > 0 || !l.readOnly);
13446
+ return updated.filter(keepLayerAfterFeatureRemoval);
12968
13447
  });
12969
13448
  updateFeatureCount();
12970
13449
  scheduleTimelineUpdate();
@@ -13173,6 +13652,13 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13173
13652
  scheduleTimelineUpdate();
13174
13653
  }
13175
13654
  const newFeatureIds = prepared.featureIds;
13655
+ if (selectedFeatureIdsRef.current.length > 0) {
13656
+ const kept = new Set(newFeatureIds);
13657
+ const removed = new Set(layer.featureIds.filter((id) => !kept.has(id)));
13658
+ if (removed.size > 0) {
13659
+ setSelectedFeatureIds((prev) => prev.some((id) => removed.has(id)) ? prev.filter((id) => !removed.has(id)) : prev);
13660
+ }
13661
+ }
13176
13662
  const updatedLayers = layersRef.current.map(
13177
13663
  (l) => l.id === layerId ? { ...l, featureIds: newFeatureIds, importing: isShardEligible(l, prepared.features.length, shardSizeRef.current) || void 0 } : l
13178
13664
  );
@@ -13450,7 +13936,18 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13450
13936
  }, [activeEditingLayerId, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, toast]);
13451
13937
  const handleDeleteSelected = useCallback(() => {
13452
13938
  if (selectedFeatureIds.length === 0) return;
13453
- const idSet = new Set(selectedFeatureIds);
13939
+ const { deletableIds, hostRequests } = splitDeleteByOwner(layersRef.current, selectedFeatureIds);
13940
+ const hostUndos = hostRequests.map((request) => {
13941
+ var _a;
13942
+ return (_a = onDeleteRequestRef.current) == null ? void 0 : _a.call(onDeleteRequestRef, request.layerId, request.featureIds);
13943
+ }).filter(isHostDeleteUndo);
13944
+ if (deletableIds.length === 0) {
13945
+ const step = withHostDeleteUndos(null, "delete features", hostUndos);
13946
+ if (step) history.push(step);
13947
+ return;
13948
+ }
13949
+ const keptIds = splitDeleteByOwner(layersRef.current, hostRequests.flatMap((request) => request.featureIds)).hostRequests.flatMap((request) => request.featureIds);
13950
+ const idSet = new Set(deletableIds);
13454
13951
  const readOnlyIdSet = /* @__PURE__ */ new Set();
13455
13952
  for (const layer of layersRef.current) {
13456
13953
  if (!layer.readOnly) continue;
@@ -13458,10 +13955,15 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13458
13955
  }
13459
13956
  const editableIds = [];
13460
13957
  const readOnlyIds = [];
13461
- for (const id of selectedFeatureIds) {
13958
+ for (const id of deletableIds) {
13462
13959
  (readOnlyIdSet.has(id) ? readOnlyIds : editableIds).push(id);
13463
13960
  }
13464
13961
  saveStateForUndo("delete features");
13962
+ if (hostUndos.length > 0) {
13963
+ const pending = pendingCaptureRef.current;
13964
+ if (pending) pending.hostUndos = [...pending.hostUndos ?? [], ...hostUndos];
13965
+ else history.push(withHostDeleteUndos(null, "delete features", hostUndos));
13966
+ }
13465
13967
  if (editableIds.length > 0 && draw.current) {
13466
13968
  editableIds.forEach((id) => {
13467
13969
  arrowFeatureIdsRef.current.delete(id);
@@ -13491,15 +13993,15 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13491
13993
  ...l,
13492
13994
  featureIds: l.featureIds.filter((id) => !idSet.has(id))
13493
13995
  }));
13494
- return updated.filter((l) => l.featureIds.length > 0 || !l.readOnly);
13996
+ return updated.filter(keepLayerAfterFeatureRemoval);
13495
13997
  });
13496
- onFeatureDelete == null ? void 0 : onFeatureDelete(selectedFeatureIds);
13497
- setSelectedFeatureIds([]);
13498
- setShowProperties(false);
13998
+ onFeatureDelete == null ? void 0 : onFeatureDelete(deletableIds);
13999
+ setSelectedFeatureIds(keptIds);
14000
+ setShowProperties(showsPropertiesFor(keptIds, layersRef.current));
13499
14001
  updateFeatureCount();
13500
14002
  scheduleTimelineUpdate();
13501
14003
  scheduleSync();
13502
- }, [selectedFeatureIds, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, onFeatureDelete]);
14004
+ }, [selectedFeatureIds, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, onFeatureDelete, history]);
13503
14005
  const handleToggleEditMode = useCallback(() => {
13504
14006
  setIsEditMode((prev) => {
13505
14007
  const newMode = !prev;
@@ -13980,7 +14482,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13980
14482
  const handleRemoveLayer = useCallback((layerId) => {
13981
14483
  if (layers.length <= 1) return;
13982
14484
  const layer = layers.find((l) => l.id === layerId);
13983
- if (!layer || !draw.current) return;
14485
+ if (!layer || isHostOwnedLayer(layer) || !draw.current) return;
13984
14486
  saveStateForUndo();
13985
14487
  layer.featureIds.forEach((id) => {
13986
14488
  try {
@@ -14056,6 +14558,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
14056
14558
  }
14057
14559
  }, [layers, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate]);
14058
14560
  const handleMoveFeatureToLayer = useCallback((featureId, targetLayerId) => {
14561
+ if (movableFeatureIds(layersRef.current, [featureId], targetLayerId).length === 0) return;
14059
14562
  saveStateForUndo();
14060
14563
  setLayers((prev) => {
14061
14564
  const updated = prev.map((l) => {
@@ -14074,8 +14577,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
14074
14577
  var _a;
14075
14578
  return ((_a = draw.current) == null ? void 0 : _a.get(id)) ?? getReadOnlyFeatureById(id) ?? void 0;
14076
14579
  }, [getReadOnlyFeatureById]);
14077
- const handleMoveFeaturesToLayer = useCallback((featureIds, targetLayerId) => {
14078
- if (!draw.current) return;
14580
+ const handleMoveFeaturesToLayer = useCallback((requestedIds, targetLayerId) => {
14581
+ const featureIds = movableFeatureIds(layersRef.current, requestedIds, targetLayerId);
14582
+ if (!draw.current || featureIds.length === 0) return;
14079
14583
  saveStateForUndo();
14080
14584
  const idSet = new Set(featureIds);
14081
14585
  const movedIds = [];
@@ -14114,8 +14618,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
14114
14618
  updateFeatureCount();
14115
14619
  }
14116
14620
  }, [saveStateForUndo, findFeatureById, updateFeatureCount, scheduleSync]);
14117
- const handleCopyFeaturesToLayer = useCallback((featureIds, targetLayerId) => {
14118
- if (!draw.current) return;
14621
+ const handleCopyFeaturesToLayer = useCallback((requestedIds, targetLayerId) => {
14622
+ const featureIds = movableFeatureIds(layersRef.current, requestedIds, targetLayerId);
14623
+ if (!draw.current || featureIds.length === 0) return;
14119
14624
  saveStateForUndo();
14120
14625
  const newIds = [];
14121
14626
  featureIds.forEach((id) => {
@@ -14133,8 +14638,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
14133
14638
  updateFeatureCount();
14134
14639
  }
14135
14640
  }, [saveStateForUndo, updateFeatureCount, findFeatureById]);
14136
- const handleCreateLayerAndMoveFeatures = useCallback((featureIds, layerName) => {
14137
- if (!draw.current) return;
14641
+ const handleCreateLayerAndMoveFeatures = useCallback((requestedIds, layerName) => {
14642
+ const featureIds = movableFeatureIds(layersRef.current, requestedIds);
14643
+ if (!draw.current || featureIds.length === 0) return;
14138
14644
  const newLayerId = `layer-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
14139
14645
  const idSet = new Set(featureIds);
14140
14646
  saveStateForUndo();
@@ -14178,8 +14684,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
14178
14684
  updateFeatureCount();
14179
14685
  }
14180
14686
  }, [saveStateForUndo, findFeatureById, updateFeatureCount, scheduleSync, withAutoColor]);
14181
- const handleCreateLayerAndCopyFeatures = useCallback((featureIds, layerName) => {
14182
- if (!draw.current) return;
14687
+ const handleCreateLayerAndCopyFeatures = useCallback((requestedIds, layerName) => {
14688
+ const featureIds = movableFeatureIds(layersRef.current, requestedIds);
14689
+ if (!draw.current || featureIds.length === 0) return;
14183
14690
  saveStateForUndo();
14184
14691
  const newIds = [];
14185
14692
  const copiedFeatures = [];
@@ -14265,7 +14772,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
14265
14772
  );
14266
14773
  const labelLayerIds = onlyLayerIds ?? [
14267
14774
  ...((_a = shardRegistryRef.current) == null ? void 0 : _a.labelLayerIds("all")) ?? ["custom-labels", "custom-labels-pinned"],
14268
- "custom-arrow-labels"
14775
+ "custom-arrow-labels",
14776
+ HOST_DECORATION_LAYER_IDS.labels
14269
14777
  ];
14270
14778
  try {
14271
14779
  labelLayerIds.forEach((id) => {
@@ -14486,7 +14994,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
14486
14994
  if (!hasArrowFeaturesRef.current || rafId !== null) return;
14487
14995
  rafId = requestAnimationFrame(() => {
14488
14996
  rafId = null;
14489
- renderArrowOverlays(paintedArrowLinesRef.current);
14997
+ renderArrowOverlays(paintedArrowLinesRef.current, { headsOnly: true });
14490
14998
  });
14491
14999
  };
14492
15000
  mapInstance.on("move", handleMove);
@@ -15761,6 +16269,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
15761
16269
  const layerStates = [];
15762
16270
  layers.forEach((layer, idx) => {
15763
16271
  var _a;
16272
+ if (isHostOwnedLayer(layer)) return;
15764
16273
  const isDataViewing = ((_a = layer.metadata) == null ? void 0 : _a.dataViewing) === true;
15765
16274
  if (!isDataViewing) {
15766
16275
  const layerFeatures = collectLayerFeatures(layer, {
@@ -15954,7 +16463,11 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
15954
16463
  if (draw.current) {
15955
16464
  draw.current.deleteAll();
15956
16465
  }
15957
- readOnlyFeatures.current.clear();
16466
+ const hostLayers = layersRef.current.filter(isHostOwnedLayer);
16467
+ const hostLayerIds = new Set(hostLayers.map((l) => l.id));
16468
+ for (const layerId of Array.from(readOnlyFeatures.current.keys())) {
16469
+ if (!hostLayerIds.has(layerId)) readOnlyFeatures.current.delete(layerId);
16470
+ }
15958
16471
  hiddenFeatures.current.clear();
15959
16472
  const featuresByIndex = /* @__PURE__ */ new Map();
15960
16473
  enriched.features.forEach((f) => {
@@ -15975,6 +16488,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
15975
16488
  let firstTruncatedLayer = "";
15976
16489
  for (const ls of sortedLayers) {
15977
16490
  if (((_a = ls.metadata) == null ? void 0 : _a.dataViewing) === true) continue;
16491
+ if (isHostOwnedLayer(ls)) continue;
15978
16492
  const capped = capFeatures(featuresByIndex.get(ls.index) ?? [], { max: featureCapRef.current });
15979
16493
  const rawFeatures = capped.features;
15980
16494
  if (capped.dropped > 0) {
@@ -16025,8 +16539,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
16025
16539
  readOnly: isReadOnly
16026
16540
  });
16027
16541
  }
16028
- layersRef.current = newLayers;
16029
- setLayers(newLayers);
16542
+ layersRef.current = [...newLayers, ...hostLayers];
16543
+ setLayers(layersRef.current);
16030
16544
  updateFeatureCount();
16031
16545
  scheduleTimelineUpdate();
16032
16546
  scheduleSync();
@@ -16310,6 +16824,14 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
16310
16824
  });
16311
16825
  return;
16312
16826
  }
16827
+ if (isHostOwnedLayer(targetLayer)) {
16828
+ toast({
16829
+ title: "Can't load into this layer",
16830
+ description: "Another view owns its features. Load the file into another layer.",
16831
+ variant: "destructive"
16832
+ });
16833
+ return;
16834
+ }
16313
16835
  if (!targetLayer) {
16314
16836
  targetLayer = currentLayers.find((l) => l.visible && !l.readOnly);
16315
16837
  }
@@ -18446,6 +18968,7 @@ export {
18446
18968
  DEFAULT_MAX_FEATURES_PER_LAYER,
18447
18969
  DebugSidebar,
18448
18970
  DrawingToolbar,
18971
+ HOST_IMAGE_PREFIX,
18449
18972
  INTERNAL_PROPERTY_KEYS,
18450
18973
  INTERNAL_PROPERTY_PREFIXES,
18451
18974
  IconPicker,