@octostar/map-component 0.6.4 → 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 (48) hide show
  1. package/dist/index.mjs +904 -202
  2. package/dist/index.mjs.map +1 -1
  3. package/dist/styles.css +1 -0
  4. package/dist/types/components/layers-panel.d.ts +8 -0
  5. package/dist/types/components/layers-panel.d.ts.map +1 -1
  6. package/dist/types/components/map-editor-canvas.d.ts.map +1 -1
  7. package/dist/types/components/timebar.d.ts +9 -1
  8. package/dist/types/components/timebar.d.ts.map +1 -1
  9. package/dist/types/index.d.ts +4 -0
  10. package/dist/types/index.d.ts.map +1 -1
  11. package/dist/types/lib/custom-layer-stack.d.ts +7 -1
  12. package/dist/types/lib/custom-layer-stack.d.ts.map +1 -1
  13. package/dist/types/lib/feature-stack.d.ts.map +1 -1
  14. package/dist/types/lib/history-diff.d.ts +2 -0
  15. package/dist/types/lib/history-diff.d.ts.map +1 -1
  16. package/dist/types/lib/host-icon-scale.d.ts +28 -0
  17. package/dist/types/lib/host-icon-scale.d.ts.map +1 -0
  18. package/dist/types/lib/host-line-decorations.d.ts +70 -0
  19. package/dist/types/lib/host-line-decorations.d.ts.map +1 -0
  20. package/dist/types/lib/host-owned-layers.d.ts +84 -0
  21. package/dist/types/lib/host-owned-layers.d.ts.map +1 -0
  22. package/dist/types/lib/label-pinning.d.ts +24 -0
  23. package/dist/types/lib/label-pinning.d.ts.map +1 -1
  24. package/dist/types/lib/map-editor-api.d.ts +67 -0
  25. package/dist/types/lib/map-editor-api.d.ts.map +1 -1
  26. package/dist/types/lib/paint-feature.d.ts +9 -2
  27. package/dist/types/lib/paint-feature.d.ts.map +1 -1
  28. package/dist/types/lib/property-utils.d.ts +1 -1
  29. package/dist/types/lib/property-utils.d.ts.map +1 -1
  30. package/dist/types/lib/selection-overlay.d.ts +2 -1
  31. package/dist/types/lib/selection-overlay.d.ts.map +1 -1
  32. package/dist/types/lib/shard-constants.d.ts +5 -1
  33. package/dist/types/lib/shard-constants.d.ts.map +1 -1
  34. package/dist/types/lib/shard-registry.d.ts +2 -0
  35. package/dist/types/lib/shard-registry.d.ts.map +1 -1
  36. package/dist/types/lib/temporal-ingest.d.ts +4 -1
  37. package/dist/types/lib/temporal-ingest.d.ts.map +1 -1
  38. package/dist/types/lib/temporal-normalize.d.ts +16 -0
  39. package/dist/types/lib/temporal-normalize.d.ts.map +1 -1
  40. package/dist/types/lib/timeline-index.d.ts +6 -5
  41. package/dist/types/lib/timeline-index.d.ts.map +1 -1
  42. package/dist/types/lib/timeline-state.d.ts +21 -5
  43. package/dist/types/lib/timeline-state.d.ts.map +1 -1
  44. package/dist/types/lib/trace-group-suggestion.d.ts +2 -1
  45. package/dist/types/lib/trace-group-suggestion.d.ts.map +1 -1
  46. package/dist/types/lib/trace-groups.d.ts +8 -4
  47. package/dist/types/lib/trace-groups.d.ts.map +1 -1
  48. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -144,7 +144,7 @@ async function featureCollectionBlobPartsAsync(collection, options) {
144
144
  (_c = options == null ? void 0 : options.onProgress) == null ? void 0 : _c.call(options, total, total);
145
145
  return coalescer.finish();
146
146
  }
147
- const ingestWorkerSource = '"use strict";(()=>{function b(e,t){let n=e.length,r=Math.max(0,t.max-(t.existing??0));return n<=r?{features:e,dropped:0,sourceCount:n}:{features:e.slice(0,r),dropped:n-r,sourceCount:n}}function S(e){let t=e.crs?.properties?.name,n=null;if(t){let r=t.match(/EPSG::?(\\d+)/i);r&&(n=`EPSG:${r[1]}`)}if(!n&&e.features.length>0){let r=T(e.features[0].geometry);if(r){let[s,a]=r;if(Math.abs(s)<=180&&Math.abs(a)<=90)return{sourceCRS:"EPSG:4326",needsReprojection:!1}}return{sourceCRS:null,needsReprojection:!1}}return{sourceCRS:n,needsReprojection:n!==null&&n!=="EPSG:4326"}}function T(e){if(!e)return null;switch(e.type){case"Point":return e.coordinates;case"MultiPoint":case"LineString":return e.coordinates[0];case"MultiLineString":case"Polygon":return e.coordinates[0]?.[0];case"MultiPolygon":return e.coordinates[0]?.[0]?.[0];default:return null}}function I(e){return e.geometry?.type==="LineString"?e.geometry.coordinates.some(n=>n.length>=3&&n[2]!==0):e.geometry?.type==="MultiLineString"?e.geometry.coordinates.some(n=>n.some(r=>r.length>=3&&r[2]!==0)):!1}function d(e){if(!e)return null;if(e instanceof Date)return e;if(typeof e=="string"||typeof e=="number"){let t=new Date(e);return isNaN(t.getTime())?null:t}return null}function h(e){return!!(e.startDate||e.startdate||e.start_date||e.start_time||e.date||e.timestamp||e.flightDate||e.time||e.datetime||e.endDate||e.enddate||e.end_date||e.end_time)}function F(e){let t=d(e.startDate)||d(e.startdate)||d(e.start_date)||d(e.start_time)||d(e.date)||d(e.timestamp)||d(e.flightDate)||d(e.time)||d(e.datetime),n=d(e.endDate)||d(e.enddate)||d(e.end_date)||d(e.end_time);return t&&n&&n<t&&([t,n]=[n,t]),{startDate:t,endDate:n}}function x(e){return"kind"in e&&e.kind==="ack"}function G(){let e=globalThis.crypto?.randomUUID?.bind(globalThis.crypto);return e?e():`f-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function _(e,t,n){switch(n.idStrategy){case"preserve":return e.id;case"layer-index":return e.id!==void 0&&e.id!==null?String(e.id):`${n.layerId}-f${t}`;case"uuid-fallback":return e.id?String(e.id):G()}}function C(e,t){if(Array.isArray(e)){if(typeof e[0]=="number"){let n=e[0],r=e[1];t[0]=Math.min(t[0],n),t[1]=Math.min(t[1],r),t[2]=Math.max(t[2],n),t[3]=Math.max(t[3],r);return}for(let n of e)C(n,t)}}function R(e,t){if(e){if(e.type==="GeometryCollection"){for(let n of e.geometries)R(n,t);return}C(e.coordinates,t)}}function D(e){let t=[1/0,1/0,-1/0,-1/0];for(let n of e)R(n.geometry,t);return t.every(n=>isFinite(n))?t:null}function O(e,t){let n;if(e.type==="text")try{n=JSON.parse(e.text)}catch(c){return{kind:"error",code:"parse-error",message:c instanceof Error?c.message:"Invalid file"}}else n=e.data;if(n&&n.type==="Feature"&&(n={type:"FeatureCollection",features:[n]}),!n||n.type!=="FeatureCollection"||!Array.isArray(n.features))return{kind:"error",code:"invalid-format",message:"Invalid GeoJSON format"};if(t.emptyIsError&&n.features.length===0)return{kind:"error",code:"empty",message:"The file contains no features"};if(n["octostar:map"])return{kind:"enriched",data:n};let{sourceCRS:r,needsReprojection:s}=S(n),a=b(n.features,{max:t.maxFeatures??1/0}),o=!1,u=!1,i=[];a.features.forEach((c,E)=>{let p=_(c,E,t);!u&&I(c)&&(u=!0);let f=c.properties||{};if(!h(f)){i.push(t.idStrategy==="preserve"?c:{...c,id:p});return}let{startDate:y,endDate:k}=F(f);(y||k)&&(o=!0),i.push({...c,...p!==void 0&&{id:p},properties:{...f,startDate:y?.toISOString()||null,endDate:k?.toISOString()||null}})});let m=n.properties?.layerMetadata;return{kind:"features",features:i,featureCount:i.length,bbox:D(i),hasTemporal:o,hasAltitude:u,reprojected:!1,sourceCRS:r,...s&&{needsReprojection:s},...m&&{layerMetadata:m},...a.dropped>0&&{truncated:{droppedCount:a.dropped,sourceFeatureCount:a.sourceCount,maxFeatures:t.maxFeatures}}}}var N=5e3;function M(e,t){let n=Number.isNaN(t)?N:Math.max(1,Math.floor(t)),r=[];for(let s=0;s<e.length;s+=n)r.push(e.slice(s,s+n));return r}function g(e){if(e===void 0)return!1;if(typeof e=="number")return Number.isFinite(e)&&!Object.is(e,-0);if(e===null||typeof e!="object")return!0;if(Array.isArray(e)){for(let t=0;t<e.length;t++)if(!g(e[t]))return!1;return!0}for(let t in e)if(!g(e[t]))return!1;return!0}function P(e){for(let t=0;t<e.length;t++)if(!g(e[t]))return e;try{return JSON.stringify(e)}catch{return e}}function J(e){let{kind:t,features:n,...r}=e;return r}async function w(e,t,n,r){let s;try{s=O(t,n)}catch(a){r.post({kind:"result",id:e,ok:!1,error:a instanceof Error?a.message:String(a)});return}if(s.kind!=="features"){r.post({kind:"result",id:e,ok:!0,result:s});return}try{let a=r.encode??P,o=M(s.features,r.chunkSize??N);r.post({kind:"head",id:e,summary:J(s)});let u=o.length>0?a(o[0]):null;for(let i=0;i<o.length;i++){let m=r.waitAck(i);r.post({kind:"chunk",id:e,seq:i,payload:u}),u=i+1<o.length?a(o[i+1]):null,await m}r.post({kind:"done",id:e,chunkCount:o.length})}catch(a){r.post({kind:"error",id:e,message:a instanceof Error?a.message:String(a)})}}var A=e=>self.postMessage(e),l=new Map;self.onmessage=async e=>{let t=e.data;if(x(t)){let o=`${t.id}:${t.seq}`,u=l.get(o);l.delete(o),u?.();return}let{id:n,source:r,options:s,tuning:a}=t;try{let o=r.type==="blob"?{type:"text",text:await r.blob.text()}:r;await w(n,o,s,{post:A,waitAck:u=>new Promise(i=>{l.set(`${n}:${u}`,i)}),...a?.chunkSize!==void 0&&{chunkSize:a.chunkSize},...a?.featureArrayChunks&&{encode:u=>u}})}catch(o){A({kind:"result",id:n,ok:!1,error:o instanceof Error?o.message:String(o)})}finally{l.forEach((o,u)=>{u.startsWith(`${n}:`)&&l.delete(u)})}};})();\n';
147
+ const ingestWorkerSource = '"use strict";(()=>{function b(e,t){let n=e.length,r=Math.max(0,t.max-(t.existing??0));return n<=r?{features:e,dropped:0,sourceCount:n}:{features:e.slice(0,r),dropped:n-r,sourceCount:n}}function S(e){let t=e.crs?.properties?.name,n=null;if(t){let r=t.match(/EPSG::?(\\d+)/i);r&&(n=`EPSG:${r[1]}`)}if(!n&&e.features.length>0){let r=A(e.features[0].geometry);if(r){let[s,a]=r;if(Math.abs(s)<=180&&Math.abs(a)<=90)return{sourceCRS:"EPSG:4326",needsReprojection:!1}}return{sourceCRS:null,needsReprojection:!1}}return{sourceCRS:n,needsReprojection:n!==null&&n!=="EPSG:4326"}}function A(e){if(!e)return null;switch(e.type){case"Point":return e.coordinates;case"MultiPoint":case"LineString":return e.coordinates[0];case"MultiLineString":case"Polygon":return e.coordinates[0]?.[0];case"MultiPolygon":return e.coordinates[0]?.[0]?.[0];default:return null}}function I(e){return e.geometry?.type==="LineString"?e.geometry.coordinates.some(n=>n.length>=3&&n[2]!==0):e.geometry?.type==="MultiLineString"?e.geometry.coordinates.some(n=>n.some(r=>r.length>=3&&r[2]!==0)):!1}function d(e){if(!e)return null;if(e instanceof Date)return e;if(typeof e=="string"||typeof e=="number"){let t=new Date(e);return isNaN(t.getTime())?null:t}return null}function h(e){return!!(e.startDate||e.startdate||e.start_date||e.start_time||e.date||e.timestamp||e.flightDate||e.time||e.datetime||e.endDate||e.enddate||e.end_date||e.end_time)}function F(e){let t=d(e.startDate)||d(e.startdate)||d(e.start_date)||d(e.start_time)||d(e.date)||d(e.timestamp)||d(e.flightDate)||d(e.time)||d(e.datetime),n=d(e.endDate)||d(e.enddate)||d(e.end_date)||d(e.end_time);return t&&n&&n<t&&([t,n]=[n,t]),{startDate:t,endDate:n}}function x(e){return"kind"in e&&e.kind==="ack"}function E(){let e=globalThis.crypto?.randomUUID?.bind(globalThis.crypto);return e?e():`f-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function G(e,t,n){switch(n.idStrategy){case"preserve":return e.id;case"layer-index":return e.id!==void 0&&e.id!==null?String(e.id):`${n.layerId}-f${t}`;case"uuid-fallback":return e.id?String(e.id):E()}}function C(e,t){if(Array.isArray(e)){if(typeof e[0]=="number"){let n=e[0],r=e[1];t[0]=Math.min(t[0],n),t[1]=Math.min(t[1],r),t[2]=Math.max(t[2],n),t[3]=Math.max(t[3],r);return}for(let n of e)C(n,t)}}function R(e,t){if(e){if(e.type==="GeometryCollection"){for(let n of e.geometries)R(n,t);return}C(e.coordinates,t)}}function _(e){let t=[1/0,1/0,-1/0,-1/0];for(let n of e)R(n.geometry,t);return t.every(n=>isFinite(n))?t:null}function O(e,t){let n;if(e.type==="text")try{n=JSON.parse(e.text)}catch(c){return{kind:"error",code:"parse-error",message:c instanceof Error?c.message:"Invalid file"}}else n=e.data;if(n&&n.type==="Feature"&&(n={type:"FeatureCollection",features:[n]}),!n||n.type!=="FeatureCollection"||!Array.isArray(n.features))return{kind:"error",code:"invalid-format",message:"Invalid GeoJSON format"};if(t.emptyIsError&&n.features.length===0)return{kind:"error",code:"empty",message:"The file contains no features"};if(n["octostar:map"])return{kind:"enriched",data:n};let{sourceCRS:r,needsReprojection:s}=S(n),a=b(n.features,{max:t.maxFeatures??1/0}),o=!1,u=!1,i=[];a.features.forEach((c,w)=>{let p=G(c,w,t);!u&&I(c)&&(u=!0);let g=c.properties||{};if(!h(g)){i.push(t.idStrategy==="preserve"?c:{...c,id:p});return}let{startDate:y,endDate:k}=F(g);(y||k)&&(o=!0),i.push({...c,...p!==void 0&&{id:p},properties:{...g,startDate:y?.toISOString()||null,endDate:k?.toISOString()||null}})});let m=n.properties?.layerMetadata;return{kind:"features",features:i,featureCount:i.length,bbox:_(i),hasTemporal:o,hasAltitude:u,reprojected:!1,sourceCRS:r,...s&&{needsReprojection:s},...m&&{layerMetadata:m},...a.dropped>0&&{truncated:{droppedCount:a.dropped,sourceFeatureCount:a.sourceCount,maxFeatures:t.maxFeatures}}}}var T=5e3;function J(e,t){let n=Number.isNaN(t)?T:Math.max(1,Math.floor(t)),r=[];for(let s=0;s<e.length;s+=n)r.push(e.slice(s,s+n));return r}function f(e){if(e===void 0)return!1;if(typeof e=="number")return Number.isFinite(e)&&!Object.is(e,-0);if(e===null||typeof e!="object")return!0;if(Array.isArray(e)){for(let t=0;t<e.length;t++)if(!f(e[t]))return!1;return!0}for(let t in e)if(!f(e[t]))return!1;return!0}function M(e){for(let t=0;t<e.length;t++)if(!f(e[t]))return e;try{return JSON.stringify(e)}catch{return e}}function P(e){let{kind:t,features:n,...r}=e;return r}async function D(e,t,n,r){let s;try{s=O(t,n)}catch(a){r.post({kind:"result",id:e,ok:!1,error:a instanceof Error?a.message:String(a)});return}if(s.kind!=="features"){r.post({kind:"result",id:e,ok:!0,result:s});return}try{let a=r.encode??M,o=J(s.features,r.chunkSize??T);r.post({kind:"head",id:e,summary:P(s)});let u=o.length>0?a(o[0]):null;for(let i=0;i<o.length;i++){let m=r.waitAck(i);r.post({kind:"chunk",id:e,seq:i,payload:u}),u=i+1<o.length?a(o[i+1]):null,await m}r.post({kind:"done",id:e,chunkCount:o.length})}catch(a){r.post({kind:"error",id:e,message:a instanceof Error?a.message:String(a)})}}var N=e=>self.postMessage(e),l=new Map;self.onmessage=async e=>{let t=e.data;if(x(t)){let o=`${t.id}:${t.seq}`,u=l.get(o);l.delete(o),u?.();return}let{id:n,source:r,options:s,tuning:a}=t;try{let o=r.type==="blob"?{type:"text",text:await r.blob.text()}:r;await D(n,o,s,{post:N,waitAck:u=>new Promise(i=>{l.set(`${n}:${u}`,i)}),...a?.chunkSize!==void 0&&{chunkSize:a.chunkSize},...a?.featureArrayChunks&&{encode:u=>u}})}catch(o){N({kind:"result",id:n,ok:!1,error:o instanceof Error?o.message:String(o)})}finally{l.forEach((o,u)=>{u.startsWith(`${n}:`)&&l.delete(u)})}};})();\n';
148
148
  proj4.defs("EPSG:27700", "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs");
