@octostar/map-component 0.2.18 → 0.2.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/index.cjs +470 -91
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +470 -91
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +2 -0
- package/dist/types/components/map-editor-canvas.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/feature-cap.d.ts +69 -0
- package/dist/types/lib/feature-cap.d.ts.map +1 -0
- package/dist/types/lib/geojson-serialize.d.ts +24 -0
- package/dist/types/lib/geojson-serialize.d.ts.map +1 -1
- package/dist/types/lib/ingest-pipeline.d.ts +12 -0
- package/dist/types/lib/ingest-pipeline.d.ts.map +1 -1
- package/dist/types/lib/ingest-progress.d.ts +5 -1
- package/dist/types/lib/ingest-progress.d.ts.map +1 -1
- package/dist/types/lib/layer-features.d.ts +25 -3
- package/dist/types/lib/layer-features.d.ts.map +1 -1
- package/dist/types/lib/map-editor-api.d.ts +40 -1
- package/dist/types/lib/map-editor-api.d.ts.map +1 -1
- package/dist/types/lib/temporal-ingest.d.ts +11 -1
- package/dist/types/lib/temporal-ingest.d.ts.map +1 -1
- package/dist/types/lib/yield-to-main.d.ts +2 -0
- package/dist/types/lib/yield-to-main.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -86,38 +86,85 @@ function hasAltitudeData(feature) {
|
|
|
86
86
|
}
|
|
87
87
|
return false;
|
|
88
88
|
}
|
|
89
|
+
function yieldToMain() {
|
|
90
|
+
const scheduler = globalThis.scheduler;
|
|
91
|
+
if (typeof (scheduler == null ? void 0 : scheduler.yield) === "function") {
|
|
92
|
+
return scheduler.yield();
|
|
93
|
+
}
|
|
94
|
+
const channelCtor = globalThis.MessageChannel;
|
|
95
|
+
if (typeof channelCtor === "function") {
|
|
96
|
+
return new Promise((resolve) => {
|
|
97
|
+
const channel = new channelCtor();
|
|
98
|
+
channel.port1.onmessage = () => {
|
|
99
|
+
channel.port1.close();
|
|
100
|
+
resolve();
|
|
101
|
+
};
|
|
102
|
+
channel.port2.postMessage(void 0);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
106
|
+
}
|
|
89
107
|
const PRETTY_EXPORT_MAX_FEATURES = 1e4;
|
|
90
108
|
const TARGET_PART_CHARS = 8 * 1024 * 1024;
|
|
91
|
-
function
|
|
92
|
-
const prettyMax = PRETTY_EXPORT_MAX_FEATURES;
|
|
93
|
-
if (collection.features.length <= prettyMax) {
|
|
94
|
-
return [JSON.stringify(collection, null, 2)];
|
|
95
|
-
}
|
|
96
|
-
const targetChars = TARGET_PART_CHARS;
|
|
97
|
-
const { features, ...rest } = collection;
|
|
98
|
-
const head = JSON.stringify(rest);
|
|
109
|
+
function createBlobPartCoalescer(targetChars) {
|
|
99
110
|
const parts = [];
|
|
100
111
|
let pending = [];
|
|
101
112
|
let pendingChars = 0;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
113
|
+
return {
|
|
114
|
+
push(piece) {
|
|
115
|
+
pending.push(piece);
|
|
116
|
+
pendingChars += piece.length;
|
|
117
|
+
if (pendingChars >= targetChars) {
|
|
118
|
+
parts.push(pending.join(""));
|
|
119
|
+
pending = [];
|
|
120
|
+
pendingChars = 0;
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
finish() {
|
|
124
|
+
if (pending.length > 0) parts.push(pending.join(""));
|
|
125
|
+
return parts;
|
|
109
126
|
}
|
|
110
127
|
};
|
|
111
|
-
|
|
112
|
-
|
|
128
|
+
}
|
|
129
|
+
function pushCollectionHead(coalescer, rest) {
|
|
130
|
+
const head = JSON.stringify(rest);
|
|
131
|
+
coalescer.push(head.slice(0, -1));
|
|
132
|
+
coalescer.push(head.length > 2 ? ',"features":[' : '"features":[');
|
|
133
|
+
}
|
|
134
|
+
function serializeFeatureAt(feature, index) {
|
|
135
|
+
return index === 0 ? JSON.stringify(feature) : "," + JSON.stringify(feature);
|
|
136
|
+
}
|
|
137
|
+
const DEFAULT_SLICE_BUDGET_MS = 12;
|
|
138
|
+
async function featureCollectionBlobPartsAsync(collection, options) {
|
|
139
|
+
var _a, _b, _c;
|
|
140
|
+
const prettyMax = (options == null ? void 0 : options.prettyMaxFeatures) ?? PRETTY_EXPORT_MAX_FEATURES;
|
|
141
|
+
const mapFeature = options == null ? void 0 : options.mapFeature;
|
|
142
|
+
const total = collection.features.length;
|
|
143
|
+
if (total <= prettyMax) {
|
|
144
|
+
const mapped = mapFeature ? { ...collection, features: collection.features.map(mapFeature) } : collection;
|
|
145
|
+
(_a = options == null ? void 0 : options.onProgress) == null ? void 0 : _a.call(options, total, total);
|
|
146
|
+
return [JSON.stringify(mapped, null, 2)];
|
|
147
|
+
}
|
|
148
|
+
const { features, ...rest } = collection;
|
|
149
|
+
const coalescer = createBlobPartCoalescer((options == null ? void 0 : options.targetPartChars) ?? TARGET_PART_CHARS);
|
|
150
|
+
const yieldFn = (options == null ? void 0 : options.yieldFn) ?? yieldToMain;
|
|
151
|
+
const budget = (options == null ? void 0 : options.sliceBudgetMs) ?? DEFAULT_SLICE_BUDGET_MS;
|
|
152
|
+
pushCollectionHead(coalescer, rest);
|
|
153
|
+
let sliceStart = performance.now();
|
|
113
154
|
for (let i = 0; i < features.length; i++) {
|
|
114
|
-
|
|
155
|
+
const feature = mapFeature ? mapFeature(features[i], i) : features[i];
|
|
156
|
+
coalescer.push(serializeFeatureAt(feature, i));
|
|
157
|
+
if (performance.now() - sliceStart >= budget) {
|
|
158
|
+
(_b = options == null ? void 0 : options.onProgress) == null ? void 0 : _b.call(options, i + 1, total);
|
|
159
|
+
await yieldFn();
|
|
160
|
+
sliceStart = performance.now();
|
|
161
|
+
}
|
|
115
162
|
}
|
|
116
|
-
push("]}");
|
|
117
|
-
|
|
118
|
-
return
|
|
163
|
+
coalescer.push("]}");
|
|
164
|
+
(_c = options == null ? void 0 : options.onProgress) == null ? void 0 : _c.call(options, total, total);
|
|
165
|
+
return coalescer.finish();
|
|
119
166
|
}
|
|
120
|
-
const ingestWorkerSource = '"use strict";(()=>{function
|
|
167
|
+
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=G(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 G(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 c(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=c(e.startDate)||c(e.startdate)||c(e.start_date)||c(e.start_time)||c(e.date)||c(e.timestamp)||c(e.flightDate)||c(e.time)||c(e.datetime),n=c(e.endDate)||c(e.enddate)||c(e.end_date)||c(e.end_time);return t&&n&&n<t&&([t,n]=[n,t]),{startDate:t,endDate:n}}function C(e){return"kind"in e&&e.kind==="ack"}function T(){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):T()}}function x(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)x(n,t)}}function R(e,t){if(e){if(e.type==="GeometryCollection"){for(let n of e.geometries)R(n,t);return}x(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(d){return{kind:"error",code:"parse-error",message:d instanceof Error?d.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((d,w)=>{let f=_(d,w,t);!u&&I(d)&&(u=!0);let g=d.properties||{};if(!h(g)){i.push(t.idStrategy==="preserve"?d:{...d,id:f});return}let{startDate:y,endDate:k}=F(g);(y||k)&&(o=!0),i.push({...d,...f!==void 0&&{id:f},properties:{...g,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 p(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(!p(e[t]))return!1;return!0}for(let t in e)if(!p(e[t]))return!1;return!0}function P(e){for(let t=0;t<e.length;t++)if(!p(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 A(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 E=e=>self.postMessage(e),l=new Map;self.onmessage=async e=>{let t=e.data;if(C(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 A(n,o,s,{post:E,waitAck:u=>new Promise(i=>{l.set(`${n}:${u}`,i)}),...a?.chunkSize!==void 0&&{chunkSize:a.chunkSize},...a?.featureArrayChunks&&{encode:u=>u}})}catch(o){E({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';
|
|
121
168
|
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");
|
|
122
169
|
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");
|
|
123
170
|
proj4.defs("EPSG:32630", "+proj=utm +zone=30 +datum=WGS84 +units=m +no_defs");
|
|
@@ -158,6 +205,55 @@ function reprojectGeometry(geometry, fromCRS) {
|
|
|
158
205
|
coordinates: reprojectCoords(geomWithCoords.coordinates)
|
|
159
206
|
};
|
|
160
207
|
}
|
|
208
|
+
const DEFAULT_MAX_FEATURES_PER_LAYER = 2e5;
|
|
209
|
+
function resolveFeatureCap(value) {
|
|
210
|
+
if (value === void 0) return DEFAULT_MAX_FEATURES_PER_LAYER;
|
|
211
|
+
if (value === Infinity) return Infinity;
|
|
212
|
+
if (!Number.isFinite(value) || value < 1) {
|
|
213
|
+
console.warn(
|
|
214
|
+
`[map-editor] Ignoring maxFeaturesPerLayer=${String(value)} — expected a number >= 1 or Infinity. Falling back to ${DEFAULT_MAX_FEATURES_PER_LAYER}.`
|
|
215
|
+
);
|
|
216
|
+
return DEFAULT_MAX_FEATURES_PER_LAYER;
|
|
217
|
+
}
|
|
218
|
+
return Math.floor(value);
|
|
219
|
+
}
|
|
220
|
+
function capFeatures(features, options) {
|
|
221
|
+
const sourceCount = features.length;
|
|
222
|
+
const room = Math.max(0, options.max - (options.existing ?? 0));
|
|
223
|
+
if (sourceCount <= room) {
|
|
224
|
+
return { features, dropped: 0, sourceCount };
|
|
225
|
+
}
|
|
226
|
+
return {
|
|
227
|
+
features: features.slice(0, room),
|
|
228
|
+
dropped: sourceCount - room,
|
|
229
|
+
sourceCount
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
function formatCount(value) {
|
|
233
|
+
return value.toLocaleString("en-US");
|
|
234
|
+
}
|
|
235
|
+
function formatFeatureCapToast(info) {
|
|
236
|
+
const isRestore = info.source === "restore";
|
|
237
|
+
const variant = isRestore ? "destructive" : "default";
|
|
238
|
+
const withNote = (text) => isRestore ? `${text} Re-saving this map will persist only the loaded features.` : text;
|
|
239
|
+
const layerCount = info.layerCount ?? 1;
|
|
240
|
+
if (layerCount > 1) {
|
|
241
|
+
return {
|
|
242
|
+
title: "Feature limit reached",
|
|
243
|
+
description: withNote(
|
|
244
|
+
`${formatCount(layerCount)} layers were larger than the ${formatCount(info.max)}-feature limit; ${formatCount(info.dropped)} features in total were not loaded.`
|
|
245
|
+
),
|
|
246
|
+
variant
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
return {
|
|
250
|
+
title: "Feature limit reached",
|
|
251
|
+
description: withNote(
|
|
252
|
+
`Only the first ${formatCount(info.kept)} of ${formatCount(info.sourceCount)} features were added to "${info.layerName}"; ${formatCount(info.dropped)} were skipped (per-layer limit).`
|
|
253
|
+
),
|
|
254
|
+
variant
|
|
255
|
+
};
|
|
256
|
+
}
|
|
161
257
|
function parseDate(value) {
|
|
162
258
|
if (!value) return null;
|
|
163
259
|
if (value instanceof Date) return value;
|
|
@@ -251,10 +347,11 @@ function runIngestPipeline(source, options) {
|
|
|
251
347
|
return { kind: "enriched", data };
|
|
252
348
|
}
|
|
253
349
|
const { sourceCRS, needsReprojection } = detectSourceCRS(data);
|
|
350
|
+
const capped = capFeatures(data.features, { max: options.maxFeatures ?? Infinity });
|
|
254
351
|
let hasTemporal = false;
|
|
255
352
|
let hasAltitude = false;
|
|
256
353
|
const features = [];
|
|
257
|
-
|
|
354
|
+
capped.features.forEach((f, index) => {
|
|
258
355
|
const id = assignId(f, index, options);
|
|
259
356
|
if (!hasAltitude && hasAltitudeData(f)) hasAltitude = true;
|
|
260
357
|
const props = f.properties || {};
|
|
@@ -289,7 +386,14 @@ function runIngestPipeline(source, options) {
|
|
|
289
386
|
reprojected: false,
|
|
290
387
|
sourceCRS,
|
|
291
388
|
...needsReprojection && { needsReprojection },
|
|
292
|
-
...layerMetadata && { layerMetadata }
|
|
389
|
+
...layerMetadata && { layerMetadata },
|
|
390
|
+
...capped.dropped > 0 && {
|
|
391
|
+
truncated: {
|
|
392
|
+
droppedCount: capped.dropped,
|
|
393
|
+
sourceFeatureCount: capped.sourceCount,
|
|
394
|
+
maxFeatures: options.maxFeatures
|
|
395
|
+
}
|
|
396
|
+
}
|
|
293
397
|
};
|
|
294
398
|
}
|
|
295
399
|
function decodeChunkPayload(payload) {
|
|
@@ -609,9 +713,9 @@ function createIngestProgressStore() {
|
|
|
609
713
|
listeners.forEach((listener) => listener());
|
|
610
714
|
};
|
|
611
715
|
return {
|
|
612
|
-
begin(label) {
|
|
716
|
+
begin(label, options) {
|
|
613
717
|
const id = nextId++;
|
|
614
|
-
entries.set(id, { label, received: 0, total: null });
|
|
718
|
+
entries.set(id, { label, received: 0, total: null, ...(options == null ? void 0 : options.verb) && { verb: options.verb } });
|
|
615
719
|
notify();
|
|
616
720
|
return {
|
|
617
721
|
setTotal(total) {
|
|
@@ -707,7 +811,8 @@ function IngestProgressOverlay({
|
|
|
707
811
|
className: "rounded-md border bg-background/90 px-3 py-1.5 text-xs text-muted-foreground shadow-md",
|
|
708
812
|
children: [
|
|
709
813
|
/* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
|
|
710
|
-
"Importing
|
|
814
|
+
entry.verb ?? "Importing",
|
|
815
|
+
" ",
|
|
711
816
|
entry.label,
|
|
712
817
|
"…",
|
|
713
818
|
entry.total !== null ? ` ${entry.received.toLocaleString()} / ${entry.total.toLocaleString()} features` : ""
|
|
@@ -1106,15 +1211,28 @@ function collectLayerFeatures(layer, sources) {
|
|
|
1106
1211
|
if (readOnly) pushAll(features, readOnly);
|
|
1107
1212
|
return features;
|
|
1108
1213
|
}
|
|
1109
|
-
function
|
|
1110
|
-
|
|
1111
|
-
|
|
1214
|
+
function countLayerFeatures(layer, stores) {
|
|
1215
|
+
var _a;
|
|
1216
|
+
if (layer.readOnly) return ((_a = stores.readOnlyFeatures.get(layer.id)) == null ? void 0 : _a.length) ?? 0;
|
|
1217
|
+
const hidden = stores.hiddenFeatures.get(layer.id);
|
|
1218
|
+
if (!hidden || hidden.length === 0) return layer.featureIds.length;
|
|
1219
|
+
if (layer.featureIds.length === 0) return hidden.length;
|
|
1220
|
+
const ids = new Set(layer.featureIds);
|
|
1221
|
+
let count = layer.featureIds.length;
|
|
1222
|
+
for (const feature of hidden) {
|
|
1223
|
+
if (!ids.has(String(feature.id))) count++;
|
|
1224
|
+
}
|
|
1225
|
+
return count;
|
|
1226
|
+
}
|
|
1227
|
+
function stripInternalPropertiesFromFeature(feature, keep) {
|
|
1228
|
+
return {
|
|
1229
|
+
...feature,
|
|
1112
1230
|
properties: Object.fromEntries(
|
|
1113
|
-
Object.entries(
|
|
1231
|
+
Object.entries(feature.properties ?? {}).filter(
|
|
1114
1232
|
([key]) => !key.startsWith("_") || ((keep == null ? void 0 : keep.has(key)) ?? false)
|
|
1115
1233
|
)
|
|
1116
1234
|
)
|
|
1117
|
-
}
|
|
1235
|
+
};
|
|
1118
1236
|
}
|
|
1119
1237
|
const ToastContext = react.createContext(null);
|
|
1120
1238
|
function useToast() {
|
|
@@ -6588,9 +6706,11 @@ function geometryEquals(a, b) {
|
|
|
6588
6706
|
b.coordinates
|
|
6589
6707
|
);
|
|
6590
6708
|
}
|
|
6591
|
-
function prepareFeaturesForLayer(input, caller) {
|
|
6709
|
+
function prepareFeaturesForLayer(input, caller, cap) {
|
|
6592
6710
|
const logging = mapPerfLogEnabled();
|
|
6593
6711
|
const started = logging ? performance.now() : 0;
|
|
6712
|
+
const capped = cap ? capFeatures(input, cap) : null;
|
|
6713
|
+
if (capped) input = capped.features;
|
|
6594
6714
|
const count = input.length;
|
|
6595
6715
|
const features = new Array(count);
|
|
6596
6716
|
const featureIds = new Array(count);
|
|
@@ -6633,10 +6753,17 @@ function prepareFeaturesForLayer(input, caller) {
|
|
|
6633
6753
|
withTemporalKeys: temporalCount,
|
|
6634
6754
|
hasTemporal,
|
|
6635
6755
|
reused,
|
|
6636
|
-
copied: count - reused
|
|
6756
|
+
copied: count - reused,
|
|
6757
|
+
...capped && capped.dropped > 0 && { dropped: capped.dropped }
|
|
6637
6758
|
});
|
|
6638
6759
|
}
|
|
6639
|
-
return {
|
|
6760
|
+
return {
|
|
6761
|
+
features,
|
|
6762
|
+
featureIds,
|
|
6763
|
+
hasTemporal,
|
|
6764
|
+
dropped: (capped == null ? void 0 : capped.dropped) ?? 0,
|
|
6765
|
+
sourceCount: (capped == null ? void 0 : capped.sourceCount) ?? count
|
|
6766
|
+
};
|
|
6640
6767
|
}
|
|
6641
6768
|
function scanTemporalFeatures(features, resolveLayerId, out) {
|
|
6642
6769
|
let foundTemporal = false;
|
|
@@ -7567,6 +7694,7 @@ function extract3DFlightPaths(features) {
|
|
|
7567
7694
|
});
|
|
7568
7695
|
return paths;
|
|
7569
7696
|
}
|
|
7697
|
+
const CAP_NOTICE_INTERVAL_MS = 5e3;
|
|
7570
7698
|
const DEFAULT_LOCAL_GLYPHS_URL = "/fonts/{fontstack}/{range}.pbf";
|
|
7571
7699
|
function basemapInsertAnchor(map) {
|
|
7572
7700
|
if (map.getLayer("satellite-layer")) return "satellite-layer";
|
|
@@ -7690,6 +7818,8 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
7690
7818
|
enableProperties = true,
|
|
7691
7819
|
autoOpenProperties = true,
|
|
7692
7820
|
toastProvider,
|
|
7821
|
+
maxFeaturesPerLayer,
|
|
7822
|
+
onFeaturesTruncated,
|
|
7693
7823
|
customGlobalMenuItems,
|
|
7694
7824
|
extraLayerToolbarButtons,
|
|
7695
7825
|
extraNewLayerButtons,
|
|
@@ -7797,6 +7927,31 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
7797
7927
|
const timelineStore = zustand.useStore(timelineStoreApi);
|
|
7798
7928
|
const { toast: internalToast } = useToast();
|
|
7799
7929
|
const toast = toastProvider ?? internalToast;
|
|
7930
|
+
const featureCap = react.useMemo(() => resolveFeatureCap(maxFeaturesPerLayer), [maxFeaturesPerLayer]);
|
|
7931
|
+
const featureCapRef = react.useRef(featureCap);
|
|
7932
|
+
featureCapRef.current = featureCap;
|
|
7933
|
+
const capNoticeRef = react.useRef(/* @__PURE__ */ new Map());
|
|
7934
|
+
const notifyFeatureCap = react.useCallback((info) => {
|
|
7935
|
+
if (onFeaturesTruncated) {
|
|
7936
|
+
onFeaturesTruncated(info);
|
|
7937
|
+
return;
|
|
7938
|
+
}
|
|
7939
|
+
if (info.source !== "restore") {
|
|
7940
|
+
const key = info.layerId ?? info.layerName;
|
|
7941
|
+
const now = Date.now();
|
|
7942
|
+
const last = capNoticeRef.current.get(key);
|
|
7943
|
+
if (last != null && now - last < CAP_NOTICE_INTERVAL_MS) return;
|
|
7944
|
+
capNoticeRef.current.set(key, now);
|
|
7945
|
+
}
|
|
7946
|
+
toast(formatFeatureCapToast(info));
|
|
7947
|
+
}, [onFeaturesTruncated, toast]);
|
|
7948
|
+
const countExisting = react.useCallback(
|
|
7949
|
+
(layer) => countLayerFeatures(layer, {
|
|
7950
|
+
hiddenFeatures: hiddenFeatures.current,
|
|
7951
|
+
readOnlyFeatures: readOnlyFeatures.current
|
|
7952
|
+
}),
|
|
7953
|
+
[]
|
|
7954
|
+
);
|
|
7800
7955
|
react.useEffect(() => {
|
|
7801
7956
|
const handleError = (event) => {
|
|
7802
7957
|
const msg = event.message || "";
|
|
@@ -10484,16 +10639,22 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
10484
10639
|
clusterConfig: options == null ? void 0 : options.clusterConfig,
|
|
10485
10640
|
altitudeDisplayMode: options == null ? void 0 : options.altitudeDisplayMode
|
|
10486
10641
|
};
|
|
10642
|
+
let addedFeatures = (geojson == null ? void 0 : geojson.features) ?? [];
|
|
10643
|
+
let capDropped = 0;
|
|
10487
10644
|
if (geojson) {
|
|
10645
|
+
const max = featureCapRef.current;
|
|
10488
10646
|
if (options == null ? void 0 : options.readOnly) {
|
|
10489
|
-
const prepared = prepareFeaturesForLayer(geojson.features, "addLayer");
|
|
10647
|
+
const prepared = prepareFeaturesForLayer(geojson.features, "addLayer", { max });
|
|
10490
10648
|
readOnlyFeatures.current.set(layerId, prepared.features);
|
|
10491
10649
|
layerTemporalCacheRef.current.set(layerId, { featureCount: prepared.features.length, hasTemporal: prepared.hasTemporal });
|
|
10492
10650
|
newLayer.featureIds = prepared.featureIds;
|
|
10651
|
+
addedFeatures = prepared.features;
|
|
10652
|
+
capDropped = prepared.dropped;
|
|
10493
10653
|
} else if (draw.current) {
|
|
10654
|
+
const capped = capFeatures(geojson.features, { max });
|
|
10494
10655
|
isApiAddingRef.current = true;
|
|
10495
10656
|
try {
|
|
10496
|
-
const addedIds =
|
|
10657
|
+
const addedIds = capped.features.map((f) => {
|
|
10497
10658
|
const ids = draw.current.add(f);
|
|
10498
10659
|
return ids[0];
|
|
10499
10660
|
});
|
|
@@ -10501,8 +10662,21 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
10501
10662
|
} finally {
|
|
10502
10663
|
isApiAddingRef.current = false;
|
|
10503
10664
|
}
|
|
10665
|
+
addedFeatures = capped.features;
|
|
10666
|
+
capDropped = capped.dropped;
|
|
10504
10667
|
}
|
|
10505
10668
|
}
|
|
10669
|
+
if (capDropped > 0) {
|
|
10670
|
+
notifyFeatureCap({
|
|
10671
|
+
layerId,
|
|
10672
|
+
layerName: name,
|
|
10673
|
+
kept: addedFeatures.length,
|
|
10674
|
+
dropped: capDropped,
|
|
10675
|
+
sourceCount: (geojson == null ? void 0 : geojson.features.length) ?? 0,
|
|
10676
|
+
max: featureCapRef.current,
|
|
10677
|
+
source: "api"
|
|
10678
|
+
});
|
|
10679
|
+
}
|
|
10506
10680
|
if (newLayer.visible === false && !(options == null ? void 0 : options.readOnly) && draw.current && newLayer.featureIds.length > 0) {
|
|
10507
10681
|
const features = newLayer.featureIds.map((id) => draw.current.get(id)).filter(Boolean);
|
|
10508
10682
|
hiddenFeatures.current.set(layerId, features);
|
|
@@ -10520,9 +10694,11 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
10520
10694
|
updateFeatureCount();
|
|
10521
10695
|
scheduleTimelineUpdate();
|
|
10522
10696
|
scheduleSync();
|
|
10523
|
-
if (!(options == null ? void 0 : options.skipFit) &&
|
|
10697
|
+
if (!(options == null ? void 0 : options.skipFit) && addedFeatures.length > 0 && map.current) {
|
|
10524
10698
|
try {
|
|
10525
|
-
const bbox = turf__namespace.bbox(
|
|
10699
|
+
const bbox = turf__namespace.bbox(
|
|
10700
|
+
capDropped > 0 ? { type: "FeatureCollection", features: addedFeatures } : geojson
|
|
10701
|
+
);
|
|
10526
10702
|
if (bbox.every((v) => isFinite(v))) {
|
|
10527
10703
|
map.current.fitBounds(
|
|
10528
10704
|
[[bbox[0], bbox[1]], [bbox[2], bbox[3]]],
|
|
@@ -10615,7 +10791,21 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
10615
10791
|
if (options == null ? void 0 : options.recordHistory) saveStateForUndo("add features");
|
|
10616
10792
|
if (layer.readOnly) {
|
|
10617
10793
|
const existing = readOnlyFeatures.current.get(layerId) || [];
|
|
10618
|
-
const prepared = prepareFeaturesForLayer(features, "addFeatures"
|
|
10794
|
+
const prepared = prepareFeaturesForLayer(features, "addFeatures", {
|
|
10795
|
+
max: featureCapRef.current,
|
|
10796
|
+
existing: existing.length
|
|
10797
|
+
});
|
|
10798
|
+
if (prepared.dropped > 0) {
|
|
10799
|
+
notifyFeatureCap({
|
|
10800
|
+
layerId,
|
|
10801
|
+
layerName: layer.name,
|
|
10802
|
+
kept: prepared.features.length,
|
|
10803
|
+
dropped: prepared.dropped,
|
|
10804
|
+
sourceCount: prepared.sourceCount,
|
|
10805
|
+
max: featureCapRef.current,
|
|
10806
|
+
source: "api"
|
|
10807
|
+
});
|
|
10808
|
+
}
|
|
10619
10809
|
const layerHasTemporal = (((_a = layerTemporalCacheRef.current.get(layerId)) == null ? void 0 : _a.hasTemporal) ?? false) || prepared.hasTemporal;
|
|
10620
10810
|
const combined = [...existing, ...prepared.features];
|
|
10621
10811
|
readOnlyFeatures.current.set(layerId, combined);
|
|
@@ -10635,9 +10825,24 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
10635
10825
|
}
|
|
10636
10826
|
if (!draw.current) return [];
|
|
10637
10827
|
const addedIds = [];
|
|
10828
|
+
const cappedForDraw = capFeatures(features, {
|
|
10829
|
+
max: featureCapRef.current,
|
|
10830
|
+
existing: countExisting(layer)
|
|
10831
|
+
});
|
|
10832
|
+
if (cappedForDraw.dropped > 0) {
|
|
10833
|
+
notifyFeatureCap({
|
|
10834
|
+
layerId,
|
|
10835
|
+
layerName: layer.name,
|
|
10836
|
+
kept: cappedForDraw.features.length,
|
|
10837
|
+
dropped: cappedForDraw.dropped,
|
|
10838
|
+
sourceCount: cappedForDraw.sourceCount,
|
|
10839
|
+
max: featureCapRef.current,
|
|
10840
|
+
source: "api"
|
|
10841
|
+
});
|
|
10842
|
+
}
|
|
10638
10843
|
isApiAddingRef.current = true;
|
|
10639
10844
|
try {
|
|
10640
|
-
features.forEach((f) => {
|
|
10845
|
+
cappedForDraw.features.forEach((f) => {
|
|
10641
10846
|
const { startDate, endDate } = normalizeTemporalProperties(f.properties || {});
|
|
10642
10847
|
const normalizedFeature = {
|
|
10643
10848
|
...f,
|
|
@@ -10746,12 +10951,27 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
10746
10951
|
return { type: "FeatureCollection", features: cleanedFeatures };
|
|
10747
10952
|
},
|
|
10748
10953
|
importGeoJSON: (layerId, geojson) => {
|
|
10749
|
-
const layer =
|
|
10954
|
+
const layer = layersRef.current.find((l) => l.id === layerId);
|
|
10750
10955
|
if (!layer || !draw.current || !isMapLoaded) return [];
|
|
10751
10956
|
const addedIds = [];
|
|
10957
|
+
const capped = capFeatures(geojson.features, {
|
|
10958
|
+
max: featureCapRef.current,
|
|
10959
|
+
existing: countExisting(layer)
|
|
10960
|
+
});
|
|
10961
|
+
if (capped.dropped > 0) {
|
|
10962
|
+
notifyFeatureCap({
|
|
10963
|
+
layerId,
|
|
10964
|
+
layerName: layer.name,
|
|
10965
|
+
kept: capped.features.length,
|
|
10966
|
+
dropped: capped.dropped,
|
|
10967
|
+
sourceCount: capped.sourceCount,
|
|
10968
|
+
max: featureCapRef.current,
|
|
10969
|
+
source: "api"
|
|
10970
|
+
});
|
|
10971
|
+
}
|
|
10752
10972
|
isApiAddingRef.current = true;
|
|
10753
10973
|
try {
|
|
10754
|
-
|
|
10974
|
+
capped.features.forEach((f) => {
|
|
10755
10975
|
const { startDate, endDate } = normalizeTemporalProperties(f.properties || {});
|
|
10756
10976
|
const normalizedFeature = {
|
|
10757
10977
|
...f,
|
|
@@ -10855,9 +11075,20 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
10855
11075
|
updateReadOnlyLayer: (layerId, features) => {
|
|
10856
11076
|
const layer = layersRef.current.find((l) => l.id === layerId);
|
|
10857
11077
|
if (!layer || !layer.readOnly || !isMapLoadedRef.current) return false;
|
|
10858
|
-
const prepared = prepareFeaturesForLayer(features, "updateReadOnlyLayer");
|
|
11078
|
+
const prepared = prepareFeaturesForLayer(features, "updateReadOnlyLayer", { max: featureCapRef.current });
|
|
11079
|
+
if (prepared.dropped > 0) {
|
|
11080
|
+
notifyFeatureCap({
|
|
11081
|
+
layerId,
|
|
11082
|
+
layerName: layer.name,
|
|
11083
|
+
kept: prepared.features.length,
|
|
11084
|
+
dropped: prepared.dropped,
|
|
11085
|
+
sourceCount: prepared.sourceCount,
|
|
11086
|
+
max: featureCapRef.current,
|
|
11087
|
+
source: "api"
|
|
11088
|
+
});
|
|
11089
|
+
}
|
|
10859
11090
|
readOnlyFeatures.current.set(layerId, prepared.features);
|
|
10860
|
-
layerTemporalCacheRef.current.set(layerId, { featureCount: features.length, hasTemporal: prepared.hasTemporal });
|
|
11091
|
+
layerTemporalCacheRef.current.set(layerId, { featureCount: prepared.features.length, hasTemporal: prepared.hasTemporal });
|
|
10861
11092
|
if (prepared.hasTemporal) {
|
|
10862
11093
|
scheduleTimelineUpdate();
|
|
10863
11094
|
}
|
|
@@ -10873,9 +11104,20 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
10873
11104
|
},
|
|
10874
11105
|
setLayerData: (name, geojson, options) => {
|
|
10875
11106
|
if (!isMapLoadedRef.current) return "";
|
|
10876
|
-
const prepared = prepareFeaturesForLayer(geojson.features, "setLayerData");
|
|
11107
|
+
const prepared = prepareFeaturesForLayer(geojson.features, "setLayerData", { max: featureCapRef.current });
|
|
10877
11108
|
const newFeatureIds = prepared.featureIds;
|
|
10878
11109
|
const layerId = `managed-${name}`;
|
|
11110
|
+
if (prepared.dropped > 0) {
|
|
11111
|
+
notifyFeatureCap({
|
|
11112
|
+
layerId,
|
|
11113
|
+
layerName: name,
|
|
11114
|
+
kept: prepared.features.length,
|
|
11115
|
+
dropped: prepared.dropped,
|
|
11116
|
+
sourceCount: prepared.sourceCount,
|
|
11117
|
+
max: featureCapRef.current,
|
|
11118
|
+
source: "api"
|
|
11119
|
+
});
|
|
11120
|
+
}
|
|
10879
11121
|
readOnlyFeatures.current.set(layerId, prepared.features);
|
|
10880
11122
|
layerTemporalCacheRef.current.set(layerId, { featureCount: prepared.features.length, hasTemporal: prepared.hasTemporal });
|
|
10881
11123
|
const buildLayerObj = (existing) => {
|
|
@@ -10925,9 +11167,11 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
10925
11167
|
});
|
|
10926
11168
|
updateFeatureCount();
|
|
10927
11169
|
scheduleSync();
|
|
10928
|
-
if ((options == null ? void 0 : options.fitPadding) != null &&
|
|
11170
|
+
if ((options == null ? void 0 : options.fitPadding) != null && prepared.features.length > 0 && map.current) {
|
|
10929
11171
|
try {
|
|
10930
|
-
const bbox = turf__namespace.bbox(
|
|
11172
|
+
const bbox = turf__namespace.bbox(
|
|
11173
|
+
prepared.dropped > 0 ? { type: "FeatureCollection", features: prepared.features } : geojson
|
|
11174
|
+
);
|
|
10931
11175
|
if (bbox.every((v) => isFinite(v))) {
|
|
10932
11176
|
map.current.fitBounds(
|
|
10933
11177
|
[[bbox[0], bbox[1]], [bbox[2], bbox[3]]],
|
|
@@ -13242,9 +13486,11 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13242
13486
|
source.setData({ type: "FeatureCollection", features });
|
|
13243
13487
|
}
|
|
13244
13488
|
}, [measurePoints, measureMode, isMapLoaded]);
|
|
13245
|
-
const
|
|
13489
|
+
const [ingestProgressStore] = react.useState(createIngestProgressStore);
|
|
13490
|
+
const exportInFlightRef = react.useRef(false);
|
|
13491
|
+
const handleSaveLayerGeoJSON = react.useCallback(async (layerId) => {
|
|
13246
13492
|
const layer = layers.find((l) => l.id === layerId);
|
|
13247
|
-
if (!layer) return;
|
|
13493
|
+
if (!layer || exportInFlightRef.current) return;
|
|
13248
13494
|
const features = collectLayerFeatures(layer, {
|
|
13249
13495
|
getDrawFeature: (id) => {
|
|
13250
13496
|
var _a;
|
|
@@ -13259,17 +13505,30 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13259
13505
|
if (layer.traceConfig) layerMetadata.traceConfig = layer.traceConfig;
|
|
13260
13506
|
if (layer.heatmapConfig) layerMetadata.heatmapConfig = layer.heatmapConfig;
|
|
13261
13507
|
if (layer.visualConfig) layerMetadata.visualConfig = layer.visualConfig;
|
|
13262
|
-
const cleanedFeatures = stripInternalProperties(features);
|
|
13263
13508
|
const geojson = {
|
|
13264
13509
|
type: "FeatureCollection",
|
|
13265
|
-
features
|
|
13510
|
+
features,
|
|
13266
13511
|
properties: {
|
|
13267
13512
|
layerMetadata
|
|
13268
13513
|
}
|
|
13269
13514
|
};
|
|
13270
|
-
|
|
13271
|
-
|
|
13272
|
-
|
|
13515
|
+
exportInFlightRef.current = true;
|
|
13516
|
+
const progress = ingestProgressStore.begin(layer.name, { verb: "Preparing download" });
|
|
13517
|
+
progress.setTotal(features.length);
|
|
13518
|
+
try {
|
|
13519
|
+
const parts = await featureCollectionBlobPartsAsync(geojson, {
|
|
13520
|
+
mapFeature: (f) => stripInternalPropertiesFromFeature(f),
|
|
13521
|
+
onProgress: (done) => progress.update(done)
|
|
13522
|
+
});
|
|
13523
|
+
downloadBlob(
|
|
13524
|
+
new Blob(parts, { type: "application/json" }),
|
|
13525
|
+
`${layer.name.replace(/[^a-z0-9]/gi, "_")}.geojson`
|
|
13526
|
+
);
|
|
13527
|
+
} finally {
|
|
13528
|
+
progress.end();
|
|
13529
|
+
exportInFlightRef.current = false;
|
|
13530
|
+
}
|
|
13531
|
+
}, [layers, ingestProgressStore]);
|
|
13273
13532
|
const handleLoadLayerGeoJSON = react.useCallback((layerId) => {
|
|
13274
13533
|
const input = fileInputRef.current;
|
|
13275
13534
|
if (!input) return;
|
|
@@ -13284,7 +13543,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13284
13543
|
input.dataset.createNewLayer = "true";
|
|
13285
13544
|
input.click();
|
|
13286
13545
|
}, []);
|
|
13287
|
-
const
|
|
13546
|
+
const buildEnrichedExport = react.useCallback(() => {
|
|
13288
13547
|
const allFeatures = [];
|
|
13289
13548
|
const layerStates = [];
|
|
13290
13549
|
layers.forEach((layer, idx) => {
|
|
@@ -13309,7 +13568,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13309
13568
|
const { id: _id, featureIds: _fids, hasAltitudeData: _alt, ...persistable } = layer;
|
|
13310
13569
|
layerStates.push({ index: idx, ...persistable });
|
|
13311
13570
|
});
|
|
13312
|
-
const
|
|
13571
|
+
const rawCount = allFeatures.length;
|
|
13313
13572
|
let viewport;
|
|
13314
13573
|
if (map.current && isMapLoaded) {
|
|
13315
13574
|
const c = map.current.getCenter();
|
|
@@ -13325,17 +13584,35 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13325
13584
|
...hostState
|
|
13326
13585
|
};
|
|
13327
13586
|
return {
|
|
13328
|
-
|
|
13329
|
-
|
|
13330
|
-
|
|
13587
|
+
collection: {
|
|
13588
|
+
type: "FeatureCollection",
|
|
13589
|
+
features: [...allFeatures, ...extraFeatures],
|
|
13590
|
+
"octostar:map": octostarMap
|
|
13591
|
+
},
|
|
13592
|
+
mapFeature: (feature, index) => index < rawCount ? stripInternalPropertiesFromFeature(feature, ENRICHED_EXPORT_KEEP_KEYS) : feature
|
|
13331
13593
|
};
|
|
13332
13594
|
}, [layers, isMapLoaded, getAdditionalSaveState]);
|
|
13333
|
-
const
|
|
13334
|
-
|
|
13335
|
-
|
|
13336
|
-
|
|
13337
|
-
|
|
13338
|
-
|
|
13595
|
+
const buildEnrichedGeoJSON = react.useCallback(() => {
|
|
13596
|
+
const { collection, mapFeature } = buildEnrichedExport();
|
|
13597
|
+
return { ...collection, features: collection.features.map(mapFeature) };
|
|
13598
|
+
}, [buildEnrichedExport]);
|
|
13599
|
+
const handleSaveAllGeoJSON = react.useCallback(async () => {
|
|
13600
|
+
if (!draw.current || exportInFlightRef.current) return;
|
|
13601
|
+
const { collection, mapFeature } = buildEnrichedExport();
|
|
13602
|
+
exportInFlightRef.current = true;
|
|
13603
|
+
const progress = ingestProgressStore.begin("map_export.geojson", { verb: "Preparing download" });
|
|
13604
|
+
progress.setTotal(collection.features.length);
|
|
13605
|
+
try {
|
|
13606
|
+
const parts = await featureCollectionBlobPartsAsync(collection, {
|
|
13607
|
+
mapFeature,
|
|
13608
|
+
onProgress: (done) => progress.update(done)
|
|
13609
|
+
});
|
|
13610
|
+
downloadBlob(new Blob(parts, { type: "application/geo+json" }), "map_export.geojson");
|
|
13611
|
+
} finally {
|
|
13612
|
+
progress.end();
|
|
13613
|
+
exportInFlightRef.current = false;
|
|
13614
|
+
}
|
|
13615
|
+
}, [buildEnrichedExport, ingestProgressStore]);
|
|
13339
13616
|
const handleSearchAndAddToNewLayer = react.useCallback(async () => {
|
|
13340
13617
|
if (!onSearchEngineRequest || !map.current || !draw.current) return;
|
|
13341
13618
|
const mapInstance = map.current;
|
|
@@ -13368,10 +13645,16 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13368
13645
|
});
|
|
13369
13646
|
if (result && result.features && result.features.length > 0) {
|
|
13370
13647
|
saveStateForUndo();
|
|
13648
|
+
const activeId = activeEditingLayerIdRef.current;
|
|
13649
|
+
const activeLayer = activeId ? layersRef.current.find((l) => l.id === activeId && !l.readOnly) : null;
|
|
13650
|
+
const capped = capFeatures(result.features, {
|
|
13651
|
+
max: featureCapRef.current,
|
|
13652
|
+
existing: activeLayer ? countExisting(activeLayer) : 0
|
|
13653
|
+
});
|
|
13371
13654
|
const addedIds = [];
|
|
13372
13655
|
isApiAddingRef.current = true;
|
|
13373
13656
|
try {
|
|
13374
|
-
|
|
13657
|
+
capped.features.forEach((f) => {
|
|
13375
13658
|
const { startDate, endDate } = normalizeTemporalProperties(f.properties || {});
|
|
13376
13659
|
const normalizedFeature = {
|
|
13377
13660
|
...f,
|
|
@@ -13387,17 +13670,19 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13387
13670
|
} finally {
|
|
13388
13671
|
isApiAddingRef.current = false;
|
|
13389
13672
|
}
|
|
13390
|
-
|
|
13391
|
-
|
|
13673
|
+
let targetLayerId;
|
|
13674
|
+
let targetLayerName;
|
|
13392
13675
|
if (activeLayer) {
|
|
13393
13676
|
activeLayer.featureIds = [...activeLayer.featureIds, ...addedIds];
|
|
13394
13677
|
setLayers([...layersRef.current]);
|
|
13678
|
+
targetLayerId = activeLayer.id;
|
|
13679
|
+
targetLayerName = activeLayer.name;
|
|
13395
13680
|
toast({
|
|
13396
13681
|
title: "Features added",
|
|
13397
|
-
description: `Added ${
|
|
13682
|
+
description: `Added ${addedIds.length} features to "${activeLayer.name}"`
|
|
13398
13683
|
});
|
|
13399
13684
|
} else {
|
|
13400
|
-
const layerName = `${
|
|
13685
|
+
const layerName = `${addedIds.length} workspace features`;
|
|
13401
13686
|
const newLayerId = `layer-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
13402
13687
|
const newLayer = {
|
|
13403
13688
|
id: newLayerId,
|
|
@@ -13408,9 +13693,22 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13408
13693
|
layersRef.current = [...layersRef.current, newLayer];
|
|
13409
13694
|
setLayers(layersRef.current);
|
|
13410
13695
|
setActiveEditingLayerId(newLayerId);
|
|
13696
|
+
targetLayerId = newLayerId;
|
|
13697
|
+
targetLayerName = layerName;
|
|
13411
13698
|
toast({
|
|
13412
13699
|
title: "Layer created",
|
|
13413
|
-
description: `Added ${
|
|
13700
|
+
description: `Added ${addedIds.length} features to "${layerName}"`
|
|
13701
|
+
});
|
|
13702
|
+
}
|
|
13703
|
+
if (capped.dropped > 0) {
|
|
13704
|
+
notifyFeatureCap({
|
|
13705
|
+
layerId: targetLayerId,
|
|
13706
|
+
layerName: targetLayerName,
|
|
13707
|
+
kept: addedIds.length,
|
|
13708
|
+
dropped: capped.dropped,
|
|
13709
|
+
sourceCount: capped.sourceCount,
|
|
13710
|
+
max: featureCapRef.current,
|
|
13711
|
+
source: "search"
|
|
13414
13712
|
});
|
|
13415
13713
|
}
|
|
13416
13714
|
updateFeatureCount();
|
|
@@ -13424,7 +13722,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13424
13722
|
variant: "destructive"
|
|
13425
13723
|
});
|
|
13426
13724
|
}
|
|
13427
|
-
}, [onSearchEngineRequest, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, toast]);
|
|
13725
|
+
}, [onSearchEngineRequest, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, toast, notifyFeatureCap]);
|
|
13428
13726
|
const restoreEnrichedGeoJSON = react.useCallback((enriched) => {
|
|
13429
13727
|
var _a;
|
|
13430
13728
|
const mapState = enriched["octostar:map"];
|
|
@@ -13447,9 +13745,22 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13447
13745
|
});
|
|
13448
13746
|
const sortedLayers = [...mapState.layers].sort((a, b) => a.index - b.index);
|
|
13449
13747
|
const newLayers = [];
|
|
13748
|
+
let restoreDropped = 0;
|
|
13749
|
+
let restoreSourceCount = 0;
|
|
13750
|
+
let restoreKept = 0;
|
|
13751
|
+
let truncatedLayerCount = 0;
|
|
13752
|
+
let firstTruncatedLayer = "";
|
|
13450
13753
|
for (const ls of sortedLayers) {
|
|
13451
13754
|
if (((_a = ls.metadata) == null ? void 0 : _a.dataViewing) === true) continue;
|
|
13452
|
-
const
|
|
13755
|
+
const capped = capFeatures(featuresByIndex.get(ls.index) ?? [], { max: featureCapRef.current });
|
|
13756
|
+
const rawFeatures = capped.features;
|
|
13757
|
+
if (capped.dropped > 0) {
|
|
13758
|
+
restoreDropped += capped.dropped;
|
|
13759
|
+
restoreSourceCount += capped.sourceCount;
|
|
13760
|
+
restoreKept += rawFeatures.length;
|
|
13761
|
+
truncatedLayerCount += 1;
|
|
13762
|
+
if (!firstTruncatedLayer) firstTruncatedLayer = ls.name;
|
|
13763
|
+
}
|
|
13453
13764
|
const normalized = rawFeatures.map((f) => {
|
|
13454
13765
|
const cleanProps = Object.fromEntries(
|
|
13455
13766
|
Object.entries(f.properties || {}).filter(([k]) => !k.startsWith("_"))
|
|
@@ -13511,7 +13822,18 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13511
13822
|
title: "Map restored",
|
|
13512
13823
|
description: `Restored ${newLayers.length} layers with ${totalFeatures} features`
|
|
13513
13824
|
});
|
|
13514
|
-
|
|
13825
|
+
if (restoreDropped > 0) {
|
|
13826
|
+
notifyFeatureCap({
|
|
13827
|
+
layerName: firstTruncatedLayer,
|
|
13828
|
+
kept: restoreKept,
|
|
13829
|
+
dropped: restoreDropped,
|
|
13830
|
+
sourceCount: restoreSourceCount,
|
|
13831
|
+
max: featureCapRef.current,
|
|
13832
|
+
source: "restore",
|
|
13833
|
+
layerCount: truncatedLayerCount
|
|
13834
|
+
});
|
|
13835
|
+
}
|
|
13836
|
+
}, [saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, onMapStateLoaded, toast, notifyFeatureCap]);
|
|
13515
13837
|
restoreEnrichedGeoJSONRef.current = restoreEnrichedGeoJSON;
|
|
13516
13838
|
const handleWorkspaceLoad = react.useCallback(async () => {
|
|
13517
13839
|
if (!onWorkspaceLoad) return;
|
|
@@ -13524,12 +13846,24 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13524
13846
|
}
|
|
13525
13847
|
saveStateForUndo();
|
|
13526
13848
|
const layerId = `layer-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
13527
|
-
const
|
|
13849
|
+
const layerName = "Loaded from workspace";
|
|
13850
|
+
const prepared = prepareFeaturesForLayer(result.features, "workspaceLoad", { max: featureCapRef.current });
|
|
13851
|
+
if (prepared.dropped > 0) {
|
|
13852
|
+
notifyFeatureCap({
|
|
13853
|
+
layerId,
|
|
13854
|
+
layerName,
|
|
13855
|
+
kept: prepared.features.length,
|
|
13856
|
+
dropped: prepared.dropped,
|
|
13857
|
+
sourceCount: prepared.sourceCount,
|
|
13858
|
+
max: featureCapRef.current,
|
|
13859
|
+
source: "workspace"
|
|
13860
|
+
});
|
|
13861
|
+
}
|
|
13528
13862
|
readOnlyFeatures.current.set(layerId, prepared.features);
|
|
13529
13863
|
layerTemporalCacheRef.current.set(layerId, { featureCount: prepared.features.length, hasTemporal: prepared.hasTemporal });
|
|
13530
13864
|
const newLayer = {
|
|
13531
13865
|
id: layerId,
|
|
13532
|
-
name:
|
|
13866
|
+
name: layerName,
|
|
13533
13867
|
visible: true,
|
|
13534
13868
|
featureIds: prepared.featureIds,
|
|
13535
13869
|
readOnly: true
|
|
@@ -13627,20 +13961,23 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13627
13961
|
duration: 1e3
|
|
13628
13962
|
});
|
|
13629
13963
|
}, [layers, toast]);
|
|
13630
|
-
const [ingestProgressStore] = react.useState(createIngestProgressStore);
|
|
13631
13964
|
const ingestWithProgress = react.useCallback(async (label, input, options) => {
|
|
13632
13965
|
const progress = ingestProgressStore.begin(label);
|
|
13633
13966
|
try {
|
|
13634
|
-
return await getSharedIngestClient().ingest(
|
|
13635
|
-
|
|
13636
|
-
|
|
13637
|
-
|
|
13967
|
+
return await getSharedIngestClient().ingest(
|
|
13968
|
+
input,
|
|
13969
|
+
{ ...options, maxFeatures: featureCapRef.current },
|
|
13970
|
+
{
|
|
13971
|
+
onHead: (summary) => progress.setTotal(summary.featureCount),
|
|
13972
|
+
onProgress: (received) => progress.update(received)
|
|
13973
|
+
}
|
|
13974
|
+
);
|
|
13638
13975
|
} finally {
|
|
13639
13976
|
progress.end();
|
|
13640
13977
|
}
|
|
13641
13978
|
}, [ingestProgressStore]);
|
|
13642
13979
|
const loadGeoJSONFile = react.useCallback(async (file, requestedTargetLayerId, createNewLayer) => {
|
|
13643
|
-
var _a;
|
|
13980
|
+
var _a, _b, _c;
|
|
13644
13981
|
let result;
|
|
13645
13982
|
try {
|
|
13646
13983
|
result = await ingestWithProgress(file.name, file, {
|
|
@@ -13690,7 +14027,8 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13690
14027
|
data: { type: "FeatureCollection", features: normalizedFeatures },
|
|
13691
14028
|
file,
|
|
13692
14029
|
reprojected,
|
|
13693
|
-
sourceCRS: sourceCRS ?? void 0
|
|
14030
|
+
sourceCRS: sourceCRS ?? void 0,
|
|
14031
|
+
...result.truncated && { truncated: result.truncated }
|
|
13694
14032
|
}) === true) {
|
|
13695
14033
|
return;
|
|
13696
14034
|
}
|
|
@@ -13710,6 +14048,17 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13710
14048
|
readOnlyFeatures.current.set(layerId, normalizedFeatures);
|
|
13711
14049
|
layerTemporalCacheRef.current.set(layerId, { featureCount: normalizedFeatures.length, hasTemporal: fileHasTemporal });
|
|
13712
14050
|
newLayer.featureIds = addedIds;
|
|
14051
|
+
if (result.truncated) {
|
|
14052
|
+
notifyFeatureCap({
|
|
14053
|
+
layerId,
|
|
14054
|
+
layerName: newLayer.name,
|
|
14055
|
+
kept: normalizedFeatures.length,
|
|
14056
|
+
dropped: result.truncated.droppedCount,
|
|
14057
|
+
sourceCount: result.truncated.sourceFeatureCount,
|
|
14058
|
+
max: result.truncated.maxFeatures,
|
|
14059
|
+
source: "file"
|
|
14060
|
+
});
|
|
14061
|
+
}
|
|
13713
14062
|
setLayers((prev) => [...prev, newLayer]);
|
|
13714
14063
|
updateFeatureCount();
|
|
13715
14064
|
scheduleTimelineUpdate();
|
|
@@ -13753,6 +14102,23 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13753
14102
|
return;
|
|
13754
14103
|
}
|
|
13755
14104
|
const targetId = targetLayer.id;
|
|
14105
|
+
const appendCapped = capFeatures(normalizedFeatures, {
|
|
14106
|
+
max: featureCapRef.current,
|
|
14107
|
+
existing: countExisting(targetLayer)
|
|
14108
|
+
});
|
|
14109
|
+
const appendFeatures = appendCapped.features;
|
|
14110
|
+
const totalDropped = (((_b = result.truncated) == null ? void 0 : _b.droppedCount) ?? 0) + appendCapped.dropped;
|
|
14111
|
+
if (totalDropped > 0) {
|
|
14112
|
+
notifyFeatureCap({
|
|
14113
|
+
layerId: targetId,
|
|
14114
|
+
layerName: targetLayer.name,
|
|
14115
|
+
kept: appendFeatures.length,
|
|
14116
|
+
dropped: totalDropped,
|
|
14117
|
+
sourceCount: ((_c = result.truncated) == null ? void 0 : _c.sourceFeatureCount) ?? appendCapped.sourceCount,
|
|
14118
|
+
max: featureCapRef.current,
|
|
14119
|
+
source: "file"
|
|
14120
|
+
});
|
|
14121
|
+
}
|
|
13756
14122
|
const withLayerMetadata = (l, addedIds) => ({
|
|
13757
14123
|
...l,
|
|
13758
14124
|
featureIds: [...l.featureIds, ...addedIds],
|
|
@@ -13761,7 +14127,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13761
14127
|
...(layerMetadata == null ? void 0 : layerMetadata.visualConfig) && { visualConfig: layerMetadata.visualConfig }
|
|
13762
14128
|
});
|
|
13763
14129
|
if (targetLayer.readOnly) {
|
|
13764
|
-
const addedFeatures =
|
|
14130
|
+
const addedFeatures = appendFeatures.map((f) => ({ ...f, id: crypto.randomUUID() }));
|
|
13765
14131
|
const addedIds = addedFeatures.map((f) => String(f.id));
|
|
13766
14132
|
const existing = readOnlyFeatures.current.get(targetId) || [];
|
|
13767
14133
|
readOnlyFeatures.current.set(targetId, [...existing, ...addedFeatures]);
|
|
@@ -13775,7 +14141,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13775
14141
|
const addedIds = [];
|
|
13776
14142
|
isApiAddingRef.current = true;
|
|
13777
14143
|
try {
|
|
13778
|
-
|
|
14144
|
+
appendFeatures.forEach((f) => {
|
|
13779
14145
|
const ids = draw.current.add(f);
|
|
13780
14146
|
addedIds.push(ids[0]);
|
|
13781
14147
|
});
|
|
@@ -13784,9 +14150,9 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13784
14150
|
}
|
|
13785
14151
|
setLayers((prev) => prev.map((l) => l.id === targetId ? withLayerMetadata(l, addedIds) : l));
|
|
13786
14152
|
} else {
|
|
13787
|
-
const addedIds =
|
|
14153
|
+
const addedIds = appendFeatures.map((f) => String(f.id));
|
|
13788
14154
|
const existing = hiddenFeatures.current.get(targetId) || [];
|
|
13789
|
-
hiddenFeatures.current.set(targetId, [...existing, ...
|
|
14155
|
+
hiddenFeatures.current.set(targetId, [...existing, ...appendFeatures]);
|
|
13790
14156
|
setLayers((prev) => prev.map((l) => l.id === targetId ? withLayerMetadata(l, addedIds) : l));
|
|
13791
14157
|
}
|
|
13792
14158
|
updateFeatureCount();
|
|
@@ -13795,9 +14161,9 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13795
14161
|
const reprojectMsg = reprojected ? ` (reprojected from ${sourceCRS})` : "";
|
|
13796
14162
|
toast({
|
|
13797
14163
|
title: "GeoJSON loaded",
|
|
13798
|
-
description: `Added ${
|
|
14164
|
+
description: `Added ${appendFeatures.length} features${reprojectMsg}${!(targetLayer == null ? void 0 : targetLayer.visible) ? " (layer hidden)" : ""}`
|
|
13799
14165
|
});
|
|
13800
|
-
}, [saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, restoreEnrichedGeoJSON, toast, interceptGeoJSONFileLoad, ingestWithProgress]);
|
|
14166
|
+
}, [saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, restoreEnrichedGeoJSON, toast, interceptGeoJSONFileLoad, ingestWithProgress, notifyFeatureCap]);
|
|
13801
14167
|
const handleFileChange = react.useCallback((e) => {
|
|
13802
14168
|
var _a;
|
|
13803
14169
|
const file = (_a = e.target.files) == null ? void 0 : _a[0];
|
|
@@ -13859,6 +14225,17 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13859
14225
|
readOnlyFeatures.current.set(layerId, normalizedFeatures);
|
|
13860
14226
|
layerTemporalCacheRef.current.set(layerId, { featureCount: normalizedFeatures.length, hasTemporal: result.hasTemporal });
|
|
13861
14227
|
newLayer.featureIds = addedIds;
|
|
14228
|
+
if (result.truncated) {
|
|
14229
|
+
notifyFeatureCap({
|
|
14230
|
+
layerId,
|
|
14231
|
+
layerName: newLayer.name,
|
|
14232
|
+
kept: normalizedFeatures.length,
|
|
14233
|
+
dropped: result.truncated.droppedCount,
|
|
14234
|
+
sourceCount: result.truncated.sourceFeatureCount,
|
|
14235
|
+
max: result.truncated.maxFeatures,
|
|
14236
|
+
source: "drop"
|
|
14237
|
+
});
|
|
14238
|
+
}
|
|
13862
14239
|
const nextLayers = [...layersRef.current, newLayer];
|
|
13863
14240
|
layersRef.current = nextLayers;
|
|
13864
14241
|
setLayers(nextLayers);
|
|
@@ -13881,7 +14258,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13881
14258
|
title: "Layer added",
|
|
13882
14259
|
description: `Created "${newLayer.name}" with ${addedIds.length} features${reprojectMsg} (high-performance)`
|
|
13883
14260
|
});
|
|
13884
|
-
}, [saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, restoreEnrichedGeoJSON, toast, interceptGeoJSONFileLoad, ingestWithProgress]);
|
|
14261
|
+
}, [saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, restoreEnrichedGeoJSON, toast, interceptGeoJSONFileLoad, ingestWithProgress, notifyFeatureCap]);
|
|
13885
14262
|
const handleDropGeoJSON = react.useCallback((name, data) => {
|
|
13886
14263
|
void ingestDroppedLayer(name, data);
|
|
13887
14264
|
}, [ingestDroppedLayer]);
|
|
@@ -15871,6 +16248,7 @@ function DebugSidebar({ onAddRandomPoints, onImportKML, onAddDomMarkers, onRemov
|
|
|
15871
16248
|
exports.ActionPanel = ActionPanel;
|
|
15872
16249
|
exports.ClusterPieManager = ClusterPieManager;
|
|
15873
16250
|
exports.ColorPickerPopover = ColorPickerPopover;
|
|
16251
|
+
exports.DEFAULT_MAX_FEATURES_PER_LAYER = DEFAULT_MAX_FEATURES_PER_LAYER;
|
|
15874
16252
|
exports.DebugSidebar = DebugSidebar;
|
|
15875
16253
|
exports.DrawingToolbar = DrawingToolbar;
|
|
15876
16254
|
exports.INTERNAL_PROPERTY_KEYS = INTERNAL_PROPERTY_KEYS;
|
|
@@ -15889,6 +16267,7 @@ exports.Timebar = Timebar;
|
|
|
15889
16267
|
exports.TimebarToggle = TimebarToggle;
|
|
15890
16268
|
exports.cn = cn;
|
|
15891
16269
|
exports.createClusterPieManager = createClusterPieManager;
|
|
16270
|
+
exports.featureCollectionBlobPartsAsync = featureCollectionBlobPartsAsync;
|
|
15892
16271
|
exports.getIconEmoji = getIconEmoji;
|
|
15893
16272
|
exports.isFeatureInRange = isFeatureInRange;
|
|
15894
16273
|
exports.isInternalProperty = isInternalProperty;
|