@octostar/map-component 0.2.12 → 0.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1422 -644
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +1418 -640
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +5 -0
- package/dist/types/components/cursor-coordinates-overlay.d.ts +13 -0
- package/dist/types/components/cursor-coordinates-overlay.d.ts.map +1 -0
- package/dist/types/components/debug-sidebar.d.ts.map +1 -1
- package/dist/types/components/ingest-progress-overlay.d.ts +12 -0
- package/dist/types/components/ingest-progress-overlay.d.ts.map +1 -0
- package/dist/types/components/map-drop-zone.d.ts +7 -1
- package/dist/types/components/map-drop-zone.d.ts.map +1 -1
- package/dist/types/components/map-editor-canvas.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/draw-render-gate.d.ts +10 -0
- package/dist/types/lib/draw-render-gate.d.ts.map +1 -0
- package/dist/types/lib/geojson-crs.d.ts +10 -0
- package/dist/types/lib/geojson-crs.d.ts.map +1 -0
- package/dist/types/lib/geojson-reproject.d.ts +15 -0
- package/dist/types/lib/geojson-reproject.d.ts.map +1 -0
- package/dist/types/lib/geojson-serialize.d.ts +21 -0
- package/dist/types/lib/geojson-serialize.d.ts.map +1 -0
- package/dist/types/lib/ingest-client.d.ts +43 -0
- package/dist/types/lib/ingest-client.d.ts.map +1 -0
- package/dist/types/lib/ingest-pipeline.d.ts +125 -0
- package/dist/types/lib/ingest-pipeline.d.ts.map +1 -0
- package/dist/types/lib/ingest-progress.d.ts +21 -0
- package/dist/types/lib/ingest-progress.d.ts.map +1 -0
- package/dist/types/lib/ingest-stream.d.ts +50 -0
- package/dist/types/lib/ingest-stream.d.ts.map +1 -0
- package/dist/types/lib/ingest.worker.d.ts +2 -0
- package/dist/types/lib/ingest.worker.d.ts.map +1 -0
- package/dist/types/lib/map-editor-api.d.ts +18 -0
- package/dist/types/lib/map-editor-api.d.ts.map +1 -1
- package/dist/types/lib/perf-log.d.ts +3 -0
- package/dist/types/lib/perf-log.d.ts.map +1 -0
- package/dist/types/lib/selection-diff.d.ts +24 -1
- package/dist/types/lib/selection-diff.d.ts.map +1 -1
- package/dist/types/lib/selection-hit-test.d.ts +25 -14
- package/dist/types/lib/selection-hit-test.d.ts.map +1 -1
- package/dist/types/lib/selection-spatial-index.d.ts +63 -0
- package/dist/types/lib/selection-spatial-index.d.ts.map +1 -0
- package/dist/types/lib/temporal-ingest.d.ts +53 -0
- package/dist/types/lib/temporal-ingest.d.ts.map +1 -0
- package/dist/types/lib/temporal-normalize.d.ts +11 -0
- package/dist/types/lib/temporal-normalize.d.ts.map +1 -0
- package/dist/types/lib/timeline-diff.d.ts +43 -0
- package/dist/types/lib/timeline-diff.d.ts.map +1 -0
- package/dist/types/lib/timeline-store.d.ts +1 -9
- package/dist/types/lib/timeline-store.d.ts.map +1 -1
- package/package.json +6 -4
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { jsxs,
|
|
2
|
-
import { useState, useCallback, useMemo, createContext, useContext, useRef,
|
|
1
|
+
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect, useSyncExternalStore, useCallback, useMemo, createContext, useContext, useRef, forwardRef, useImperativeHandle } from "react";
|
|
3
3
|
import maplibregl from "maplibre-gl";
|
|
4
4
|
import MapboxDraw from "@mapbox/mapbox-gl-draw";
|
|
5
5
|
import * as turf from "@turf/turf";
|
|
6
|
-
import proj4 from "proj4";
|
|
7
6
|
import * as THREE from "three";
|
|
7
|
+
import proj4 from "proj4";
|
|
8
8
|
import { Button, Modal, Input, App, message, Tooltip, Dropdown, Divider, Popover, Switch, Slider, Tag, Select, Collapse, ColorPicker, Tabs, Card, Table, DatePicker } from "antd";
|
|
9
9
|
import { clsx } from "clsx";
|
|
10
10
|
import { twMerge } from "tailwind-merge";
|
|
@@ -12,8 +12,699 @@ import { MousePointer2, Square, Hexagon, Circle, MoreVertical, ChevronDown, Filt
|
|
|
12
12
|
import { createPortal } from "react-dom";
|
|
13
13
|
import { format } from "date-fns";
|
|
14
14
|
import { useStore, createStore } from "zustand";
|
|
15
|
+
import Flatbush from "flatbush";
|
|
15
16
|
import dayjs from "dayjs";
|
|
16
17
|
import * as toGeoJSON from "@mapbox/togeojson";
|
|
18
|
+
function detectSourceCRS(geojson) {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
const crsName = (_b = (_a = geojson.crs) == null ? void 0 : _a.properties) == null ? void 0 : _b.name;
|
|
21
|
+
let sourceCRS = null;
|
|
22
|
+
if (crsName) {
|
|
23
|
+
const epsgMatch = crsName.match(/EPSG::?(\d+)/i);
|
|
24
|
+
if (epsgMatch) sourceCRS = `EPSG:${epsgMatch[1]}`;
|
|
25
|
+
}
|
|
26
|
+
if (!sourceCRS && geojson.features.length > 0) {
|
|
27
|
+
const firstCoord = getFirstCoordinate(geojson.features[0].geometry);
|
|
28
|
+
if (firstCoord) {
|
|
29
|
+
const [x, y] = firstCoord;
|
|
30
|
+
if (Math.abs(x) <= 180 && Math.abs(y) <= 90) {
|
|
31
|
+
return { sourceCRS: "EPSG:4326", needsReprojection: false };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return { sourceCRS: null, needsReprojection: false };
|
|
35
|
+
}
|
|
36
|
+
return { sourceCRS, needsReprojection: sourceCRS !== null && sourceCRS !== "EPSG:4326" };
|
|
37
|
+
}
|
|
38
|
+
function getFirstCoordinate(geometry) {
|
|
39
|
+
var _a, _b, _c;
|
|
40
|
+
if (!geometry) return null;
|
|
41
|
+
switch (geometry.type) {
|
|
42
|
+
case "Point":
|
|
43
|
+
return geometry.coordinates;
|
|
44
|
+
case "MultiPoint":
|
|
45
|
+
case "LineString":
|
|
46
|
+
return geometry.coordinates[0];
|
|
47
|
+
case "MultiLineString":
|
|
48
|
+
case "Polygon":
|
|
49
|
+
return (_a = geometry.coordinates[0]) == null ? void 0 : _a[0];
|
|
50
|
+
case "MultiPolygon":
|
|
51
|
+
return (_c = (_b = geometry.coordinates[0]) == null ? void 0 : _b[0]) == null ? void 0 : _c[0];
|
|
52
|
+
default:
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function hasAltitudeData(feature) {
|
|
57
|
+
var _a, _b;
|
|
58
|
+
if (((_a = feature.geometry) == null ? void 0 : _a.type) === "LineString") {
|
|
59
|
+
const coords = feature.geometry.coordinates;
|
|
60
|
+
return coords.some((c) => c.length >= 3 && c[2] !== 0);
|
|
61
|
+
}
|
|
62
|
+
if (((_b = feature.geometry) == null ? void 0 : _b.type) === "MultiLineString") {
|
|
63
|
+
const coords = feature.geometry.coordinates;
|
|
64
|
+
return coords.some((line) => line.some((c) => c.length >= 3 && c[2] !== 0));
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
const PRETTY_EXPORT_MAX_FEATURES = 1e4;
|
|
69
|
+
const TARGET_PART_CHARS = 8 * 1024 * 1024;
|
|
70
|
+
function featureCollectionBlobParts(collection, options) {
|
|
71
|
+
const prettyMax = PRETTY_EXPORT_MAX_FEATURES;
|
|
72
|
+
if (collection.features.length <= prettyMax) {
|
|
73
|
+
return [JSON.stringify(collection, null, 2)];
|
|
74
|
+
}
|
|
75
|
+
const targetChars = TARGET_PART_CHARS;
|
|
76
|
+
const { features, ...rest } = collection;
|
|
77
|
+
const head = JSON.stringify(rest);
|
|
78
|
+
const parts = [];
|
|
79
|
+
let pending = [];
|
|
80
|
+
let pendingChars = 0;
|
|
81
|
+
const push = (piece) => {
|
|
82
|
+
pending.push(piece);
|
|
83
|
+
pendingChars += piece.length;
|
|
84
|
+
if (pendingChars >= targetChars) {
|
|
85
|
+
parts.push(pending.join(""));
|
|
86
|
+
pending = [];
|
|
87
|
+
pendingChars = 0;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
push(head.slice(0, -1));
|
|
91
|
+
push(head.length > 2 ? ',"features":[' : '"features":[');
|
|
92
|
+
for (let i = 0; i < features.length; i++) {
|
|
93
|
+
push(i === 0 ? JSON.stringify(features[i]) : "," + JSON.stringify(features[i]));
|
|
94
|
+
}
|
|
95
|
+
push("]}");
|
|
96
|
+
if (pending.length > 0) parts.push(pending.join(""));
|
|
97
|
+
return parts;
|
|
98
|
+
}
|
|
99
|
+
const ingestWorkerSource = '"use strict";(()=>{function p(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=w(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 w(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 S(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 i(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 b(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 I(e){let t=i(e.startDate)||i(e.startdate)||i(e.start_date)||i(e.start_time)||i(e.date)||i(e.timestamp)||i(e.flightDate)||i(e.time)||i(e.datetime),n=i(e.endDate)||i(e.enddate)||i(e.end_date)||i(e.end_time);return t&&n&&n<t&&([t,n]=[n,t]),{startDate:t,endDate:n}}function h(e){return"kind"in e&&e.kind==="ack"}function J(){let e=globalThis.crypto?.randomUUID?.bind(globalThis.crypto);return e?e():`f-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function D(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):J()}}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 M(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 x(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}=p(n),a=!1,o=!1,u=[];n.features.forEach((d,G)=>{let m=D(d,G,t);!o&&S(d)&&(o=!0);let g=d.properties||{};if(!b(g)){u.push(t.idStrategy==="preserve"?d:{...d,id:m});return}let{startDate:y,endDate:k}=I(g);(y||k)&&(a=!0),u.push({...d,...m!==void 0&&{id:m},properties:{...g,startDate:y?.toISOString()||null,endDate:k?.toISOString()||null}})});let c=n.properties?.layerMetadata;return{kind:"features",features:u,featureCount:u.length,bbox:M(u),hasTemporal:a,hasAltitude:o,reprojected:!1,sourceCRS:r,...s&&{needsReprojection:s},...c&&{layerMetadata:c}}}var O=5e3;function P(e,t){let n=Number.isNaN(t)?O: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 A(e){for(let t=0;t<e.length;t++)if(!f(e[t]))return e;try{return JSON.stringify(e)}catch{return e}}function E(e){let{kind:t,features:n,...r}=e;return r}async function N(e,t,n,r){let s;try{s=x(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??A,o=P(s.features,r.chunkSize??O);r.post({kind:"head",id:e,summary:E(s)});let u=o.length>0?a(o[0]):null;for(let c=0;c<o.length;c++){let d=r.waitAck(c);r.post({kind:"chunk",id:e,seq:c,payload:u}),u=c+1<o.length?a(o[c+1]):null,await d}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 F=e=>self.postMessage(e),l=new Map;self.onmessage=async e=>{let t=e.data;if(h(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 N(n,o,s,{post:F,waitAck:u=>new Promise(c=>{l.set(`${n}:${u}`,c)}),...a?.chunkSize!==void 0&&{chunkSize:a.chunkSize},...a?.featureArrayChunks&&{encode:u=>u}})}catch(o){F({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';
|
|
100
|
+
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");
|
|
101
|
+
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");
|
|
102
|
+
proj4.defs("EPSG:32630", "+proj=utm +zone=30 +datum=WGS84 +units=m +no_defs");
|
|
103
|
+
proj4.defs("EPSG:32631", "+proj=utm +zone=31 +datum=WGS84 +units=m +no_defs");
|
|
104
|
+
function reprojectFeatures(features, sourceCRS) {
|
|
105
|
+
if (!proj4.defs(sourceCRS)) return null;
|
|
106
|
+
try {
|
|
107
|
+
return features.map((feature) => ({
|
|
108
|
+
...feature,
|
|
109
|
+
geometry: reprojectGeometry(feature.geometry, sourceCRS)
|
|
110
|
+
}));
|
|
111
|
+
} catch (e) {
|
|
112
|
+
console.error("Reprojection failed:", e);
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function reprojectGeometry(geometry, fromCRS) {
|
|
117
|
+
if (!geometry) return geometry;
|
|
118
|
+
const transform = (coord) => {
|
|
119
|
+
const [x, y] = proj4(fromCRS, "EPSG:4326", [coord[0], coord[1]]);
|
|
120
|
+
return coord.length > 2 ? [x, y, ...coord.slice(2)] : [x, y];
|
|
121
|
+
};
|
|
122
|
+
const reprojectCoords = (coords) => {
|
|
123
|
+
if (typeof coords[0] === "number") {
|
|
124
|
+
return transform(coords);
|
|
125
|
+
}
|
|
126
|
+
return coords.map(reprojectCoords);
|
|
127
|
+
};
|
|
128
|
+
if (geometry.type === "GeometryCollection") {
|
|
129
|
+
return {
|
|
130
|
+
type: "GeometryCollection",
|
|
131
|
+
geometries: geometry.geometries.map((g) => reprojectGeometry(g, fromCRS))
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
const geomWithCoords = geometry;
|
|
135
|
+
return {
|
|
136
|
+
...geomWithCoords,
|
|
137
|
+
coordinates: reprojectCoords(geomWithCoords.coordinates)
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function parseDate(value) {
|
|
141
|
+
if (!value) return null;
|
|
142
|
+
if (value instanceof Date) return value;
|
|
143
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
144
|
+
const date = new Date(value);
|
|
145
|
+
return isNaN(date.getTime()) ? null : date;
|
|
146
|
+
}
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
function hasAnyTemporalValue(properties) {
|
|
150
|
+
return !!(properties.startDate || properties.startdate || properties.start_date || properties.start_time || properties.date || properties.timestamp || properties.flightDate || properties.time || properties.datetime || properties.endDate || properties.enddate || properties.end_date || properties.end_time);
|
|
151
|
+
}
|
|
152
|
+
function normalizeTemporalProperties(properties) {
|
|
153
|
+
let startDate = parseDate(properties.startDate) || parseDate(properties.startdate) || parseDate(properties.start_date) || parseDate(properties.start_time) || parseDate(properties.date) || parseDate(properties.timestamp) || parseDate(properties.flightDate) || parseDate(properties.time) || parseDate(properties.datetime);
|
|
154
|
+
let endDate = parseDate(properties.endDate) || parseDate(properties.enddate) || parseDate(properties.end_date) || parseDate(properties.end_time);
|
|
155
|
+
if (startDate && endDate && endDate < startDate) {
|
|
156
|
+
[startDate, endDate] = [endDate, startDate];
|
|
157
|
+
}
|
|
158
|
+
return { startDate, endDate };
|
|
159
|
+
}
|
|
160
|
+
function generateUuid() {
|
|
161
|
+
var _a, _b;
|
|
162
|
+
const uuid = (_b = (_a = globalThis.crypto) == null ? void 0 : _a.randomUUID) == null ? void 0 : _b.bind(globalThis.crypto);
|
|
163
|
+
return uuid ? uuid() : `f-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
|
|
164
|
+
}
|
|
165
|
+
function assignId(feature, index, options) {
|
|
166
|
+
switch (options.idStrategy) {
|
|
167
|
+
case "preserve":
|
|
168
|
+
return feature.id;
|
|
169
|
+
case "layer-index":
|
|
170
|
+
return feature.id !== void 0 && feature.id !== null ? String(feature.id) : `${options.layerId}-f${index}`;
|
|
171
|
+
case "uuid-fallback":
|
|
172
|
+
return feature.id ? String(feature.id) : generateUuid();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function scanCoords(coords, box) {
|
|
176
|
+
if (!Array.isArray(coords)) return;
|
|
177
|
+
if (typeof coords[0] === "number") {
|
|
178
|
+
const x = coords[0];
|
|
179
|
+
const y = coords[1];
|
|
180
|
+
box[0] = Math.min(box[0], x);
|
|
181
|
+
box[1] = Math.min(box[1], y);
|
|
182
|
+
box[2] = Math.max(box[2], x);
|
|
183
|
+
box[3] = Math.max(box[3], y);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
for (const c of coords) scanCoords(c, box);
|
|
187
|
+
}
|
|
188
|
+
function scanGeometry(geometry, box) {
|
|
189
|
+
if (!geometry) return;
|
|
190
|
+
if (geometry.type === "GeometryCollection") {
|
|
191
|
+
for (const g of geometry.geometries) scanGeometry(g, box);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
scanCoords(geometry.coordinates, box);
|
|
195
|
+
}
|
|
196
|
+
function computeFeatureCollectionBbox(features) {
|
|
197
|
+
const box = [Infinity, Infinity, -Infinity, -Infinity];
|
|
198
|
+
for (const f of features) scanGeometry(f.geometry, box);
|
|
199
|
+
return box.every((v) => isFinite(v)) ? box : null;
|
|
200
|
+
}
|
|
201
|
+
function runIngestPipeline(source, options) {
|
|
202
|
+
var _a;
|
|
203
|
+
let data;
|
|
204
|
+
if (source.type === "text") {
|
|
205
|
+
try {
|
|
206
|
+
data = JSON.parse(source.text);
|
|
207
|
+
} catch (err) {
|
|
208
|
+
return {
|
|
209
|
+
kind: "error",
|
|
210
|
+
code: "parse-error",
|
|
211
|
+
message: err instanceof Error ? err.message : "Invalid file"
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
data = source.data;
|
|
216
|
+
}
|
|
217
|
+
if (data && data.type === "Feature") {
|
|
218
|
+
data = {
|
|
219
|
+
type: "FeatureCollection",
|
|
220
|
+
features: [data]
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
if (!data || data.type !== "FeatureCollection" || !Array.isArray(data.features)) {
|
|
224
|
+
return { kind: "error", code: "invalid-format", message: "Invalid GeoJSON format" };
|
|
225
|
+
}
|
|
226
|
+
if (options.emptyIsError && data.features.length === 0) {
|
|
227
|
+
return { kind: "error", code: "empty", message: "The file contains no features" };
|
|
228
|
+
}
|
|
229
|
+
if (data["octostar:map"]) {
|
|
230
|
+
return { kind: "enriched", data };
|
|
231
|
+
}
|
|
232
|
+
const { sourceCRS, needsReprojection } = detectSourceCRS(data);
|
|
233
|
+
let hasTemporal = false;
|
|
234
|
+
let hasAltitude = false;
|
|
235
|
+
const features = [];
|
|
236
|
+
data.features.forEach((f, index) => {
|
|
237
|
+
const id = assignId(f, index, options);
|
|
238
|
+
if (!hasAltitude && hasAltitudeData(f)) hasAltitude = true;
|
|
239
|
+
const props = f.properties || {};
|
|
240
|
+
if (!hasAnyTemporalValue(props)) {
|
|
241
|
+
features.push(options.idStrategy === "preserve" ? f : { ...f, id });
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
const { startDate, endDate } = normalizeTemporalProperties(props);
|
|
245
|
+
if (startDate || endDate) hasTemporal = true;
|
|
246
|
+
features.push({
|
|
247
|
+
...f,
|
|
248
|
+
// Omit the key rather than set `id: undefined` ('preserve' + id-less
|
|
249
|
+
// feature): an own undefined key survives structured clone but is
|
|
250
|
+
// dropped by JSON chunks, so it would make the transfer encoding
|
|
251
|
+
// observable. Never undefined for the other strategies.
|
|
252
|
+
...id !== void 0 && { id },
|
|
253
|
+
properties: {
|
|
254
|
+
...props,
|
|
255
|
+
startDate: (startDate == null ? void 0 : startDate.toISOString()) || null,
|
|
256
|
+
endDate: (endDate == null ? void 0 : endDate.toISOString()) || null
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
const layerMetadata = (_a = data.properties) == null ? void 0 : _a.layerMetadata;
|
|
261
|
+
return {
|
|
262
|
+
kind: "features",
|
|
263
|
+
features,
|
|
264
|
+
featureCount: features.length,
|
|
265
|
+
bbox: computeFeatureCollectionBbox(features),
|
|
266
|
+
hasTemporal,
|
|
267
|
+
hasAltitude,
|
|
268
|
+
reprojected: false,
|
|
269
|
+
sourceCRS,
|
|
270
|
+
...needsReprojection && { needsReprojection },
|
|
271
|
+
...layerMetadata && { layerMetadata }
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
function decodeChunkPayload(payload) {
|
|
275
|
+
return typeof payload === "string" ? JSON.parse(payload) : payload;
|
|
276
|
+
}
|
|
277
|
+
const fromStorage = (() => {
|
|
278
|
+
var _a;
|
|
279
|
+
try {
|
|
280
|
+
return ((_a = globalThis.localStorage) == null ? void 0 : _a.getItem("octostar-map-perf-log")) === "1";
|
|
281
|
+
} catch {
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
})();
|
|
285
|
+
function mapPerfLogEnabled() {
|
|
286
|
+
return fromStorage || globalThis.__octostarMapPerfLog === true;
|
|
287
|
+
}
|
|
288
|
+
function mapPerfLog(area, message2, data) {
|
|
289
|
+
if (!mapPerfLogEnabled()) return;
|
|
290
|
+
if (data === void 0) {
|
|
291
|
+
console.info(`[map-perf:${area}] ${message2}`);
|
|
292
|
+
} else {
|
|
293
|
+
console.info(`[map-perf:${area}] ${message2}`, data);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
function finalizeReprojection(result) {
|
|
297
|
+
if (result.kind !== "features" || !result.needsReprojection || !result.sourceCRS) return result;
|
|
298
|
+
const reprojected = reprojectFeatures(result.features, result.sourceCRS);
|
|
299
|
+
if (!reprojected) {
|
|
300
|
+
return { ...result, needsReprojection: false };
|
|
301
|
+
}
|
|
302
|
+
return {
|
|
303
|
+
...result,
|
|
304
|
+
features: reprojected,
|
|
305
|
+
reprojected: true,
|
|
306
|
+
needsReprojection: false,
|
|
307
|
+
bbox: computeFeatureCollectionBbox(reprojected)
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
function createWorkerPort() {
|
|
311
|
+
if (typeof Worker === "undefined") {
|
|
312
|
+
mapPerfLog("ingest", "Worker unavailable in this environment — using main-thread pipeline");
|
|
313
|
+
return null;
|
|
314
|
+
}
|
|
315
|
+
let url = null;
|
|
316
|
+
try {
|
|
317
|
+
url = URL.createObjectURL(new Blob([ingestWorkerSource], { type: "text/javascript" }));
|
|
318
|
+
const worker = new Worker(url);
|
|
319
|
+
let pendingUrl = url;
|
|
320
|
+
const revokePendingUrl = () => {
|
|
321
|
+
if (pendingUrl) URL.revokeObjectURL(pendingUrl);
|
|
322
|
+
pendingUrl = null;
|
|
323
|
+
};
|
|
324
|
+
mapPerfLog("ingest", "worker spawned");
|
|
325
|
+
return {
|
|
326
|
+
post: (msg) => worker.postMessage(msg),
|
|
327
|
+
onMessage: (cb) => {
|
|
328
|
+
worker.onmessage = (e) => {
|
|
329
|
+
revokePendingUrl();
|
|
330
|
+
cb(e.data);
|
|
331
|
+
};
|
|
332
|
+
},
|
|
333
|
+
onError: (cb) => {
|
|
334
|
+
worker.onerror = (e) => {
|
|
335
|
+
revokePendingUrl();
|
|
336
|
+
cb(e);
|
|
337
|
+
};
|
|
338
|
+
worker.onmessageerror = (e) => cb(e);
|
|
339
|
+
},
|
|
340
|
+
terminate: () => {
|
|
341
|
+
revokePendingUrl();
|
|
342
|
+
worker.terminate();
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
} catch (err) {
|
|
346
|
+
if (url) URL.revokeObjectURL(url);
|
|
347
|
+
console.warn(
|
|
348
|
+
"[map-component] Ingest worker could not be spawned (CSP may block blob: workers); file parsing will run on the main thread.",
|
|
349
|
+
err
|
|
350
|
+
);
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
const INGEST_STALL_TIMEOUT_MS = 12e4;
|
|
355
|
+
function assembleStreamResult(stream) {
|
|
356
|
+
return finalizeReprojection({ kind: "features", ...stream.summary, features: stream.features });
|
|
357
|
+
}
|
|
358
|
+
function createIngestClient(portFactory = createWorkerPort) {
|
|
359
|
+
let port = null;
|
|
360
|
+
let portUnavailable = false;
|
|
361
|
+
let nextId = 0;
|
|
362
|
+
const pending = /* @__PURE__ */ new Map();
|
|
363
|
+
const rejectAllPending = (reason) => {
|
|
364
|
+
pending.forEach((request) => {
|
|
365
|
+
clearTimeout(request.timeout);
|
|
366
|
+
request.reject(new Error(reason));
|
|
367
|
+
});
|
|
368
|
+
pending.clear();
|
|
369
|
+
};
|
|
370
|
+
const abandonPort = (reason) => {
|
|
371
|
+
rejectAllPending(reason);
|
|
372
|
+
port == null ? void 0 : port.terminate();
|
|
373
|
+
port = null;
|
|
374
|
+
};
|
|
375
|
+
const armWatchdog = (request) => {
|
|
376
|
+
clearTimeout(request.timeout);
|
|
377
|
+
request.timeout = setTimeout(() => {
|
|
378
|
+
console.warn(
|
|
379
|
+
`[map-component] Ingest worker unresponsive for "${request.label}" after ${INGEST_STALL_TIMEOUT_MS}ms; it will be respawned on next use.`
|
|
380
|
+
);
|
|
381
|
+
abandonPort("Ingest worker unresponsive — the file could not be parsed");
|
|
382
|
+
}, INGEST_STALL_TIMEOUT_MS);
|
|
383
|
+
};
|
|
384
|
+
const callHook = (request, invoke) => {
|
|
385
|
+
if (!request.hooks) return;
|
|
386
|
+
try {
|
|
387
|
+
invoke(request.hooks);
|
|
388
|
+
} catch (err) {
|
|
389
|
+
console.warn("[map-component] Ingest stream hook threw; progress reporting disabled for this request.", err);
|
|
390
|
+
request.hooks = void 0;
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
const settle = (id, request) => {
|
|
394
|
+
pending.delete(id);
|
|
395
|
+
clearTimeout(request.timeout);
|
|
396
|
+
};
|
|
397
|
+
const handleChunk = (activePort, request, msg) => {
|
|
398
|
+
const stream = request.stream;
|
|
399
|
+
if (!stream || msg.seq !== stream.nextSeq) {
|
|
400
|
+
abandonPort("Ingest worker sent an out-of-order chunk");
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
armWatchdog(request);
|
|
404
|
+
const features = decodeChunkPayload(msg.payload);
|
|
405
|
+
features.forEach((f) => stream.features.push(f));
|
|
406
|
+
stream.nextSeq += 1;
|
|
407
|
+
callHook(request, (hooks) => {
|
|
408
|
+
var _a;
|
|
409
|
+
return (_a = hooks.onProgress) == null ? void 0 : _a.call(hooks, stream.features.length, stream.summary.featureCount);
|
|
410
|
+
});
|
|
411
|
+
activePort.post({ kind: "ack", id: msg.id, seq: msg.seq });
|
|
412
|
+
};
|
|
413
|
+
const handleMessage = (activePort, msg) => {
|
|
414
|
+
const request = pending.get(msg.id);
|
|
415
|
+
if (!request) return;
|
|
416
|
+
switch (msg.kind) {
|
|
417
|
+
case "result": {
|
|
418
|
+
if (request.stream) {
|
|
419
|
+
abandonPort("Ingest worker sent a single-shot result mid-stream");
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
if (!msg.ok) {
|
|
423
|
+
settle(msg.id, request);
|
|
424
|
+
mapPerfLog("ingest", `worker request "${request.label}" finished`, {
|
|
425
|
+
ms: Math.round(performance.now() - request.startedAt),
|
|
426
|
+
ok: false
|
|
427
|
+
});
|
|
428
|
+
request.reject(new Error(msg.error));
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
let finalized;
|
|
432
|
+
try {
|
|
433
|
+
finalized = finalizeReprojection(msg.result);
|
|
434
|
+
} catch (err) {
|
|
435
|
+
settle(msg.id, request);
|
|
436
|
+
request.reject(err instanceof Error ? err : new Error(String(err)));
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
settle(msg.id, request);
|
|
440
|
+
mapPerfLog("ingest", `worker request "${request.label}" finished`, {
|
|
441
|
+
ms: Math.round(performance.now() - request.startedAt),
|
|
442
|
+
ok: true
|
|
443
|
+
});
|
|
444
|
+
request.resolve(finalized);
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
case "head":
|
|
448
|
+
if (request.stream) {
|
|
449
|
+
abandonPort("Ingest worker restarted a stream mid-request");
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
armWatchdog(request);
|
|
453
|
+
request.stream = {
|
|
454
|
+
summary: msg.summary,
|
|
455
|
+
features: [],
|
|
456
|
+
nextSeq: 0
|
|
457
|
+
};
|
|
458
|
+
callHook(request, (hooks) => {
|
|
459
|
+
var _a;
|
|
460
|
+
return (_a = hooks.onHead) == null ? void 0 : _a.call(hooks, msg.summary);
|
|
461
|
+
});
|
|
462
|
+
return;
|
|
463
|
+
case "chunk":
|
|
464
|
+
try {
|
|
465
|
+
handleChunk(activePort, request, msg);
|
|
466
|
+
} catch (err) {
|
|
467
|
+
console.warn("[map-component] Ingest chunk could not be processed; abandoning the worker.", err);
|
|
468
|
+
abandonPort("Ingest worker sent an unreadable chunk");
|
|
469
|
+
}
|
|
470
|
+
return;
|
|
471
|
+
case "done": {
|
|
472
|
+
const stream = request.stream;
|
|
473
|
+
if (!stream) {
|
|
474
|
+
abandonPort("Ingest worker completed a stream that never started");
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
if (msg.chunkCount !== stream.nextSeq) {
|
|
478
|
+
abandonPort("Ingest worker stream ended with missing chunks");
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
let assembled;
|
|
482
|
+
try {
|
|
483
|
+
assembled = assembleStreamResult(stream);
|
|
484
|
+
} catch (err) {
|
|
485
|
+
settle(msg.id, request);
|
|
486
|
+
request.reject(err instanceof Error ? err : new Error(String(err)));
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
settle(msg.id, request);
|
|
490
|
+
mapPerfLog("ingest", `worker request "${request.label}" streamed`, {
|
|
491
|
+
ms: Math.round(performance.now() - request.startedAt),
|
|
492
|
+
features: stream.features.length,
|
|
493
|
+
chunks: msg.chunkCount
|
|
494
|
+
});
|
|
495
|
+
request.resolve(assembled);
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
case "error":
|
|
499
|
+
settle(msg.id, request);
|
|
500
|
+
mapPerfLog("ingest", `worker request "${request.label}" failed mid-stream`, {
|
|
501
|
+
ms: Math.round(performance.now() - request.startedAt)
|
|
502
|
+
});
|
|
503
|
+
request.reject(new Error(msg.message));
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
const ensurePort = () => {
|
|
508
|
+
if (portUnavailable || port) return port;
|
|
509
|
+
try {
|
|
510
|
+
port = portFactory();
|
|
511
|
+
} catch {
|
|
512
|
+
port = null;
|
|
513
|
+
}
|
|
514
|
+
if (!port) {
|
|
515
|
+
portUnavailable = true;
|
|
516
|
+
return null;
|
|
517
|
+
}
|
|
518
|
+
const activePort = port;
|
|
519
|
+
activePort.onMessage((msg) => handleMessage(activePort, msg));
|
|
520
|
+
activePort.onError((err) => {
|
|
521
|
+
console.warn("[map-component] Ingest worker crashed; it will be respawned on next use.", err);
|
|
522
|
+
abandonPort("Ingest worker crashed");
|
|
523
|
+
});
|
|
524
|
+
return port;
|
|
525
|
+
};
|
|
526
|
+
const runInline = async (input, options) => {
|
|
527
|
+
const text = typeof input === "string" ? input : await input.text();
|
|
528
|
+
const startedAt = performance.now();
|
|
529
|
+
const result = finalizeReprojection(runIngestPipeline({ type: "text", text }, options));
|
|
530
|
+
mapPerfLog("ingest", "main-thread pipeline finished (no worker)", {
|
|
531
|
+
ms: Math.round(performance.now() - startedAt)
|
|
532
|
+
});
|
|
533
|
+
return result;
|
|
534
|
+
};
|
|
535
|
+
return {
|
|
536
|
+
ingest(input, options, stream, tuning) {
|
|
537
|
+
if (typeof input === "object" && !(input instanceof Blob)) {
|
|
538
|
+
return Promise.resolve().then(
|
|
539
|
+
() => finalizeReprojection(runIngestPipeline({ type: "parsed", data: input }, options))
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
const activePort = ensurePort();
|
|
543
|
+
if (!activePort) return runInline(input, options);
|
|
544
|
+
const id = nextId++;
|
|
545
|
+
const label = input instanceof File ? input.name : typeof input === "string" ? "text" : "blob";
|
|
546
|
+
return new Promise((resolve, reject) => {
|
|
547
|
+
const request = {
|
|
548
|
+
resolve,
|
|
549
|
+
reject,
|
|
550
|
+
startedAt: performance.now(),
|
|
551
|
+
label,
|
|
552
|
+
hooks: stream
|
|
553
|
+
};
|
|
554
|
+
armWatchdog(request);
|
|
555
|
+
pending.set(id, request);
|
|
556
|
+
try {
|
|
557
|
+
activePort.post({
|
|
558
|
+
id,
|
|
559
|
+
source: typeof input === "string" ? { type: "text", text: input } : { type: "blob", blob: input },
|
|
560
|
+
options,
|
|
561
|
+
...tuning && { tuning }
|
|
562
|
+
});
|
|
563
|
+
} catch (err) {
|
|
564
|
+
settle(id, request);
|
|
565
|
+
throw err;
|
|
566
|
+
}
|
|
567
|
+
});
|
|
568
|
+
},
|
|
569
|
+
dispose() {
|
|
570
|
+
abandonPort("Ingest client disposed");
|
|
571
|
+
portUnavailable = false;
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
let sharedClient = null;
|
|
576
|
+
function getSharedIngestClient() {
|
|
577
|
+
if (!sharedClient) sharedClient = createIngestClient();
|
|
578
|
+
return sharedClient;
|
|
579
|
+
}
|
|
580
|
+
function createIngestProgressStore() {
|
|
581
|
+
const entries = /* @__PURE__ */ new Map();
|
|
582
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
583
|
+
let nextId = 0;
|
|
584
|
+
let snapshot = [];
|
|
585
|
+
let dirty = false;
|
|
586
|
+
const notify = () => {
|
|
587
|
+
dirty = true;
|
|
588
|
+
listeners.forEach((listener) => listener());
|
|
589
|
+
};
|
|
590
|
+
return {
|
|
591
|
+
begin(label) {
|
|
592
|
+
const id = nextId++;
|
|
593
|
+
entries.set(id, { label, received: 0, total: null });
|
|
594
|
+
notify();
|
|
595
|
+
return {
|
|
596
|
+
setTotal(total) {
|
|
597
|
+
const entry = entries.get(id);
|
|
598
|
+
if (!entry || entry.total === total) return;
|
|
599
|
+
entry.total = total;
|
|
600
|
+
notify();
|
|
601
|
+
},
|
|
602
|
+
update(received) {
|
|
603
|
+
const entry = entries.get(id);
|
|
604
|
+
if (!entry || entry.received === received) return;
|
|
605
|
+
entry.received = received;
|
|
606
|
+
notify();
|
|
607
|
+
},
|
|
608
|
+
end() {
|
|
609
|
+
if (entries.delete(id)) notify();
|
|
610
|
+
}
|
|
611
|
+
};
|
|
612
|
+
},
|
|
613
|
+
subscribe(listener) {
|
|
614
|
+
listeners.add(listener);
|
|
615
|
+
return () => listeners.delete(listener);
|
|
616
|
+
},
|
|
617
|
+
getSnapshot() {
|
|
618
|
+
if (dirty) {
|
|
619
|
+
const next = [];
|
|
620
|
+
entries.forEach((entry, id) => next.push({ id, ...entry }));
|
|
621
|
+
snapshot = next;
|
|
622
|
+
dirty = false;
|
|
623
|
+
}
|
|
624
|
+
return snapshot;
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
function CursorCoordinatesOverlay({ map }) {
|
|
629
|
+
const [coords, setCoords] = useState(null);
|
|
630
|
+
useEffect(() => {
|
|
631
|
+
if (!map) return;
|
|
632
|
+
let pending = null;
|
|
633
|
+
let frame = 0;
|
|
634
|
+
const flush = () => {
|
|
635
|
+
frame = 0;
|
|
636
|
+
setCoords(pending);
|
|
637
|
+
};
|
|
638
|
+
const schedule = (next) => {
|
|
639
|
+
pending = next;
|
|
640
|
+
if (!frame) frame = requestAnimationFrame(flush);
|
|
641
|
+
};
|
|
642
|
+
const onMove = (e) => schedule({ lng: e.lngLat.lng, lat: e.lngLat.lat });
|
|
643
|
+
const onOut = () => schedule(null);
|
|
644
|
+
map.on("mousemove", onMove);
|
|
645
|
+
map.on("mouseout", onOut);
|
|
646
|
+
return () => {
|
|
647
|
+
if (frame) cancelAnimationFrame(frame);
|
|
648
|
+
try {
|
|
649
|
+
map.off("mousemove", onMove);
|
|
650
|
+
map.off("mouseout", onOut);
|
|
651
|
+
} catch {
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
}, [map]);
|
|
655
|
+
if (!coords) return null;
|
|
656
|
+
return /* @__PURE__ */ jsxs(
|
|
657
|
+
"div",
|
|
658
|
+
{
|
|
659
|
+
className: "absolute bottom-1 right-12 z-10 pointer-events-none font-mono text-[10px] text-muted-foreground/70 select-none",
|
|
660
|
+
"data-testid": "cursor-coordinates",
|
|
661
|
+
children: [
|
|
662
|
+
coords.lat.toFixed(5),
|
|
663
|
+
", ",
|
|
664
|
+
coords.lng.toFixed(5)
|
|
665
|
+
]
|
|
666
|
+
}
|
|
667
|
+
);
|
|
668
|
+
}
|
|
669
|
+
const NO_IMPORTS = Object.freeze([]);
|
|
670
|
+
const getServerSnapshot = () => NO_IMPORTS;
|
|
671
|
+
function IngestProgressOverlay({
|
|
672
|
+
store,
|
|
673
|
+
bottomPx
|
|
674
|
+
}) {
|
|
675
|
+
const entries = useSyncExternalStore(store.subscribe, store.getSnapshot, getServerSnapshot);
|
|
676
|
+
if (entries.length === 0) return null;
|
|
677
|
+
return /* @__PURE__ */ jsx(
|
|
678
|
+
"div",
|
|
679
|
+
{
|
|
680
|
+
className: "absolute left-1/2 z-10 flex -translate-x-1/2 flex-col gap-1 pointer-events-none",
|
|
681
|
+
style: { bottom: bottomPx },
|
|
682
|
+
"data-testid": "ingest-progress",
|
|
683
|
+
children: entries.map((entry) => /* @__PURE__ */ jsxs(
|
|
684
|
+
"div",
|
|
685
|
+
{
|
|
686
|
+
className: "rounded-md border bg-background/90 px-3 py-1.5 text-xs text-muted-foreground shadow-md",
|
|
687
|
+
children: [
|
|
688
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
689
|
+
"Importing ",
|
|
690
|
+
entry.label,
|
|
691
|
+
"…",
|
|
692
|
+
entry.total !== null ? ` ${entry.received.toLocaleString()} / ${entry.total.toLocaleString()} features` : ""
|
|
693
|
+
] }),
|
|
694
|
+
entry.total !== null && entry.total > 0 && /* @__PURE__ */ jsx("div", { className: "mt-1 h-1 w-48 overflow-hidden rounded bg-muted", children: /* @__PURE__ */ jsx(
|
|
695
|
+
"div",
|
|
696
|
+
{
|
|
697
|
+
className: "h-full bg-primary",
|
|
698
|
+
style: { width: `${Math.min(100, entry.received / entry.total * 100)}%` }
|
|
699
|
+
}
|
|
700
|
+
) })
|
|
701
|
+
]
|
|
702
|
+
},
|
|
703
|
+
entry.id
|
|
704
|
+
))
|
|
705
|
+
}
|
|
706
|
+
);
|
|
707
|
+
}
|
|
17
708
|
const ICONS = [
|
|
18
709
|
// Location & Places
|
|
19
710
|
{ id: "map-pin", emoji: "📍", name: "Map Pin", category: "places" },
|
|
@@ -4503,26 +5194,6 @@ function StatusIndicator({ featureCount, selectedCount = 0 }) {
|
|
|
4503
5194
|
}
|
|
4504
5195
|
);
|
|
4505
5196
|
}
|
|
4506
|
-
function parseDate(value) {
|
|
4507
|
-
if (!value) return null;
|
|
4508
|
-
if (value instanceof Date) return value;
|
|
4509
|
-
if (typeof value === "string" || typeof value === "number") {
|
|
4510
|
-
const date = new Date(value);
|
|
4511
|
-
return isNaN(date.getTime()) ? null : date;
|
|
4512
|
-
}
|
|
4513
|
-
return null;
|
|
4514
|
-
}
|
|
4515
|
-
function hasAnyTemporalValue(properties) {
|
|
4516
|
-
return !!(properties.startDate || properties.startdate || properties.start_date || properties.start_time || properties.date || properties.timestamp || properties.flightDate || properties.time || properties.datetime || properties.endDate || properties.enddate || properties.end_date || properties.end_time);
|
|
4517
|
-
}
|
|
4518
|
-
function normalizeTemporalProperties(properties) {
|
|
4519
|
-
let startDate = parseDate(properties.startDate) || parseDate(properties.startdate) || parseDate(properties.start_date) || parseDate(properties.start_time) || parseDate(properties.date) || parseDate(properties.timestamp) || parseDate(properties.flightDate) || parseDate(properties.time) || parseDate(properties.datetime);
|
|
4520
|
-
let endDate = parseDate(properties.endDate) || parseDate(properties.enddate) || parseDate(properties.end_date) || parseDate(properties.end_time);
|
|
4521
|
-
if (startDate && endDate && endDate < startDate) {
|
|
4522
|
-
[startDate, endDate] = [endDate, startDate];
|
|
4523
|
-
}
|
|
4524
|
-
return { startDate, endDate };
|
|
4525
|
-
}
|
|
4526
5197
|
function isFeatureInRange(feature, rangeStart, rangeEnd) {
|
|
4527
5198
|
if (!feature.startDate && !feature.endDate) return true;
|
|
4528
5199
|
if (!rangeStart || !rangeEnd) return true;
|
|
@@ -4616,7 +5287,8 @@ const timelineStoreInitializer = (set, get) => ({
|
|
|
4616
5287
|
const computedMax = maxDate;
|
|
4617
5288
|
const sameFeatureIds = state.temporalFeatures.length === timedFeatures.length && timedFeatures.every((f, i) => f.id === state.temporalFeatures[i].id);
|
|
4618
5289
|
const sameDates = ((_a = state.globalMinDate) == null ? void 0 : _a.getTime()) === (computedMin == null ? void 0 : computedMin.getTime()) && ((_b = state.globalMaxDate) == null ? void 0 : _b.getTime()) === (computedMax == null ? void 0 : computedMax.getTime());
|
|
4619
|
-
|
|
5290
|
+
const sameUntimed = state.untimedFeatureIds.length === untimedIds.length && untimedIds.every((id, i) => id === state.untimedFeatureIds[i]);
|
|
5291
|
+
if (sameFeatureIds && sameDates && sameUntimed && state.hasTemporalData) return;
|
|
4620
5292
|
const histogramBins = minDate && maxDate ? computeHistogramBins(timedFeatures, minDate, maxDate) : [];
|
|
4621
5293
|
set({
|
|
4622
5294
|
hasTemporalData: true,
|
|
@@ -5141,7 +5813,7 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
|
|
|
5141
5813
|
}
|
|
5142
5814
|
);
|
|
5143
5815
|
}
|
|
5144
|
-
function MapDropZone({ onDrop, children }) {
|
|
5816
|
+
function MapDropZone({ onDrop, onDropFile, children }) {
|
|
5145
5817
|
const [isDragOver, setIsDragOver] = useState(false);
|
|
5146
5818
|
const handleDragOver = useCallback((e) => {
|
|
5147
5819
|
e.preventDefault();
|
|
@@ -5176,13 +5848,17 @@ function MapDropZone({ onDrop, children }) {
|
|
|
5176
5848
|
for (let i = 0; i < files.length; i++) {
|
|
5177
5849
|
const file = files[i];
|
|
5178
5850
|
if (!file.name.match(/\.(geojson|json)$/i)) continue;
|
|
5851
|
+
const name = file.name.replace(/\.(geojson|json)$/i, "");
|
|
5852
|
+
if (onDropFile) {
|
|
5853
|
+
onDropFile(name, file);
|
|
5854
|
+
continue;
|
|
5855
|
+
}
|
|
5179
5856
|
const reader = new FileReader();
|
|
5180
5857
|
reader.onload = (evt) => {
|
|
5181
5858
|
var _a;
|
|
5182
5859
|
try {
|
|
5183
5860
|
const parsed = JSON.parse((_a = evt.target) == null ? void 0 : _a.result);
|
|
5184
5861
|
if (parsed.type === "FeatureCollection" && Array.isArray(parsed.features)) {
|
|
5185
|
-
const name = file.name.replace(/\.(geojson|json)$/i, "");
|
|
5186
5862
|
onDrop(name, parsed);
|
|
5187
5863
|
}
|
|
5188
5864
|
} catch (err) {
|
|
@@ -5192,7 +5868,7 @@ function MapDropZone({ onDrop, children }) {
|
|
|
5192
5868
|
reader.readAsText(file);
|
|
5193
5869
|
}
|
|
5194
5870
|
}
|
|
5195
|
-
}, [onDrop]);
|
|
5871
|
+
}, [onDrop, onDropFile]);
|
|
5196
5872
|
return /* @__PURE__ */ jsxs(
|
|
5197
5873
|
"div",
|
|
5198
5874
|
{
|
|
@@ -5430,15 +6106,20 @@ function createRafCoalescer(run, scheduler = rafScheduler) {
|
|
|
5430
6106
|
};
|
|
5431
6107
|
}
|
|
5432
6108
|
const DEFAULT_LABEL_PRIORITY = 100;
|
|
6109
|
+
const DEFAULT_VISIBLE_STROKE_OPACITY = 1;
|
|
6110
|
+
const DEFAULT_VISIBLE_FILL_OPACITY = 0.2;
|
|
5433
6111
|
function createSelectionPaintCache() {
|
|
5434
6112
|
return {
|
|
5435
6113
|
presentIds: /* @__PURE__ */ new Set(),
|
|
5436
6114
|
appliedSelectedIds: /* @__PURE__ */ new Set(),
|
|
5437
6115
|
basePriorityById: /* @__PURE__ */ new Map(),
|
|
6116
|
+
appliedHiddenIds: /* @__PURE__ */ new Set(),
|
|
6117
|
+
visibleStrokeOpacityById: /* @__PURE__ */ new Map(),
|
|
6118
|
+
visibleFillOpacityById: /* @__PURE__ */ new Map(),
|
|
5438
6119
|
updatable: true
|
|
5439
6120
|
};
|
|
5440
6121
|
}
|
|
5441
|
-
function recordPaintedFeature(cache, featureId, basePriority, isSelected) {
|
|
6122
|
+
function recordPaintedFeature(cache, featureId, basePriority, isSelected, visibleStrokeOpacity, visibleFillOpacity, isTimelineHidden) {
|
|
5442
6123
|
if (cache.presentIds.has(featureId)) {
|
|
5443
6124
|
cache.updatable = false;
|
|
5444
6125
|
} else {
|
|
@@ -5446,6 +6127,13 @@ function recordPaintedFeature(cache, featureId, basePriority, isSelected) {
|
|
|
5446
6127
|
}
|
|
5447
6128
|
cache.basePriorityById.set(featureId, basePriority);
|
|
5448
6129
|
if (isSelected) cache.appliedSelectedIds.add(featureId);
|
|
6130
|
+
if (visibleStrokeOpacity !== DEFAULT_VISIBLE_STROKE_OPACITY) {
|
|
6131
|
+
cache.visibleStrokeOpacityById.set(featureId, visibleStrokeOpacity);
|
|
6132
|
+
}
|
|
6133
|
+
if (visibleFillOpacity !== DEFAULT_VISIBLE_FILL_OPACITY) {
|
|
6134
|
+
cache.visibleFillOpacityById.set(featureId, visibleFillOpacity);
|
|
6135
|
+
}
|
|
6136
|
+
if (isTimelineHidden) cache.appliedHiddenIds.add(featureId);
|
|
5449
6137
|
}
|
|
5450
6138
|
function applySelectionFastPath(cache, nextSelectedIds, source) {
|
|
5451
6139
|
if (!cache || !cache.updatable || !source) return false;
|
|
@@ -5493,6 +6181,49 @@ function buildSelectionDiff(cache, nextSelectedIds) {
|
|
|
5493
6181
|
});
|
|
5494
6182
|
return update.length > 0 ? { update } : null;
|
|
5495
6183
|
}
|
|
6184
|
+
function buildTimelineVisibilityDiff(cache, nextVisibleSet) {
|
|
6185
|
+
const update = [];
|
|
6186
|
+
const nextHiddenIds = /* @__PURE__ */ new Set();
|
|
6187
|
+
cache.presentIds.forEach((id) => {
|
|
6188
|
+
const nextHidden = nextVisibleSet !== null && !nextVisibleSet.has(id);
|
|
6189
|
+
if (nextHidden) nextHiddenIds.add(id);
|
|
6190
|
+
if (nextHidden === cache.appliedHiddenIds.has(id)) return;
|
|
6191
|
+
if (nextHidden) {
|
|
6192
|
+
update.push({
|
|
6193
|
+
id,
|
|
6194
|
+
addOrUpdateProperties: [
|
|
6195
|
+
{ key: "stroke-opacity", value: 0 },
|
|
6196
|
+
{ key: "fill-opacity", value: 0 },
|
|
6197
|
+
{ key: "isTimelineHidden", value: 1 }
|
|
6198
|
+
]
|
|
6199
|
+
});
|
|
6200
|
+
} else {
|
|
6201
|
+
update.push({
|
|
6202
|
+
id,
|
|
6203
|
+
addOrUpdateProperties: [
|
|
6204
|
+
{ key: "stroke-opacity", value: cache.visibleStrokeOpacityById.get(id) ?? DEFAULT_VISIBLE_STROKE_OPACITY },
|
|
6205
|
+
{ key: "fill-opacity", value: cache.visibleFillOpacityById.get(id) ?? DEFAULT_VISIBLE_FILL_OPACITY },
|
|
6206
|
+
{ key: "isTimelineHidden", value: 0 }
|
|
6207
|
+
]
|
|
6208
|
+
});
|
|
6209
|
+
}
|
|
6210
|
+
});
|
|
6211
|
+
return { diff: update.length > 0 ? { update } : null, nextHiddenIds };
|
|
6212
|
+
}
|
|
6213
|
+
function applyTimelineFastPath(cache, nextVisibleSet, source) {
|
|
6214
|
+
var _a;
|
|
6215
|
+
if (!cache || !cache.updatable || !source) return { applied: false, toggled: 0 };
|
|
6216
|
+
const { diff, nextHiddenIds } = buildTimelineVisibilityDiff(cache, nextVisibleSet);
|
|
6217
|
+
if (diff) {
|
|
6218
|
+
try {
|
|
6219
|
+
source.updateData(diff);
|
|
6220
|
+
} catch {
|
|
6221
|
+
return { applied: false, toggled: 0 };
|
|
6222
|
+
}
|
|
6223
|
+
}
|
|
6224
|
+
cache.appliedHiddenIds = nextHiddenIds;
|
|
6225
|
+
return { applied: true, toggled: ((_a = diff == null ? void 0 : diff.update) == null ? void 0 : _a.length) ?? 0 };
|
|
6226
|
+
}
|
|
5496
6227
|
function deepClone(value) {
|
|
5497
6228
|
try {
|
|
5498
6229
|
return structuredClone(value);
|
|
@@ -5545,15 +6276,80 @@ function geometryEquals(a, b) {
|
|
|
5545
6276
|
b.coordinates
|
|
5546
6277
|
);
|
|
5547
6278
|
}
|
|
5548
|
-
function
|
|
5549
|
-
const
|
|
5550
|
-
|
|
5551
|
-
const
|
|
5552
|
-
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
6279
|
+
function prepareFeaturesForLayer(input, caller) {
|
|
6280
|
+
const logging = mapPerfLogEnabled();
|
|
6281
|
+
const started = logging ? performance.now() : 0;
|
|
6282
|
+
const count = input.length;
|
|
6283
|
+
const features = new Array(count);
|
|
6284
|
+
const featureIds = new Array(count);
|
|
6285
|
+
let hasTemporal = false;
|
|
6286
|
+
let temporalCount = 0;
|
|
6287
|
+
let reused = 0;
|
|
6288
|
+
for (let i = 0; i < count; i++) {
|
|
6289
|
+
const f = input[i];
|
|
6290
|
+
const props = f.properties || {};
|
|
6291
|
+
if (!hasAnyTemporalValue(props)) {
|
|
6292
|
+
if (typeof f.id === "string" && f.id) {
|
|
6293
|
+
features[i] = f;
|
|
6294
|
+
featureIds[i] = f.id;
|
|
6295
|
+
reused++;
|
|
6296
|
+
} else {
|
|
6297
|
+
const id2 = f.id ? String(f.id) : crypto.randomUUID();
|
|
6298
|
+
features[i] = { ...f, id: id2 };
|
|
6299
|
+
featureIds[i] = id2;
|
|
6300
|
+
}
|
|
6301
|
+
continue;
|
|
6302
|
+
}
|
|
6303
|
+
const id = f.id ? String(f.id) : crypto.randomUUID();
|
|
6304
|
+
featureIds[i] = id;
|
|
6305
|
+
const { startDate, endDate } = normalizeTemporalProperties(props);
|
|
6306
|
+
if (startDate || endDate) hasTemporal = true;
|
|
6307
|
+
temporalCount++;
|
|
6308
|
+
features[i] = {
|
|
6309
|
+
...f,
|
|
6310
|
+
id,
|
|
6311
|
+
properties: {
|
|
6312
|
+
...props,
|
|
6313
|
+
startDate: (startDate == null ? void 0 : startDate.toISOString()) || null,
|
|
6314
|
+
endDate: (endDate == null ? void 0 : endDate.toISOString()) || null
|
|
6315
|
+
}
|
|
6316
|
+
};
|
|
6317
|
+
}
|
|
6318
|
+
if (logging) {
|
|
6319
|
+
mapPerfLog("normalize", `${caller ?? "prepareFeaturesForLayer"} normalized ${count} features`, {
|
|
6320
|
+
ms: Math.round((performance.now() - started) * 10) / 10,
|
|
6321
|
+
withTemporalKeys: temporalCount,
|
|
6322
|
+
hasTemporal,
|
|
6323
|
+
reused,
|
|
6324
|
+
copied: count - reused
|
|
6325
|
+
});
|
|
6326
|
+
}
|
|
6327
|
+
return { features, featureIds, hasTemporal };
|
|
6328
|
+
}
|
|
6329
|
+
function scanTemporalFeatures(features, resolveLayerId, out) {
|
|
6330
|
+
let foundTemporal = false;
|
|
6331
|
+
for (let i = 0; i < features.length; i++) {
|
|
6332
|
+
const feature = features[i];
|
|
6333
|
+
const id = feature.id;
|
|
6334
|
+
const props = feature.properties || {};
|
|
6335
|
+
if (!hasAnyTemporalValue(props)) {
|
|
6336
|
+
out.untimedIds.push(id);
|
|
6337
|
+
continue;
|
|
6338
|
+
}
|
|
6339
|
+
const { startDate, endDate } = normalizeTemporalProperties(props);
|
|
6340
|
+
if (startDate || endDate) {
|
|
6341
|
+
out.temporal.push({ id, startDate, endDate, layerId: resolveLayerId(id) });
|
|
6342
|
+
foundTemporal = true;
|
|
6343
|
+
} else {
|
|
6344
|
+
out.untimedIds.push(id);
|
|
6345
|
+
}
|
|
6346
|
+
}
|
|
6347
|
+
return foundTemporal;
|
|
6348
|
+
}
|
|
6349
|
+
function shouldDiffDrawRender({ mode, pointerDown, hasSelection }) {
|
|
6350
|
+
if (mode === "view_select") return false;
|
|
6351
|
+
if (mode === "simple_select" || mode === "direct_select") return pointerDown && hasSelection;
|
|
6352
|
+
return true;
|
|
5557
6353
|
}
|
|
5558
6354
|
function extendBounds(bounds, coords) {
|
|
5559
6355
|
if (!Array.isArray(coords) || coords.length === 0) return;
|
|
@@ -5579,29 +6375,106 @@ function boundsDisjoint(a, b) {
|
|
|
5579
6375
|
function pointInBounds(lng, lat, b) {
|
|
5580
6376
|
return lng >= b.minLng && lng <= b.maxLng && lat >= b.minLat && lat <= b.maxLat;
|
|
5581
6377
|
}
|
|
6378
|
+
function buildGroupSpatialIndex(features) {
|
|
6379
|
+
var _a;
|
|
6380
|
+
const boxes = [];
|
|
6381
|
+
const positions = [];
|
|
6382
|
+
for (let p = 0; p < features.length; p++) {
|
|
6383
|
+
const geom = (_a = features[p]) == null ? void 0 : _a.geometry;
|
|
6384
|
+
const b = computeBounds(geom == null ? void 0 : geom.coordinates);
|
|
6385
|
+
if (!isFinite(b.minLng) || !isFinite(b.minLat) || !isFinite(b.maxLng) || !isFinite(b.maxLat)) {
|
|
6386
|
+
continue;
|
|
6387
|
+
}
|
|
6388
|
+
boxes.push(b.minLng, b.minLat, b.maxLng, b.maxLat);
|
|
6389
|
+
positions.push(p);
|
|
6390
|
+
}
|
|
6391
|
+
if (positions.length === 0) {
|
|
6392
|
+
return { tree: null, positions, size: features.length };
|
|
6393
|
+
}
|
|
6394
|
+
const startedAt = performance.now();
|
|
6395
|
+
const tree = new Flatbush(positions.length);
|
|
6396
|
+
for (let i = 0; i < boxes.length; i += 4) {
|
|
6397
|
+
tree.add(boxes[i], boxes[i + 1], boxes[i + 2], boxes[i + 3]);
|
|
6398
|
+
}
|
|
6399
|
+
tree.finish();
|
|
6400
|
+
mapPerfLog("spatial-index", "built group index", {
|
|
6401
|
+
indexed: positions.length,
|
|
6402
|
+
of: features.length,
|
|
6403
|
+
ms: Math.round(performance.now() - startedAt)
|
|
6404
|
+
});
|
|
6405
|
+
return { tree, positions, size: features.length };
|
|
6406
|
+
}
|
|
6407
|
+
const indexCache = /* @__PURE__ */ new WeakMap();
|
|
6408
|
+
const failedBuilds = /* @__PURE__ */ new WeakSet();
|
|
6409
|
+
function getGroupSpatialIndex(features) {
|
|
6410
|
+
if (failedBuilds.has(features)) return void 0;
|
|
6411
|
+
let index = indexCache.get(features);
|
|
6412
|
+
if (!index) {
|
|
6413
|
+
try {
|
|
6414
|
+
index = buildGroupSpatialIndex(features);
|
|
6415
|
+
} catch {
|
|
6416
|
+
failedBuilds.add(features);
|
|
6417
|
+
return void 0;
|
|
6418
|
+
}
|
|
6419
|
+
indexCache.set(features, index);
|
|
6420
|
+
}
|
|
6421
|
+
return index;
|
|
6422
|
+
}
|
|
6423
|
+
function queryCandidatePositions(index, bounds) {
|
|
6424
|
+
if (!index.tree) return [];
|
|
6425
|
+
const items = index.tree.search(bounds.minLng, bounds.minLat, bounds.maxLng, bounds.maxLat);
|
|
6426
|
+
const positions = items.map((i) => index.positions[i]);
|
|
6427
|
+
positions.sort((a, b) => a - b);
|
|
6428
|
+
return positions;
|
|
6429
|
+
}
|
|
6430
|
+
function collectVisibleFeatureGroups(drawFeatures, readOnlyByLayer, layers) {
|
|
6431
|
+
const groups = [];
|
|
6432
|
+
if (drawFeatures) groups.push({ features: drawFeatures });
|
|
6433
|
+
const layerById = new Map(layers.map((l) => [l.id, l]));
|
|
6434
|
+
readOnlyByLayer.forEach((features, layerId) => {
|
|
6435
|
+
var _a;
|
|
6436
|
+
if ((_a = layerById.get(layerId)) == null ? void 0 : _a.visible) {
|
|
6437
|
+
groups.push({ features, index: getGroupSpatialIndex(features) });
|
|
6438
|
+
}
|
|
6439
|
+
});
|
|
6440
|
+
return groups;
|
|
6441
|
+
}
|
|
6442
|
+
function featureHitsSelection(feature, selectionPolygon, selectionBounds, rectExactForPoints) {
|
|
6443
|
+
const geom = feature.geometry;
|
|
6444
|
+
if ((geom == null ? void 0 : geom.type) === "Point") {
|
|
6445
|
+
const lng = geom.coordinates[0];
|
|
6446
|
+
const lat = geom.coordinates[1];
|
|
6447
|
+
return typeof lng === "number" && typeof lat === "number" && pointInBounds(lng, lat, selectionBounds) && (rectExactForPoints || turf.booleanPointInPolygon(geom.coordinates, selectionPolygon));
|
|
6448
|
+
}
|
|
6449
|
+
if ((geom == null ? void 0 : geom.type) === "LineString" || (geom == null ? void 0 : geom.type) === "Polygon" || (geom == null ? void 0 : geom.type) === "MultiPoint" || (geom == null ? void 0 : geom.type) === "MultiLineString" || (geom == null ? void 0 : geom.type) === "MultiPolygon") {
|
|
6450
|
+
return !boundsDisjoint(computeBounds(geom.coordinates), selectionBounds) && turf.booleanIntersects(feature, selectionPolygon);
|
|
6451
|
+
}
|
|
6452
|
+
return false;
|
|
6453
|
+
}
|
|
5582
6454
|
function hitTestSelection(featureGroups, selectionPolygon, options) {
|
|
5583
6455
|
const selectionBounds = computeBounds(selectionPolygon.geometry.coordinates);
|
|
5584
6456
|
const rectExactForPoints = (options == null ? void 0 : options.axisAlignedRectangle) === true;
|
|
5585
6457
|
const selectedIds = [];
|
|
5586
|
-
|
|
5587
|
-
|
|
6458
|
+
let visited = 0;
|
|
6459
|
+
let total = 0;
|
|
6460
|
+
for (const group of featureGroups) {
|
|
6461
|
+
const { features, index } = group;
|
|
6462
|
+
total += features.length;
|
|
6463
|
+
const useIndex = index !== void 0 && index.size === features.length;
|
|
6464
|
+
const candidates = useIndex ? queryCandidatePositions(index, selectionBounds) : null;
|
|
6465
|
+
const count = candidates ? candidates.length : features.length;
|
|
6466
|
+
visited += count;
|
|
6467
|
+
for (let i = 0; i < count; i++) {
|
|
6468
|
+
const feature = candidates ? features[candidates[i]] : features[i];
|
|
5588
6469
|
try {
|
|
5589
|
-
|
|
5590
|
-
let isInside = false;
|
|
5591
|
-
if ((geom == null ? void 0 : geom.type) === "Point") {
|
|
5592
|
-
const lng = geom.coordinates[0];
|
|
5593
|
-
const lat = geom.coordinates[1];
|
|
5594
|
-
isInside = typeof lng === "number" && typeof lat === "number" && pointInBounds(lng, lat, selectionBounds) && (rectExactForPoints || turf.booleanPointInPolygon(geom.coordinates, selectionPolygon));
|
|
5595
|
-
} else if ((geom == null ? void 0 : geom.type) === "LineString" || (geom == null ? void 0 : geom.type) === "Polygon" || (geom == null ? void 0 : geom.type) === "MultiPoint" || (geom == null ? void 0 : geom.type) === "MultiLineString" || (geom == null ? void 0 : geom.type) === "MultiPolygon") {
|
|
5596
|
-
isInside = !boundsDisjoint(computeBounds(geom.coordinates), selectionBounds) && turf.booleanIntersects(feature, selectionPolygon);
|
|
5597
|
-
}
|
|
5598
|
-
if (isInside && feature.id) {
|
|
6470
|
+
if (featureHitsSelection(feature, selectionPolygon, selectionBounds, rectExactForPoints) && feature.id) {
|
|
5599
6471
|
selectedIds.push(String(feature.id));
|
|
5600
6472
|
}
|
|
5601
6473
|
} catch {
|
|
5602
6474
|
}
|
|
5603
6475
|
}
|
|
5604
6476
|
}
|
|
6477
|
+
mapPerfLog("hit-test", "selection gesture", { visited, total, selected: selectedIds.length });
|
|
5605
6478
|
return selectedIds;
|
|
5606
6479
|
}
|
|
5607
6480
|
const OTHER_BUCKET_KEY = "__other__";
|
|
@@ -5910,92 +6783,6 @@ function ClusterPieManager(props) {
|
|
|
5910
6783
|
}, [visible, updateMarkers]);
|
|
5911
6784
|
return null;
|
|
5912
6785
|
}
|
|
5913
|
-
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");
|
|
5914
|
-
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");
|
|
5915
|
-
proj4.defs("EPSG:32630", "+proj=utm +zone=30 +datum=WGS84 +units=m +no_defs");
|
|
5916
|
-
proj4.defs("EPSG:32631", "+proj=utm +zone=31 +datum=WGS84 +units=m +no_defs");
|
|
5917
|
-
function detectAndReprojectGeoJSON(geojson) {
|
|
5918
|
-
var _a;
|
|
5919
|
-
const crsProperty = geojson.crs;
|
|
5920
|
-
let sourceCRS = null;
|
|
5921
|
-
if ((_a = crsProperty == null ? void 0 : crsProperty.properties) == null ? void 0 : _a.name) {
|
|
5922
|
-
const crsName = crsProperty.properties.name;
|
|
5923
|
-
const epsgMatch = crsName.match(/EPSG::?(\d+)/i);
|
|
5924
|
-
if (epsgMatch) {
|
|
5925
|
-
sourceCRS = `EPSG:${epsgMatch[1]}`;
|
|
5926
|
-
}
|
|
5927
|
-
}
|
|
5928
|
-
if (!sourceCRS && geojson.features.length > 0) {
|
|
5929
|
-
const firstCoord = getFirstCoordinate(geojson.features[0].geometry);
|
|
5930
|
-
if (firstCoord) {
|
|
5931
|
-
const [x, y] = firstCoord;
|
|
5932
|
-
const looksLikeWGS84 = Math.abs(x) <= 180 && Math.abs(y) <= 90;
|
|
5933
|
-
if (looksLikeWGS84) {
|
|
5934
|
-
return { features: geojson, reprojected: false, sourceCRS: "EPSG:4326" };
|
|
5935
|
-
}
|
|
5936
|
-
}
|
|
5937
|
-
}
|
|
5938
|
-
if (sourceCRS === "EPSG:4326") {
|
|
5939
|
-
return { features: geojson, reprojected: false, sourceCRS };
|
|
5940
|
-
}
|
|
5941
|
-
if (sourceCRS && proj4.defs(sourceCRS)) {
|
|
5942
|
-
try {
|
|
5943
|
-
const reprojectedFeatures = geojson.features.map((feature) => ({
|
|
5944
|
-
...feature,
|
|
5945
|
-
geometry: reprojectGeometry(feature.geometry, sourceCRS)
|
|
5946
|
-
}));
|
|
5947
|
-
return {
|
|
5948
|
-
features: { ...geojson, type: "FeatureCollection", features: reprojectedFeatures },
|
|
5949
|
-
reprojected: true,
|
|
5950
|
-
sourceCRS
|
|
5951
|
-
};
|
|
5952
|
-
} catch (e) {
|
|
5953
|
-
console.error("Reprojection failed:", e);
|
|
5954
|
-
}
|
|
5955
|
-
}
|
|
5956
|
-
return { features: geojson, reprojected: false, sourceCRS };
|
|
5957
|
-
}
|
|
5958
|
-
function getFirstCoordinate(geometry) {
|
|
5959
|
-
var _a, _b, _c;
|
|
5960
|
-
if (!geometry) return null;
|
|
5961
|
-
switch (geometry.type) {
|
|
5962
|
-
case "Point":
|
|
5963
|
-
return geometry.coordinates;
|
|
5964
|
-
case "MultiPoint":
|
|
5965
|
-
case "LineString":
|
|
5966
|
-
return geometry.coordinates[0];
|
|
5967
|
-
case "MultiLineString":
|
|
5968
|
-
case "Polygon":
|
|
5969
|
-
return (_a = geometry.coordinates[0]) == null ? void 0 : _a[0];
|
|
5970
|
-
case "MultiPolygon":
|
|
5971
|
-
return (_c = (_b = geometry.coordinates[0]) == null ? void 0 : _b[0]) == null ? void 0 : _c[0];
|
|
5972
|
-
default:
|
|
5973
|
-
return null;
|
|
5974
|
-
}
|
|
5975
|
-
}
|
|
5976
|
-
function reprojectGeometry(geometry, fromCRS) {
|
|
5977
|
-
const transform = (coord) => {
|
|
5978
|
-
const [x, y] = proj4(fromCRS, "EPSG:4326", [coord[0], coord[1]]);
|
|
5979
|
-
return coord.length > 2 ? [x, y, ...coord.slice(2)] : [x, y];
|
|
5980
|
-
};
|
|
5981
|
-
const reprojectCoords = (coords) => {
|
|
5982
|
-
if (typeof coords[0] === "number") {
|
|
5983
|
-
return transform(coords);
|
|
5984
|
-
}
|
|
5985
|
-
return coords.map(reprojectCoords);
|
|
5986
|
-
};
|
|
5987
|
-
if (geometry.type === "GeometryCollection") {
|
|
5988
|
-
return {
|
|
5989
|
-
type: "GeometryCollection",
|
|
5990
|
-
geometries: geometry.geometries.map((g) => reprojectGeometry(g, fromCRS))
|
|
5991
|
-
};
|
|
5992
|
-
}
|
|
5993
|
-
const geomWithCoords = geometry;
|
|
5994
|
-
return {
|
|
5995
|
-
...geomWithCoords,
|
|
5996
|
-
coordinates: reprojectCoords(geomWithCoords.coordinates)
|
|
5997
|
-
};
|
|
5998
|
-
}
|
|
5999
6786
|
const EMOJI_CANVAS_SIZE = 48;
|
|
6000
6787
|
function renderEmojiToCanvas(emoji, size = EMOJI_CANVAS_SIZE) {
|
|
6001
6788
|
const ratio = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
|
|
@@ -6135,17 +6922,6 @@ function createFlightPath3DLayer(layerId, mapInstance, flightPaths) {
|
|
|
6135
6922
|
}
|
|
6136
6923
|
};
|
|
6137
6924
|
}
|
|
6138
|
-
function hasAltitudeData(feature) {
|
|
6139
|
-
if (feature.geometry.type === "LineString") {
|
|
6140
|
-
const coords = feature.geometry.coordinates;
|
|
6141
|
-
return coords.some((c) => c.length >= 3 && c[2] !== 0);
|
|
6142
|
-
}
|
|
6143
|
-
if (feature.geometry.type === "MultiLineString") {
|
|
6144
|
-
const coords = feature.geometry.coordinates;
|
|
6145
|
-
return coords.some((line) => line.some((c) => c.length >= 3 && c[2] !== 0));
|
|
6146
|
-
}
|
|
6147
|
-
return false;
|
|
6148
|
-
}
|
|
6149
6925
|
function extract3DFlightPaths(features) {
|
|
6150
6926
|
const paths = [];
|
|
6151
6927
|
features.forEach((feature) => {
|
|
@@ -6411,7 +7187,6 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
6411
7187
|
const [visibleFeatureCount, setVisibleFeatureCount] = useState(Infinity);
|
|
6412
7188
|
const lastLabelVisibility = useRef(false);
|
|
6413
7189
|
const [labelsSuppressed, setLabelsSuppressed] = useState(true);
|
|
6414
|
-
const [cursorCoords, setCursorCoords] = useState(null);
|
|
6415
7190
|
const [contextMenu, setContextMenu] = useState(null);
|
|
6416
7191
|
const [timelineStoreApi] = useState(createTimelineStore);
|
|
6417
7192
|
const timelineStore = useStore(timelineStoreApi);
|
|
@@ -6628,19 +7403,32 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
6628
7403
|
const syncRef = useRef(() => {
|
|
6629
7404
|
});
|
|
6630
7405
|
const trySelectionFastPathRef = useRef(null);
|
|
7406
|
+
const tryTimelineFastPathRef = useRef(null);
|
|
6631
7407
|
const syncCoalescerRef = useRef(null);
|
|
6632
7408
|
if (syncCoalescerRef.current === null) {
|
|
6633
7409
|
syncCoalescerRef.current = createRafCoalescer((reasons) => {
|
|
6634
|
-
var _a;
|
|
6635
|
-
if (reasons.
|
|
6636
|
-
|
|
7410
|
+
var _a, _b;
|
|
7411
|
+
if (!reasons.has("full")) {
|
|
7412
|
+
let handled = true;
|
|
7413
|
+
if (reasons.has("timeline")) handled = ((_a = tryTimelineFastPathRef.current) == null ? void 0 : _a.call(tryTimelineFastPathRef)) ?? false;
|
|
7414
|
+
if (handled && reasons.has("selection")) handled = ((_b = trySelectionFastPathRef.current) == null ? void 0 : _b.call(trySelectionFastPathRef)) ?? false;
|
|
7415
|
+
if (handled) {
|
|
7416
|
+
mapPerfLog("sync", "frame handled by fast path(s)", reasons);
|
|
7417
|
+
return;
|
|
7418
|
+
}
|
|
7419
|
+
mapPerfLog("sync", "fast path bailed — full rebuild", reasons);
|
|
6637
7420
|
}
|
|
6638
7421
|
syncRef.current();
|
|
6639
7422
|
});
|
|
6640
7423
|
}
|
|
7424
|
+
const fullSyncCallersRef = useRef([]);
|
|
6641
7425
|
const scheduleSync = useCallback((reason = "full") => {
|
|
6642
|
-
var _a;
|
|
6643
|
-
(
|
|
7426
|
+
var _a, _b;
|
|
7427
|
+
if (reason === "full" && mapPerfLogEnabled() && fullSyncCallersRef.current.length < 4) {
|
|
7428
|
+
const stack = (_a = new Error().stack) == null ? void 0 : _a.split("\n").slice(2, 5).map((line) => line.trim()).join(" ← ");
|
|
7429
|
+
if (stack) fullSyncCallersRef.current.push(stack);
|
|
7430
|
+
}
|
|
7431
|
+
(_b = syncCoalescerRef.current) == null ? void 0 : _b.schedule(reason);
|
|
6644
7432
|
}, []);
|
|
6645
7433
|
useEffect(() => {
|
|
6646
7434
|
scheduleSync();
|
|
@@ -6731,10 +7519,106 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
6731
7519
|
}, []);
|
|
6732
7520
|
const isSyncingRef = useRef(false);
|
|
6733
7521
|
const selectionPaintCacheRef = useRef(null);
|
|
7522
|
+
const paintedArrowLinesRef = useRef([]);
|
|
7523
|
+
const renderArrowOverlays = useCallback((arrowLines) => {
|
|
7524
|
+
const mapInstance = map.current;
|
|
7525
|
+
if (!mapInstance) return;
|
|
7526
|
+
const arrowHeadSource = mapInstance.getSource("arrow-heads");
|
|
7527
|
+
if (arrowHeadSource) {
|
|
7528
|
+
const arrowHeadTriangles = [];
|
|
7529
|
+
const headLength = 16;
|
|
7530
|
+
const headWidth = 10;
|
|
7531
|
+
arrowLines.forEach((f) => {
|
|
7532
|
+
const coords = f.geometry.coordinates;
|
|
7533
|
+
if (coords.length < 2) return;
|
|
7534
|
+
const end = coords[coords.length - 1];
|
|
7535
|
+
const prev = coords[coords.length - 2];
|
|
7536
|
+
const endScreen = mapInstance.project(end);
|
|
7537
|
+
const prevScreen = mapInstance.project(prev);
|
|
7538
|
+
const dx = endScreen.x - prevScreen.x;
|
|
7539
|
+
const dy = endScreen.y - prevScreen.y;
|
|
7540
|
+
const len = Math.sqrt(dx * dx + dy * dy);
|
|
7541
|
+
if (len < 1e-3) return;
|
|
7542
|
+
const dirX = dx / len;
|
|
7543
|
+
const dirY = dy / len;
|
|
7544
|
+
const perpX = -dirY;
|
|
7545
|
+
const perpY = dirX;
|
|
7546
|
+
const tipScreen = { x: endScreen.x, y: endScreen.y };
|
|
7547
|
+
const baseLeftScreen = {
|
|
7548
|
+
x: endScreen.x - dirX * headLength - perpX * headWidth,
|
|
7549
|
+
y: endScreen.y - dirY * headLength - perpY * headWidth
|
|
7550
|
+
};
|
|
7551
|
+
const baseRightScreen = {
|
|
7552
|
+
x: endScreen.x - dirX * headLength + perpX * headWidth,
|
|
7553
|
+
y: endScreen.y - dirY * headLength + perpY * headWidth
|
|
7554
|
+
};
|
|
7555
|
+
const tipGeo = mapInstance.unproject([tipScreen.x, tipScreen.y]);
|
|
7556
|
+
const baseLeftGeo = mapInstance.unproject([baseLeftScreen.x, baseLeftScreen.y]);
|
|
7557
|
+
const baseRightGeo = mapInstance.unproject([baseRightScreen.x, baseRightScreen.y]);
|
|
7558
|
+
arrowHeadTriangles.push({
|
|
7559
|
+
type: "Feature",
|
|
7560
|
+
geometry: {
|
|
7561
|
+
type: "Polygon",
|
|
7562
|
+
coordinates: [[
|
|
7563
|
+
[tipGeo.lng, tipGeo.lat],
|
|
7564
|
+
[baseLeftGeo.lng, baseLeftGeo.lat],
|
|
7565
|
+
[baseRightGeo.lng, baseRightGeo.lat],
|
|
7566
|
+
[tipGeo.lng, tipGeo.lat]
|
|
7567
|
+
// Close the polygon
|
|
7568
|
+
]]
|
|
7569
|
+
},
|
|
7570
|
+
properties: {
|
|
7571
|
+
...f.properties
|
|
7572
|
+
}
|
|
7573
|
+
});
|
|
7574
|
+
});
|
|
7575
|
+
arrowHeadSource.setData({ type: "FeatureCollection", features: arrowHeadTriangles });
|
|
7576
|
+
}
|
|
7577
|
+
const arrowLabelSource = mapInstance.getSource("arrow-labels");
|
|
7578
|
+
if (arrowLabelSource) {
|
|
7579
|
+
const arrowLabelPoints = [];
|
|
7580
|
+
arrowLines.forEach((f) => {
|
|
7581
|
+
var _a;
|
|
7582
|
+
const name = (_a = f.properties) == null ? void 0 : _a.name;
|
|
7583
|
+
if (!name) return;
|
|
7584
|
+
const coords = f.geometry.coordinates;
|
|
7585
|
+
if (coords.length < 2) return;
|
|
7586
|
+
const start = coords[0];
|
|
7587
|
+
const end = coords[coords.length - 1];
|
|
7588
|
+
const midPoint = [
|
|
7589
|
+
(start[0] + end[0]) / 2,
|
|
7590
|
+
(start[1] + end[1]) / 2
|
|
7591
|
+
];
|
|
7592
|
+
const dLng = end[0] - start[0];
|
|
7593
|
+
const dLat = end[1] - start[1];
|
|
7594
|
+
const angleFromEast = Math.atan2(dLat, dLng) * (180 / Math.PI);
|
|
7595
|
+
let labelBearing = -angleFromEast;
|
|
7596
|
+
labelBearing = (labelBearing % 360 + 540) % 360 - 180;
|
|
7597
|
+
if (labelBearing > 90) {
|
|
7598
|
+
labelBearing -= 180;
|
|
7599
|
+
} else if (labelBearing < -90) {
|
|
7600
|
+
labelBearing += 180;
|
|
7601
|
+
}
|
|
7602
|
+
arrowLabelPoints.push({
|
|
7603
|
+
type: "Feature",
|
|
7604
|
+
geometry: {
|
|
7605
|
+
type: "Point",
|
|
7606
|
+
coordinates: midPoint
|
|
7607
|
+
},
|
|
7608
|
+
properties: {
|
|
7609
|
+
...f.properties,
|
|
7610
|
+
labelBearing
|
|
7611
|
+
}
|
|
7612
|
+
});
|
|
7613
|
+
});
|
|
7614
|
+
arrowLabelSource.setData({ type: "FeatureCollection", features: arrowLabelPoints });
|
|
7615
|
+
}
|
|
7616
|
+
}, []);
|
|
6734
7617
|
const syncFeaturesToCustomLayers = useCallback(() => {
|
|
6735
7618
|
if (!map.current) return;
|
|
6736
7619
|
if (isSyncingRef.current) return;
|
|
6737
7620
|
isSyncingRef.current = true;
|
|
7621
|
+
const fullSyncStart = performance.now();
|
|
6738
7622
|
try {
|
|
6739
7623
|
const source = map.current.getSource("custom-features");
|
|
6740
7624
|
if (!source) return;
|
|
@@ -6857,7 +7741,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
6857
7741
|
const layer = featureToLayer.get(featureId);
|
|
6858
7742
|
const visualConfig = layer == null ? void 0 : layer.visualConfig;
|
|
6859
7743
|
const isTimelineVisible = visibleSet === null || visibleSet.has(featureId);
|
|
6860
|
-
const baseOpacity = ((_a = f.properties) == null ? void 0 : _a["stroke-opacity"]) ??
|
|
7744
|
+
const baseOpacity = ((_a = f.properties) == null ? void 0 : _a["stroke-opacity"]) ?? DEFAULT_VISIBLE_STROKE_OPACITY;
|
|
6861
7745
|
let strokeColor = ((_b = f.properties) == null ? void 0 : _b.stroke) || "#3b82f6";
|
|
6862
7746
|
const colorConfig = visualConfig == null ? void 0 : visualConfig.color;
|
|
6863
7747
|
if (colorConfig) {
|
|
@@ -6959,7 +7843,17 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
6959
7843
|
basePriority = DEFAULT_LABEL_PRIORITY + Math.abs(h) % 1e3;
|
|
6960
7844
|
}
|
|
6961
7845
|
const labelPriority = isFeatureSelected ? 0 : basePriority;
|
|
6962
|
-
|
|
7846
|
+
const visibleStrokeOpacity = hideFlatFor3DOnly ? 0 : baseOpacity;
|
|
7847
|
+
const visibleFillOpacity = hideFlatFor3DOnly ? 0 : ((_n = f.properties) == null ? void 0 : _n["fill-opacity"]) ?? DEFAULT_VISIBLE_FILL_OPACITY;
|
|
7848
|
+
recordPaintedFeature(
|
|
7849
|
+
paintCache,
|
|
7850
|
+
featureId,
|
|
7851
|
+
basePriority,
|
|
7852
|
+
isFeatureSelected === 1,
|
|
7853
|
+
visibleStrokeOpacity,
|
|
7854
|
+
visibleFillOpacity,
|
|
7855
|
+
!isTimelineVisible
|
|
7856
|
+
);
|
|
6963
7857
|
return {
|
|
6964
7858
|
type: "Feature",
|
|
6965
7859
|
id: featureId,
|
|
@@ -6980,9 +7874,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
6980
7874
|
iconSize: featureIconSize,
|
|
6981
7875
|
stroke: strokeColor,
|
|
6982
7876
|
"stroke-width": strokeWidth,
|
|
6983
|
-
"stroke-opacity":
|
|
7877
|
+
"stroke-opacity": isTimelineVisible ? visibleStrokeOpacity : 0,
|
|
6984
7878
|
fill: strokeColor,
|
|
6985
|
-
"fill-opacity":
|
|
7879
|
+
"fill-opacity": isTimelineVisible ? visibleFillOpacity : 0,
|
|
6986
7880
|
pointRadius,
|
|
6987
7881
|
isHiddenFor3DOnly: hideFlatFor3DOnly ? 1 : 0,
|
|
6988
7882
|
isTimelineHidden: isTimelineVisible ? 0 : 1,
|
|
@@ -7081,104 +7975,19 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
7081
7975
|
});
|
|
7082
7976
|
traceSource.setData({ type: "FeatureCollection", features: traceSegments });
|
|
7083
7977
|
}
|
|
7084
|
-
|
|
7085
|
-
if (arrowHeadSource && map.current) {
|
|
7086
|
-
const arrowHeadTriangles = [];
|
|
7087
|
-
const mapInstance = map.current;
|
|
7978
|
+
{
|
|
7088
7979
|
let sawArrowFeature = false;
|
|
7089
|
-
const
|
|
7090
|
-
const headWidth = 10;
|
|
7980
|
+
const arrowLines = [];
|
|
7091
7981
|
sourceData.features.forEach((f) => {
|
|
7092
7982
|
var _a;
|
|
7093
7983
|
const isArrow = ((_a = f.properties) == null ? void 0 : _a.kind) === "arrow" || arrowFeatureIdsRef.current.has(String(f.id));
|
|
7094
|
-
if (isArrow)
|
|
7095
|
-
|
|
7096
|
-
|
|
7097
|
-
if (coords.length < 2) return;
|
|
7098
|
-
const end = coords[coords.length - 1];
|
|
7099
|
-
const prev = coords[coords.length - 2];
|
|
7100
|
-
const endScreen = mapInstance.project(end);
|
|
7101
|
-
const prevScreen = mapInstance.project(prev);
|
|
7102
|
-
const dx = endScreen.x - prevScreen.x;
|
|
7103
|
-
const dy = endScreen.y - prevScreen.y;
|
|
7104
|
-
const len = Math.sqrt(dx * dx + dy * dy);
|
|
7105
|
-
if (len < 1e-3) return;
|
|
7106
|
-
const dirX = dx / len;
|
|
7107
|
-
const dirY = dy / len;
|
|
7108
|
-
const perpX = -dirY;
|
|
7109
|
-
const perpY = dirX;
|
|
7110
|
-
const tipScreen = { x: endScreen.x, y: endScreen.y };
|
|
7111
|
-
const baseLeftScreen = {
|
|
7112
|
-
x: endScreen.x - dirX * headLength - perpX * headWidth,
|
|
7113
|
-
y: endScreen.y - dirY * headLength - perpY * headWidth
|
|
7114
|
-
};
|
|
7115
|
-
const baseRightScreen = {
|
|
7116
|
-
x: endScreen.x - dirX * headLength + perpX * headWidth,
|
|
7117
|
-
y: endScreen.y - dirY * headLength + perpY * headWidth
|
|
7118
|
-
};
|
|
7119
|
-
const tipGeo = mapInstance.unproject([tipScreen.x, tipScreen.y]);
|
|
7120
|
-
const baseLeftGeo = mapInstance.unproject([baseLeftScreen.x, baseLeftScreen.y]);
|
|
7121
|
-
const baseRightGeo = mapInstance.unproject([baseRightScreen.x, baseRightScreen.y]);
|
|
7122
|
-
arrowHeadTriangles.push({
|
|
7123
|
-
type: "Feature",
|
|
7124
|
-
geometry: {
|
|
7125
|
-
type: "Polygon",
|
|
7126
|
-
coordinates: [[
|
|
7127
|
-
[tipGeo.lng, tipGeo.lat],
|
|
7128
|
-
[baseLeftGeo.lng, baseLeftGeo.lat],
|
|
7129
|
-
[baseRightGeo.lng, baseRightGeo.lat],
|
|
7130
|
-
[tipGeo.lng, tipGeo.lat]
|
|
7131
|
-
// Close the polygon
|
|
7132
|
-
]]
|
|
7133
|
-
},
|
|
7134
|
-
properties: {
|
|
7135
|
-
...f.properties
|
|
7136
|
-
}
|
|
7137
|
-
});
|
|
7984
|
+
if (!isArrow) return;
|
|
7985
|
+
sawArrowFeature = true;
|
|
7986
|
+
if (f.geometry.type === "LineString") arrowLines.push(f);
|
|
7138
7987
|
});
|
|
7139
|
-
arrowHeadSource.setData({ type: "FeatureCollection", features: arrowHeadTriangles });
|
|
7140
7988
|
hasArrowFeaturesRef.current = sawArrowFeature;
|
|
7141
|
-
|
|
7142
|
-
|
|
7143
|
-
if (arrowLabelSource) {
|
|
7144
|
-
const arrowLabelPoints = [];
|
|
7145
|
-
sourceData.features.forEach((f) => {
|
|
7146
|
-
var _a, _b;
|
|
7147
|
-
const isArrow = ((_a = f.properties) == null ? void 0 : _a.kind) === "arrow" || arrowFeatureIdsRef.current.has(String(f.id));
|
|
7148
|
-
if (f.geometry.type !== "LineString" || !isArrow) return;
|
|
7149
|
-
const name = (_b = f.properties) == null ? void 0 : _b.name;
|
|
7150
|
-
if (!name) return;
|
|
7151
|
-
const coords = f.geometry.coordinates;
|
|
7152
|
-
if (coords.length < 2) return;
|
|
7153
|
-
const start = coords[0];
|
|
7154
|
-
const end = coords[coords.length - 1];
|
|
7155
|
-
const midPoint = [
|
|
7156
|
-
(start[0] + end[0]) / 2,
|
|
7157
|
-
(start[1] + end[1]) / 2
|
|
7158
|
-
];
|
|
7159
|
-
const dLng = end[0] - start[0];
|
|
7160
|
-
const dLat = end[1] - start[1];
|
|
7161
|
-
const angleFromEast = Math.atan2(dLat, dLng) * (180 / Math.PI);
|
|
7162
|
-
let labelBearing = -angleFromEast;
|
|
7163
|
-
labelBearing = (labelBearing % 360 + 540) % 360 - 180;
|
|
7164
|
-
if (labelBearing > 90) {
|
|
7165
|
-
labelBearing -= 180;
|
|
7166
|
-
} else if (labelBearing < -90) {
|
|
7167
|
-
labelBearing += 180;
|
|
7168
|
-
}
|
|
7169
|
-
arrowLabelPoints.push({
|
|
7170
|
-
type: "Feature",
|
|
7171
|
-
geometry: {
|
|
7172
|
-
type: "Point",
|
|
7173
|
-
coordinates: midPoint
|
|
7174
|
-
},
|
|
7175
|
-
properties: {
|
|
7176
|
-
...f.properties,
|
|
7177
|
-
labelBearing
|
|
7178
|
-
}
|
|
7179
|
-
});
|
|
7180
|
-
});
|
|
7181
|
-
arrowLabelSource.setData({ type: "FeatureCollection", features: arrowLabelPoints });
|
|
7989
|
+
paintedArrowLinesRef.current = arrowLines;
|
|
7990
|
+
renderArrowOverlays(arrowLines);
|
|
7182
7991
|
}
|
|
7183
7992
|
if (update3DFlightPathsRef == null ? void 0 : update3DFlightPathsRef.current) {
|
|
7184
7993
|
update3DFlightPathsRef.current();
|
|
@@ -7188,11 +7997,18 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
7188
7997
|
setVisibleFeatureCount(countVisibleFeatures(threshold));
|
|
7189
7998
|
setLabelsSuppressed(false);
|
|
7190
7999
|
}
|
|
8000
|
+
const requestedBy = fullSyncCallersRef.current.splice(0);
|
|
8001
|
+
mapPerfLog("sync", "full rebuild", {
|
|
8002
|
+
features: sourceData.features.length,
|
|
8003
|
+
ms: Math.round(performance.now() - fullSyncStart),
|
|
8004
|
+
requestedBy
|
|
8005
|
+
});
|
|
7191
8006
|
} finally {
|
|
7192
8007
|
isSyncingRef.current = false;
|
|
7193
8008
|
}
|
|
7194
|
-
}, [layers, hashStringToColor$1, autoLabelConfig, countVisibleFeatures]);
|
|
8009
|
+
}, [layers, hashStringToColor$1, autoLabelConfig, countVisibleFeatures, renderArrowOverlays]);
|
|
7195
8010
|
const update3DFlightPaths = useCallback(() => {
|
|
8011
|
+
var _a;
|
|
7196
8012
|
if (!map.current || !is3DTerrainEnabled) {
|
|
7197
8013
|
if (map.current && flightPath3DLayerId.current) {
|
|
7198
8014
|
try {
|
|
@@ -7213,20 +8029,21 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
7213
8029
|
const allFeatures = [];
|
|
7214
8030
|
const currentLayers = layersRef.current;
|
|
7215
8031
|
if (draw.current) {
|
|
7216
|
-
const
|
|
7217
|
-
|
|
7218
|
-
if (
|
|
7219
|
-
const featureId
|
|
7220
|
-
|
|
7221
|
-
|
|
7222
|
-
|
|
8032
|
+
const traceFeatureIds = /* @__PURE__ */ new Set();
|
|
8033
|
+
for (const l of currentLayers) {
|
|
8034
|
+
if (((_a = l.traceConfig) == null ? void 0 : _a.enabled) !== true) continue;
|
|
8035
|
+
for (const featureId of l.featureIds) traceFeatureIds.add(featureId);
|
|
8036
|
+
}
|
|
8037
|
+
const drawFeatures = draw.current.getAll().features.filter(
|
|
8038
|
+
(feature) => isFeatureVisibleInTimeline(feature) && traceFeatureIds.has(feature.id)
|
|
8039
|
+
);
|
|
7223
8040
|
pushAll(allFeatures, drawFeatures);
|
|
7224
8041
|
}
|
|
7225
8042
|
readOnlyFeatures.current.forEach((features, layerId2) => {
|
|
7226
|
-
var
|
|
8043
|
+
var _a2;
|
|
7227
8044
|
const layer2 = currentLayers.find((l) => l.id === layerId2);
|
|
7228
8045
|
const altitudeMode = (layer2 == null ? void 0 : layer2.altitudeDisplayMode) ?? "both";
|
|
7229
|
-
const traceEnabled = ((
|
|
8046
|
+
const traceEnabled = ((_a2 = layer2 == null ? void 0 : layer2.traceConfig) == null ? void 0 : _a2.enabled) === true;
|
|
7230
8047
|
if ((layer2 == null ? void 0 : layer2.visible) && traceEnabled && (altitudeMode === "3d" || altitudeMode === "both")) {
|
|
7231
8048
|
const visibleFeatures = features.filter(isFeatureVisibleInTimeline);
|
|
7232
8049
|
pushAll(allFeatures, visibleFeatures);
|
|
@@ -7281,52 +8098,24 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
7281
8098
|
featureToLayer.set(fid, layer.id);
|
|
7282
8099
|
}
|
|
7283
8100
|
}
|
|
7284
|
-
const
|
|
7285
|
-
|
|
7286
|
-
|
|
7287
|
-
|
|
7288
|
-
|
|
7289
|
-
|
|
7290
|
-
continue;
|
|
7291
|
-
}
|
|
7292
|
-
const { startDate, endDate } = normalizeTemporalProperties(props);
|
|
7293
|
-
if (startDate || endDate) {
|
|
7294
|
-
temporalFeatures.push({
|
|
7295
|
-
id: feature.id,
|
|
7296
|
-
startDate,
|
|
7297
|
-
endDate,
|
|
7298
|
-
layerId: featureToLayer.get(feature.id) || "default"
|
|
7299
|
-
});
|
|
7300
|
-
} else {
|
|
7301
|
-
untimedIds.push(feature.id);
|
|
7302
|
-
}
|
|
7303
|
-
}
|
|
8101
|
+
const scan = { temporal: [], untimedIds: [] };
|
|
8102
|
+
scanTemporalFeatures(
|
|
8103
|
+
drawFeatures,
|
|
8104
|
+
(id) => featureToLayer.get(id) || "default",
|
|
8105
|
+
scan
|
|
8106
|
+
);
|
|
7304
8107
|
readOnlyFeatures.current.forEach((features, layerId) => {
|
|
7305
8108
|
const layer = currentLayers.find((l) => l.id === layerId);
|
|
7306
8109
|
if (!(layer == null ? void 0 : layer.visible)) return;
|
|
7307
8110
|
const cached = layerTemporalCacheRef.current.get(layerId);
|
|
7308
8111
|
if (cached && cached.featureCount === features.length && !cached.hasTemporal) {
|
|
7309
|
-
for (const f of features) untimedIds.push(f.id);
|
|
8112
|
+
for (const f of features) scan.untimedIds.push(f.id);
|
|
7310
8113
|
return;
|
|
7311
8114
|
}
|
|
7312
|
-
|
|
7313
|
-
for (const feature of features) {
|
|
7314
|
-
const props = feature.properties || {};
|
|
7315
|
-
if (!hasAnyTemporalValue(props)) {
|
|
7316
|
-
untimedIds.push(feature.id);
|
|
7317
|
-
continue;
|
|
7318
|
-
}
|
|
7319
|
-
const { startDate, endDate } = normalizeTemporalProperties(props);
|
|
7320
|
-
if (startDate || endDate) {
|
|
7321
|
-
temporalFeatures.push({ id: feature.id, startDate, endDate, layerId });
|
|
7322
|
-
layerHasTemporal = true;
|
|
7323
|
-
} else {
|
|
7324
|
-
untimedIds.push(feature.id);
|
|
7325
|
-
}
|
|
7326
|
-
}
|
|
8115
|
+
const layerHasTemporal = scanTemporalFeatures(features, () => layerId, scan);
|
|
7327
8116
|
layerTemporalCacheRef.current.set(layerId, { featureCount: features.length, hasTemporal: layerHasTemporal });
|
|
7328
8117
|
});
|
|
7329
|
-
timelineStoreApi.getState().setTemporalFeatures(
|
|
8118
|
+
timelineStoreApi.getState().setTemporalFeatures(scan.temporal, scan.untimedIds);
|
|
7330
8119
|
}, [timelineStoreApi]);
|
|
7331
8120
|
const scheduleTimelineUpdate = useCallback(() => {
|
|
7332
8121
|
if (timelineUpdateTimerRef.current) clearTimeout(timelineUpdateTimerRef.current);
|
|
@@ -7602,6 +8391,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
7602
8391
|
}, [finalizeCapture]);
|
|
7603
8392
|
useEffect(() => {
|
|
7604
8393
|
if (!mapContainer.current || map.current) return;
|
|
8394
|
+
let removeDrawGateListeners;
|
|
7605
8395
|
try {
|
|
7606
8396
|
const baseStyle = createBaseStyle({
|
|
7607
8397
|
glyphsUrl,
|
|
@@ -7660,12 +8450,6 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
7660
8450
|
]
|
|
7661
8451
|
});
|
|
7662
8452
|
mapInstance.addControl(drawInstance);
|
|
7663
|
-
mapInstance.on("mousemove", (e) => {
|
|
7664
|
-
setCursorCoords({ lng: e.lngLat.lng, lat: e.lngLat.lat });
|
|
7665
|
-
});
|
|
7666
|
-
mapInstance.on("mouseout", () => {
|
|
7667
|
-
setCursorCoords(null);
|
|
7668
|
-
});
|
|
7669
8453
|
requestAnimationFrame(() => {
|
|
7670
8454
|
try {
|
|
7671
8455
|
const container = mapInstance.getContainer();
|
|
@@ -8640,8 +9424,52 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
8640
9424
|
onFeatureCreate == null ? void 0 : onFeatureCreate(feature);
|
|
8641
9425
|
});
|
|
8642
9426
|
});
|
|
9427
|
+
let drawGatePointerDown = false;
|
|
9428
|
+
const onDrawGatePointerDown = () => {
|
|
9429
|
+
drawGatePointerDown = true;
|
|
9430
|
+
};
|
|
9431
|
+
const onDrawGatePointerUp = () => {
|
|
9432
|
+
drawGatePointerDown = false;
|
|
9433
|
+
};
|
|
9434
|
+
const drawGateCanvas = mapInstance.getCanvasContainer();
|
|
9435
|
+
drawGateCanvas.addEventListener("pointerdown", onDrawGatePointerDown);
|
|
9436
|
+
window.addEventListener("pointerup", onDrawGatePointerUp);
|
|
9437
|
+
window.addEventListener("pointercancel", onDrawGatePointerUp);
|
|
9438
|
+
window.addEventListener("blur", onDrawGatePointerUp);
|
|
9439
|
+
removeDrawGateListeners = () => {
|
|
9440
|
+
drawGateCanvas.removeEventListener("pointerdown", onDrawGatePointerDown);
|
|
9441
|
+
window.removeEventListener("pointerup", onDrawGatePointerUp);
|
|
9442
|
+
window.removeEventListener("pointercancel", onDrawGatePointerUp);
|
|
9443
|
+
window.removeEventListener("blur", onDrawGatePointerUp);
|
|
9444
|
+
};
|
|
9445
|
+
let lastDrawGeometries = /* @__PURE__ */ new Map();
|
|
9446
|
+
let drawGateSkips = 0;
|
|
8643
9447
|
mapInstance.on("draw.render", () => {
|
|
8644
|
-
|
|
9448
|
+
if (!shouldDiffDrawRender({
|
|
9449
|
+
mode: drawInstance.getMode(),
|
|
9450
|
+
pointerDown: drawGatePointerDown,
|
|
9451
|
+
hasSelection: drawInstance.getSelectedIds().length > 0
|
|
9452
|
+
})) {
|
|
9453
|
+
drawGateSkips++;
|
|
9454
|
+
return;
|
|
9455
|
+
}
|
|
9456
|
+
if (drawGateSkips > 0) {
|
|
9457
|
+
mapPerfLog("sync", "draw.render diff resumed", { skippedWhileIdle: drawGateSkips });
|
|
9458
|
+
drawGateSkips = 0;
|
|
9459
|
+
}
|
|
9460
|
+
const features = drawInstance.getAll().features;
|
|
9461
|
+
let changed = features.length !== lastDrawGeometries.size;
|
|
9462
|
+
const next = /* @__PURE__ */ new Map();
|
|
9463
|
+
features.forEach((f) => {
|
|
9464
|
+
const id = String(f.id);
|
|
9465
|
+
next.set(id, f.geometry);
|
|
9466
|
+
if (!changed) {
|
|
9467
|
+
const prev = lastDrawGeometries.get(id);
|
|
9468
|
+
if (!prev || !geometryEquals(prev, f.geometry)) changed = true;
|
|
9469
|
+
}
|
|
9470
|
+
});
|
|
9471
|
+
lastDrawGeometries = next;
|
|
9472
|
+
if (changed) scheduleSync();
|
|
8645
9473
|
});
|
|
8646
9474
|
mapInstance.on("draw.update", (e) => {
|
|
8647
9475
|
const activeLayerId = activeEditingLayerIdRef.current;
|
|
@@ -8683,7 +9511,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
8683
9511
|
}
|
|
8684
9512
|
});
|
|
8685
9513
|
scheduleSync();
|
|
8686
|
-
if (e.action === "change_coordinates" && !hasRevertedFeatures) {
|
|
9514
|
+
if ((e.action === "move" || e.action === "change_coordinates") && !hasRevertedFeatures) {
|
|
8687
9515
|
scheduleTimelineUpdate();
|
|
8688
9516
|
recordMoveFromPreDrag();
|
|
8689
9517
|
}
|
|
@@ -8823,6 +9651,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
8823
9651
|
var _a;
|
|
8824
9652
|
if (timelineUpdateTimerRef.current) clearTimeout(timelineUpdateTimerRef.current);
|
|
8825
9653
|
(_a = syncCoalescerRef.current) == null ? void 0 : _a.cancel();
|
|
9654
|
+
removeDrawGateListeners == null ? void 0 : removeDrawGateListeners();
|
|
8826
9655
|
if (map.current) {
|
|
8827
9656
|
map.current.remove();
|
|
8828
9657
|
map.current = null;
|
|
@@ -9000,8 +9829,10 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9000
9829
|
const allFeatures = [...drawFeatures, ...readOnlyFeaturesList];
|
|
9001
9830
|
const currentLayers = layersRef.current;
|
|
9002
9831
|
const targetLayerIds = layerIds ?? currentLayers.map((l) => l.id);
|
|
9003
|
-
const targetFeatureIds =
|
|
9004
|
-
|
|
9832
|
+
const targetFeatureIds = new Set(
|
|
9833
|
+
currentLayers.filter((l) => targetLayerIds.includes(l.id)).flatMap((l) => l.featureIds)
|
|
9834
|
+
);
|
|
9835
|
+
const targetFeatures = allFeatures.filter((f) => targetFeatureIds.has(f.id));
|
|
9005
9836
|
if (targetFeatures.length === 0) return;
|
|
9006
9837
|
const fc = turf.featureCollection(targetFeatures);
|
|
9007
9838
|
const bbox = turf.bbox(fc);
|
|
@@ -9022,6 +9853,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9022
9853
|
map.current.flyTo({ center: center.geometry.coordinates });
|
|
9023
9854
|
},
|
|
9024
9855
|
listLayers: () => [...layersRef.current],
|
|
9856
|
+
// Worker parse + streamed transfer + the canvas progress overlay, with
|
|
9857
|
+
// layer creation left to the host (see MapEditorHandle docs).
|
|
9858
|
+
parseGeoJSONText: (label, text) => ingestWithProgress(label, text, { idStrategy: "preserve" }),
|
|
9025
9859
|
addLayer: (name, geojson, options) => {
|
|
9026
9860
|
if (!isMapLoadedRef.current) return "";
|
|
9027
9861
|
if (options == null ? void 0 : options.recordHistory) saveStateForUndo(`add layer "${name}"`);
|
|
@@ -9051,28 +9885,10 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9051
9885
|
};
|
|
9052
9886
|
if (geojson) {
|
|
9053
9887
|
if (options == null ? void 0 : options.readOnly) {
|
|
9054
|
-
|
|
9055
|
-
|
|
9056
|
-
|
|
9057
|
-
|
|
9058
|
-
if (!hasAnyTemporalValue(props)) {
|
|
9059
|
-
return { ...f, id };
|
|
9060
|
-
}
|
|
9061
|
-
const { startDate, endDate } = normalizeTemporalProperties(props);
|
|
9062
|
-
if (startDate || endDate) layerHasTemporal = true;
|
|
9063
|
-
return {
|
|
9064
|
-
...f,
|
|
9065
|
-
id,
|
|
9066
|
-
properties: {
|
|
9067
|
-
...props,
|
|
9068
|
-
startDate: (startDate == null ? void 0 : startDate.toISOString()) || null,
|
|
9069
|
-
endDate: (endDate == null ? void 0 : endDate.toISOString()) || null
|
|
9070
|
-
}
|
|
9071
|
-
};
|
|
9072
|
-
});
|
|
9073
|
-
readOnlyFeatures.current.set(layerId, featuresWithIds);
|
|
9074
|
-
layerTemporalCacheRef.current.set(layerId, { featureCount: featuresWithIds.length, hasTemporal: layerHasTemporal });
|
|
9075
|
-
newLayer.featureIds = featuresWithIds.map((f) => String(f.id));
|
|
9888
|
+
const prepared = prepareFeaturesForLayer(geojson.features, "addLayer");
|
|
9889
|
+
readOnlyFeatures.current.set(layerId, prepared.features);
|
|
9890
|
+
layerTemporalCacheRef.current.set(layerId, { featureCount: prepared.features.length, hasTemporal: prepared.hasTemporal });
|
|
9891
|
+
newLayer.featureIds = prepared.featureIds;
|
|
9076
9892
|
} else if (draw.current) {
|
|
9077
9893
|
isApiAddingRef.current = true;
|
|
9078
9894
|
try {
|
|
@@ -9198,29 +10014,12 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9198
10014
|
if (options == null ? void 0 : options.recordHistory) saveStateForUndo("add features");
|
|
9199
10015
|
if (layer.readOnly) {
|
|
9200
10016
|
const existing = readOnlyFeatures.current.get(layerId) || [];
|
|
9201
|
-
|
|
9202
|
-
const
|
|
9203
|
-
|
|
9204
|
-
const props = f.properties || {};
|
|
9205
|
-
if (!hasAnyTemporalValue(props)) {
|
|
9206
|
-
return { ...f, id };
|
|
9207
|
-
}
|
|
9208
|
-
const { startDate, endDate } = normalizeTemporalProperties(props);
|
|
9209
|
-
if (startDate || endDate) layerHasTemporal = true;
|
|
9210
|
-
return {
|
|
9211
|
-
...f,
|
|
9212
|
-
id,
|
|
9213
|
-
properties: {
|
|
9214
|
-
...props,
|
|
9215
|
-
startDate: (startDate == null ? void 0 : startDate.toISOString()) || null,
|
|
9216
|
-
endDate: (endDate == null ? void 0 : endDate.toISOString()) || null
|
|
9217
|
-
}
|
|
9218
|
-
};
|
|
9219
|
-
});
|
|
9220
|
-
const combined = [...existing, ...newFeaturesWithIds];
|
|
10017
|
+
const prepared = prepareFeaturesForLayer(features, "addFeatures");
|
|
10018
|
+
const layerHasTemporal = (((_a = layerTemporalCacheRef.current.get(layerId)) == null ? void 0 : _a.hasTemporal) ?? false) || prepared.hasTemporal;
|
|
10019
|
+
const combined = [...existing, ...prepared.features];
|
|
9221
10020
|
readOnlyFeatures.current.set(layerId, combined);
|
|
9222
10021
|
layerTemporalCacheRef.current.set(layerId, { featureCount: combined.length, hasTemporal: layerHasTemporal });
|
|
9223
|
-
const addedIds2 =
|
|
10022
|
+
const addedIds2 = prepared.featureIds;
|
|
9224
10023
|
const updatedLayers2 = layersRef.current.map(
|
|
9225
10024
|
(l) => l.id === layerId ? { ...l, featureIds: [...l.featureIds, ...addedIds2] } : l
|
|
9226
10025
|
);
|
|
@@ -9455,31 +10254,13 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9455
10254
|
updateReadOnlyLayer: (layerId, features) => {
|
|
9456
10255
|
const layer = layersRef.current.find((l) => l.id === layerId);
|
|
9457
10256
|
if (!layer || !layer.readOnly || !isMapLoadedRef.current) return false;
|
|
9458
|
-
|
|
9459
|
-
|
|
9460
|
-
|
|
9461
|
-
|
|
9462
|
-
if (!hasAnyTemporalValue(props)) {
|
|
9463
|
-
return { ...f, id };
|
|
9464
|
-
}
|
|
9465
|
-
const { startDate, endDate } = normalizeTemporalProperties(props);
|
|
9466
|
-
if (startDate || endDate) layerHasTemporal = true;
|
|
9467
|
-
return {
|
|
9468
|
-
...f,
|
|
9469
|
-
id,
|
|
9470
|
-
properties: {
|
|
9471
|
-
...props,
|
|
9472
|
-
startDate: (startDate == null ? void 0 : startDate.toISOString()) || null,
|
|
9473
|
-
endDate: (endDate == null ? void 0 : endDate.toISOString()) || null
|
|
9474
|
-
}
|
|
9475
|
-
};
|
|
9476
|
-
});
|
|
9477
|
-
readOnlyFeatures.current.set(layerId, featuresWithIds);
|
|
9478
|
-
layerTemporalCacheRef.current.set(layerId, { featureCount: features.length, hasTemporal: layerHasTemporal });
|
|
9479
|
-
if (layerHasTemporal) {
|
|
10257
|
+
const prepared = prepareFeaturesForLayer(features, "updateReadOnlyLayer");
|
|
10258
|
+
readOnlyFeatures.current.set(layerId, prepared.features);
|
|
10259
|
+
layerTemporalCacheRef.current.set(layerId, { featureCount: features.length, hasTemporal: prepared.hasTemporal });
|
|
10260
|
+
if (prepared.hasTemporal) {
|
|
9480
10261
|
scheduleTimelineUpdate();
|
|
9481
10262
|
}
|
|
9482
|
-
const newFeatureIds =
|
|
10263
|
+
const newFeatureIds = prepared.featureIds;
|
|
9483
10264
|
const updatedLayers = layersRef.current.map(
|
|
9484
10265
|
(l) => l.id === layerId ? { ...l, featureIds: newFeatureIds } : l
|
|
9485
10266
|
);
|
|
@@ -9491,29 +10272,11 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9491
10272
|
},
|
|
9492
10273
|
setLayerData: (name, geojson, options) => {
|
|
9493
10274
|
if (!isMapLoadedRef.current) return "";
|
|
9494
|
-
|
|
9495
|
-
const
|
|
9496
|
-
const id = f.id ? String(f.id) : crypto.randomUUID();
|
|
9497
|
-
const props = f.properties || {};
|
|
9498
|
-
if (!hasAnyTemporalValue(props)) {
|
|
9499
|
-
return { ...f, id };
|
|
9500
|
-
}
|
|
9501
|
-
const { startDate, endDate } = normalizeTemporalProperties(props);
|
|
9502
|
-
if (startDate || endDate) layerHasTemporal = true;
|
|
9503
|
-
return {
|
|
9504
|
-
...f,
|
|
9505
|
-
id,
|
|
9506
|
-
properties: {
|
|
9507
|
-
...props,
|
|
9508
|
-
startDate: (startDate == null ? void 0 : startDate.toISOString()) || null,
|
|
9509
|
-
endDate: (endDate == null ? void 0 : endDate.toISOString()) || null
|
|
9510
|
-
}
|
|
9511
|
-
};
|
|
9512
|
-
});
|
|
9513
|
-
const newFeatureIds = featuresWithIds.map((f) => String(f.id));
|
|
10275
|
+
const prepared = prepareFeaturesForLayer(geojson.features, "setLayerData");
|
|
10276
|
+
const newFeatureIds = prepared.featureIds;
|
|
9514
10277
|
const layerId = `managed-${name}`;
|
|
9515
|
-
readOnlyFeatures.current.set(layerId,
|
|
9516
|
-
layerTemporalCacheRef.current.set(layerId, { featureCount:
|
|
10278
|
+
readOnlyFeatures.current.set(layerId, prepared.features);
|
|
10279
|
+
layerTemporalCacheRef.current.set(layerId, { featureCount: prepared.features.length, hasTemporal: prepared.hasTemporal });
|
|
9517
10280
|
const buildLayerObj = (existing) => {
|
|
9518
10281
|
const base = {
|
|
9519
10282
|
id: layerId,
|
|
@@ -10744,18 +11507,23 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
10744
11507
|
useEffect(() => {
|
|
10745
11508
|
if (!map.current || !isMapLoaded) return;
|
|
10746
11509
|
const mapInstance = map.current;
|
|
11510
|
+
let rafId = null;
|
|
10747
11511
|
const handleMove = () => {
|
|
10748
|
-
if (!hasArrowFeaturesRef.current) return;
|
|
10749
|
-
|
|
11512
|
+
if (!hasArrowFeaturesRef.current || rafId !== null) return;
|
|
11513
|
+
rafId = requestAnimationFrame(() => {
|
|
11514
|
+
rafId = null;
|
|
11515
|
+
renderArrowOverlays(paintedArrowLinesRef.current);
|
|
11516
|
+
});
|
|
10750
11517
|
};
|
|
10751
11518
|
mapInstance.on("move", handleMove);
|
|
10752
11519
|
return () => {
|
|
11520
|
+
if (rafId !== null) cancelAnimationFrame(rafId);
|
|
10753
11521
|
try {
|
|
10754
11522
|
mapInstance.off("move", handleMove);
|
|
10755
11523
|
} catch {
|
|
10756
11524
|
}
|
|
10757
11525
|
};
|
|
10758
|
-
}, [isMapLoaded]);
|
|
11526
|
+
}, [isMapLoaded, renderArrowOverlays]);
|
|
10759
11527
|
useEffect(() => {
|
|
10760
11528
|
if (!map.current || !isMapLoaded || !onViewportChange) return;
|
|
10761
11529
|
const mapInstance = map.current;
|
|
@@ -11078,6 +11846,29 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
11078
11846
|
return applySelectionFastPath(selectionPaintCacheRef.current, next, source);
|
|
11079
11847
|
}, []);
|
|
11080
11848
|
trySelectionFastPathRef.current = trySelectionFastPath;
|
|
11849
|
+
const tryTimelineFastPath = useCallback(() => {
|
|
11850
|
+
const m = map.current;
|
|
11851
|
+
if (!m) return true;
|
|
11852
|
+
if (hasArrowFeaturesRef.current) return false;
|
|
11853
|
+
if (layersRef.current.some((l) => {
|
|
11854
|
+
var _a;
|
|
11855
|
+
return l.visible && ((_a = l.traceConfig) == null ? void 0 : _a.enabled);
|
|
11856
|
+
})) return false;
|
|
11857
|
+
const source = m.getSource("custom-features");
|
|
11858
|
+
const { applied, toggled } = applyTimelineFastPath(
|
|
11859
|
+
selectionPaintCacheRef.current,
|
|
11860
|
+
timelineVisibleIdsRef.current,
|
|
11861
|
+
source
|
|
11862
|
+
);
|
|
11863
|
+
if (applied) {
|
|
11864
|
+
const threshold = autoLabelConfig.enabled ? autoLabelConfig.threshold : 220;
|
|
11865
|
+
setVisibleFeatureCount(countVisibleFeatures(threshold));
|
|
11866
|
+
setLabelsSuppressed(false);
|
|
11867
|
+
mapPerfLog("timeline", "fast path applied", { toggled });
|
|
11868
|
+
}
|
|
11869
|
+
return applied;
|
|
11870
|
+
}, [autoLabelConfig, countVisibleFeatures]);
|
|
11871
|
+
tryTimelineFastPathRef.current = tryTimelineFastPath;
|
|
11081
11872
|
const collectSelectionFeatureGroups = useCallback(() => {
|
|
11082
11873
|
return collectVisibleFeatureGroups(
|
|
11083
11874
|
draw.current ? draw.current.getAll().features : null,
|
|
@@ -11831,7 +12622,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
11831
12622
|
layerMetadata
|
|
11832
12623
|
}
|
|
11833
12624
|
};
|
|
11834
|
-
const blob = new Blob(
|
|
12625
|
+
const blob = new Blob(featureCollectionBlobParts(geojson), { type: "application/json" });
|
|
11835
12626
|
downloadBlob(blob, `${layer.name.replace(/[^a-z0-9]/gi, "_")}.geojson`);
|
|
11836
12627
|
}, [layers]);
|
|
11837
12628
|
const handleLoadLayerGeoJSON = useCallback((layerId) => {
|
|
@@ -11908,7 +12699,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
11908
12699
|
const handleSaveAllGeoJSON = useCallback(() => {
|
|
11909
12700
|
if (!draw.current) return;
|
|
11910
12701
|
const geojson = buildEnrichedGeoJSON();
|
|
11911
|
-
const blob = new Blob(
|
|
12702
|
+
const blob = new Blob(featureCollectionBlobParts(geojson), { type: "application/geo+json" });
|
|
11912
12703
|
downloadBlob(blob, "map_export.geojson");
|
|
11913
12704
|
}, [buildEnrichedGeoJSON]);
|
|
11914
12705
|
const handleSearchAndAddToNewLayer = useCallback(async () => {
|
|
@@ -12099,26 +12890,14 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
12099
12890
|
}
|
|
12100
12891
|
saveStateForUndo();
|
|
12101
12892
|
const layerId = `layer-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
12102
|
-
|
|
12103
|
-
|
|
12104
|
-
|
|
12105
|
-
const id = f.id ? String(f.id) : crypto.randomUUID();
|
|
12106
|
-
if (!hasAnyTemporalValue(props)) return { ...f, id };
|
|
12107
|
-
const { startDate, endDate } = normalizeTemporalProperties(props);
|
|
12108
|
-
if (startDate || endDate) wsHasTemporal = true;
|
|
12109
|
-
return {
|
|
12110
|
-
...f,
|
|
12111
|
-
id,
|
|
12112
|
-
properties: { ...props, startDate: (startDate == null ? void 0 : startDate.toISOString()) || null, endDate: (endDate == null ? void 0 : endDate.toISOString()) || null }
|
|
12113
|
-
};
|
|
12114
|
-
});
|
|
12115
|
-
readOnlyFeatures.current.set(layerId, featuresWithIds);
|
|
12116
|
-
layerTemporalCacheRef.current.set(layerId, { featureCount: featuresWithIds.length, hasTemporal: wsHasTemporal });
|
|
12893
|
+
const prepared = prepareFeaturesForLayer(result.features, "workspaceLoad");
|
|
12894
|
+
readOnlyFeatures.current.set(layerId, prepared.features);
|
|
12895
|
+
layerTemporalCacheRef.current.set(layerId, { featureCount: prepared.features.length, hasTemporal: prepared.hasTemporal });
|
|
12117
12896
|
const newLayer = {
|
|
12118
12897
|
id: layerId,
|
|
12119
12898
|
name: "Loaded from workspace",
|
|
12120
12899
|
visible: true,
|
|
12121
|
-
featureIds:
|
|
12900
|
+
featureIds: prepared.featureIds,
|
|
12122
12901
|
readOnly: true
|
|
12123
12902
|
};
|
|
12124
12903
|
setLayers((prev) => [...prev, newLayer]);
|
|
@@ -12127,7 +12906,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
12127
12906
|
scheduleSync();
|
|
12128
12907
|
toast({
|
|
12129
12908
|
title: "Features loaded",
|
|
12130
|
-
description: `Created layer with ${
|
|
12909
|
+
description: `Created layer with ${prepared.features.length} features`
|
|
12131
12910
|
});
|
|
12132
12911
|
} catch (error) {
|
|
12133
12912
|
toast({
|
|
@@ -12214,195 +12993,206 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
12214
12993
|
duration: 1e3
|
|
12215
12994
|
});
|
|
12216
12995
|
}, [layers, toast]);
|
|
12217
|
-
const
|
|
12218
|
-
|
|
12219
|
-
const
|
|
12220
|
-
|
|
12221
|
-
|
|
12222
|
-
|
|
12223
|
-
|
|
12224
|
-
|
|
12225
|
-
|
|
12226
|
-
|
|
12227
|
-
|
|
12228
|
-
|
|
12229
|
-
|
|
12230
|
-
|
|
12231
|
-
|
|
12232
|
-
|
|
12233
|
-
|
|
12234
|
-
|
|
12235
|
-
|
|
12236
|
-
|
|
12237
|
-
|
|
12238
|
-
|
|
12239
|
-
|
|
12240
|
-
|
|
12241
|
-
|
|
12242
|
-
|
|
12243
|
-
|
|
12244
|
-
|
|
12245
|
-
|
|
12246
|
-
return;
|
|
12247
|
-
}
|
|
12248
|
-
if (!draw.current) return;
|
|
12249
|
-
const { features: geojson, reprojected, sourceCRS } = detectAndReprojectGeoJSON(rawGeojson);
|
|
12250
|
-
saveStateForUndo();
|
|
12251
|
-
const layerMetadata = (_b = rawGeojson.properties) == null ? void 0 : _b.layerMetadata;
|
|
12252
|
-
let fileHasTemporal = false;
|
|
12253
|
-
const normalizedFeatures = geojson.features.map((f) => {
|
|
12254
|
-
const props = f.properties || {};
|
|
12255
|
-
if (!hasAnyTemporalValue(props)) return f;
|
|
12256
|
-
const { startDate, endDate } = normalizeTemporalProperties(props);
|
|
12257
|
-
if (startDate || endDate) fileHasTemporal = true;
|
|
12258
|
-
return {
|
|
12259
|
-
...f,
|
|
12260
|
-
properties: {
|
|
12261
|
-
...props,
|
|
12262
|
-
startDate: (startDate == null ? void 0 : startDate.toISOString()) || null,
|
|
12263
|
-
endDate: (endDate == null ? void 0 : endDate.toISOString()) || null
|
|
12264
|
-
}
|
|
12265
|
-
};
|
|
12266
|
-
});
|
|
12267
|
-
if (createNewLayer) {
|
|
12268
|
-
if (interceptGeoJSONFileLoad != null && interceptGeoJSONFileLoad({
|
|
12269
|
-
kind: "newLayer",
|
|
12270
|
-
data: { type: "FeatureCollection", features: normalizedFeatures },
|
|
12271
|
-
file,
|
|
12272
|
-
reprojected,
|
|
12273
|
-
sourceCRS: sourceCRS ?? void 0
|
|
12274
|
-
}) === true) {
|
|
12275
|
-
return;
|
|
12276
|
-
}
|
|
12277
|
-
const fileName = file.name.replace(/\.geojson$|\.json$/i, "");
|
|
12278
|
-
const layerId = `layer-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
12279
|
-
const newLayer = {
|
|
12280
|
-
id: layerId,
|
|
12281
|
-
name: (layerMetadata == null ? void 0 : layerMetadata.name) || fileName,
|
|
12282
|
-
visible: true,
|
|
12283
|
-
featureIds: [],
|
|
12284
|
-
readOnly: true,
|
|
12285
|
-
...(layerMetadata == null ? void 0 : layerMetadata.traceConfig) && { traceConfig: layerMetadata.traceConfig },
|
|
12286
|
-
...(layerMetadata == null ? void 0 : layerMetadata.heatmapConfig) && { heatmapConfig: layerMetadata.heatmapConfig },
|
|
12287
|
-
...(layerMetadata == null ? void 0 : layerMetadata.visualConfig) && { visualConfig: layerMetadata.visualConfig }
|
|
12288
|
-
};
|
|
12289
|
-
const addedIds = [];
|
|
12290
|
-
const featuresWithIds = [];
|
|
12291
|
-
normalizedFeatures.forEach((f) => {
|
|
12292
|
-
const featureId = f.id ? String(f.id) : crypto.randomUUID();
|
|
12293
|
-
const normalizedFeature = { ...f, id: featureId };
|
|
12294
|
-
featuresWithIds.push(normalizedFeature);
|
|
12295
|
-
addedIds.push(featureId);
|
|
12296
|
-
});
|
|
12297
|
-
readOnlyFeatures.current.set(layerId, featuresWithIds);
|
|
12298
|
-
layerTemporalCacheRef.current.set(layerId, { featureCount: featuresWithIds.length, hasTemporal: fileHasTemporal });
|
|
12299
|
-
newLayer.featureIds = addedIds;
|
|
12300
|
-
setLayers((prev) => [...prev, newLayer]);
|
|
12301
|
-
updateFeatureCount();
|
|
12302
|
-
scheduleTimelineUpdate();
|
|
12303
|
-
scheduleSync();
|
|
12304
|
-
if (map.current && geojson.features.length > 0) {
|
|
12305
|
-
try {
|
|
12306
|
-
const bbox = turf.bbox(geojson);
|
|
12307
|
-
if (bbox && bbox.every((v) => isFinite(v))) {
|
|
12308
|
-
map.current.fitBounds(
|
|
12309
|
-
[[bbox[0], bbox[1]], [bbox[2], bbox[3]]],
|
|
12310
|
-
{ padding: 50, maxZoom: 16, duration: 1e3 }
|
|
12311
|
-
);
|
|
12312
|
-
}
|
|
12313
|
-
} catch (e2) {
|
|
12314
|
-
}
|
|
12315
|
-
}
|
|
12316
|
-
const reprojectMsg2 = reprojected ? ` (reprojected from ${sourceCRS})` : "";
|
|
12317
|
-
toast({
|
|
12318
|
-
title: "Layer created",
|
|
12319
|
-
description: `Created "${newLayer.name}" with ${addedIds.length} features${reprojectMsg2} (high-performance mode)`
|
|
12320
|
-
});
|
|
12321
|
-
return;
|
|
12322
|
-
}
|
|
12323
|
-
let targetLayer = layers.find((l) => l.id === requestedTargetLayerId && !l.readOnly);
|
|
12324
|
-
if (!targetLayer) {
|
|
12325
|
-
targetLayer = layers.find((l) => l.visible && !l.readOnly);
|
|
12326
|
-
}
|
|
12327
|
-
if (!targetLayer) {
|
|
12328
|
-
targetLayer = layers.find((l) => !l.readOnly);
|
|
12329
|
-
}
|
|
12330
|
-
if (targetLayer == null ? void 0 : targetLayer.visible) {
|
|
12331
|
-
const addedIds = [];
|
|
12332
|
-
isApiAddingRef.current = true;
|
|
12333
|
-
try {
|
|
12334
|
-
normalizedFeatures.forEach((f) => {
|
|
12335
|
-
const ids = draw.current.add(f);
|
|
12336
|
-
addedIds.push(ids[0]);
|
|
12337
|
-
});
|
|
12338
|
-
} finally {
|
|
12339
|
-
isApiAddingRef.current = false;
|
|
12340
|
-
}
|
|
12341
|
-
const targetId = targetLayer.id;
|
|
12342
|
-
setLayers((prev) => prev.map((l) => {
|
|
12343
|
-
if (l.id !== targetId) return l;
|
|
12344
|
-
return {
|
|
12345
|
-
...l,
|
|
12346
|
-
featureIds: [...l.featureIds, ...addedIds],
|
|
12347
|
-
...(layerMetadata == null ? void 0 : layerMetadata.traceConfig) && { traceConfig: layerMetadata.traceConfig },
|
|
12348
|
-
...(layerMetadata == null ? void 0 : layerMetadata.heatmapConfig) && { heatmapConfig: layerMetadata.heatmapConfig },
|
|
12349
|
-
...(layerMetadata == null ? void 0 : layerMetadata.visualConfig) && { visualConfig: layerMetadata.visualConfig }
|
|
12350
|
-
};
|
|
12351
|
-
}));
|
|
12352
|
-
} else if (targetLayer) {
|
|
12353
|
-
const featuresWithIds = normalizedFeatures.map((f) => ({
|
|
12354
|
-
...f,
|
|
12355
|
-
id: f.id || `feature-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`
|
|
12356
|
-
}));
|
|
12357
|
-
const targetId = targetLayer.id;
|
|
12358
|
-
const addedIds = featuresWithIds.map((f) => f.id);
|
|
12359
|
-
const existing = hiddenFeatures.current.get(targetId) || [];
|
|
12360
|
-
hiddenFeatures.current.set(targetId, [...existing, ...featuresWithIds]);
|
|
12361
|
-
setLayers((prev) => prev.map((l) => {
|
|
12362
|
-
if (l.id !== targetId) return l;
|
|
12363
|
-
return {
|
|
12364
|
-
...l,
|
|
12365
|
-
featureIds: [...l.featureIds, ...addedIds],
|
|
12366
|
-
...(layerMetadata == null ? void 0 : layerMetadata.traceConfig) && { traceConfig: layerMetadata.traceConfig },
|
|
12367
|
-
...(layerMetadata == null ? void 0 : layerMetadata.heatmapConfig) && { heatmapConfig: layerMetadata.heatmapConfig },
|
|
12368
|
-
...(layerMetadata == null ? void 0 : layerMetadata.visualConfig) && { visualConfig: layerMetadata.visualConfig }
|
|
12369
|
-
};
|
|
12370
|
-
}));
|
|
12371
|
-
}
|
|
12372
|
-
updateFeatureCount();
|
|
12373
|
-
scheduleTimelineUpdate();
|
|
12374
|
-
scheduleSync();
|
|
12375
|
-
const reprojectMsg = reprojected ? ` (reprojected from ${sourceCRS})` : "";
|
|
12996
|
+
const [ingestProgressStore] = useState(createIngestProgressStore);
|
|
12997
|
+
const ingestWithProgress = useCallback(async (label, input, options) => {
|
|
12998
|
+
const progress = ingestProgressStore.begin(label);
|
|
12999
|
+
try {
|
|
13000
|
+
return await getSharedIngestClient().ingest(input, options, {
|
|
13001
|
+
onHead: (summary) => progress.setTotal(summary.featureCount),
|
|
13002
|
+
onProgress: (received) => progress.update(received)
|
|
13003
|
+
});
|
|
13004
|
+
} finally {
|
|
13005
|
+
progress.end();
|
|
13006
|
+
}
|
|
13007
|
+
}, [ingestProgressStore]);
|
|
13008
|
+
const loadGeoJSONFile = useCallback(async (file, requestedTargetLayerId, createNewLayer) => {
|
|
13009
|
+
let result;
|
|
13010
|
+
try {
|
|
13011
|
+
result = await ingestWithProgress(file.name, file, {
|
|
13012
|
+
idStrategy: "uuid-fallback",
|
|
13013
|
+
emptyIsError: true
|
|
13014
|
+
});
|
|
13015
|
+
} catch (error) {
|
|
13016
|
+
toast({
|
|
13017
|
+
title: "Failed to load GeoJSON",
|
|
13018
|
+
description: error instanceof Error ? error.message : "Invalid file",
|
|
13019
|
+
variant: "destructive"
|
|
13020
|
+
});
|
|
13021
|
+
return;
|
|
13022
|
+
}
|
|
13023
|
+
if (result.kind === "error") {
|
|
13024
|
+
if (result.code === "empty") {
|
|
12376
13025
|
toast({
|
|
12377
|
-
title: "GeoJSON
|
|
12378
|
-
description:
|
|
13026
|
+
title: "Empty GeoJSON",
|
|
13027
|
+
description: result.message,
|
|
13028
|
+
variant: "destructive"
|
|
12379
13029
|
});
|
|
12380
|
-
}
|
|
13030
|
+
} else {
|
|
12381
13031
|
toast({
|
|
12382
13032
|
title: "Failed to load GeoJSON",
|
|
12383
|
-
description:
|
|
13033
|
+
description: result.message,
|
|
12384
13034
|
variant: "destructive"
|
|
12385
13035
|
});
|
|
12386
13036
|
}
|
|
12387
|
-
|
|
12388
|
-
|
|
12389
|
-
|
|
12390
|
-
|
|
12391
|
-
|
|
13037
|
+
return;
|
|
13038
|
+
}
|
|
13039
|
+
if (result.kind === "enriched") {
|
|
13040
|
+
const rawGeojson = result.data;
|
|
13041
|
+
if (interceptGeoJSONFileLoad != null && interceptGeoJSONFileLoad({ kind: "enriched", data: rawGeojson, file }) === true) {
|
|
13042
|
+
return;
|
|
13043
|
+
}
|
|
13044
|
+
if (!draw.current) return;
|
|
13045
|
+
restoreEnrichedGeoJSON(rawGeojson);
|
|
13046
|
+
return;
|
|
13047
|
+
}
|
|
13048
|
+
if (!draw.current) return;
|
|
13049
|
+
const { features: normalizedFeatures, reprojected, sourceCRS, hasTemporal: fileHasTemporal } = result;
|
|
13050
|
+
const layerMetadata = result.layerMetadata;
|
|
13051
|
+
saveStateForUndo();
|
|
13052
|
+
if (createNewLayer) {
|
|
13053
|
+
if (interceptGeoJSONFileLoad != null && interceptGeoJSONFileLoad({
|
|
13054
|
+
kind: "newLayer",
|
|
13055
|
+
data: { type: "FeatureCollection", features: normalizedFeatures },
|
|
13056
|
+
file,
|
|
13057
|
+
reprojected,
|
|
13058
|
+
sourceCRS: sourceCRS ?? void 0
|
|
13059
|
+
}) === true) {
|
|
13060
|
+
return;
|
|
13061
|
+
}
|
|
13062
|
+
const fileName = file.name.replace(/\.geojson$|\.json$/i, "");
|
|
13063
|
+
const layerId = `layer-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
13064
|
+
const newLayer = {
|
|
13065
|
+
id: layerId,
|
|
13066
|
+
name: (layerMetadata == null ? void 0 : layerMetadata.name) || fileName,
|
|
13067
|
+
visible: true,
|
|
13068
|
+
featureIds: [],
|
|
13069
|
+
readOnly: true,
|
|
13070
|
+
...(layerMetadata == null ? void 0 : layerMetadata.traceConfig) && { traceConfig: layerMetadata.traceConfig },
|
|
13071
|
+
...(layerMetadata == null ? void 0 : layerMetadata.heatmapConfig) && { heatmapConfig: layerMetadata.heatmapConfig },
|
|
13072
|
+
...(layerMetadata == null ? void 0 : layerMetadata.visualConfig) && { visualConfig: layerMetadata.visualConfig }
|
|
13073
|
+
};
|
|
13074
|
+
const addedIds = normalizedFeatures.map((f) => String(f.id));
|
|
13075
|
+
readOnlyFeatures.current.set(layerId, normalizedFeatures);
|
|
13076
|
+
layerTemporalCacheRef.current.set(layerId, { featureCount: normalizedFeatures.length, hasTemporal: fileHasTemporal });
|
|
13077
|
+
newLayer.featureIds = addedIds;
|
|
13078
|
+
setLayers((prev) => [...prev, newLayer]);
|
|
13079
|
+
updateFeatureCount();
|
|
13080
|
+
scheduleTimelineUpdate();
|
|
13081
|
+
scheduleSync();
|
|
13082
|
+
if (map.current && result.bbox) {
|
|
13083
|
+
const bbox = result.bbox;
|
|
13084
|
+
map.current.fitBounds(
|
|
13085
|
+
[[bbox[0], bbox[1]], [bbox[2], bbox[3]]],
|
|
13086
|
+
{ padding: 50, maxZoom: 16, duration: 1e3 }
|
|
13087
|
+
);
|
|
13088
|
+
}
|
|
13089
|
+
const reprojectMsg2 = reprojected ? ` (reprojected from ${sourceCRS})` : "";
|
|
13090
|
+
toast({
|
|
13091
|
+
title: "Layer created",
|
|
13092
|
+
description: `Created "${newLayer.name}" with ${addedIds.length} features${reprojectMsg2} (high-performance mode)`
|
|
13093
|
+
});
|
|
13094
|
+
return;
|
|
13095
|
+
}
|
|
13096
|
+
const currentLayers = layersRef.current;
|
|
13097
|
+
let targetLayer = currentLayers.find((l) => l.id === requestedTargetLayerId && !l.readOnly);
|
|
13098
|
+
if (!targetLayer) {
|
|
13099
|
+
targetLayer = currentLayers.find((l) => l.visible && !l.readOnly);
|
|
13100
|
+
}
|
|
13101
|
+
if (!targetLayer) {
|
|
13102
|
+
targetLayer = currentLayers.find((l) => !l.readOnly);
|
|
13103
|
+
}
|
|
13104
|
+
if (targetLayer == null ? void 0 : targetLayer.visible) {
|
|
13105
|
+
const addedIds = [];
|
|
13106
|
+
isApiAddingRef.current = true;
|
|
13107
|
+
try {
|
|
13108
|
+
normalizedFeatures.forEach((f) => {
|
|
13109
|
+
const ids = draw.current.add(f);
|
|
13110
|
+
addedIds.push(ids[0]);
|
|
13111
|
+
});
|
|
13112
|
+
} finally {
|
|
13113
|
+
isApiAddingRef.current = false;
|
|
13114
|
+
}
|
|
13115
|
+
const targetId = targetLayer.id;
|
|
13116
|
+
setLayers((prev) => prev.map((l) => {
|
|
13117
|
+
if (l.id !== targetId) return l;
|
|
13118
|
+
return {
|
|
13119
|
+
...l,
|
|
13120
|
+
featureIds: [...l.featureIds, ...addedIds],
|
|
13121
|
+
...(layerMetadata == null ? void 0 : layerMetadata.traceConfig) && { traceConfig: layerMetadata.traceConfig },
|
|
13122
|
+
...(layerMetadata == null ? void 0 : layerMetadata.heatmapConfig) && { heatmapConfig: layerMetadata.heatmapConfig },
|
|
13123
|
+
...(layerMetadata == null ? void 0 : layerMetadata.visualConfig) && { visualConfig: layerMetadata.visualConfig }
|
|
13124
|
+
};
|
|
13125
|
+
}));
|
|
13126
|
+
} else if (targetLayer) {
|
|
13127
|
+
const targetId = targetLayer.id;
|
|
13128
|
+
const addedIds = normalizedFeatures.map((f) => String(f.id));
|
|
13129
|
+
const existing = hiddenFeatures.current.get(targetId) || [];
|
|
13130
|
+
hiddenFeatures.current.set(targetId, [...existing, ...normalizedFeatures]);
|
|
13131
|
+
setLayers((prev) => prev.map((l) => {
|
|
13132
|
+
if (l.id !== targetId) return l;
|
|
13133
|
+
return {
|
|
13134
|
+
...l,
|
|
13135
|
+
featureIds: [...l.featureIds, ...addedIds],
|
|
13136
|
+
...(layerMetadata == null ? void 0 : layerMetadata.traceConfig) && { traceConfig: layerMetadata.traceConfig },
|
|
13137
|
+
...(layerMetadata == null ? void 0 : layerMetadata.heatmapConfig) && { heatmapConfig: layerMetadata.heatmapConfig },
|
|
13138
|
+
...(layerMetadata == null ? void 0 : layerMetadata.visualConfig) && { visualConfig: layerMetadata.visualConfig }
|
|
13139
|
+
};
|
|
13140
|
+
}));
|
|
13141
|
+
}
|
|
13142
|
+
updateFeatureCount();
|
|
13143
|
+
scheduleTimelineUpdate();
|
|
13144
|
+
scheduleSync();
|
|
13145
|
+
const reprojectMsg = reprojected ? ` (reprojected from ${sourceCRS})` : "";
|
|
13146
|
+
toast({
|
|
13147
|
+
title: "GeoJSON loaded",
|
|
13148
|
+
description: `Added ${normalizedFeatures.length} features${reprojectMsg}${!(targetLayer == null ? void 0 : targetLayer.visible) ? " (layer hidden)" : ""}`
|
|
13149
|
+
});
|
|
13150
|
+
}, [saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, restoreEnrichedGeoJSON, toast, interceptGeoJSONFileLoad, ingestWithProgress]);
|
|
13151
|
+
const handleFileChange = useCallback((e) => {
|
|
12392
13152
|
var _a;
|
|
13153
|
+
const file = (_a = e.target.files) == null ? void 0 : _a[0];
|
|
13154
|
+
if (!file) return;
|
|
13155
|
+
const requestedTargetLayerId = e.target.dataset.targetLayer || activeEditingLayerId;
|
|
13156
|
+
const createNewLayer = e.target.dataset.createNewLayer === "true";
|
|
13157
|
+
delete e.target.dataset.createNewLayer;
|
|
13158
|
+
e.target.value = "";
|
|
13159
|
+
void loadGeoJSONFile(file, requestedTargetLayerId, createNewLayer);
|
|
13160
|
+
}, [activeEditingLayerId, loadGeoJSONFile]);
|
|
13161
|
+
const ingestDroppedLayer = useCallback(async (name, input) => {
|
|
13162
|
+
if (!map.current) return;
|
|
13163
|
+
const layerId = `layer-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
13164
|
+
const startedAt = performance.now();
|
|
13165
|
+
let result;
|
|
13166
|
+
try {
|
|
13167
|
+
result = await ingestWithProgress(name, input, { idStrategy: "layer-index", layerId });
|
|
13168
|
+
} catch (error) {
|
|
13169
|
+
toast({
|
|
13170
|
+
title: "Failed to load GeoJSON",
|
|
13171
|
+
description: error instanceof Error ? error.message : "Invalid file",
|
|
13172
|
+
variant: "destructive"
|
|
13173
|
+
});
|
|
13174
|
+
return;
|
|
13175
|
+
}
|
|
12393
13176
|
if (!map.current) return;
|
|
12394
|
-
if (
|
|
13177
|
+
if (result.kind === "error") {
|
|
13178
|
+
toast({
|
|
13179
|
+
title: "Failed to load GeoJSON",
|
|
13180
|
+
description: result.message,
|
|
13181
|
+
variant: "destructive"
|
|
13182
|
+
});
|
|
13183
|
+
return;
|
|
13184
|
+
}
|
|
13185
|
+
if (result.kind === "enriched") {
|
|
13186
|
+
const data = result.data;
|
|
12395
13187
|
if (interceptGeoJSONFileLoad != null && interceptGeoJSONFileLoad({ kind: "enriched", data, sourceName: name }) === true) {
|
|
12396
13188
|
return;
|
|
12397
13189
|
}
|
|
12398
13190
|
restoreEnrichedGeoJSON(data);
|
|
12399
13191
|
return;
|
|
12400
13192
|
}
|
|
12401
|
-
const { features:
|
|
13193
|
+
const { features: normalizedFeatures, reprojected, sourceCRS } = result;
|
|
13194
|
+
const layerMetadata = result.layerMetadata;
|
|
12402
13195
|
saveStateForUndo();
|
|
12403
|
-
const layerMetadata = (_a = data.properties) == null ? void 0 : _a.layerMetadata;
|
|
12404
|
-
const layerId = `layer-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
12405
|
-
const layerHasAltitudeData = reprojectedData.features.some((f) => hasAltitudeData(f));
|
|
12406
13196
|
const newLayer = {
|
|
12407
13197
|
id: layerId,
|
|
12408
13198
|
name: (layerMetadata == null ? void 0 : layerMetadata.name) || name,
|
|
@@ -12413,34 +13203,11 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
12413
13203
|
...(layerMetadata == null ? void 0 : layerMetadata.traceConfig) && { traceConfig: layerMetadata.traceConfig },
|
|
12414
13204
|
...(layerMetadata == null ? void 0 : layerMetadata.heatmapConfig) && { heatmapConfig: layerMetadata.heatmapConfig },
|
|
12415
13205
|
...(layerMetadata == null ? void 0 : layerMetadata.visualConfig) && { visualConfig: layerMetadata.visualConfig },
|
|
12416
|
-
...
|
|
13206
|
+
...result.hasAltitude && { hasAltitudeData: true, altitudeDisplayMode: "both" }
|
|
12417
13207
|
};
|
|
12418
|
-
const
|
|
12419
|
-
const addedIds = [];
|
|
12420
|
-
let dropHasTemporal = false;
|
|
12421
|
-
reprojectedData.features.forEach((f, index) => {
|
|
12422
|
-
const featureId = f.id !== void 0 && f.id !== null ? String(f.id) : `${layerId}-f${index}`;
|
|
12423
|
-
const props = f.properties || {};
|
|
12424
|
-
if (!hasAnyTemporalValue(props)) {
|
|
12425
|
-
normalizedFeatures.push({ ...f, id: featureId });
|
|
12426
|
-
addedIds.push(featureId);
|
|
12427
|
-
return;
|
|
12428
|
-
}
|
|
12429
|
-
const { startDate, endDate } = normalizeTemporalProperties(props);
|
|
12430
|
-
if (startDate || endDate) dropHasTemporal = true;
|
|
12431
|
-
normalizedFeatures.push({
|
|
12432
|
-
...f,
|
|
12433
|
-
id: featureId,
|
|
12434
|
-
properties: {
|
|
12435
|
-
...props,
|
|
12436
|
-
startDate: (startDate == null ? void 0 : startDate.toISOString()) || null,
|
|
12437
|
-
endDate: (endDate == null ? void 0 : endDate.toISOString()) || null
|
|
12438
|
-
}
|
|
12439
|
-
});
|
|
12440
|
-
addedIds.push(featureId);
|
|
12441
|
-
});
|
|
13208
|
+
const addedIds = normalizedFeatures.map((f) => f.id);
|
|
12442
13209
|
readOnlyFeatures.current.set(layerId, normalizedFeatures);
|
|
12443
|
-
layerTemporalCacheRef.current.set(layerId, { featureCount: normalizedFeatures.length, hasTemporal:
|
|
13210
|
+
layerTemporalCacheRef.current.set(layerId, { featureCount: normalizedFeatures.length, hasTemporal: result.hasTemporal });
|
|
12444
13211
|
newLayer.featureIds = addedIds;
|
|
12445
13212
|
const nextLayers = [...layersRef.current, newLayer];
|
|
12446
13213
|
layersRef.current = nextLayers;
|
|
@@ -12448,28 +13215,35 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
12448
13215
|
updateFeatureCount();
|
|
12449
13216
|
scheduleTimelineUpdate();
|
|
12450
13217
|
scheduleSync();
|
|
12451
|
-
if (
|
|
12452
|
-
|
|
12453
|
-
|
|
12454
|
-
|
|
12455
|
-
|
|
12456
|
-
|
|
12457
|
-
{ padding: 50, maxZoom: 16, duration: 1e3 }
|
|
12458
|
-
);
|
|
12459
|
-
}
|
|
12460
|
-
} catch (e) {
|
|
12461
|
-
}
|
|
13218
|
+
if (result.bbox) {
|
|
13219
|
+
const bbox = result.bbox;
|
|
13220
|
+
map.current.fitBounds(
|
|
13221
|
+
[[bbox[0], bbox[1]], [bbox[2], bbox[3]]],
|
|
13222
|
+
{ padding: 50, maxZoom: 16, duration: 1e3 }
|
|
13223
|
+
);
|
|
12462
13224
|
}
|
|
13225
|
+
mapPerfLog("ingest", `dropped layer "${newLayer.name}" applied`, {
|
|
13226
|
+
features: addedIds.length,
|
|
13227
|
+
totalMs: Math.round(performance.now() - startedAt)
|
|
13228
|
+
});
|
|
12463
13229
|
const reprojectMsg = reprojected ? ` (reprojected from ${sourceCRS})` : "";
|
|
12464
13230
|
toast({
|
|
12465
13231
|
title: "Layer added",
|
|
12466
13232
|
description: `Created "${newLayer.name}" with ${addedIds.length} features${reprojectMsg} (high-performance)`
|
|
12467
13233
|
});
|
|
12468
|
-
}, [saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, restoreEnrichedGeoJSON, toast, interceptGeoJSONFileLoad]);
|
|
13234
|
+
}, [saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, restoreEnrichedGeoJSON, toast, interceptGeoJSONFileLoad, ingestWithProgress]);
|
|
13235
|
+
const handleDropGeoJSON = useCallback((name, data) => {
|
|
13236
|
+
void ingestDroppedLayer(name, data);
|
|
13237
|
+
}, [ingestDroppedLayer]);
|
|
13238
|
+
const handleDropGeoJSONFile = useCallback((name, file) => {
|
|
13239
|
+
void ingestDroppedLayer(name, file);
|
|
13240
|
+
}, [ingestDroppedLayer]);
|
|
12469
13241
|
const handleTimelineFilterChange = useCallback((visibleIds, hiddenIds, untimedIds) => {
|
|
12470
13242
|
if (!draw.current || !map.current) return;
|
|
12471
|
-
|
|
12472
|
-
|
|
13243
|
+
const nextVisible = new Set(visibleIds);
|
|
13244
|
+
untimedIds.forEach((id) => nextVisible.add(id));
|
|
13245
|
+
timelineVisibleIdsRef.current = nextVisible;
|
|
13246
|
+
scheduleSync("timeline");
|
|
12473
13247
|
}, [scheduleSync]);
|
|
12474
13248
|
const prevTimelineEnabledRef = useRef(timelineStore.isEnabled);
|
|
12475
13249
|
useEffect(() => {
|
|
@@ -12478,7 +13252,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
12478
13252
|
prevTimelineEnabledRef.current = isNowEnabled;
|
|
12479
13253
|
if (!isNowEnabled || !timelineStore.hasTemporalData) {
|
|
12480
13254
|
timelineVisibleIdsRef.current = null;
|
|
12481
|
-
scheduleSync();
|
|
13255
|
+
scheduleSync("timeline");
|
|
12482
13256
|
} else if (!wasEnabled && isNowEnabled) {
|
|
12483
13257
|
updateTimelineStore();
|
|
12484
13258
|
}
|
|
@@ -12853,7 +13627,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
12853
13627
|
] }) });
|
|
12854
13628
|
}
|
|
12855
13629
|
const toastContextValue = toastProvider ?? null;
|
|
12856
|
-
return /* @__PURE__ */ jsx(TimelineStoreContext.Provider, { value: timelineStoreApi, children: /* @__PURE__ */ jsx(ToastContext.Provider, { value: toastContextValue, children: /* @__PURE__ */ jsx(MapDropZone, { onDrop: handleDropGeoJSON, children: /* @__PURE__ */ jsxs("div", { className: `map-container w-full h-full min-w-0 relative overflow-hidden isolate ${className || ""}`, "data-testid": "map-editor-canvas", children: [
|
|
13630
|
+
return /* @__PURE__ */ jsx(TimelineStoreContext.Provider, { value: timelineStoreApi, children: /* @__PURE__ */ jsx(ToastContext.Provider, { value: toastContextValue, children: /* @__PURE__ */ jsx(MapDropZone, { onDrop: handleDropGeoJSON, onDropFile: handleDropGeoJSONFile, children: /* @__PURE__ */ jsxs("div", { className: `map-container w-full h-full min-w-0 relative overflow-hidden isolate ${className || ""}`, "data-testid": "map-editor-canvas", children: [
|
|
12857
13631
|
/* @__PURE__ */ jsx(
|
|
12858
13632
|
"div",
|
|
12859
13633
|
{
|
|
@@ -13332,16 +14106,12 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
13332
14106
|
))
|
|
13333
14107
|
}
|
|
13334
14108
|
),
|
|
13335
|
-
|
|
13336
|
-
|
|
14109
|
+
/* @__PURE__ */ jsx(CursorCoordinatesOverlay, { map: isMapLoaded ? map.current : null }),
|
|
14110
|
+
/* @__PURE__ */ jsx(
|
|
14111
|
+
IngestProgressOverlay,
|
|
13337
14112
|
{
|
|
13338
|
-
|
|
13339
|
-
|
|
13340
|
-
children: [
|
|
13341
|
-
cursorCoords.lat.toFixed(5),
|
|
13342
|
-
", ",
|
|
13343
|
-
cursorCoords.lng.toFixed(5)
|
|
13344
|
-
]
|
|
14113
|
+
store: ingestProgressStore,
|
|
14114
|
+
bottomPx: timelineStore.isEnabled ? TIMEBAR_HEIGHT + TIMEBAR_BOTTOM_OFFSET + 8 : 32
|
|
13345
14115
|
}
|
|
13346
14116
|
),
|
|
13347
14117
|
/* @__PURE__ */ jsx(
|
|
@@ -14107,7 +14877,15 @@ function DebugSidebar({ onAddRandomPoints, onImportKML, onAddDomMarkers, onRemov
|
|
|
14107
14877
|
const geojson = parseKMLToGeoJSON(content);
|
|
14108
14878
|
if (geojson && onImportKML) {
|
|
14109
14879
|
const layerName = file.name.replace(/\.(kml|kmz)$/i, "");
|
|
14110
|
-
|
|
14880
|
+
void getSharedIngestClient().ingest(geojson, { idStrategy: "preserve" }).then((result) => {
|
|
14881
|
+
onImportKML(
|
|
14882
|
+
layerName,
|
|
14883
|
+
result.kind === "features" ? { type: "FeatureCollection", features: result.features } : geojson
|
|
14884
|
+
);
|
|
14885
|
+
}).catch((err) => {
|
|
14886
|
+
console.warn("[map-component] KML ingest normalization failed:", err);
|
|
14887
|
+
onImportKML(layerName, geojson);
|
|
14888
|
+
});
|
|
14111
14889
|
}
|
|
14112
14890
|
};
|
|
14113
14891
|
reader.readAsText(file);
|