149
149
  proj4.defs("EPSG:3857", "+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs");
150
150
  proj4.defs("EPSG:32630", "+proj=utm +zone=30 +datum=WGS84 +units=m +no_defs");
@@ -272,6 +272,23 @@ function normalizeTemporalProperties(properties) {
272
272
  }
273
273
  return { startDate, endDate };
274
274
  }
275
+ const timelineFieldsKey = (fields) => fields ? JSON.stringify([fields.start, fields.end ?? null]) : "";
276
+ function hasTimelineValue(properties, fields) {
277
+ return fields ? !!properties[fields.start] : hasAnyTemporalValue(properties);
278
+ }
279
+ const anyTimelineDate = (features, fields) => features.some((f) => {
280
+ const properties = f.properties ?? {};
281
+ if (!hasTimelineValue(properties, fields)) return false;
282
+ const { startDate, endDate } = readTimelineDates(properties, fields);
283
+ return startDate !== null || endDate !== null;
284
+ });
285
+ function readTimelineDates(properties, fields) {
286
+ if (!fields) return normalizeTemporalProperties(properties);
287
+ const startDate = parseDate(properties[fields.start]);
288
+ if (!startDate) return { startDate: null, endDate: null };
289
+ const endDate = fields.end ? parseDate(properties[fields.end]) : null;
290
+ return endDate && endDate < startDate ? { startDate: endDate, endDate: startDate } : { startDate, endDate };
291
+ }
275
292
  function generateUuid() {
276
293
  var _a, _b;
277
294
  const uuid = (_b = (_a = globalThis.crypto) == null ? void 0 : _a.randomUUID) == null ? void 0 : _b.bind(globalThis.crypto);
@@ -759,6 +776,27 @@ function installInlinedMaplibreWorker() {
759
776
  }
760
777
  setWorkerUrl(URL.createObjectURL(new Blob([maplibreWorkerSource], { type: "text/javascript" })));
761
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
+ }
762
800
  const SELECTED_STATE_KEY = "selected";
763
801
  const SELECTED = ["boolean", ["feature-state", SELECTED_STATE_KEY], false];
764
802
  const SELECTED_STATE = Object.freeze({ [SELECTED_STATE_KEY]: true });
@@ -770,6 +808,18 @@ const TRACE_ENDPOINT = ["boolean", ["feature-state", TRACE_ENDPOINT_KEY], false]
770
808
  const LABEL_NEVER_HIDE_PROP = "_labelNeverHide";
771
809
  const PINNED_LABEL_FILTER = ["==", ["get", LABEL_NEVER_HIDE_PROP], 1];
772
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
+ ];
773
823
  function computeLabelNeverHide(label) {
774
824
  return (label == null ? void 0 : label.neverHide) && !label.hidden ? 1 : 0;
775
825
  }
@@ -835,6 +885,23 @@ function buildCustomLabelPaint(opts) {
835
885
  "text-opacity": (opts == null ? void 0 : opts.hideSelected) ? ["case", TIMELINE_HIDDEN, 0, SELECTED, 0, visibleOpacity] : visibleOpacity
836
886
  };
837
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
+ }
838
905
  const DEFAULT_FEATURE_COLOR = "#3b82f6";
839
906
  const LAYER_COLOR_PALETTE = [
840
907
  "#3FB37F",
@@ -895,8 +962,10 @@ const CUSTOM_LAYER_ROLES = [
895
962
  "point-shadow",
896
963
  "point",
897
964
  "point-icon",
965
+ "host-icon",
898
966
  "labels",
899
- "labels-pinned"
967
+ "labels-pinned",
968
+ "host-labels"
900
969
  ];
901
970
  const SHARED_SOURCE_ID = "custom-features";
902
971
  function customSourceSpec() {
@@ -953,6 +1022,11 @@ function shardInsertAnchor(role) {
953
1022
  return "custom-arrow-heads";
954
1023
  case "labels-pinned":
955
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";
956
1030
  }
957
1031
  }
958
1032
  const POINT_RADIUS = ["case", TRACE_ENDPOINT, ["get", "_endpointRadius"], ["coalesce", ["get", "pointRadius"], 5]];
@@ -961,6 +1035,7 @@ function unlessTimelineHidden(value) {
961
1035
  }
962
1036
  function buildLayer(role, sourceId, opts) {
963
1037
  const id = customLayerId(role, sourceId);
1038
+ const shared = sourceId === SHARED_SOURCE_ID;
964
1039
  switch (role) {
965
1040
  // Custom polygon fill layer - preserves original styling
966
1041
  case "polygon-fill":
@@ -1099,7 +1174,7 @@ function buildLayer(role, sourceId, opts) {
1099
1174
  id,
1100
1175
  type: "symbol",
1101
1176
  source: sourceId,
1102
- filter: ["all", ["==", "$type", "Point"], ["!=", "icon", ""]],
1177
+ filter: shared ? ["all", ["==", "$type", "Point"], ["!=", "icon", ""], ["!=", HOST_OWNED_PROP, 1]] : ["all", ["==", "$type", "Point"], ["!=", "icon", ""]],
1103
1178
  layout: {
1104
1179
  "icon-image": ["get", "icon"],
1105
1180
  "icon-size": ["/", ["coalesce", ["get", "iconSize"], 24], EMOJI_CANVAS_SIZE],
@@ -1129,7 +1204,7 @@ function buildLayer(role, sourceId, opts) {
1129
1204
  id,
1130
1205
  type: "symbol",
1131
1206
  source: sourceId,
1132
- filter: UNPINNED_LABEL_FILTER,
1207
+ filter: shared ? ["all", UNPINNED_LABEL_FILTER, NOT_HOST_FILTER] : UNPINNED_LABEL_FILTER,
1133
1208
  layout: {
1134
1209
  ...buildCustomLabelLayout(),
1135
1210
  "visibility": opts.labelsVisible ? "visible" : "none",
@@ -1181,7 +1256,7 @@ function buildLayer(role, sourceId, opts) {
1181
1256
  id,
1182
1257
  type: "symbol",
1183
1258
  source: sourceId,
1184
- filter: PINNED_LABEL_FILTER,
1259
+ filter: shared ? ["all", PINNED_LABEL_FILTER, NOT_HOST_FILTER] : PINNED_LABEL_FILTER,
1185
1260
  layout: {
1186
1261
  ...buildCustomLabelLayout(),
1187
1262
  "visibility": "visible",
@@ -1194,6 +1269,29 @@ function buildLayer(role, sourceId, opts) {
1194
1269
  },
1195
1270
  paint: buildCustomLabelPaint({ hideSelected: true })
1196
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
+ }
1197
1295
  }
1198
1296
  }
1199
1297
  function buildCustomLayerStack(sourceId, roles, opts) {
@@ -1204,6 +1302,7 @@ function isShardEligible(layer, featureCount, shardSize) {
1204
1302
  var _a;
1205
1303
  if (!layer.readOnly) return false;
1206
1304
  if ((_a = layer.traceConfig) == null ? void 0 : _a.enabled) return false;
1305
+ if (layer.hostOwned) return false;
1207
1306
  if (!isUsableShardSize(shardSize)) return false;
1208
1307
  return featureCount > shardSize;
1209
1308
  }
@@ -1259,6 +1358,7 @@ function shardFingerprintsEqual(a, b) {
1259
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);
1260
1359
  }
1261
1360
  const INTERACTIVE_ROLES = ["point", "line", "polygon-fill"];
1361
+ const HOST_INTERACTIVE_ROLES = [...INTERACTIVE_ROLES, "host-icon"];
1262
1362
  function createShardRegistry(host, hooks) {
1263
1363
  const states = /* @__PURE__ */ new Map();
1264
1364
  let sharedLayerIds = [];
@@ -1380,7 +1480,8 @@ function createShardRegistry(host, hooks) {
1380
1480
  },
1381
1481
  labelLayerIds(kind, opts) {
1382
1482
  const roles = kind === "unpinned" ? ["labels"] : kind === "pinned" ? ["labels-pinned"] : ["labels", "labels-pinned"];
1383
- 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)));
1384
1485
  states.forEach((state) => {
1385
1486
  if ((opts == null ? void 0 : opts.visibleLayersOnly) && !state.visible) return;
1386
1487
  state.stacks.forEach((stack) => {
@@ -1393,8 +1494,10 @@ function createShardRegistry(host, hooks) {
1393
1494
  return ids;
1394
1495
  },
1395
1496
  interactiveLayerIds() {
1497
+ var _a;
1498
+ const sharedRoles = ((_a = hooks.hostIconInteractive) == null ? void 0 : _a.call(hooks)) ? HOST_INTERACTIVE_ROLES : INTERACTIVE_ROLES;
1396
1499
  const ids = sharedLayerIds.filter(
1397
- (id) => INTERACTIVE_ROLES.some((role) => id === customLayerId(role, SHARED_SOURCE_ID))
1500
+ (id) => sharedRoles.some((role) => id === customLayerId(role, SHARED_SOURCE_ID))
1398
1501
  );
1399
1502
  states.forEach((state) => {
1400
1503
  if (!state.visible) return;
@@ -1527,6 +1630,79 @@ function formatGradientStop(value) {
1527
1630
  }
1528
1631
  return new Intl.NumberFormat("en-US", { maximumFractionDigits: 2 }).format(value);
1529
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
+ }
1530
1706
  const ICONS = [
1531
1707
  // Location & Places
1532
1708
  { id: "map-pin", emoji: "📍", name: "Map Pin", category: "places" },
@@ -1693,24 +1869,24 @@ function isIntervalVisible(s, e, w) {
1693
1869
  return (noStart ? e : s) <= w.t1 && (noEnd ? s : e) >= w.t0;
1694
1870
  }
1695
1871
  const interval = { s: NaN, e: NaN };
1696
- function readInterval(f) {
1872
+ function readInterval(f, fields) {
1697
1873
  interval.s = NaN;
1698
1874
  interval.e = NaN;
1699
1875
  const props = f.properties;
1700
- if (!props || !hasAnyTemporalValue(props)) return;
1701
- const { startDate, endDate } = normalizeTemporalProperties(props);
1876
+ if (!props || !hasTimelineValue(props, fields)) return;
1877
+ const { startDate, endDate } = readTimelineDates(props, fields);
1702
1878
  const s = startDate ? startDate.getTime() : NaN;
1703
1879
  const e = endDate ? endDate.getTime() : NaN;
1704
1880
  interval.s = Number.isNaN(s) ? e : s;
1705
1881
  interval.e = Number.isNaN(e) ? s : e;
1706
1882
  }
1707
- function featureInterval(f) {
1708
- readInterval(f);
1883
+ function featureInterval(f, fields) {
1884
+ readInterval(f, fields);
1709
1885
  return { s: interval.s, e: interval.e };
1710
1886
  }
1711
- function isFeatureVisible(f, w) {
1887
+ function isFeatureVisible(f, w, fields) {
1712
1888
  if (w === null) return true;
1713
- readInterval(f);
1889
+ readInterval(f, fields);
1714
1890
  return isIntervalVisible(interval.s, interval.e, w);
1715
1891
  }
1716
1892
  function collectRepeats(features) {
@@ -1730,13 +1906,13 @@ function collectRepeats(features) {
1730
1906
  }
1731
1907
  return repeats;
1732
1908
  }
1733
- function buildIndex(features) {
1909
+ function buildIndex(features, fields) {
1734
1910
  const size = features.length;
1735
1911
  const starts = new Float64Array(size);
1736
1912
  const ends = new Float64Array(size);
1737
1913
  let timed = 0;
1738
1914
  for (let i = 0; i < size; i++) {
1739
- readInterval(features[i]);
1915
+ readInterval(features[i], fields);
1740
1916
  starts[i] = interval.s;
1741
1917
  ends[i] = interval.e;
1742
1918
  if (!Number.isNaN(interval.s)) timed++;
@@ -1762,14 +1938,14 @@ function buildIndex(features) {
1762
1938
  };
1763
1939
  }
1764
1940
  const cache$1 = /* @__PURE__ */ new WeakMap();
1765
- function getTimelineIndex(features) {
1766
- let index = cache$1.get(features);
1767
- if (!index) {
1768
- const started = performance.now();
1769
- index = buildIndex(features);
1770
- cache$1.set(features, index);
1771
- mapPerfLog("timeline", "index built", { n: features.length, ms: Math.round(performance.now() - started) });
1772
- }
1941
+ function getTimelineIndex(features, fields) {
1942
+ const key = timelineFieldsKey(fields);
1943
+ const cached = cache$1.get(features);
1944
+ if ((cached == null ? void 0 : cached.key) === key) return cached.index;
1945
+ const started = performance.now();
1946
+ const index = buildIndex(features, fields);
1947
+ cache$1.set(features, { key, index });
1948
+ mapPerfLog("timeline", "index built", { n: features.length, ms: Math.round(performance.now() - started) });
1773
1949
  return index;
1774
1950
  }
1775
1951
  function isVisibleAt(index, position, w) {
@@ -1830,21 +2006,29 @@ function countVisible(index, w) {
1830
2006
  const TRACE_DEFAULT_COLOR = "#3b82f6";
1831
2007
  const TRACE_UNGROUPED_KEY = "__all__";
1832
2008
  const cache = /* @__PURE__ */ new WeakMap();
1833
- function getTraceGroups(features, groupByField) {
2009
+ function getTraceGroups(features, groupByField, fields) {
1834
2010
  const field = groupByField || null;
1835
- let byField = cache.get(features);
1836
- if (!byField) {
1837
- byField = /* @__PURE__ */ new Map();
1838
- cache.set(features, byField);
2011
+ const fieldsKey = timelineFieldsKey(fields);
2012
+ let entry = cache.get(features);
2013
+ if ((entry == null ? void 0 : entry.fieldsKey) !== fieldsKey) {
2014
+ entry = { fieldsKey, byField: /* @__PURE__ */ new Map() };
2015
+ cache.set(features, entry);
1839
2016
  }
2017
+ const { byField } = entry;
1840
2018
  const fieldKey = field ?? "";
1841
2019
  let groups = byField.get(fieldKey);
1842
2020
  if (!groups) {
1843
- groups = buildTraceGroups(features, field);
2021
+ groups = buildTraceGroups(features, field, fields);
1844
2022
  byField.set(fieldKey, groups);
1845
2023
  }
1846
2024
  return groups;
1847
2025
  }
2026
+ function traceTime(feature, fields) {
2027
+ const props = feature.properties;
2028
+ if (!fields) return (props == null ? void 0 : props.startDate) ? new Date(props.startDate).getTime() : null;
2029
+ const { startDate } = readTimelineDates(props ?? {}, fields);
2030
+ return startDate ? startDate.getTime() : null;
2031
+ }
1848
2032
  function sortKey(time) {
1849
2033
  return Number.isNaN(time) ? -Infinity : time;
1850
2034
  }
@@ -1855,20 +2039,22 @@ function compareStaged(a, b) {
1855
2039
  if (ka > kb) return 1;
1856
2040
  return 0;
1857
2041
  }
1858
- function buildTraceGroups(features, field) {
2042
+ function buildTraceGroups(features, field, fields) {
1859
2043
  var _a;
1860
2044
  const staged = /* @__PURE__ */ new Map();
1861
2045
  for (let position = 0; position < features.length; position++) {
1862
2046
  const feature = features[position];
1863
- if (feature.id == null || feature.geometry.type !== "Point" || !((_a = feature.properties) == null ? void 0 : _a.startDate)) continue;
1864
- const raw = field ? feature.properties[field] : void 0;
2047
+ if (feature.id == null || feature.geometry.type !== "Point") continue;
2048
+ const time = traceTime(feature, fields);
2049
+ if (time === null) continue;
2050
+ const raw = field ? (_a = feature.properties) == null ? void 0 : _a[field] : void 0;
1865
2051
  const key = field && raw != null && raw !== "" ? String(raw) : TRACE_UNGROUPED_KEY;
1866
2052
  let bucket = staged.get(key);
1867
2053
  if (!bucket) {
1868
2054
  bucket = [];
1869
2055
  staged.set(key, bucket);
1870
2056
  }
1871
- bucket.push({ feature, time: new Date(feature.properties.startDate).getTime(), position });
2057
+ bucket.push({ feature, time, position });
1872
2058
  }
1873
2059
  const count = staged.size;
1874
2060
  const groups = [];
@@ -2138,6 +2324,11 @@ const DEFAULT_LABEL_PRIORITY = 100;
2138
2324
  const DEFAULT_VISIBLE_STROKE_OPACITY = 1;
2139
2325
  const DEFAULT_VISIBLE_FILL_OPACITY = 0.2;
2140
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
+ ];
2141
2332
  const ANNOTATION_PASSTHROUGH_KEYS = [
2142
2333
  "kind",
2143
2334
  "text",
@@ -2166,7 +2357,7 @@ function resolveIcon(value) {
2166
2357
  if (typeof value !== "string" || value === "") return "";
2167
2358
  if (value !== lastIcon) {
2168
2359
  lastIcon = value;
2169
- lastResolvedIcon = isEmojiIcon(value) ? value : EMOJI_BY_ID.get(value) ?? "";
2360
+ lastResolvedIcon = value.startsWith(HOST_IMAGE_PREFIX) || isEmojiIcon(value) ? value : EMOJI_BY_ID.get(value) ?? "";
2170
2361
  }
2171
2362
  return lastResolvedIcon;
2172
2363
  }
@@ -2181,6 +2372,16 @@ const clusterHidesPoints = (layer) => {
2181
2372
  function layerHidesPoints(layer) {
2182
2373
  return heatmapHidesPoints(layer) || clusterHidesPoints(layer);
2183
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
+ }
2184
2385
  function styleFeatureForPaint(f, layer, ctx, slim) {
2185
2386
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
2186
2387
  const featureId = String(f.id);
@@ -2199,20 +2400,18 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
2199
2400
  let strokeWidth = ((_c = f.properties) == null ? void 0 : _c["stroke-width"]) || 2;
2200
2401
  let pointRadius = Math.round(3 + strokeWidth);
2201
2402
  const sizeConfig = visualConfig == null ? void 0 : visualConfig.size;
2202
- 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) {
2203
2407
  if (sizeConfig.mode === "override" && sizeConfig.overrideValue !== void 0) {
2204
2408
  strokeWidth = Math.max(1, Math.min(10, sizeConfig.overrideValue));
2205
2409
  pointRadius = Math.round(3 + strokeWidth);
2206
- } else if (sizeConfig.mode === "field" && sizeConfig.fieldName && layer) {
2207
- const range = ctx.sizeFieldRanges.get(layer.id);
2208
- if (range && f.properties) {
2209
- const rawVal = f.properties[sizeConfig.fieldName];
2210
- const val = typeof rawVal === "number" ? rawVal : typeof rawVal === "string" && rawVal.trim() !== "" ? Number(rawVal) : NaN;
2211
- if (isFinite(val)) {
2212
- const normalized = range.max > range.min ? (val - range.min) / (range.max - range.min) : 0.5;
2213
- strokeWidth = 2 + normalized * 8;
2214
- pointRadius = Math.round(2 + normalized * 16);
2215
- }
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);
2216
2415
  }
2217
2416
  }
2218
2417
  }
@@ -2236,7 +2435,9 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
2236
2435
  }
2237
2436
  }
2238
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 = "";
2239
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;
2240
2441
  const iconConfig = visualConfig == null ? void 0 : visualConfig.icon;
2241
2442
  const layerIcon = !featureIcon && (iconConfig == null ? void 0 : iconConfig.enabled) ? resolveIcon(iconConfig.icon) : "";
2242
2443
  if (layerIcon) {
@@ -2255,7 +2456,12 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
2255
2456
  RENDER_PASSTHROUGH_KEYS.forEach((key) => {
2256
2457
  if (key in props) sanitizedProps[key] = sanitizeValue(props[key]);
2257
2458
  });
2258
- 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)) {
2259
2465
  ANNOTATION_PASSTHROUGH_KEYS.forEach((key) => {
2260
2466
  if (key in props) sanitizedProps[key] = sanitizeValue(props[key]);
2261
2467
  });
@@ -2280,7 +2486,7 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
2280
2486
  }
2281
2487
  const visibleStrokeOpacity = hideFlatFor3DOnly ? 0 : baseOpacity;
2282
2488
  const visibleFillOpacity = hideFlatFor3DOnly ? 0 : ((_k = f.properties) == null ? void 0 : _k["fill-opacity"]) ?? DEFAULT_VISIBLE_FILL_OPACITY;
2283
- return {
2489
+ const styled = {
2284
2490
  feature: {
2285
2491
  type: "Feature",
2286
2492
  id: featureId,
@@ -2308,6 +2514,8 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
2308
2514
  }
2309
2515
  }
2310
2516
  };
2517
+ if (layer == null ? void 0 : layer.hostOwned) styled.feature.properties[HOST_OWNED_PROP] = 1;
2518
+ return styled;
2311
2519
  }
2312
2520
  function layerFieldRanges(visualConfig, forEachProperties) {
2313
2521
  const sizeConfig = visualConfig == null ? void 0 : visualConfig.size;
@@ -2405,6 +2613,224 @@ function frameYield(scheduler = defaultScheduler, fallbackMs = 50) {
2405
2613
  }, fallbackMs);
2406
2614
  });
2407
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
+ }
2408
2834
  function placeContextMenu(point2, parent, menu) {
2409
2835
  const scaleX = parent.offsetWidth > 0 ? parent.rect.width / parent.offsetWidth : 1;
2410
2836
  const scaleY = parent.offsetHeight > 0 ? parent.rect.height / parent.offsetHeight : 1;
@@ -4607,7 +5033,8 @@ function LayersPanel({
4607
5033
  onClick: () => onFitToLayerFeatures(layer.id)
4608
5034
  }
4609
5035
  ] : [],
4610
- ...layers.length > 1 ? [
5036
+ // A host-owned layer is removed by its host, never from here.
5037
+ ...layers.length > 1 && !layer.hostOwned ? [
4611
5038
  { type: "divider" },
4612
5039
  {
4613
5040
  key: "delete",
@@ -5667,6 +6094,7 @@ function resolveTooltipFeature(rendered, lookup) {
5667
6094
  };
5668
6095
  }
5669
6096
  const DEFAULT_POINT_RADIUS = 5;
6097
+ const DEFAULT_ICON_SIZE = 24;
5670
6098
  const MAX_POINT_RADIUS = 18;
5671
6099
  const SAME_SPOT_PX = 1;
5672
6100
  const CROWD = 16;
@@ -5676,8 +6104,12 @@ const distance = (a, b) => Math.hypot(a.x - b.x, a.y - b.y);
5676
6104
  function paintedRadius(f) {
5677
6105
  var _a, _b;
5678
6106
  const p = f.properties ?? {};
5679
- 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;
5680
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
+ }
5681
6113
  const r = ((_b = f.state) == null ? void 0 : _b[TRACE_ENDPOINT_KEY]) === true ? p._endpointRadius : p.pointRadius;
5682
6114
  return typeof r === "number" && Number.isFinite(r) ? r : DEFAULT_POINT_RADIUS;
5683
6115
  }
@@ -7619,6 +8051,7 @@ function useTimelineStore(selector) {
7619
8051
  return useStore(store, select);
7620
8052
  }
7621
8053
  const TIMEBAR_HEIGHT = 158;
8054
+ const EMPTY_TIMEBAR_HEIGHT = 46;
7622
8055
  const TIMEBAR_BOTTOM_OFFSET = 12;
7623
8056
  const DEFAULT_LABELS = {
7624
8057
  play: "Play",
@@ -7857,6 +8290,7 @@ function Timebar({
7857
8290
  selectionDisplay = "bars",
7858
8291
  className,
7859
8292
  timebarExtra,
8293
+ keepExtraWhenEmpty = false,
7860
8294
  formatCount: formatCount2,
7861
8295
  labels: labelOverrides
7862
8296
  }) {
@@ -8005,7 +8439,19 @@ function Timebar({
8005
8439
  };
8006
8440
  }, [isPlaying, globalMinDate, globalMaxDate, setRange, setPlaying]);
8007
8441
  if (!isEnabled || !hasTemporalData || !globalMinDate || !globalMaxDate) {
8008
- return null;
8442
+ if (!isEnabled || !keepExtraWhenEmpty) return null;
8443
+ return /* @__PURE__ */ jsx(
8444
+ "div",
8445
+ {
8446
+ className: cn(
8447
+ "absolute bottom-3 left-4 right-4 z-20 bg-background/95 floating-panel rounded-lg shadow-lg border border-border px-4 flex items-center justify-end",
8448
+ className
8449
+ ),
8450
+ style: { height: EMPTY_TIMEBAR_HEIGHT },
8451
+ "data-testid": "timebar-panel-empty",
8452
+ children: timebarExtra
8453
+ }
8454
+ );
8009
8455
  }
8010
8456
  const totalRange = globalMaxDate.getTime() - globalMinDate.getTime();
8011
8457
  const startPercent = rangeStart ? (rangeStart.getTime() - globalMinDate.getTime()) / totalRange * 100 : 0;
@@ -8313,6 +8759,9 @@ function historyLayersEqual(a, b) {
8313
8759
  const { featureIds: _bIds, ...bRest } = b;
8314
8760
  return JSON.stringify(aRest) === JSON.stringify(bRest);
8315
8761
  }
8762
+ function historyFeatureContentEqual(a, b) {
8763
+ return JSON.stringify(a.geometry) === JSON.stringify(b.geometry) && JSON.stringify(a.properties ?? {}) === JSON.stringify(b.properties ?? {});
8764
+ }
8316
8765
  function diffHistorySnapshots(before, after, beforeLayers, afterLayers) {
8317
8766
  const allFeatureIds = /* @__PURE__ */ new Set();
8318
8767
  before.forEach((_v, k) => allFeatureIds.add(k));
@@ -8326,9 +8775,7 @@ function diffHistorySnapshots(before, after, beforeLayers, afterLayers) {
8326
8775
  return;
8327
8776
  }
8328
8777
  if (b.feature === a.feature) return;
8329
- if (JSON.stringify(b.feature.geometry) !== JSON.stringify(a.feature.geometry) || JSON.stringify(b.feature.properties ?? {}) !== JSON.stringify(a.feature.properties ?? {})) {
8330
- featureIds.add(id);
8331
- }
8778
+ if (!historyFeatureContentEqual(b.feature, a.feature)) featureIds.add(id);
8332
8779
  });
8333
8780
  const allLayerIds = /* @__PURE__ */ new Set();
8334
8781
  beforeLayers.forEach((_v, k) => allLayerIds.add(k));
@@ -8670,25 +9117,25 @@ function pushCopy(copies, id, copy, first) {
8670
9117
  if (list) list.push(copy);
8671
9118
  else copies.set(id, [first, copy]);
8672
9119
  }
8673
- function collectCopies(slices) {
9120
+ function collectCopies(slices, fields) {
8674
9121
  const copies = /* @__PURE__ */ new Map();
8675
9122
  if (slices.length === 1) {
8676
9123
  const { features, start, end } = slices[0];
8677
- const index = getTimelineIndex(features);
9124
+ const index = getTimelineIndex(features, fields);
8678
9125
  index.repeats.forEach((positions, id) => {
8679
9126
  const inside = positions.filter((p) => p >= start && p < end);
8680
- if (inside.length > 1) copies.set(id, inside.map((position) => ({ index, position })));
9127
+ if (inside.length > 1) copies.set(id, inside.map((position) => ({ features, index, position })));
8681
9128
  });
8682
9129
  return copies;
8683
9130
  }
8684
9131
  const first = /* @__PURE__ */ new Map();
8685
9132
  slices.forEach(({ features, start, end }) => {
8686
- const index = getTimelineIndex(features);
9133
+ const index = getTimelineIndex(features, fields);
8687
9134
  for (let position = start; position < end; position++) {
8688
9135
  const raw = features[position].id;
8689
9136
  if (raw === void 0 || raw === null) continue;
8690
9137
  const id = String(raw);
8691
- const copy = { index, position };
9138
+ const copy = { features, index, position };
8692
9139
  const seen = first.get(id);
8693
9140
  if (seen) pushCopy(copies, id, copy, seen);
8694
9141
  else first.set(id, copy);
@@ -8696,13 +9143,13 @@ function collectCopies(slices) {
8696
9143
  });
8697
9144
  return copies;
8698
9145
  }
8699
- function copiesOf(record) {
8700
- record.copies ?? (record.copies = collectCopies(record.slices));
9146
+ function copiesOf(record, fields) {
9147
+ record.copies ?? (record.copies = collectCopies(record.slices, fields));
8701
9148
  return record.copies;
8702
9149
  }
8703
- function shouldHide(record, id, index, position, w) {
9150
+ function shouldHide(record, id, index, position, w, fields) {
8704
9151
  if (isVisibleAt(index, position, w)) return false;
8705
- const copies = copiesOf(record).get(id);
9152
+ const copies = copiesOf(record, fields).get(id);
8706
9153
  return !copies || copies.every((c) => !isVisibleAt(c.index, c.position, w));
8707
9154
  }
8708
9155
  function setHidden(host, record, id, hide) {
@@ -8720,7 +9167,27 @@ function idAt(features, position) {
8720
9167
  const raw = features[position].id;
8721
9168
  return raw === void 0 || raw === null ? null : String(raw);
8722
9169
  }
8723
- function seedTimelineSource(host, applied, sourceId, slices, w) {
9170
+ function hiddenAt(record, w, fields) {
9171
+ const hide = /* @__PURE__ */ new Set();
9172
+ if (w === null) return hide;
9173
+ record.slices.forEach(({ features, start, end }) => {
9174
+ const index = getTimelineIndex(features, fields);
9175
+ for (let position = start; position < end; position++) {
9176
+ const id = idAt(features, position);
9177
+ if (id !== null && shouldHide(record, id, index, position, w, fields)) hide.add(id);
9178
+ }
9179
+ });
9180
+ return hide;
9181
+ }
9182
+ function setHiddenSet(host, record, hide, changed) {
9183
+ Array.from(record.hidden).forEach((id) => {
9184
+ if (!hide.has(id) && setHidden(host, record, id, false)) changed.push(id);
9185
+ });
9186
+ hide.forEach((id) => {
9187
+ if (setHidden(host, record, id, true)) changed.push(id);
9188
+ });
9189
+ }
9190
+ function seedTimelineSource(host, applied, sourceId, slices, w, fields) {
8724
9191
  const handle = host.source(sourceId);
8725
9192
  const old = applied.get(sourceId);
8726
9193
  if (!handle) {
@@ -8734,27 +9201,38 @@ function seedTimelineSource(host, applied, sourceId, slices, w) {
8734
9201
  slices,
8735
9202
  hidden: (old == null ? void 0 : old.handle) === handle ? old.hidden : /* @__PURE__ */ new Set(),
8736
9203
  copies: null,
8737
- window: w
9204
+ window: w,
9205
+ stale: false
8738
9206
  };
8739
9207
  applied.set(sourceId, record);
8740
- const hide = /* @__PURE__ */ new Set();
8741
- if (w !== null) {
8742
- slices.forEach(({ features, start, end }) => {
8743
- const index = getTimelineIndex(features);
8744
- for (let position = start; position < end; position++) {
8745
- const id = idAt(features, position);
8746
- if (id !== null && shouldHide(record, id, index, position, w)) hide.add(id);
8747
- }
8748
- });
8749
- }
8750
- let calls = 0;
8751
- Array.from(record.hidden).forEach((id) => {
8752
- if (!hide.has(id) && setHidden(host, record, id, false)) calls++;
8753
- });
8754
- hide.forEach((id) => {
8755
- if (setHidden(host, record, id, true)) calls++;
9208
+ const changed = [];
9209
+ setHiddenSet(host, record, hiddenAt(record, w, fields), changed);
9210
+ return changed.length;
9211
+ }
9212
+ function reindexCopies(record, fields) {
9213
+ if (!record.copies) return;
9214
+ const indexes = new Map(record.slices.map((s) => [s.features, getTimelineIndex(s.features, fields)]));
9215
+ record.copies.forEach((list) => list.forEach((copy) => {
9216
+ copy.index = indexes.get(copy.features) ?? copy.index;
9217
+ }));
9218
+ }
9219
+ function rederive(host, record, w, fields, changed) {
9220
+ reindexCopies(record, fields);
9221
+ setHiddenSet(host, record, hiddenAt(record, w, fields), changed);
9222
+ record.window = w;
9223
+ record.stale = false;
9224
+ }
9225
+ function reindexTimelineSources(host, applied, w, isActive = () => true, fields) {
9226
+ const changed = [];
9227
+ applied.forEach((record, sourceId) => {
9228
+ if (host.source(sourceId) !== record.handle) {
9229
+ applied.delete(sourceId);
9230
+ return;
9231
+ }
9232
+ if (isActive(sourceId)) rederive(host, record, w, fields, changed);
9233
+ else record.stale = true;
8756
9234
  });
8757
- return calls;
9235
+ return changed;
8758
9236
  }
8759
9237
  function isTimelineHiddenOn(applied, sourceId, id) {
8760
9238
  var _a;
@@ -8775,14 +9253,19 @@ function ownerOf(owners, position) {
8775
9253
  }
8776
9254
  return found && position < found.end ? found : null;
8777
9255
  }
8778
- function groupBySliceArray(host, applied, next, isActive) {
9256
+ function groupBySliceArray(host, applied, next, isActive, fields, changed) {
8779
9257
  const groups = [];
8780
9258
  applied.forEach((record, sourceId) => {
8781
9259
  if (host.source(sourceId) !== record.handle) {
8782
9260
  applied.delete(sourceId);
8783
9261
  return;
8784
9262
  }
8785
- if (!isActive(sourceId) || sameWindow(record.window, next)) return;
9263
+ if (!isActive(sourceId)) return;
9264
+ if (record.stale) {
9265
+ rederive(host, record, next, fields, changed);
9266
+ return;
9267
+ }
9268
+ if (sameWindow(record.window, next)) return;
8786
9269
  record.slices.forEach(({ features, start, end }) => {
8787
9270
  let group = groups.find((g) => g.features === features && sameWindow(g.from, record.window));
8788
9271
  if (!group) {
@@ -8795,19 +9278,19 @@ function groupBySliceArray(host, applied, next, isActive) {
8795
9278
  });
8796
9279
  return groups;
8797
9280
  }
8798
- function applyTimelineWindow(host, applied, next, isActive = () => true) {
9281
+ function applyTimelineWindow(host, applied, next, isActive = () => true, fields) {
8799
9282
  const flipped = [];
8800
9283
  const positions = [];
8801
- groupBySliceArray(host, applied, next, isActive).forEach(({ features, from, owners }) => {
9284
+ groupBySliceArray(host, applied, next, isActive, fields, flipped).forEach(({ features, from, owners }) => {
8802
9285
  owners.sort((a, b) => a.start - b.start);
8803
- const index = getTimelineIndex(features);
9286
+ const index = getTimelineIndex(features, fields);
8804
9287
  positions.length = 0;
8805
9288
  flippedPositions(index, from, next, positions);
8806
9289
  positions.forEach((position) => {
8807
9290
  const owner = ownerOf(owners, position);
8808
9291
  const id = owner ? idAt(features, position) : null;
8809
9292
  if (!owner || id === null) return;
8810
- if (setHidden(host, owner.record, id, shouldHide(owner.record, id, index, position, next))) flipped.push(id);
9293
+ if (setHidden(host, owner.record, id, shouldHide(owner.record, id, index, position, next, fields))) flipped.push(id);
8811
9294
  });
8812
9295
  });
8813
9296
  return flipped;
@@ -8830,16 +9313,16 @@ const MIN_COVERAGE = 0.9;
8830
9313
  const MAX_GROUPS = 500;
8831
9314
  const MIN_POINTS_PER_GROUP = 2;
8832
9315
  const MAX_SAMPLES = 1e4;
8833
- function isTracePoint(f) {
8834
- var _a, _b;
8835
- return !!f && f.id != null && ((_a = f.geometry) == null ? void 0 : _a.type) === "Point" && !!((_b = f.properties) == null ? void 0 : _b.startDate);
9316
+ function isTracePoint(f, timelineFields) {
9317
+ var _a;
9318
+ return !!f && f.id != null && ((_a = f.geometry) == null ? void 0 : _a.type) === "Point" && traceTime(f, timelineFields) !== null;
8836
9319
  }
8837
9320
  function identityRank(field) {
8838
9321
  const name = field.toLowerCase();
8839
9322
  if (NOT_IDENTITY.has(name) || CATEGORY_SUFFIX.test(name)) return -1;
8840
9323
  return IDENTITY_PATTERNS.findIndex((pattern) => pattern.test(name));
8841
9324
  }
8842
- function suggestTraceGroupField(features, fields) {
9325
+ function suggestTraceGroupField(features, fields, timelineFields) {
8843
9326
  var _a;
8844
9327
  const candidates = fields.map((field) => ({ field, rank: identityRank(field) })).filter((c) => c.rank >= 0).sort((a, b) => a.rank - b.rank || a.field.localeCompare(b.field));
8845
9328
  if (candidates.length === 0) return null;
@@ -8847,7 +9330,7 @@ function suggestTraceGroupField(features, fields) {
8847
9330
  const points = [];
8848
9331
  for (let i = 0; i < features.length && points.length < MAX_SAMPLES; i += step) {
8849
9332
  const f = features[i];
8850
- if (isTracePoint(f)) points.push(f);
9333
+ if (isTracePoint(f, timelineFields)) points.push(f);
8851
9334
  }
8852
9335
  if (points.length < 2) return null;
8853
9336
  const splitsIntoTracks = (field) => {
@@ -8981,17 +9464,17 @@ function prepareFeaturesForLayer(input, caller, cap) {
8981
9464
  sourceCount: (capped == null ? void 0 : capped.sourceCount) ?? count
8982
9465
  };
8983
9466
  }
8984
- function scanTemporalFeatures(features, resolveLayerId, out) {
9467
+ function scanTemporalFeatures(features, resolveLayerId, out, fields) {
8985
9468
  let foundTemporal = false;
8986
9469
  for (let i = 0; i < features.length; i++) {
8987
9470
  const feature = features[i];
8988
9471
  const id = feature.id;
8989
9472
  const props = feature.properties || {};
8990
- if (!hasAnyTemporalValue(props)) {
9473
+ if (!hasTimelineValue(props, fields)) {
8991
9474
  out.untimedIds.push(id);
8992
9475
  continue;
8993
9476
  }
8994
- const { startDate, endDate } = normalizeTemporalProperties(props);
9477
+ const { startDate, endDate } = readTimelineDates(props, fields);
8995
9478
  if (startDate || endDate) {
8996
9479
  out.temporal.push({ id, startDate, endDate, layerId: resolveLayerId(id) });
8997
9480
  foundTemporal = true;
@@ -9059,6 +9542,7 @@ function hitTestSelection(featureGroups, selectionPolygon, options) {
9059
9542
  const SELECTION_OVERLAY_SOURCE_ID = "selection-overlay";
9060
9543
  const SELECTION_OVERLAY_LAYER_IDS = {
9061
9544
  iconRing: "selection-overlay-icon-ring",
9545
+ hostIconRing: "selection-overlay-host-icon-ring",
9062
9546
  line: "selection-overlay-line",
9063
9547
  polygon: "selection-overlay-polygon",
9064
9548
  label: "selection-overlay-label"
@@ -9070,7 +9554,7 @@ function buildSelectionOverlayStack() {
9070
9554
  id: SELECTION_OVERLAY_LAYER_IDS.iconRing,
9071
9555
  type: "circle",
9072
9556
  source,
9073
- filter: ["all", ["==", "$type", "Point"], ["!=", "icon", ""], ["!=", "isHiddenByHeatmap", 1]],
9557
+ filter: ["all", ["==", "$type", "Point"], ["!=", "icon", ""], ["!=", "isHiddenByHeatmap", 1], ["!=", HOST_OWNED_PROP, 1]],
9074
9558
  paint: {
9075
9559
  "circle-color": "transparent",
9076
9560
  "circle-radius": ["/", ["coalesce", ["get", "iconSize"], 24], 1.6],
@@ -9079,6 +9563,20 @@ function buildSelectionOverlayStack() {
9079
9563
  "circle-stroke-opacity": 1
9080
9564
  }
9081
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
+ },
9082
9580
  {
9083
9581
  id: SELECTION_OVERLAY_LAYER_IDS.line,
9084
9582
  type: "line",
@@ -9105,6 +9603,8 @@ function buildSelectionOverlayStack() {
9105
9603
  id: SELECTION_OVERLAY_LAYER_IDS.label,
9106
9604
  type: "symbol",
9107
9605
  source,
9606
+ // A selected host feature keeps its label in the shared `host-labels` layer.
9607
+ filter: NOT_HOST_FILTER,
9108
9608
  layout: {
9109
9609
  ...buildCustomLabelLayout(),
9110
9610
  // Never hidden by the auto-label density cap, which only flips the
@@ -9189,6 +9689,10 @@ const INTERNAL_PROPERTY_KEYS = /* @__PURE__ */ new Set([
9189
9689
  "fontColor",
9190
9690
  "fontWeight",
9191
9691
  "arrowSize",
9692
+ "arrowInset",
9693
+ "iconFullZoom",
9694
+ "iconMinZoom",
9695
+ "iconMinScale",
9192
9696
  "label",
9193
9697
  "entityType",
9194
9698
  "kind",
@@ -9215,7 +9719,11 @@ const STYLING_PROPERTY_KEYS = [
9215
9719
  "fontSize",
9216
9720
  "fontColor",
9217
9721
  "fontWeight",
9218
- "arrowSize"
9722
+ "arrowSize",
9723
+ "arrowInset",
9724
+ "iconFullZoom",
9725
+ "iconMinZoom",
9726
+ "iconMinScale"
9219
9727
  ];
9220
9728
  const INTERNAL_PROPERTY_PREFIXES = [
9221
9729
  "IsHiddenBy",
@@ -9635,7 +10143,6 @@ function ClusterPieManager(props) {
9635
10143
  }
9636
10144
  const EMPTY_ID_SET = /* @__PURE__ */ new Set();
9637
10145
  const EMPTY_SOURCES = [];
9638
- 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"];
9639
10146
  const EMPTY_LABEL_MAP = /* @__PURE__ */ new Map();
9640
10147
  const TICK_COUNT_SETTLE_MS = 300;
9641
10148
  const SPATIAL_COUNT_MIN_FEATURES = 5e3;
@@ -9657,7 +10164,7 @@ function emojiCanvasToImageData(canvas) {
9657
10164
  const id = ctx.getImageData(0, 0, canvas.width, canvas.height);
9658
10165
  return { width: canvas.width, height: canvas.height, data: new Uint8Array(id.data.buffer) };
9659
10166
  }
9660
- function loadEmojiIconsIntoMap(mapInstance) {
10167
+ function loadEmojiIconsIntoMap(mapInstance, hostImages) {
9661
10168
  const ratio = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
9662
10169
  for (const { emoji } of ICONS) {
9663
10170
  if (!emoji || mapInstance.hasImage(emoji)) continue;
@@ -9668,10 +10175,19 @@ function loadEmojiIconsIntoMap(mapInstance) {
9668
10175
  }
9669
10176
  }
9670
10177
  mapInstance.setMissingStyleImageResolver((id) => {
9671
- if (mapInstance.hasImage(id) || !isEmojiIcon(id)) return;
10178
+ if (mapInstance.hasImage(id)) return;
9672
10179
  try {
9673
- const canvas = renderEmojiToCanvas(id);
9674
- 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
+ }
9675
10191
  } catch {
9676
10192
  }
9677
10193
  });
@@ -9781,7 +10297,7 @@ function createFlightPath3DLayer(layerId, mapInstance, flightPaths) {
9781
10297
  }
9782
10298
  };
9783
10299
  }
9784
- function extract3DFlightPaths(features) {
10300
+ function extract3DFlightPaths(features, fields) {
9785
10301
  const paths = [];
9786
10302
  features.forEach((feature) => {
9787
10303
  var _a, _b;
@@ -9809,13 +10325,12 @@ function extract3DFlightPaths(features) {
9809
10325
  });
9810
10326
  const pointsByTarget = /* @__PURE__ */ new Map();
9811
10327
  features.forEach((feature) => {
9812
- var _a, _b;
10328
+ var _a;
9813
10329
  if (feature.geometry.type === "Point") {
9814
10330
  const coords = feature.geometry.coordinates;
9815
10331
  if (coords.length >= 3 && coords[2] !== 0) {
9816
10332
  const targetId = ((_a = feature.properties) == null ? void 0 : _a.TargetID) || "default-points";
9817
- const startDateStr = (_b = feature.properties) == null ? void 0 : _b.startDate;
9818
- const timestamp = startDateStr ? new Date(startDateStr).getTime() : 0;
10333
+ const timestamp = traceTime(feature, fields) ?? 0;
9819
10334
  if (!pointsByTarget.has(targetId)) {
9820
10335
  pointsByTarget.set(targetId, []);
9821
10336
  }
@@ -9886,6 +10401,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9886
10401
  onFeatureCreate,
9887
10402
  onFeatureUpdate,
9888
10403
  onFeatureDelete,
10404
+ onDeleteRequest,
10405
+ iconImageProvider,
9889
10406
  onLayerChange,
9890
10407
  onActiveEditingLayerChange,
9891
10408
  onTimelineChange,
@@ -9927,6 +10444,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9927
10444
  featureCountProvider,
9928
10445
  fitBoundsProvider,
9929
10446
  timebarExtra,
10447
+ timelineFields,
10448
+ keepTimebarExtra = false,
9930
10449
  onOpenInNewTab,
9931
10450
  onEntityContextMenu
9932
10451
  }, ref) {
@@ -9983,6 +10502,14 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9983
10502
  const moveLabelsBeforeBasemapSymbolsRef = useRef(null);
9984
10503
  const tooltipProviderRef = useRef(tooltipProvider);
9985
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;
10511
+ const onFeatureUpdateRef = useRef(onFeatureUpdate);
10512
+ onFeatureUpdateRef.current = onFeatureUpdate;
9986
10513
  const restoreEnrichedGeoJSONRef = useRef(null);
9987
10514
  const [isMapLoaded, setIsMapLoaded] = useState(false);
9988
10515
  const isMapLoadedRef = useRef(false);
@@ -10021,6 +10548,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10021
10548
  const pendingFeatureKindRef = useRef(null);
10022
10549
  const arrowFeatureIdsRef = useRef(/* @__PURE__ */ new Set());
10023
10550
  const hasArrowFeaturesRef = useRef(false);
10551
+ const hadHostDecorationsRef = useRef(false);
10024
10552
  const [circleDrawCenter, setCircleDrawCenter] = useState(null);
10025
10553
  const [circleDrawPreview, setCircleDrawPreview] = useState(null);
10026
10554
  const isDrawingCircle = useRef(false);
@@ -10041,6 +10569,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10041
10569
  const ingestProgressStoreRef = useRef(null);
10042
10570
  const bindHoverHandlersRef = useRef(null);
10043
10571
  const unbindHoverHandlersRef = useRef(null);
10572
+ const hostIconBoundRef = useRef(false);
10044
10573
  const [labelsSuppressed, setLabelsSuppressed] = useState(true);
10045
10574
  const labelsSuppressedRef = useRef(labelsSuppressed);
10046
10575
  labelsSuppressedRef.current = labelsSuppressed;
@@ -10048,6 +10577,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10048
10577
  const [timelineStoreApi] = useState(createTimelineStore);
10049
10578
  const timelineEnabled = useStore(timelineStoreApi, (s) => s.isEnabled);
10050
10579
  const timelineHasData = useStore(timelineStoreApi, (s) => s.hasTemporalData);
10580
+ const timebarHeight = timelineHasData ? TIMEBAR_HEIGHT : EMPTY_TIMEBAR_HEIGHT;
10051
10581
  const { toast: internalToast } = useToast();
10052
10582
  const toast = toastProvider ?? internalToast;
10053
10583
  const featureCap = useMemo(() => resolveFeatureCap(maxFeaturesPerLayer), [maxFeaturesPerLayer]);
@@ -10270,7 +10800,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10270
10800
  const applySelectionState$1 = useCallback((nextIds, options) => {
10271
10801
  if (!isMapLoaded || !draw.current) {
10272
10802
  setSelectedFeatureIds(nextIds);
10273
- if (options == null ? void 0 : options.focusProperties) setShowProperties(nextIds.length > 0);
10803
+ if (options == null ? void 0 : options.focusProperties) setShowProperties(showsPropertiesFor(nextIds, layersRef.current));
10274
10804
  if (onFeatureSelect) {
10275
10805
  onFeatureSelect(nextIds.length > 0 ? nextIds.map((id) => getFeatureById(id)).filter(Boolean) : []);
10276
10806
  }
@@ -10307,7 +10837,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10307
10837
  }
10308
10838
  setSelectedFeatureIds(nextIds);
10309
10839
  selectedFeatureIdsRef.current = nextIds;
10310
- if (options == null ? void 0 : options.focusProperties) setShowProperties(nextIds.length > 0);
10840
+ if (options == null ? void 0 : options.focusProperties) setShowProperties(showsPropertiesFor(nextIds, layersRef.current));
10311
10841
  if (onFeatureSelect) {
10312
10842
  onFeatureSelect(nextIds.map((id) => getFeatureById(id)).filter(Boolean));
10313
10843
  }
@@ -10343,6 +10873,10 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10343
10873
  }, []);
10344
10874
  const timelineWindowRef = useRef(null);
10345
10875
  const appliedTimelineRef = useRef(/* @__PURE__ */ new Map());
10876
+ const timelineFieldsRef = useRef(timelineFields);
10877
+ const fieldsChangingRef = useRef(false);
10878
+ const timelineFieldsId = timelineFieldsKey(timelineFields);
10879
+ const pickedTimelineFields = useMemo(() => timelineFields, [timelineFieldsId]);
10346
10880
  const isTimelineSourceActive = useCallback((sourceId) => {
10347
10881
  var _a;
10348
10882
  const shard = parseShardSourceId(sourceId);
@@ -10387,7 +10921,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10387
10921
  if (sameWindow(next, timelineWindowRef.current)) return;
10388
10922
  timelineWindowRef.current = next;
10389
10923
  scheduleSync("timeline");
10390
- (_a = update3DFlightPathsRef.current) == null ? void 0 : _a.call(update3DFlightPathsRef);
10924
+ if (!fieldsChangingRef.current) (_a = update3DFlightPathsRef.current) == null ? void 0 : _a.call(update3DFlightPathsRef);
10391
10925
  };
10392
10926
  follow(timelineStoreApi.getState());
10393
10927
  return timelineStoreApi.subscribe(follow);
@@ -10414,7 +10948,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10414
10948
  layers.forEach((layer) => {
10415
10949
  var _a;
10416
10950
  if (!((_a = layer.traceConfig) == null ? void 0 : _a.enabled) || !layer.visible) return;
10417
- for (const group of getTraceGroups(traceSourceFeatures(layer, featById), layer.traceConfig.groupByField)) {
10951
+ for (const group of getTraceGroups(traceSourceFeatures(layer, featById), layer.traceConfig.groupByField, pickedTimelineFields)) {
10418
10952
  for (const id of group.ids) tracePointColors.set(id, group.color);
10419
10953
  }
10420
10954
  });
@@ -10450,7 +10984,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10450
10984
  colorMap.set(fid, color);
10451
10985
  });
10452
10986
  return colorMap;
10453
- }, [selectedFeatureIds, layers, getAllFeatures, traceSourceFeatures]);
10987
+ }, [selectedFeatureIds, layers, getAllFeatures, traceSourceFeatures, pickedTimelineFields]);
10454
10988
  const countVisibleFeatures = useCallback((threshold) => {
10455
10989
  const m = map.current;
10456
10990
  if (!m) return 0;
@@ -10458,7 +10992,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10458
10992
  const w = timelineWindowRef.current;
10459
10993
  const groupOf = (features) => {
10460
10994
  if (w === null) return { features };
10461
- const index = getTimelineIndex(features);
10995
+ const index = getTimelineIndex(features, timelineFieldsRef.current);
10462
10996
  const group = { features, isVisible: (p) => isVisibleAt(index, p, w) };
10463
10997
  const spatial = features.length >= SPATIAL_COUNT_MIN_FEATURES ? getGroupSpatialIndex(features) : void 0;
10464
10998
  if (spatial) group.indexed = { spatial, visibleTotal: countVisible(index, w) };
@@ -10467,11 +11001,12 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10467
11001
  const groups = [];
10468
11002
  if (draw.current) {
10469
11003
  const features = draw.current.getAll().features;
10470
- groups.push(w === null ? { features } : { features, isVisible: (p) => isFeatureVisible(features[p], w) });
11004
+ groups.push(w === null ? { features } : { features, isVisible: (p) => isFeatureVisible(features[p], w, timelineFieldsRef.current) });
10471
11005
  }
10472
11006
  readOnlyFeatures.current.forEach((features, layerId) => {
10473
11007
  const layer = layersRef.current.find((l) => l.id === layerId);
10474
- 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));
10475
11010
  });
10476
11011
  return countFeaturesInBounds(
10477
11012
  groups,
@@ -10483,7 +11018,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10483
11018
  const tracePaintCacheRef = useRef(null);
10484
11019
  const traceEndpointsRef = useRef(/* @__PURE__ */ new Set());
10485
11020
  const paintedArrowLinesRef = useRef([]);
10486
- const renderArrowOverlays = useCallback((arrowLines) => {
11021
+ const renderArrowOverlays = useCallback((arrowLines, options) => {
10487
11022
  const mapInstance = map.current;
10488
11023
  if (!mapInstance) return;
10489
11024
  const arrowHeadSource = mapInstance.getSource("arrow-heads");
@@ -10538,7 +11073,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10538
11073
  arrowHeadSource.setData({ type: "FeatureCollection", features: arrowHeadTriangles });
10539
11074
  }
10540
11075
  const arrowLabelSource = mapInstance.getSource("arrow-labels");
10541
- if (arrowLabelSource) {
11076
+ if (arrowLabelSource && !(options == null ? void 0 : options.headsOnly)) {
10542
11077
  const arrowLabelPoints = [];
10543
11078
  arrowLines.forEach((f) => {
10544
11079
  var _a;
@@ -10588,6 +11123,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10588
11123
  if (!source) return;
10589
11124
  const drawFeatures = (draw.current ? draw.current.getAll().features : []).filter((f) => isPaintableGeometry(f.geometry));
10590
11125
  const timelineWindow = timelineWindowRef.current;
11126
+ const timelineFieldsNow = timelineFieldsRef.current;
10591
11127
  const currentLayers = layersRef.current;
10592
11128
  const isLayerVisible = (layer) => {
10593
11129
  return layer.visible;
@@ -10610,7 +11146,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10610
11146
  const layer = currentLayers.find((l) => l.id === layerId);
10611
11147
  if (layer && isLayerVisible(layer)) {
10612
11148
  pushAll(allFeatures, features);
10613
- addSlice(features);
11149
+ if (!isHostOwnedLayer(layer)) addSlice(features);
10614
11150
  }
10615
11151
  });
10616
11152
  const featureById = /* @__PURE__ */ new Map();
@@ -10666,8 +11202,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10666
11202
  var _a2;
10667
11203
  if (!((_a2 = layer.traceConfig) == null ? void 0 : _a2.enabled) || !layer.visible) return;
10668
11204
  const traceFeatures = traceSourceFeatures(layer, featureById);
10669
- const traceIndex = getTimelineIndex(traceFeatures);
10670
- const groups = getTraceGroups(traceFeatures, layer.traceConfig.groupByField);
11205
+ const traceIndex = getTimelineIndex(traceFeatures, timelineFieldsNow);
11206
+ const groups = getTraceGroups(traceFeatures, layer.traceConfig.groupByField, timelineFieldsNow);
10671
11207
  const pointsHidden = layerHidesPoints(layer);
10672
11208
  for (const group of groups) {
10673
11209
  paintedTraceGroups.push(pointsHidden && group.label !== null ? { ...group, label: null } : group);
@@ -10694,8 +11230,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10694
11230
  source.setData(sourceData);
10695
11231
  overlayPaintContextRef.current = paintContext;
10696
11232
  const stateHost = featureStateHostFor(map.current);
10697
- seedTimelineSource(stateHost, appliedTimelineRef.current, SHARED_SOURCE_ID, sharedSlices, timelineWindow);
10698
- applyTimelineWindow(stateHost, appliedTimelineRef.current, timelineWindow, isTimelineSourceActive);
11233
+ seedTimelineSource(stateHost, appliedTimelineRef.current, SHARED_SOURCE_ID, sharedSlices, timelineWindow, timelineFieldsNow);
11234
+ applyTimelineWindow(stateHost, appliedTimelineRef.current, timelineWindow, isTimelineSourceActive, timelineFieldsNow);
10699
11235
  (_a = reconcileSelectionRef.current) == null ? void 0 : _a.call(reconcileSelectionRef);
10700
11236
  const traceSource = map.current.getSource(TRACE_SOURCE_ID);
10701
11237
  const tracePaint = paintTraceAt(paintedTraceGroups, traceIndexes, timelineWindow);
@@ -10712,12 +11248,17 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10712
11248
  let sawArrowFeature = false;
10713
11249
  const arrowLines = [];
10714
11250
  const pushArrow = (styled, record) => {
10715
- const { s, e } = record ? featureInterval(record) : { s: NaN, e: NaN };
11251
+ const { s, e } = record ? featureInterval(record, timelineFieldsNow) : { s: NaN, e: NaN };
10716
11252
  arrowLines.push(isIntervalVisible(s, e, timelineWindow) ? styled : { ...styled, properties: { ...styled.properties, "stroke-opacity": 0, "fill-opacity": 0 } });
10717
11253
  };
11254
+ const hostLines = [];
10718
11255
  sourceData.features.forEach((f, i) => {
10719
- var _a2;
10720
- 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));
10721
11262
  if (!isArrow) return;
10722
11263
  sawArrowFeature = true;
10723
11264
  if (f.geometry.type === "LineString") pushArrow(f, allFeatures[i]);
@@ -10733,6 +11274,11 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10733
11274
  hasArrowFeaturesRef.current = sawArrowFeature;
10734
11275
  paintedArrowLinesRef.current = arrowLines;
10735
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
+ }
10736
11282
  }
10737
11283
  if (update3DFlightPathsRef == null ? void 0 : update3DFlightPathsRef.current) {
10738
11284
  update3DFlightPathsRef.current();
@@ -10775,7 +11321,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10775
11321
  const timelineWindow = timelineWindowRef.current;
10776
11322
  const visibleIn = (features) => {
10777
11323
  if (timelineWindow === null) return [...features];
10778
- const index = getTimelineIndex(features);
11324
+ const index = getTimelineIndex(features, timelineFieldsRef.current);
10779
11325
  return features.filter((_, p) => isVisibleAt(index, p, timelineWindow));
10780
11326
  };
10781
11327
  const allFeatures = [];
@@ -10786,7 +11332,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10786
11332
  if (((_a = l.traceConfig) == null ? void 0 : _a.enabled) !== true) continue;
10787
11333
  for (const featureId of l.featureIds) traceFeatureIds.add(featureId);
10788
11334
  }
10789
- const drawFeatures = draw.current.getAll().features.filter((feature) => traceFeatureIds.has(feature.id) && isFeatureVisible(feature, timelineWindow));
11335
+ const drawFeatures = draw.current.getAll().features.filter((feature) => traceFeatureIds.has(feature.id) && isFeatureVisible(feature, timelineWindow, timelineFieldsRef.current));
10790
11336
  pushAll(allFeatures, drawFeatures);
10791
11337
  }
10792
11338
  readOnlyFeatures.current.forEach((features, layerId2) => {
@@ -10798,7 +11344,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10798
11344
  pushAll(allFeatures, visibleIn(features));
10799
11345
  }
10800
11346
  });
10801
- const flightPaths = extract3DFlightPaths(allFeatures);
11347
+ const flightPaths = extract3DFlightPaths(allFeatures, timelineFieldsRef.current);
10802
11348
  if (flightPaths.length === 0) {
10803
11349
  if (flightPath3DLayerId.current) {
10804
11350
  try {
@@ -10901,7 +11447,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10901
11447
  appliedTimelineRef.current,
10902
11448
  shardSourceId(layer.id, index),
10903
11449
  [{ features, start, end }],
10904
- timelineWindowRef.current
11450
+ timelineWindowRef.current,
11451
+ timelineFieldsRef.current
10905
11452
  );
10906
11453
  (_a2 = reconcileSelectionRef.current) == null ? void 0 : _a2.call(reconcileSelectionRef, { overlay: !overlayRestyled });
10907
11454
  overlayRestyled = true;
@@ -10946,6 +11493,11 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10946
11493
  return () => clearTimeout(timer);
10947
11494
  }
10948
11495
  }, [layers, is3DTerrainEnabled]);
11496
+ const layerDatesUnder = useCallback((layerId, features, fields) => {
11497
+ const cached = layerTemporalCacheRef.current.get(layerId);
11498
+ if (!cached) return anyTimelineDate(features, fields);
11499
+ return (cached.fieldsKey ?? "") === timelineFieldsKey(fields) ? cached.hasTemporal : anyTimelineDate(features, fields);
11500
+ }, []);
10949
11501
  const updateTimelineStore = useCallback(() => {
10950
11502
  const drawFeatures = draw.current ? draw.current.getAll().features : [];
10951
11503
  const currentLayers = layersRef.current;
@@ -10956,24 +11508,55 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10956
11508
  }
10957
11509
  }
10958
11510
  const scan = { temporal: [], untimedIds: [] };
11511
+ const fields = timelineFieldsRef.current;
11512
+ const fieldsKey = timelineFieldsKey(fields);
10959
11513
  scanTemporalFeatures(
10960
11514
  drawFeatures,
10961
11515
  (id) => featureToLayer.get(id) || "default",
10962
- scan
11516
+ scan,
11517
+ fields
10963
11518
  );
10964
11519
  readOnlyFeatures.current.forEach((features, layerId) => {
10965
11520
  const layer = currentLayers.find((l) => l.id === layerId);
10966
- if (!(layer == null ? void 0 : layer.visible)) return;
11521
+ if (!(layer == null ? void 0 : layer.visible) || isHostOwnedLayer(layer)) return;
10967
11522
  const cached = layerTemporalCacheRef.current.get(layerId);
10968
- if (cached && cached.featureCount === features.length && !cached.hasTemporal) {
11523
+ if (cached && (cached.fieldsKey ?? "") === fieldsKey && cached.featureCount === features.length && !cached.hasTemporal) {
10969
11524
  for (const f of features) scan.untimedIds.push(f.id);
10970
11525
  return;
10971
11526
  }
10972
- const layerHasTemporal = scanTemporalFeatures(features, () => layerId, scan);
10973
- layerTemporalCacheRef.current.set(layerId, { featureCount: features.length, hasTemporal: layerHasTemporal });
11527
+ const layerHasTemporal = scanTemporalFeatures(features, () => layerId, scan, fields);
11528
+ layerTemporalCacheRef.current.set(layerId, { featureCount: features.length, hasTemporal: layerHasTemporal, fieldsKey });
10974
11529
  });
10975
11530
  timelineStoreApi.getState().setTemporalFeatures(scan.temporal, scan.untimedIds);
11531
+ mapPerfLog("timeline", "store scanned", { timed: scan.temporal.length, untimed: scan.untimedIds.length });
10976
11532
  }, [timelineStoreApi]);
11533
+ useEffect(() => {
11534
+ if (timelineFieldsKey(timelineFieldsRef.current) === timelineFieldsKey(timelineFields)) return;
11535
+ timelineFieldsRef.current = timelineFields;
11536
+ if (timelineUpdateTimerRef.current) {
11537
+ clearTimeout(timelineUpdateTimerRef.current);
11538
+ timelineUpdateTimerRef.current = null;
11539
+ }
11540
+ fieldsChangingRef.current = true;
11541
+ try {
11542
+ updateTimelineStore();
11543
+ const store = timelineStoreApi.getState();
11544
+ store.setPlaying(false);
11545
+ store.setRange(store.globalMinDate, store.globalMaxDate);
11546
+ } finally {
11547
+ fieldsChangingRef.current = false;
11548
+ }
11549
+ if (map.current) {
11550
+ reindexTimelineSources(
11551
+ featureStateHostFor(map.current),
11552
+ appliedTimelineRef.current,
11553
+ timelineWindowRef.current,
11554
+ isTimelineSourceActive,
11555
+ timelineFields
11556
+ );
11557
+ }
11558
+ scheduleSync();
11559
+ }, [timelineFields, updateTimelineStore, timelineStoreApi, scheduleSync, isTimelineSourceActive]);
10977
11560
  const scheduleTimelineUpdate = useCallback(() => {
10978
11561
  if (timelineUpdateTimerRef.current) clearTimeout(timelineUpdateTimerRef.current);
10979
11562
  timelineUpdateTimerRef.current = setTimeout(() => {
@@ -10983,10 +11566,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10983
11566
  }, [updateTimelineStore]);
10984
11567
  const collectHistoryFeatures = useCallback(
10985
11568
  (overrides) => {
10986
- var _a;
10987
11569
  const featureToLayer = /* @__PURE__ */ new Map();
10988
11570
  for (const l of layersRef.current) {
10989
- if (((_a = l.metadata) == null ? void 0 : _a.dataViewing) === true) continue;
11571
+ if (isHistoryExcludedLayer(l)) continue;
10990
11572
  for (const fid of l.featureIds) featureToLayer.set(fid, l.id);
10991
11573
  }
10992
11574
  const result = /* @__PURE__ */ new Map();
@@ -11002,9 +11584,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11002
11584
  }
11003
11585
  }
11004
11586
  readOnlyFeatures.current.forEach((features, layerId) => {
11005
- var _a2;
11006
11587
  const layer = layersRef.current.find((l) => l.id === layerId);
11007
- if (((_a2 = layer == null ? void 0 : layer.metadata) == null ? void 0 : _a2.dataViewing) === true) return;
11588
+ if (isHistoryExcludedLayer(layer)) return;
11008
11589
  for (const f of features) {
11009
11590
  if (f.id == null) continue;
11010
11591
  result.set(String(f.id), { feature: f, layerId, store: "readOnly" });
@@ -11033,10 +11614,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11033
11614
  []
11034
11615
  );
11035
11616
  const collectHistoryLayers = useCallback(() => {
11036
- var _a;
11037
11617
  const result = /* @__PURE__ */ new Map();
11038
11618
  for (const l of layersRef.current) {
11039
- if (((_a = l.metadata) == null ? void 0 : _a.dataViewing) === true) continue;
11619
+ if (isHistoryExcludedLayer(l)) continue;
11040
11620
  const { importing: _importing, ...record } = l;
11041
11621
  result.set(l.id, { ...record, featureIds: [...l.featureIds] });
11042
11622
  }
@@ -11123,10 +11703,30 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11123
11703
  if (!isMapLoaded) return;
11124
11704
  cleanupOrphanLayerSources(new Set(layers.map((l) => l.id)));
11125
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]);
11126
11715
  const applyHistoryState = useCallback(
11127
11716
  (featureIds, layerIds, targetFeatures, targetLayers) => {
11717
+ const wasApiAdding = isApiAddingRef.current;
11128
11718
  isApiAddingRef.current = true;
11129
11719
  isSelectingReadOnlyRef.current = true;
11720
+ const notify = onFeatureUpdateRef.current;
11721
+ const drawnBefore = /* @__PURE__ */ new Map();
11722
+ if (notify) {
11723
+ featureIds.forEach((id) => {
11724
+ var _a, _b;
11725
+ if (((_a = targetFeatures.get(id)) == null ? void 0 : _a.store) !== "draw") return;
11726
+ const feature = (_b = draw.current) == null ? void 0 : _b.get(id);
11727
+ if (feature) drawnBefore.set(id, feature);
11728
+ });
11729
+ }
11130
11730
  try {
11131
11731
  featureIds.forEach((id) => {
11132
11732
  var _a;
@@ -11185,8 +11785,15 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11185
11785
  });
11186
11786
  layersRef.current = next;
11187
11787
  setLayers(next);
11788
+ drawnBefore.forEach((before, id) => {
11789
+ var _a;
11790
+ const target = targetFeatures.get(id);
11791
+ if (!target || historyFeatureContentEqual(before, target.feature)) return;
11792
+ const restored = (_a = draw.current) == null ? void 0 : _a.get(id);
11793
+ if (restored) notify == null ? void 0 : notify(restored);
11794
+ });
11188
11795
  } finally {
11189
- isApiAddingRef.current = false;
11796
+ isApiAddingRef.current = wasApiAdding;
11190
11797
  }
11191
11798
  cleanupOrphanLayerSources(new Set(layersRef.current.map((l) => l.id)));
11192
11799
  layerTemporalCacheRef.current.clear();
@@ -11247,8 +11854,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11247
11854
  pending.beforeSelectedIds,
11248
11855
  [...selectedFeatureIdsRef.current]
11249
11856
  );
11250
- if (command) {
11251
- history.push(command);
11857
+ const step = withHostDeleteUndos(command, pending.label, pending.hostUndos ?? []);
11858
+ if (step) {
11859
+ history.push(step);
11252
11860
  }
11253
11861
  }, [collectHistoryFeatures, collectHistoryLayers, buildDiffCommand, history]);
11254
11862
  const saveStateForUndo = useCallback(
@@ -11383,7 +11991,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11383
11991
  var _a2;
11384
11992
  return (_a2 = unbindHoverHandlersRef.current) == null ? void 0 : _a2.call(unbindHoverHandlersRef, id);
11385
11993
  }),
11386
- labelsVisible: () => lastLabelVisibility.current
11994
+ labelsVisible: () => lastLabelVisibility.current,
11995
+ hostIconInteractive: () => hostIconBoundRef.current
11387
11996
  });
11388
11997
  shardRegistryRef.current.registerShared(sharedStack.map((spec) => spec.id));
11389
11998
  mapInstance.addSource("arrow-heads", {
@@ -11430,6 +12039,14 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11430
12039
  "text-opacity": ["coalesce", ["get", "stroke-opacity"], 1]
11431
12040
  }
11432
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);
11433
12050
  mapInstance.addSource(TRACE_SOURCE_ID, {
11434
12051
  type: "geojson",
11435
12052
  data: { type: "FeatureCollection", features: [] },
@@ -11573,7 +12190,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11573
12190
  const highlightFields = /* @__PURE__ */ new Set();
11574
12191
  if (((_a2 = visualConfig == null ? void 0 : visualConfig.size) == null ? void 0 : _a2.mode) === "field" && visualConfig.size.fieldName) highlightFields.add(visualConfig.size.fieldName);
11575
12192
  if (((_b2 = visualConfig == null ? void 0 : visualConfig.color) == null ? void 0 : _b2.mode) === "field" && visualConfig.color.fieldName) highlightFields.add(visualConfig.color.fieldName);
11576
- 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);
11577
12194
  const name = props.name;
11578
12195
  let html = '<div class="text-sm space-y-0.5">';
11579
12196
  if (name) html += `<div class="font-medium">${escapeHtml(name)}</div>`;
@@ -11836,7 +12453,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11836
12453
  tracePopupRef.current.remove();
11837
12454
  }
11838
12455
  });
11839
- loadEmojiIconsIntoMap(mapInstance);
12456
+ loadEmojiIconsIntoMap(mapInstance, () => iconImageProviderRef.current);
11840
12457
  setIsMapLoaded(true);
11841
12458
  isMapLoadedRef.current = true;
11842
12459
  updateFeatureCount();
@@ -12179,6 +12796,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12179
12796
  onFeatureDelete == null ? void 0 : onFeatureDelete(deletedIds);
12180
12797
  });
12181
12798
  onDrawEvent(mapInstance, "draw.selectionchange", (e) => {
12799
+ var _a;
12182
12800
  if (isSelectingReadOnlyRef.current) {
12183
12801
  return;
12184
12802
  }
@@ -12209,13 +12827,13 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12209
12827
  setShowProperties(ids.length > 0);
12210
12828
  }
12211
12829
  scheduleSync("selection");
12212
- onFeatureSelect == null ? void 0 : onFeatureSelect(e.features);
12830
+ (_a = onFeatureSelectRef.current) == null ? void 0 : _a.call(onFeatureSelectRef, e.features);
12213
12831
  });
12214
12832
  onDrawEvent(mapInstance, "draw.modechange", () => {
12215
12833
  scheduleSync();
12216
12834
  });
12217
12835
  mapInstance.on("click", (e) => {
12218
- var _a, _b;
12836
+ var _a, _b, _c;
12219
12837
  if (!enableSelectionRef.current) return;
12220
12838
  if (e.originalEvent.button !== 0) return;
12221
12839
  if (contextMenuFiredRef.current) return;
@@ -12276,7 +12894,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12276
12894
  }
12277
12895
  setSelectedFeatureIds(nextIds);
12278
12896
  selectedFeatureIdsRef.current = nextIds;
12279
- if (enableProperties) setShowProperties(nextIds.length > 0);
12897
+ if (enableProperties) setShowProperties(showsPropertiesFor(nextIds, layersRef.current));
12280
12898
  scheduleSync("selection");
12281
12899
  const selectedFeatures2 = [];
12282
12900
  for (const id of nextIds) {
@@ -12285,7 +12903,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12285
12903
  if (found) selectedFeatures2.push(found);
12286
12904
  });
12287
12905
  }
12288
- onFeatureSelect == null ? void 0 : onFeatureSelect(selectedFeatures2);
12906
+ (_c = onFeatureSelectRef.current) == null ? void 0 : _c.call(onFeatureSelectRef, selectedFeatures2);
12289
12907
  requestAnimationFrame(() => {
12290
12908
  isSelectingReadOnlyRef.current = false;
12291
12909
  });
@@ -12395,6 +13013,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12395
13013
  if (wantedVisible) {
12396
13014
  const hidden = hiddenFeatures.current.get(layerId) || [];
12397
13015
  const newIds = [];
13016
+ const wasApiAdding = isApiAddingRef.current;
12398
13017
  isApiAddingRef.current = true;
12399
13018
  try {
12400
13019
  hidden.forEach((f) => {
@@ -12402,7 +13021,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12402
13021
  newIds.push(ids[0]);
12403
13022
  });
12404
13023
  } finally {
12405
- isApiAddingRef.current = false;
13024
+ isApiAddingRef.current = wasApiAdding;
12406
13025
  }
12407
13026
  hiddenFeatures.current.delete(layerId);
12408
13027
  next.visible = true;
@@ -12520,6 +13139,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12520
13139
  parseGeoJSONText: (label, text) => ingestWithProgress(label, text, { idStrategy: "preserve" }),
12521
13140
  addLayer: (name, geojson, options) => {
12522
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;
12523
13144
  if (options == null ? void 0 : options.recordHistory) saveStateForUndo(`add layer "${name}"`);
12524
13145
  const layerId = `layer-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
12525
13146
  const newLayer = {
@@ -12532,7 +13153,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12532
13153
  // visibility toggle).
12533
13154
  visible: (options == null ? void 0 : options.visible) ?? true,
12534
13155
  featureIds: [],
12535
- readOnly: options == null ? void 0 : options.readOnly,
13156
+ readOnly,
13157
+ ...hostOwned ? { hostOwned: true } : {},
12536
13158
  group: options == null ? void 0 : options.group,
12537
13159
  metadata: options == null ? void 0 : options.metadata,
12538
13160
  // Per-layer visual configs are passed through verbatim so that hosts
@@ -12549,7 +13171,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12549
13171
  let capDropped = 0;
12550
13172
  if (geojson) {
12551
13173
  const max = featureCapRef.current;
12552
- if (options == null ? void 0 : options.readOnly) {
13174
+ if (readOnly) {
12553
13175
  const prepared = prepareFeaturesForLayer(geojson.features, "addLayer", { max });
12554
13176
  readOnlyFeatures.current.set(layerId, prepared.features);
12555
13177
  layerTemporalCacheRef.current.set(layerId, { featureCount: prepared.features.length, hasTemporal: prepared.hasTemporal });
@@ -12561,6 +13183,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12561
13183
  }
12562
13184
  } else if (draw.current) {
12563
13185
  const capped = capFeatures(geojson.features, { max });
13186
+ const wasApiAdding = isApiAddingRef.current;
12564
13187
  isApiAddingRef.current = true;
12565
13188
  try {
12566
13189
  const addedIds = capped.features.map((f) => {
@@ -12569,7 +13192,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12569
13192
  });
12570
13193
  newLayer.featureIds = addedIds;
12571
13194
  } finally {
12572
- isApiAddingRef.current = false;
13195
+ isApiAddingRef.current = wasApiAdding;
12573
13196
  }
12574
13197
  addedFeatures = capped.features;
12575
13198
  capDropped = capped.dropped;
@@ -12586,7 +13209,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12586
13209
  source: "api"
12587
13210
  });
12588
13211
  }
12589
- 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) {
12590
13213
  const features = newLayer.featureIds.map((id) => draw.current.get(id)).filter(Boolean);
12591
13214
  hiddenFeatures.current.set(layerId, features);
12592
13215
  newLayer.featureIds.forEach((id) => {
@@ -12665,6 +13288,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12665
13288
  if (visible) {
12666
13289
  const hidden = hiddenFeatures.current.get(layerId) || [];
12667
13290
  const newIds = [];
13291
+ const wasApiAdding = isApiAddingRef.current;
12668
13292
  isApiAddingRef.current = true;
12669
13293
  try {
12670
13294
  hidden.forEach((f) => {
@@ -12672,7 +13296,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12672
13296
  newIds.push(ids[0]);
12673
13297
  });
12674
13298
  } finally {
12675
- isApiAddingRef.current = false;
13299
+ isApiAddingRef.current = wasApiAdding;
12676
13300
  }
12677
13301
  hiddenFeatures.current.delete(layerId);
12678
13302
  nextLayers = layersRef.current.map(
@@ -12698,7 +13322,6 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12698
13322
  scheduleSync();
12699
13323
  },
12700
13324
  addFeatures: (layerId, features, options) => {
12701
- var _a;
12702
13325
  const layer = layersRef.current.find((l) => l.id === layerId);
12703
13326
  if (!layer || !isMapLoadedRef.current) return [];
12704
13327
  if (options == null ? void 0 : options.recordHistory) saveStateForUndo("add features");
@@ -12720,10 +13343,16 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12720
13343
  existing: existing.length
12721
13344
  });
12722
13345
  }
12723
- const layerHasTemporal = (((_a = layerTemporalCacheRef.current.get(layerId)) == null ? void 0 : _a.hasTemporal) ?? false) || prepared.hasTemporal;
13346
+ const fields = timelineFieldsRef.current;
13347
+ const addsDates = fields ? anyTimelineDate(prepared.features, fields) : prepared.hasTemporal;
13348
+ const layerHasTemporal = layerDatesUnder(layerId, existing, fields) || addsDates;
12724
13349
  const combined = [...existing, ...prepared.features];
12725
13350
  readOnlyFeatures.current.set(layerId, combined);
12726
- layerTemporalCacheRef.current.set(layerId, { featureCount: combined.length, hasTemporal: layerHasTemporal });
13351
+ layerTemporalCacheRef.current.set(layerId, {
13352
+ featureCount: combined.length,
13353
+ hasTemporal: layerHasTemporal,
13354
+ fieldsKey: timelineFieldsKey(fields)
13355
+ });
12727
13356
  const addedIds2 = prepared.featureIds;
12728
13357
  const updatedLayers2 = layersRef.current.map(
12729
13358
  (l) => l.id === layerId ? { ...l, featureIds: [...l.featureIds, ...addedIds2], importing: isShardEligible(l, combined.length, shardSizeRef.current) || void 0 } : l
@@ -12756,6 +13385,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12756
13385
  existing: existingInLayer
12757
13386
  });
12758
13387
  }
13388
+ const wasApiAdding = isApiAddingRef.current;
12759
13389
  isApiAddingRef.current = true;
12760
13390
  try {
12761
13391
  cappedForDraw.features.forEach((f) => {
@@ -12772,7 +13402,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12772
13402
  addedIds.push(ids[0]);
12773
13403
  });
12774
13404
  } finally {
12775
- isApiAddingRef.current = false;
13405
+ isApiAddingRef.current = wasApiAdding;
12776
13406
  }
12777
13407
  const updatedLayers = layersRef.current.map(
12778
13408
  (l) => l.id === layerId ? { ...l, featureIds: [...l.featureIds, ...addedIds] } : l
@@ -12813,7 +13443,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12813
13443
  ...l,
12814
13444
  featureIds: l.featureIds.filter((id) => !idSet.has(id))
12815
13445
  }));
12816
- return updated.filter((l) => l.featureIds.length > 0 || !l.readOnly);
13446
+ return updated.filter(keepLayerAfterFeatureRemoval);
12817
13447
  });
12818
13448
  updateFeatureCount();
12819
13449
  scheduleTimelineUpdate();
@@ -12887,6 +13517,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12887
13517
  existing: existingInLayer
12888
13518
  });
12889
13519
  }
13520
+ const wasApiAdding = isApiAddingRef.current;
12890
13521
  isApiAddingRef.current = true;
12891
13522
  try {
12892
13523
  capped.features.forEach((f) => {
@@ -12903,7 +13534,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12903
13534
  addedIds.push(ids[0]);
12904
13535
  });
12905
13536
  } finally {
12906
- isApiAddingRef.current = false;
13537
+ isApiAddingRef.current = wasApiAdding;
12907
13538
  }
12908
13539
  setLayers((prev) => prev.map(
12909
13540
  (l) => l.id === layerId ? { ...l, featureIds: [...l.featureIds, ...addedIds] } : l
@@ -13008,12 +13639,26 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13008
13639
  source: "api"
13009
13640
  });
13010
13641
  }
13642
+ const fields = timelineFieldsRef.current;
13643
+ const hadDates = fields ? layerDatesUnder(layerId, readOnlyFeatures.current.get(layerId) ?? [], fields) : false;
13644
+ const hasDates = fields ? anyTimelineDate(prepared.features, fields) : prepared.hasTemporal;
13011
13645
  readOnlyFeatures.current.set(layerId, prepared.features);
13012
- layerTemporalCacheRef.current.set(layerId, { featureCount: prepared.features.length, hasTemporal: prepared.hasTemporal });
13013
- if (prepared.hasTemporal) {
13646
+ layerTemporalCacheRef.current.set(layerId, {
13647
+ featureCount: prepared.features.length,
13648
+ hasTemporal: hasDates,
13649
+ fieldsKey: timelineFieldsKey(fields)
13650
+ });
13651
+ if (hasDates || hadDates) {
13014
13652
  scheduleTimelineUpdate();
13015
13653
  }
13016
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
+ }
13017
13662
  const updatedLayers = layersRef.current.map(
13018
13663
  (l) => l.id === layerId ? { ...l, featureIds: newFeatureIds, importing: isShardEligible(l, prepared.features.length, shardSizeRef.current) || void 0 } : l
13019
13664
  );
@@ -13158,6 +13803,17 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13158
13803
  }
13159
13804
  return cloneFeatures(features);
13160
13805
  },
13806
+ readLayerFeatures: (layerId) => {
13807
+ const readOnly = readOnlyFeatures.current.get(layerId);
13808
+ if (readOnly) return readOnly;
13809
+ const layer = layersRef.current.find((l) => l.id === layerId);
13810
+ if (!layer) return [];
13811
+ if (!layer.visible) return hiddenFeatures.current.get(layerId) ?? [];
13812
+ return layer.featureIds.flatMap((id) => {
13813
+ var _a;
13814
+ return ((_a = draw.current) == null ? void 0 : _a.get(id)) ?? [];
13815
+ });
13816
+ },
13161
13817
  getTimelineRange: () => {
13162
13818
  const ts = timelineStoreApi.getState();
13163
13819
  return {
@@ -13280,7 +13936,18 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13280
13936
  }, [activeEditingLayerId, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, toast]);
13281
13937
  const handleDeleteSelected = useCallback(() => {
13282
13938
  if (selectedFeatureIds.length === 0) return;
13283
- 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);
13284
13951
  const readOnlyIdSet = /* @__PURE__ */ new Set();
13285
13952
  for (const layer of layersRef.current) {
13286
13953
  if (!layer.readOnly) continue;
@@ -13288,10 +13955,15 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13288
13955
  }
13289
13956
  const editableIds = [];
13290
13957
  const readOnlyIds = [];
13291
- for (const id of selectedFeatureIds) {
13958
+ for (const id of deletableIds) {
13292
13959
  (readOnlyIdSet.has(id) ? readOnlyIds : editableIds).push(id);
13293
13960
  }
13294
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
+ }
13295
13967
  if (editableIds.length > 0 && draw.current) {
13296
13968
  editableIds.forEach((id) => {
13297
13969
  arrowFeatureIdsRef.current.delete(id);
@@ -13321,15 +13993,15 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13321
13993
  ...l,
13322
13994
  featureIds: l.featureIds.filter((id) => !idSet.has(id))
13323
13995
  }));
13324
- return updated.filter((l) => l.featureIds.length > 0 || !l.readOnly);
13996
+ return updated.filter(keepLayerAfterFeatureRemoval);
13325
13997
  });
13326
- onFeatureDelete == null ? void 0 : onFeatureDelete(selectedFeatureIds);
13327
- setSelectedFeatureIds([]);
13328
- setShowProperties(false);
13998
+ onFeatureDelete == null ? void 0 : onFeatureDelete(deletableIds);
13999
+ setSelectedFeatureIds(keptIds);
14000
+ setShowProperties(showsPropertiesFor(keptIds, layersRef.current));
13329
14001
  updateFeatureCount();
13330
14002
  scheduleTimelineUpdate();
13331
14003
  scheduleSync();
13332
- }, [selectedFeatureIds, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, onFeatureDelete]);
14004
+ }, [selectedFeatureIds, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, onFeatureDelete, history]);
13333
14005
  const handleToggleEditMode = useCallback(() => {
13334
14006
  setIsEditMode((prev) => {
13335
14007
  const newMode = !prev;
@@ -13761,6 +14433,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13761
14433
  }
13762
14434
  let featureId = oldId;
13763
14435
  const targetId = newId !== oldId ? newId : oldId;
14436
+ const wasApiAdding = isApiAddingRef.current;
13764
14437
  isApiAddingRef.current = true;
13765
14438
  try {
13766
14439
  if (newId !== oldId) {
@@ -13769,7 +14442,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13769
14442
  draw.current.add({ ...feature, id: targetId, properties: updatedProps });
13770
14443
  featureId = targetId;
13771
14444
  } finally {
13772
- isApiAddingRef.current = false;
14445
+ isApiAddingRef.current = wasApiAdding;
13773
14446
  }
13774
14447
  if (draw.current.get(featureId)) {
13775
14448
  draw.current.setFeatureProperty(featureId, "_unsaved", false);
@@ -13809,7 +14482,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13809
14482
  const handleRemoveLayer = useCallback((layerId) => {
13810
14483
  if (layers.length <= 1) return;
13811
14484
  const layer = layers.find((l) => l.id === layerId);
13812
- if (!layer || !draw.current) return;
14485
+ if (!layer || isHostOwnedLayer(layer) || !draw.current) return;
13813
14486
  saveStateForUndo();
13814
14487
  layer.featureIds.forEach((id) => {
13815
14488
  try {
@@ -13860,6 +14533,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13860
14533
  } else {
13861
14534
  const features = hiddenFeatures.current.get(layerId) || [];
13862
14535
  const newIds = [];
14536
+ const wasApiAdding = isApiAddingRef.current;
13863
14537
  isApiAddingRef.current = true;
13864
14538
  try {
13865
14539
  features.forEach((f) => {
@@ -13867,7 +14541,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13867
14541
  newIds.push(ids[0]);
13868
14542
  });
13869
14543
  } finally {
13870
- isApiAddingRef.current = false;
14544
+ isApiAddingRef.current = wasApiAdding;
13871
14545
  }
13872
14546
  hiddenFeatures.current.delete(layerId);
13873
14547
  nextLayers = currentLayers.map(
@@ -13884,6 +14558,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13884
14558
  }
13885
14559
  }, [layers, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate]);
13886
14560
  const handleMoveFeatureToLayer = useCallback((featureId, targetLayerId) => {
14561
+ if (movableFeatureIds(layersRef.current, [featureId], targetLayerId).length === 0) return;
13887
14562
  saveStateForUndo();
13888
14563
  setLayers((prev) => {
13889
14564
  const updated = prev.map((l) => {
@@ -13902,8 +14577,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13902
14577
  var _a;
13903
14578
  return ((_a = draw.current) == null ? void 0 : _a.get(id)) ?? getReadOnlyFeatureById(id) ?? void 0;
13904
14579
  }, [getReadOnlyFeatureById]);
13905
- const handleMoveFeaturesToLayer = useCallback((featureIds, targetLayerId) => {
13906
- 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;
13907
14583
  saveStateForUndo();
13908
14584
  const idSet = new Set(featureIds);
13909
14585
  const movedIds = [];
@@ -13942,8 +14618,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13942
14618
  updateFeatureCount();
13943
14619
  }
13944
14620
  }, [saveStateForUndo, findFeatureById, updateFeatureCount, scheduleSync]);
13945
- const handleCopyFeaturesToLayer = useCallback((featureIds, targetLayerId) => {
13946
- 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;
13947
14624
  saveStateForUndo();
13948
14625
  const newIds = [];
13949
14626
  featureIds.forEach((id) => {
@@ -13961,8 +14638,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13961
14638
  updateFeatureCount();
13962
14639
  }
13963
14640
  }, [saveStateForUndo, updateFeatureCount, findFeatureById]);
13964
- const handleCreateLayerAndMoveFeatures = useCallback((featureIds, layerName) => {
13965
- 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;
13966
14644
  const newLayerId = `layer-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
13967
14645
  const idSet = new Set(featureIds);
13968
14646
  saveStateForUndo();
@@ -14006,8 +14684,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
14006
14684
  updateFeatureCount();
14007
14685
  }
14008
14686
  }, [saveStateForUndo, findFeatureById, updateFeatureCount, scheduleSync, withAutoColor]);
14009
- const handleCreateLayerAndCopyFeatures = useCallback((featureIds, layerName) => {
14010
- 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;
14011
14690
  saveStateForUndo();
14012
14691
  const newIds = [];
14013
14692
  const copiedFeatures = [];
@@ -14093,7 +14772,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
14093
14772
  );
14094
14773
  const labelLayerIds = onlyLayerIds ?? [
14095
14774
  ...((_a = shardRegistryRef.current) == null ? void 0 : _a.labelLayerIds("all")) ?? ["custom-labels", "custom-labels-pinned"],
14096
- "custom-arrow-labels"
14775
+ "custom-arrow-labels",
14776
+ HOST_DECORATION_LAYER_IDS.labels
14097
14777
  ];
14098
14778
  try {
14099
14779
  labelLayerIds.forEach((id) => {
@@ -14314,7 +14994,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
14314
14994
  if (!hasArrowFeaturesRef.current || rafId !== null) return;
14315
14995
  rafId = requestAnimationFrame(() => {
14316
14996
  rafId = null;
14317
- renderArrowOverlays(paintedArrowLinesRef.current);
14997
+ renderArrowOverlays(paintedArrowLinesRef.current, { headsOnly: true });
14318
14998
  });
14319
14999
  };
14320
15000
  mapInstance.on("move", handleMove);
@@ -14579,8 +15259,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
14579
15259
  }, [layers, traceFieldSource]);
14580
15260
  const getSuggestedTraceField = useCallback((layerId) => {
14581
15261
  const layer = layers.find((l) => l.id === layerId);
14582
- return layer ? suggestTraceGroupField(traceFieldSource(layer), getAvailableTraceFields(layerId)) : null;
14583
- }, [layers, traceFieldSource, getAvailableTraceFields]);
15262
+ return layer ? suggestTraceGroupField(traceFieldSource(layer), getAvailableTraceFields(layerId), pickedTimelineFields) : null;
15263
+ }, [layers, traceFieldSource, getAvailableTraceFields, pickedTimelineFields]);
14584
15264
  const handleMeasureModeChange = useCallback((mode) => {
14585
15265
  setMeasureMode(mode);
14586
15266
  setMeasurePoints([]);
@@ -14768,7 +15448,13 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
14768
15448
  trace.window = next;
14769
15449
  endpointsMoved = traceDiff.endpointOn.length;
14770
15450
  }
14771
- const flipped = applyTimelineWindow(featureStateHostFor(m), appliedTimelineRef.current, next, isTimelineSourceActive);
15451
+ const flipped = applyTimelineWindow(
15452
+ featureStateHostFor(m),
15453
+ appliedTimelineRef.current,
15454
+ next,
15455
+ isTimelineSourceActive,
15456
+ timelineFieldsRef.current
15457
+ );
14772
15458
  const threshold = autoLabelConfig.enabled ? autoLabelConfig.threshold : 220;
14773
15459
  const count = countVisibleFeatures(threshold);
14774
15460
  if (tickCountTimerRef.current) clearTimeout(tickCountTimerRef.current);
@@ -15583,6 +16269,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
15583
16269
  const layerStates = [];
15584
16270
  layers.forEach((layer, idx) => {
15585
16271
  var _a;
16272
+ if (isHostOwnedLayer(layer)) return;
15586
16273
  const isDataViewing = ((_a = layer.metadata) == null ? void 0 : _a.dataViewing) === true;
15587
16274
  if (!isDataViewing) {
15588
16275
  const layerFeatures = collectLayerFeatures(layer, {
@@ -15695,6 +16382,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
15695
16382
  existing: existingInActive
15696
16383
  });
15697
16384
  const addedIds = [];
16385
+ const wasApiAdding = isApiAddingRef.current;
15698
16386
  isApiAddingRef.current = true;
15699
16387
  try {
15700
16388
  capped.features.forEach((f) => {
@@ -15711,7 +16399,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
15711
16399
  addedIds.push(ids[0]);
15712
16400
  });
15713
16401
  } finally {
15714
- isApiAddingRef.current = false;
16402
+ isApiAddingRef.current = wasApiAdding;
15715
16403
  }
15716
16404
  let targetLayerId;
15717
16405
  let targetLayerName;
@@ -15775,7 +16463,11 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
15775
16463
  if (draw.current) {
15776
16464
  draw.current.deleteAll();
15777
16465
  }
15778
- 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
+ }
15779
16471
  hiddenFeatures.current.clear();
15780
16472
  const featuresByIndex = /* @__PURE__ */ new Map();
15781
16473
  enriched.features.forEach((f) => {
@@ -15796,6 +16488,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
15796
16488
  let firstTruncatedLayer = "";
15797
16489
  for (const ls of sortedLayers) {
15798
16490
  if (((_a = ls.metadata) == null ? void 0 : _a.dataViewing) === true) continue;
16491
+ if (isHostOwnedLayer(ls)) continue;
15799
16492
  const capped = capFeatures(featuresByIndex.get(ls.index) ?? [], { max: featureCapRef.current });
15800
16493
  const rawFeatures = capped.features;
15801
16494
  if (capped.dropped > 0) {
@@ -15829,13 +16522,14 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
15829
16522
  if (isReadOnly) {
15830
16523
  readOnlyFeatures.current.set(layerId, featuresWithIds);
15831
16524
  } else if (draw.current) {
16525
+ const wasApiAdding = isApiAddingRef.current;
15832
16526
  isApiAddingRef.current = true;
15833
16527
  try {
15834
16528
  for (const f of featuresWithIds) {
15835
16529
  draw.current.add(f);
15836
16530
  }
15837
16531
  } finally {
15838
- isApiAddingRef.current = false;
16532
+ isApiAddingRef.current = wasApiAdding;
15839
16533
  }
15840
16534
  }
15841
16535
  newLayers.push({
@@ -15845,8 +16539,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
15845
16539
  readOnly: isReadOnly
15846
16540
  });
15847
16541
  }
15848
- layersRef.current = newLayers;
15849
- setLayers(newLayers);
16542
+ layersRef.current = [...newLayers, ...hostLayers];
16543
+ setLayers(layersRef.current);
15850
16544
  updateFeatureCount();
15851
16545
  scheduleTimelineUpdate();
15852
16546
  scheduleSync();
@@ -16130,6 +16824,14 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
16130
16824
  });
16131
16825
  return;
16132
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
+ }
16133
16835
  if (!targetLayer) {
16134
16836
  targetLayer = currentLayers.find((l) => l.visible && !l.readOnly);
16135
16837
  }
@@ -16176,14 +16878,11 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
16176
16878
  const addedIds = addedFeatures.map((f) => String(f.id));
16177
16879
  const existing = readOnlyFeatures.current.get(targetId) || [];
16178
16880
  readOnlyFeatures.current.set(targetId, [...existing, ...addedFeatures]);
16179
- const cached = layerTemporalCacheRef.current.get(targetId);
16180
- layerTemporalCacheRef.current.set(targetId, {
16181
- featureCount: ((cached == null ? void 0 : cached.featureCount) ?? existing.length) + addedFeatures.length,
16182
- hasTemporal: ((cached == null ? void 0 : cached.hasTemporal) ?? false) || fileHasTemporal
16183
- });
16881
+ layerTemporalCacheRef.current.delete(targetId);
16184
16882
  setLayers((prev) => prev.map((l) => l.id === targetId ? withLayerMetadata(l, addedIds) : l));
16185
16883
  } else if (targetLayer.visible) {
16186
16884
  const addedIds = [];
16885
+ const wasApiAdding = isApiAddingRef.current;
16187
16886
  isApiAddingRef.current = true;
16188
16887
  try {
16189
16888
  appendFeatures.forEach((f) => {
@@ -16191,7 +16890,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
16191
16890
  addedIds.push(ids[0]);
16192
16891
  });
16193
16892
  } finally {
16194
- isApiAddingRef.current = false;
16893
+ isApiAddingRef.current = wasApiAdding;
16195
16894
  }
16196
16895
  setLayers((prev) => prev.map((l) => l.id === targetId ? withLayerMetadata(l, addedIds) : l));
16197
16896
  } else {
@@ -17065,11 +17764,11 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
17065
17764
  ] })
17066
17765
  }
17067
17766
  ),
17068
- enableTimeline && timelineHasData && /* @__PURE__ */ jsx(
17767
+ enableTimeline && (timelineHasData || timelineFields || keepTimebarExtra) && /* @__PURE__ */ jsx(
17069
17768
  "div",
17070
17769
  {
17071
17770
  className: "absolute left-4 z-[200] transition-all",
17072
- style: { bottom: timelineEnabled ? TIMEBAR_HEIGHT + TIMEBAR_BOTTOM_OFFSET + 8 : 48 },
17771
+ style: { bottom: timelineEnabled ? timebarHeight + TIMEBAR_BOTTOM_OFFSET + 8 : 48 },
17073
17772
  children: /* @__PURE__ */ jsx(Tooltip, { title: "Timeline", placement: "right", children: /* @__PURE__ */ jsx(
17074
17773
  Button,
17075
17774
  {
@@ -17225,7 +17924,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
17225
17924
  selectedFeatureIds,
17226
17925
  selectedFeatureColors,
17227
17926
  selectionDisplay: "line",
17228
- timebarExtra
17927
+ timebarExtra,
17928
+ keepExtraWhenEmpty: !!timelineFields || keepTimebarExtra
17229
17929
  }
17230
17930
  ),
17231
17931
  contextMenu && /* @__PURE__ */ jsx(
@@ -17242,7 +17942,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
17242
17942
  IngestProgressOverlay,
17243
17943
  {
17244
17944
  store: ingestProgressStore,
17245
- bottomPx: timelineEnabled ? TIMEBAR_HEIGHT + TIMEBAR_BOTTOM_OFFSET + 8 : 32
17945
+ bottomPx: timelineEnabled ? timebarHeight + TIMEBAR_BOTTOM_OFFSET + 8 : 32
17246
17946
  }
17247
17947
  ),
17248
17948
  /* @__PURE__ */ jsx(
@@ -18268,6 +18968,7 @@ export {
18268
18968
  DEFAULT_MAX_FEATURES_PER_LAYER,
18269
18969
  DebugSidebar,
18270
18970
  DrawingToolbar,
18971
+ HOST_IMAGE_PREFIX,
18271
18972
  INTERNAL_PROPERTY_KEYS,
18272
18973
  INTERNAL_PROPERTY_PREFIXES,
18273
18974
  IconPicker,
@@ -18294,6 +18995,7 @@ export {
18294
18995
  isValidIconValue,
18295
18996
  normalizeTemporalProperties,
18296
18997
  parseKMLToGeoJSON,
18998
+ readTimelineDates,
18297
18999
  useToast as toast,
18298
19000
  useTimelineStore,
18299
19001
  useTimelineStoreApi,