@trackunit/react-map 0.2.296 → 0.2.297
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/index.cjs.js +269 -7
- package/index.esm.js +269 -7
- package/migrations/entry.js.map +1 -0
- package/package.json +2 -1
- package/src/layers/__testHelpers.fillTiling.d.ts +18 -0
- package/src/layers/useShapes/clipper2PolygonDifference.d.ts +37 -0
- package/src/layers/useShapes/shapeFillTiling.d.ts +17 -3
- package/src/layers/useShapes/useShapeFillTiling.d.ts +1 -1
- package/translation11.cjs.js +8 -8
- package/translation11.esm.js +8 -8
- package/translation12.cjs.js +8 -8
- package/translation12.esm.js +8 -8
- package/translation13.cjs.js +8 -8
- package/translation13.esm.js +8 -8
- package/translation14.cjs.js +8 -8
- package/translation14.esm.js +8 -8
- package/translation15.cjs.js +8 -8
- package/translation15.esm.js +8 -8
- package/translation16.cjs.js +8 -8
- package/translation16.esm.js +8 -8
- package/translation17.cjs.js +8 -8
- package/translation17.esm.js +8 -8
- package/translation2.cjs.js +8 -8
- package/translation2.esm.js +8 -8
- package/translation3.cjs.js +8 -8
- package/translation3.esm.js +8 -8
- package/translation5.cjs.js +8 -8
- package/translation5.esm.js +8 -8
- package/translation6.cjs.js +8 -8
- package/translation6.esm.js +8 -8
- package/translation8.cjs.js +8 -8
- package/translation8.esm.js +8 -8
- package/translation9.cjs.js +8 -8
- package/translation9.esm.js +8 -8
package/index.esm.js
CHANGED
|
@@ -9609,14 +9609,14 @@ const groupKeyOf = (group) => group
|
|
|
9609
9609
|
* time and only the ones that throw are skipped, so one degenerate neighbour costs the overlap with
|
|
9610
9610
|
* that neighbour alone rather than every clip of the subject.
|
|
9611
9611
|
*/
|
|
9612
|
-
const clipAgainstHigherRanked = (subject, clips) => {
|
|
9612
|
+
const clipAgainstHigherRanked = (subject, clips, polygonDifference) => {
|
|
9613
9613
|
let fallbacks = 0;
|
|
9614
9614
|
let lastError;
|
|
9615
9615
|
const onFallback = (error) => {
|
|
9616
9616
|
fallbacks += 1;
|
|
9617
9617
|
lastError = error;
|
|
9618
9618
|
};
|
|
9619
|
-
const batched =
|
|
9619
|
+
const batched = polygonDifference(subject, clips.map(clip => clip.geometry), onFallback);
|
|
9620
9620
|
if (fallbacks === 0)
|
|
9621
9621
|
return { geometry: batched, failure: null };
|
|
9622
9622
|
// The batch failed: subtract one clip at a time and skip only the clips that throw on their own.
|
|
@@ -9626,7 +9626,7 @@ const clipAgainstHigherRanked = (subject, clips) => {
|
|
|
9626
9626
|
if (current === null)
|
|
9627
9627
|
break;
|
|
9628
9628
|
const before = fallbacks;
|
|
9629
|
-
const next =
|
|
9629
|
+
const next = polygonDifference(current, [clip.geometry], onFallback);
|
|
9630
9630
|
if (fallbacks > before) {
|
|
9631
9631
|
skipped.push(clip.id);
|
|
9632
9632
|
continue;
|
|
@@ -9638,7 +9638,7 @@ const clipAgainstHigherRanked = (subject, clips) => {
|
|
|
9638
9638
|
};
|
|
9639
9639
|
/** Promote `id` to the front of `order` (no-op if not present). */
|
|
9640
9640
|
const promoteToFront = (order, id) => order.includes(id) ? [id, ...order.filter(item => item !== id)] : order;
|
|
9641
|
-
const computePromotionGroupFills = ({ members, winnerId, restingPeerFills = new Map(), layerGeodesic, featureStyles, onDifferenceFallback, }) => {
|
|
9641
|
+
const computePromotionGroupFills = ({ members, winnerId, restingPeerFills = new Map(), layerGeodesic, featureStyles, polygonDifference = geoJsonPolygonDifference, onDifferenceFallback, }) => {
|
|
9642
9642
|
// Densify before peer-vs-winner clip so promotion clips follow great-circle
|
|
9643
9643
|
// arcs. Always defer to densifyGeodesicFeatures' per-feature resolution
|
|
9644
9644
|
// (geodesic override > layer default) rather than short-circuiting on
|
|
@@ -9679,7 +9679,7 @@ const computePromotionGroupFills = ({ members, winnerId, restingPeerFills = new
|
|
|
9679
9679
|
subject = restingPolygonal;
|
|
9680
9680
|
}
|
|
9681
9681
|
const subjectMercator = projectPolygonalToWebMercator(subject);
|
|
9682
|
-
const clippedMercator =
|
|
9682
|
+
const clippedMercator = polygonDifference(subjectMercator, [winnerMercator], error => {
|
|
9683
9683
|
onDifferenceFallback?.(memberId, error);
|
|
9684
9684
|
});
|
|
9685
9685
|
const clipped = clippedMercator === null ? null : unprojectPolygonalFromWebMercator(clippedMercator);
|
|
@@ -9688,7 +9688,7 @@ const computePromotionGroupFills = ({ members, winnerId, restingPeerFills = new
|
|
|
9688
9688
|
return result;
|
|
9689
9689
|
};
|
|
9690
9690
|
const computeFillTiling = (input) => {
|
|
9691
|
-
const { features, viewportBounds, resolveStackOrder, selectedFeatureId, suppressedFeatureIds, layerGeodesic, featureStyles, } = input;
|
|
9691
|
+
const { features, viewportBounds, resolveStackOrder, selectedFeatureId, suppressedFeatureIds, layerGeodesic, featureStyles, polygonDifference = geoJsonPolygonDifference, } = input;
|
|
9692
9692
|
// Validation boundary (SAGA-664): validate each input feature's polygonal
|
|
9693
9693
|
// geometry once here — O(n) — dropping malformed geometry. The downstream O(n²)
|
|
9694
9694
|
// overlap loop then runs the pure predicates on trusted geometry without a
|
|
@@ -9806,7 +9806,7 @@ const computeFillTiling = (input) => {
|
|
|
9806
9806
|
// Nothing above touches this member: no override, the adapter renders the full geometry.
|
|
9807
9807
|
if (higherRanked.length === 0)
|
|
9808
9808
|
continue;
|
|
9809
|
-
const { geometry: clippedMercator, failure } = clipAgainstHigherRanked(mercatorOf(record), higherRanked.map(above => ({ id: above.id, geometry: mercatorOf(above) })));
|
|
9809
|
+
const { geometry: clippedMercator, failure } = clipAgainstHigherRanked(mercatorOf(record), higherRanked.map(above => ({ id: above.id, geometry: mercatorOf(above) })), polygonDifference);
|
|
9810
9810
|
if (failure !== null) {
|
|
9811
9811
|
differenceFailures.push({ featureId: id, clipFeatureIds: failure.clipFeatureIds, error: failure.error });
|
|
9812
9812
|
}
|
|
@@ -12039,6 +12039,198 @@ const captureFillTilingDifferenceFailures = (differenceFailures, layerHandleId,
|
|
|
12039
12039
|
}
|
|
12040
12040
|
};
|
|
12041
12041
|
|
|
12042
|
+
/**
|
|
12043
|
+
* Clipper2 scales coordinates to integers by 10^precision. Fill tiling clips in Web Mercator
|
|
12044
|
+
* metres, so 3 keeps millimetres.
|
|
12045
|
+
*/
|
|
12046
|
+
const MERCATOR_PRECISION = 3;
|
|
12047
|
+
/** Metres added around the subject bbox before trimming clips, so rect edges stay clear of subject vertices. */
|
|
12048
|
+
const RECT_CLIP_MARGIN = 1;
|
|
12049
|
+
const polygonsOf = (geometry) => geometry.type === "Polygon" ? [geometry.coordinates] : geometry.coordinates;
|
|
12050
|
+
const signedArea = (ring) => {
|
|
12051
|
+
let sum = 0;
|
|
12052
|
+
for (let i = 0; i + 1 < ring.length; i++) {
|
|
12053
|
+
const current = ring[i];
|
|
12054
|
+
const next = ring[i + 1];
|
|
12055
|
+
if (current === undefined || next === undefined)
|
|
12056
|
+
continue;
|
|
12057
|
+
sum += current[0] * next[1] - next[0] * current[1];
|
|
12058
|
+
}
|
|
12059
|
+
return sum / 2;
|
|
12060
|
+
};
|
|
12061
|
+
/**
|
|
12062
|
+
* GeoJSON rings become Clipper2 paths with the closing vertex dropped. Exterior rings are forced
|
|
12063
|
+
* counter-clockwise and holes clockwise so that NonZero winding matches polygon-clipping for
|
|
12064
|
+
* well-nested, non-overlapping holes: holes subtract, and clips that overlap each other still union.
|
|
12065
|
+
*
|
|
12066
|
+
* Known divergence for invalid hole configurations that the schema does not reject: NonZero sums
|
|
12067
|
+
* windings, so where two holes of one polygon overlap (winding −1) the area counts as filled, and
|
|
12068
|
+
* the part of a hole that pokes outside its exterior (winding −1 as well) is painted. polygon-clipping
|
|
12069
|
+
* excludes any region inside an interior ring instead. See the spec for the pinned numbers.
|
|
12070
|
+
*/
|
|
12071
|
+
const appendRingsAsPaths = (clipper, paths, geometries) => {
|
|
12072
|
+
for (const geometry of geometries) {
|
|
12073
|
+
for (const rings of polygonsOf(geometry)) {
|
|
12074
|
+
rings.forEach((ring, ringIndex) => {
|
|
12075
|
+
const wantCounterClockwise = ringIndex === 0;
|
|
12076
|
+
const oriented = signedArea(ring) > 0 === wantCounterClockwise ? ring : [...ring].reverse();
|
|
12077
|
+
// Drop the closing vertex; Clipper2 paths are implicitly closed.
|
|
12078
|
+
const flat = [];
|
|
12079
|
+
for (const [x, y] of oriented.slice(0, -1))
|
|
12080
|
+
flat.push(x, y);
|
|
12081
|
+
const path = clipper.MakePathD(flat);
|
|
12082
|
+
paths.push_back(path);
|
|
12083
|
+
path.delete();
|
|
12084
|
+
});
|
|
12085
|
+
}
|
|
12086
|
+
}
|
|
12087
|
+
};
|
|
12088
|
+
/**
|
|
12089
|
+
* Closed GeoJSON ring from a tree node. `polygon()` hands out an owned copy whose `view()` is
|
|
12090
|
+
* x, y, z per vertex (Z build); it is released as soon as the coordinates are copied out.
|
|
12091
|
+
*/
|
|
12092
|
+
const ringOf = (node) => {
|
|
12093
|
+
const path = node.polygon();
|
|
12094
|
+
try {
|
|
12095
|
+
const xyz = path.view();
|
|
12096
|
+
const ring = [];
|
|
12097
|
+
for (let i = 0; i + 2 < xyz.length; i += 3) {
|
|
12098
|
+
ring.push([xyz[i] ?? 0, xyz[i + 1] ?? 0]);
|
|
12099
|
+
}
|
|
12100
|
+
const first = ring[0];
|
|
12101
|
+
if (first !== undefined)
|
|
12102
|
+
ring.push(first);
|
|
12103
|
+
return ring;
|
|
12104
|
+
}
|
|
12105
|
+
finally {
|
|
12106
|
+
path.delete();
|
|
12107
|
+
}
|
|
12108
|
+
};
|
|
12109
|
+
/**
|
|
12110
|
+
* Walk the PolyTree: each child of an outer is a hole, each child of a hole is an island.
|
|
12111
|
+
* `child()` returns non-owning references into the tree and must not be deleted.
|
|
12112
|
+
*/
|
|
12113
|
+
const collectPolygons = (node, into) => {
|
|
12114
|
+
const outerCount = node.count();
|
|
12115
|
+
for (let i = 0; i < outerCount; i++) {
|
|
12116
|
+
const outer = node.child(i);
|
|
12117
|
+
const rings = [ringOf(outer)];
|
|
12118
|
+
const holeCount = outer.count();
|
|
12119
|
+
for (let h = 0; h < holeCount; h++) {
|
|
12120
|
+
const hole = outer.child(h);
|
|
12121
|
+
rings.push(ringOf(hole));
|
|
12122
|
+
collectPolygons(hole, into);
|
|
12123
|
+
}
|
|
12124
|
+
into.push(rings);
|
|
12125
|
+
}
|
|
12126
|
+
};
|
|
12127
|
+
const bboxOf = (geometry) => {
|
|
12128
|
+
let minX = Infinity;
|
|
12129
|
+
let minY = Infinity;
|
|
12130
|
+
let maxX = -Infinity;
|
|
12131
|
+
let maxY = -Infinity;
|
|
12132
|
+
for (const rings of polygonsOf(geometry)) {
|
|
12133
|
+
const exterior = rings[0];
|
|
12134
|
+
if (exterior === undefined)
|
|
12135
|
+
continue;
|
|
12136
|
+
for (const [x, y] of exterior) {
|
|
12137
|
+
if (x < minX)
|
|
12138
|
+
minX = x;
|
|
12139
|
+
if (x > maxX)
|
|
12140
|
+
maxX = x;
|
|
12141
|
+
if (y < minY)
|
|
12142
|
+
minY = y;
|
|
12143
|
+
if (y > maxY)
|
|
12144
|
+
maxY = y;
|
|
12145
|
+
}
|
|
12146
|
+
}
|
|
12147
|
+
return [minX, minY, maxX, maxY];
|
|
12148
|
+
};
|
|
12149
|
+
/**
|
|
12150
|
+
* Build the difference function on an instantiated module. Throws (from Clipper2 or from the
|
|
12151
|
+
* bridge itself) propagate to the caller, which owns the fallback and the reporting; every embind
|
|
12152
|
+
* object is released in `finally` either way.
|
|
12153
|
+
*/
|
|
12154
|
+
const createClipper2PolygonDifference = (clipper) => (subject, clips) => {
|
|
12155
|
+
if (clips.length === 0)
|
|
12156
|
+
return subject;
|
|
12157
|
+
const owned = [];
|
|
12158
|
+
try {
|
|
12159
|
+
const subjectPaths = new clipper.PathsD();
|
|
12160
|
+
owned.push(subjectPaths);
|
|
12161
|
+
appendRingsAsPaths(clipper, subjectPaths, [subject]);
|
|
12162
|
+
const clipPaths = new clipper.PathsD();
|
|
12163
|
+
owned.push(clipPaths);
|
|
12164
|
+
appendRingsAsPaths(clipper, clipPaths, clips);
|
|
12165
|
+
// Trim every clip to the subject's bbox first (O(n)), so a country-sized clip only
|
|
12166
|
+
// contributes the few edges near a site-sized subject.
|
|
12167
|
+
const [minX, minY, maxX, maxY] = bboxOf(subject);
|
|
12168
|
+
const rect = new clipper.RectD(minX - RECT_CLIP_MARGIN, minY - RECT_CLIP_MARGIN, maxX + RECT_CLIP_MARGIN, maxY + RECT_CLIP_MARGIN);
|
|
12169
|
+
owned.push(rect);
|
|
12170
|
+
const trimmedClips = clipper.RectClipPathsD(rect, clipPaths, MERCATOR_PRECISION);
|
|
12171
|
+
owned.push(trimmedClips);
|
|
12172
|
+
const solution = new clipper.PolyPathD();
|
|
12173
|
+
owned.push(solution);
|
|
12174
|
+
clipper.BooleanOpOutD(clipper.ClipType.Difference, clipper.FillRule.NonZero, subjectPaths, trimmedClips, solution, MERCATOR_PRECISION);
|
|
12175
|
+
const polygons = [];
|
|
12176
|
+
collectPolygons(solution, polygons);
|
|
12177
|
+
const [single] = polygons;
|
|
12178
|
+
if (single === undefined)
|
|
12179
|
+
return null;
|
|
12180
|
+
if (polygons.length === 1)
|
|
12181
|
+
return { type: "Polygon", coordinates: single };
|
|
12182
|
+
return { type: "MultiPolygon", coordinates: polygons };
|
|
12183
|
+
}
|
|
12184
|
+
finally {
|
|
12185
|
+
for (const object of owned)
|
|
12186
|
+
object.delete();
|
|
12187
|
+
}
|
|
12188
|
+
};
|
|
12189
|
+
let sharedEngine = null;
|
|
12190
|
+
let loadedEngine;
|
|
12191
|
+
let unusable = false;
|
|
12192
|
+
const createEngine = async (options) => {
|
|
12193
|
+
const { default: createClipper2Module } = await import('clipper2-wasm/dist/es/clipper2z.js');
|
|
12194
|
+
// Emscripten writes load failures and aborts to console.error as well as throwing. The thrown
|
|
12195
|
+
// error is what callers act on (rejected load, or a throw from the returned function that the
|
|
12196
|
+
// fill-tiling hook reports and falls back from), so keep the duplicate stderr channel quiet.
|
|
12197
|
+
const clipper = await createClipper2Module({ ...options, printErr: () => undefined });
|
|
12198
|
+
return createClipper2PolygonDifference(clipper);
|
|
12199
|
+
};
|
|
12200
|
+
/**
|
|
12201
|
+
* Polygon difference backed by Clipper2 compiled to WebAssembly: a drop-in for
|
|
12202
|
+
* `geoJsonPolygonDifference` in fill tiling, roughly 6× faster on the same inputs. Unlike
|
|
12203
|
+
* `geoJsonPolygonDifference` it throws on failure instead of returning the subject unclipped:
|
|
12204
|
+
* polygon-clipping is still available as an exact fallback, and an Emscripten abort disables the
|
|
12205
|
+
* module for good, so the caller decides how to degrade and report.
|
|
12206
|
+
*
|
|
12207
|
+
* The module (~210 KB) is fetched and instantiated on first call and shared afterwards, including a
|
|
12208
|
+
* failed load: callers keep `geoJsonPolygonDifference` until the promise resolves and stay on it for
|
|
12209
|
+
* the page lifetime if it rejects (no WebAssembly support, blocked asset, …). `options.wasmBinary`
|
|
12210
|
+
* bypasses the fetch; engines created with options are not shared.
|
|
12211
|
+
*/
|
|
12212
|
+
const loadClipper2PolygonDifference = (options) => {
|
|
12213
|
+
if (unusable)
|
|
12214
|
+
return Promise.reject(new Error("Clipper2 was marked unusable after a runtime failure"));
|
|
12215
|
+
sharedEngine ?? (sharedEngine = createEngine(undefined).then(engine => {
|
|
12216
|
+
loadedEngine = engine;
|
|
12217
|
+
return engine;
|
|
12218
|
+
}));
|
|
12219
|
+
return sharedEngine;
|
|
12220
|
+
};
|
|
12221
|
+
/** The shared engine when it has already loaded, so a later mount can use it for its first pass. */
|
|
12222
|
+
const getLoadedClipper2PolygonDifference = () => loadedEngine;
|
|
12223
|
+
/**
|
|
12224
|
+
* Called when the shared engine threw: an Emscripten abort disables the module for the rest of the
|
|
12225
|
+
* page, so no later mount may adopt it and no reload is attempted.
|
|
12226
|
+
*/
|
|
12227
|
+
const markClipper2PolygonDifferenceUnusable = () => {
|
|
12228
|
+
unusable = true;
|
|
12229
|
+
loadedEngine = undefined;
|
|
12230
|
+
};
|
|
12231
|
+
/** Whether the shared engine was marked unusable; callers stay on polygon-clipping silently. */
|
|
12232
|
+
const isClipper2PolygonDifferenceUnusable = () => unusable;
|
|
12233
|
+
|
|
12042
12234
|
/** Lists the ids of features dropped from fill tiling, or a placeholder when none carry an id. */
|
|
12043
12235
|
const formatDroppedInvalidFeatureIds = (dropped) => dropped
|
|
12044
12236
|
.map(entry => (entry.feature.id !== undefined ? String(entry.feature.id) : undefined))
|
|
@@ -12240,6 +12432,13 @@ const useShapeFillTiling = ({ api, handles, onFillGeometriesChange, onZIndexOver
|
|
|
12240
12432
|
const errorHandler = useErrorHandlerOrNull();
|
|
12241
12433
|
/** Handle/feature keys already reported to Sentry this session. */
|
|
12242
12434
|
const sessionReportedDedupeKeysRef = useRef(new Set());
|
|
12435
|
+
/**
|
|
12436
|
+
* Clipper2 WebAssembly difference once loaded, wrapped so that a failure reports once and
|
|
12437
|
+
* hands the clip (and every later clip) back to polygon-clipping. `undefined` = default path.
|
|
12438
|
+
*/
|
|
12439
|
+
const polygonDifferenceRef = useRef(undefined);
|
|
12440
|
+
/** Load lifecycle; `settled` (loaded, failed or unusable) means the effect never re-subscribes. */
|
|
12441
|
+
const clipper2StatusRef = useRef("idle");
|
|
12243
12442
|
const tilingContentKey = useMemo(() => buildTilingContentKey(handles), [handles]);
|
|
12244
12443
|
const tilingHandles = useMemo(() => handles.filter((handle) => handle.layerType === "shapes" && handle.overlap?.mode === "tile"), [handles]);
|
|
12245
12444
|
const hasTilingHandles = tilingHandles.length > 0;
|
|
@@ -12381,6 +12580,7 @@ const useShapeFillTiling = ({ api, handles, onFillGeometriesChange, onZIndexOver
|
|
|
12381
12580
|
restingPeerFills,
|
|
12382
12581
|
layerGeodesic: handle?.style.geodesic,
|
|
12383
12582
|
featureStyles: handle?.featureStyles,
|
|
12583
|
+
polygonDifference: polygonDifferenceRef.current,
|
|
12384
12584
|
onDifferenceFallback: (featureId, error) => {
|
|
12385
12585
|
unclippedPeerIds.push(featureId);
|
|
12386
12586
|
if (errorHandler === null)
|
|
@@ -12498,6 +12698,7 @@ const useShapeFillTiling = ({ api, handles, onFillGeometriesChange, onZIndexOver
|
|
|
12498
12698
|
suppressedFeatureIds: suppressedFillIdsByHandleRef.current?.get(handle.id),
|
|
12499
12699
|
layerGeodesic: handle.style.geodesic,
|
|
12500
12700
|
featureStyles: handle.featureStyles,
|
|
12701
|
+
polygonDifference: polygonDifferenceRef.current,
|
|
12501
12702
|
});
|
|
12502
12703
|
// The dev warnings live here, not in computeFillTiling: recompute runs from
|
|
12503
12704
|
// effects and idle callbacks, so the pure function stays silent (SAGA-907).
|
|
@@ -12565,6 +12766,67 @@ const useShapeFillTiling = ({ api, handles, onFillGeometriesChange, onZIndexOver
|
|
|
12565
12766
|
flushPendingRestingRecompute();
|
|
12566
12767
|
}, IDLE_RECOMPUTE_DEBOUNCE_MS);
|
|
12567
12768
|
}, [flushPendingRestingRecompute]);
|
|
12769
|
+
// Use the Clipper2 WebAssembly difference for the clip phase once a tiling layer exists. An engine
|
|
12770
|
+
// that already loaded (an earlier map on this page) is adopted synchronously here, before the
|
|
12771
|
+
// mount recompute below, so the first pass already uses it. Otherwise the load runs in the
|
|
12772
|
+
// background and the resting clips are re-tiled through the idle path when it resolves, so a load
|
|
12773
|
+
// finishing mid-pan never freezes the gesture. A failed load (no WebAssembly, blocked asset) or a
|
|
12774
|
+
// failing clip keeps polygon-clipping for the rest of this map's life, reported once each.
|
|
12775
|
+
useEffect(() => {
|
|
12776
|
+
if (!hasTilingHandles || clipper2StatusRef.current !== "idle")
|
|
12777
|
+
return;
|
|
12778
|
+
if (isClipper2PolygonDifferenceUnusable()) {
|
|
12779
|
+
// Another map on this page already hit a runtime failure and reported it.
|
|
12780
|
+
clipper2StatusRef.current = "settled";
|
|
12781
|
+
return;
|
|
12782
|
+
}
|
|
12783
|
+
const adopt = (clipper2Difference) => {
|
|
12784
|
+
clipper2StatusRef.current = "settled";
|
|
12785
|
+
polygonDifferenceRef.current = (subject, clips, onFallback) => {
|
|
12786
|
+
try {
|
|
12787
|
+
return clipper2Difference(subject, clips);
|
|
12788
|
+
}
|
|
12789
|
+
catch (error) {
|
|
12790
|
+
// An Emscripten abort disables the module for good: for this map and any later one.
|
|
12791
|
+
markClipper2PolygonDifferenceUnusable();
|
|
12792
|
+
polygonDifferenceRef.current = undefined;
|
|
12793
|
+
errorHandler?.captureException(new Error(`Clipper2 WebAssembly difference failed; fill tiling falls back to polygon-clipping: ${String(error)}`), { level: "warning", fingerprint: ["react-map", "fill-tiling", "clipper2-difference-failed"] });
|
|
12794
|
+
return geoJsonPolygonDifference(subject, clips, onFallback);
|
|
12795
|
+
}
|
|
12796
|
+
};
|
|
12797
|
+
};
|
|
12798
|
+
const loaded = getLoadedClipper2PolygonDifference();
|
|
12799
|
+
if (loaded !== undefined) {
|
|
12800
|
+
adopt(loaded);
|
|
12801
|
+
return;
|
|
12802
|
+
}
|
|
12803
|
+
clipper2StatusRef.current = "loading";
|
|
12804
|
+
let cancelled = false;
|
|
12805
|
+
loadClipper2PolygonDifference()
|
|
12806
|
+
.then(clipper2Difference => {
|
|
12807
|
+
if (cancelled)
|
|
12808
|
+
return;
|
|
12809
|
+
adopt(clipper2Difference);
|
|
12810
|
+
// Re-tile the resting clips with the engine, but never mid-gesture: while the map moves the
|
|
12811
|
+
// existing `idle` handler flushes the pending recompute once the movement settles.
|
|
12812
|
+
lastComputeInputKeyRef.current = null;
|
|
12813
|
+
pendingRestingRecomputeRef.current = true;
|
|
12814
|
+
if (!isMapMovingRef.current)
|
|
12815
|
+
scheduleIdleRestingRecompute();
|
|
12816
|
+
})
|
|
12817
|
+
.catch((error) => {
|
|
12818
|
+
if (cancelled)
|
|
12819
|
+
return;
|
|
12820
|
+
clipper2StatusRef.current = "settled";
|
|
12821
|
+
errorHandler?.captureException(new Error(`Clipper2 WebAssembly engine failed to load; fill tiling stays on polygon-clipping: ${String(error)}`), { level: "warning", fingerprint: ["react-map", "fill-tiling", "clipper2-load-failed"] });
|
|
12822
|
+
});
|
|
12823
|
+
return () => {
|
|
12824
|
+
cancelled = true;
|
|
12825
|
+
// Unmounted mid-load: allow the next mount of a tiling layer to subscribe again.
|
|
12826
|
+
if (clipper2StatusRef.current === "loading")
|
|
12827
|
+
clipper2StatusRef.current = "idle";
|
|
12828
|
+
};
|
|
12829
|
+
}, [hasTilingHandles, scheduleIdleRestingRecompute, errorHandler]);
|
|
12568
12830
|
const clearSelectionPromotion = useCallback((handleId, featureId) => {
|
|
12569
12831
|
const groupKey = featureToGroupKeyByHandleRef.current.get(handleId)?.get(featureId);
|
|
12570
12832
|
if (groupKey === undefined)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry.js","sourceRoot":"","sources":["../../../../../libs/react/map/migrations/entry.ts"],"names":[],"mappings":"","sourcesContent":["export {};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-map",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.297",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"@trackunit/shared-utils": "1.22.43",
|
|
20
20
|
"@trackunit/ui-design-tokens": "1.21.41",
|
|
21
21
|
"@floating-ui/react": "^0.26.25",
|
|
22
|
+
"clipper2-wasm": "0.4.0",
|
|
22
23
|
"es-toolkit": "^1.52.0",
|
|
23
24
|
"tailwind-merge": "^3.7.0",
|
|
24
25
|
"zod": "^3.25.76"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type GeoJsonFeature } from "@trackunit/geo-json-utils";
|
|
2
|
+
export type DenseGeofenceFixtureOptions = Readonly<{
|
|
3
|
+
seed?: number;
|
|
4
|
+
/** Include a few 100–300 km polygons that get geodesically densified and overlap everything. */
|
|
5
|
+
regionalPolygons?: boolean;
|
|
6
|
+
/** 1 = one metro area (~63×67 km); 3 = ~190×200 km. */
|
|
7
|
+
spread?: number;
|
|
8
|
+
}>;
|
|
9
|
+
/**
|
|
10
|
+
* Deterministic, dense, overlapping geofence layer: 60 % circle geofences 300 m–15 km (32–150
|
|
11
|
+
* vertices), 37 % irregular drawn sites with 12–60 vertices, 3 % regional polygons.
|
|
12
|
+
*/
|
|
13
|
+
export declare const denseGeofenceFixture: (count: number, { seed, regionalPolygons, spread }?: DenseGeofenceFixtureOptions) => Array<GeoJsonFeature>;
|
|
14
|
+
/**
|
|
15
|
+
* The Clipper2 `.wasm` next to the ES build. vitest-jsdom cannot fetch it, so specs hand the
|
|
16
|
+
* binary over the way a bundler would.
|
|
17
|
+
*/
|
|
18
|
+
export declare const readClipper2WasmBinary: () => ArrayBuffer;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Clipper2ZFactoryFunction } from "clipper2-wasm/dist/es/clipper2z.js";
|
|
2
|
+
import type { PolygonDifference } from "./shapeFillTiling";
|
|
3
|
+
/** The instantiated Clipper2 module: the bound API plus the Emscripten runtime (`HEAPU8`, …). */
|
|
4
|
+
export type Clipper2Module = Awaited<ReturnType<Clipper2ZFactoryFunction>>;
|
|
5
|
+
/** Subset of the Emscripten module options this loader uses. */
|
|
6
|
+
export type Clipper2LoadOptions = Readonly<{
|
|
7
|
+
/** Pre-fetched binary; when omitted the loader fetches `clipper2z.wasm` next to the script. */
|
|
8
|
+
wasmBinary?: ArrayBuffer;
|
|
9
|
+
}>;
|
|
10
|
+
/**
|
|
11
|
+
* Build the difference function on an instantiated module. Throws (from Clipper2 or from the
|
|
12
|
+
* bridge itself) propagate to the caller, which owns the fallback and the reporting; every embind
|
|
13
|
+
* object is released in `finally` either way.
|
|
14
|
+
*/
|
|
15
|
+
export declare const createClipper2PolygonDifference: (clipper: Clipper2Module) => PolygonDifference;
|
|
16
|
+
/**
|
|
17
|
+
* Polygon difference backed by Clipper2 compiled to WebAssembly: a drop-in for
|
|
18
|
+
* `geoJsonPolygonDifference` in fill tiling, roughly 6× faster on the same inputs. Unlike
|
|
19
|
+
* `geoJsonPolygonDifference` it throws on failure instead of returning the subject unclipped:
|
|
20
|
+
* polygon-clipping is still available as an exact fallback, and an Emscripten abort disables the
|
|
21
|
+
* module for good, so the caller decides how to degrade and report.
|
|
22
|
+
*
|
|
23
|
+
* The module (~210 KB) is fetched and instantiated on first call and shared afterwards, including a
|
|
24
|
+
* failed load: callers keep `geoJsonPolygonDifference` until the promise resolves and stay on it for
|
|
25
|
+
* the page lifetime if it rejects (no WebAssembly support, blocked asset, …). `options.wasmBinary`
|
|
26
|
+
* bypasses the fetch; engines created with options are not shared.
|
|
27
|
+
*/
|
|
28
|
+
export declare const loadClipper2PolygonDifference: (options?: Clipper2LoadOptions) => Promise<PolygonDifference>;
|
|
29
|
+
/** The shared engine when it has already loaded, so a later mount can use it for its first pass. */
|
|
30
|
+
export declare const getLoadedClipper2PolygonDifference: () => PolygonDifference | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Called when the shared engine threw: an Emscripten abort disables the module for the rest of the
|
|
33
|
+
* page, so no later mount may adopt it and no reload is attempted.
|
|
34
|
+
*/
|
|
35
|
+
export declare const markClipper2PolygonDifferenceUnusable: () => void;
|
|
36
|
+
/** Whether the shared engine was marked unusable; callers stay on polygon-clipping silently. */
|
|
37
|
+
export declare const isClipper2PolygonDifferenceUnusable: () => boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type GeoJsonBbox, type GeoJsonFeature, type GeoJsonGeometry, type GeoJsonMultiPolygon, type GeoJsonPosition } from "@trackunit/geo-json-utils";
|
|
1
|
+
import { type GeoJsonBbox, type GeoJsonFeature, type GeoJsonGeometry, type GeoJsonMultiPolygon, type GeoJsonPolygon, type GeoJsonPosition } from "@trackunit/geo-json-utils";
|
|
2
2
|
import { type ShapeStyle } from "@trackunit/react-map-adapter-shared";
|
|
3
3
|
import type { ResolveShapeStackOrder } from "./shapeStackOrder";
|
|
4
4
|
/**
|
|
@@ -22,6 +22,15 @@ export declare const EMPTY_FILL: GeoJsonMultiPolygon;
|
|
|
22
22
|
* hit-testing (stroke remains interactive).
|
|
23
23
|
*/
|
|
24
24
|
export declare const isFillSuppressed: (style: ShapeStyle | undefined) => boolean;
|
|
25
|
+
type PolygonalGeometry = GeoJsonPolygon | GeoJsonMultiPolygon;
|
|
26
|
+
/**
|
|
27
|
+
* Polygon difference used to clip lower-ranked fills: `subject` minus the union of `clips`, or
|
|
28
|
+
* `null` when nothing remains. `geoJsonPolygonDifference` is the default; the fill-tiling hook
|
|
29
|
+
* swaps in the Clipper2 WebAssembly engine once it has loaded. Implementations handed to the tiling
|
|
30
|
+
* functions follow `geoJsonPolygonDifference`'s contract: when the difference cannot be computed
|
|
31
|
+
* they call `onFallback` and return `subject` unclipped.
|
|
32
|
+
*/
|
|
33
|
+
export type PolygonDifference = (subject: PolygonalGeometry, clips: ReadonlyArray<PolygonalGeometry>, onFallback?: (error: unknown) => void) => PolygonalGeometry | null;
|
|
25
34
|
/** Per-feature visible fill lookup for hit-testing (clipped geometry from tiling). */
|
|
26
35
|
export type VisibleFillLookup = (featureId: string) => GeoJsonGeometry | null | undefined;
|
|
27
36
|
export type FillTilingInput = Readonly<{
|
|
@@ -52,6 +61,8 @@ export type FillTilingInput = Readonly<{
|
|
|
52
61
|
* whether that feature's edges should be densified (overrides `layerGeodesic`).
|
|
53
62
|
*/
|
|
54
63
|
featureStyles: ReadonlyMap<string, ShapeStyle> | undefined;
|
|
64
|
+
/** Difference implementation for the clip phase; defaults to `geoJsonPolygonDifference`. */
|
|
65
|
+
polygonDifference?: PolygonDifference;
|
|
55
66
|
}>;
|
|
56
67
|
export type FillTilingResult = Readonly<{
|
|
57
68
|
/** Feature id → clipped fill geometry. Only clipped/covered features appear. */
|
|
@@ -174,8 +185,11 @@ export type PromotionGroupFillsInput = Readonly<{
|
|
|
174
185
|
restingPeerFills?: ReadonlyMap<string, GeoJsonGeometry>;
|
|
175
186
|
layerGeodesic?: boolean;
|
|
176
187
|
featureStyles?: ReadonlyMap<string, ShapeStyle>;
|
|
177
|
-
/**
|
|
188
|
+
/** Difference implementation for the peer clips; defaults to `geoJsonPolygonDifference`. */
|
|
189
|
+
polygonDifference?: PolygonDifference;
|
|
190
|
+
/** Called when the difference failed for a peer and the peer kept its fill unclipped (SAGA-743). */
|
|
178
191
|
onDifferenceFallback?: (featureId: string, error: unknown) => void;
|
|
179
192
|
}>;
|
|
180
|
-
export declare const computePromotionGroupFills: ({ members, winnerId, restingPeerFills, layerGeodesic, featureStyles, onDifferenceFallback, }: PromotionGroupFillsInput) => ReadonlyMap<string, GeoJsonGeometry>;
|
|
193
|
+
export declare const computePromotionGroupFills: ({ members, winnerId, restingPeerFills, layerGeodesic, featureStyles, polygonDifference, onDifferenceFallback, }: PromotionGroupFillsInput) => ReadonlyMap<string, GeoJsonGeometry>;
|
|
181
194
|
export declare const computeFillTiling: (input: FillTilingInput) => FillTilingResult;
|
|
195
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type GeoJsonGeometry, type GeoJsonPosition } from "@trackunit/geo-json-utils";
|
|
2
2
|
import type { MapApi } from "../../core/types";
|
|
3
3
|
import type { LayerHandle, ShapesUnderCursorHit } from "../types";
|
|
4
4
|
/**
|
package/translation11.cjs.js
CHANGED
|
@@ -13,24 +13,24 @@ var translation = {
|
|
|
13
13
|
"controls.stepper.decrease": "Diminuir",
|
|
14
14
|
"controls.stepper.increase": "Aumentar",
|
|
15
15
|
"controls.zoom": "Ampliar",
|
|
16
|
-
"draw.clear": "
|
|
17
|
-
"draw.limitReached": "
|
|
18
|
-
"draw.polygon": "
|
|
19
|
-
"draw.select": "
|
|
20
|
-
"draw.selectDisabled": "
|
|
16
|
+
"draw.clear": "Apagar desenho",
|
|
17
|
+
"draw.limitReached": "Limite de polígono atingido. Apague o desenho para desenhar novamente",
|
|
18
|
+
"draw.polygon": "Desenhar polígono",
|
|
19
|
+
"draw.select": "Editar polígono",
|
|
20
|
+
"draw.selectDisabled": "Desenhe um polígono primeiro",
|
|
21
21
|
"map.loading": "Carregar mapa",
|
|
22
22
|
"map.loadingData": "Loading map data",
|
|
23
23
|
"map.loadingErrorMessage": "Não foi possível carregar o mapa. Tente novamente mais tarde.",
|
|
24
24
|
"multiGeometry.badge.tooltip": "Parte de uma forma de várias partes",
|
|
25
25
|
"settings.mapStyle.dark": "Escuro",
|
|
26
|
-
"settings.mapStyle.disabledWhileDrawing": "
|
|
26
|
+
"settings.mapStyle.disabledWhileDrawing": "Termine o desenho para alterar o estilo do mapa",
|
|
27
27
|
"settings.mapStyle.light": "Claro",
|
|
28
28
|
"settings.mapStyle.roadmap": "Mapa de estrada",
|
|
29
29
|
"settings.mapStyle.roads": "Estradas",
|
|
30
30
|
"settings.mapStyle.satellite": "Satélite",
|
|
31
31
|
"settings.mapStyle.title": "Estilo do mapa",
|
|
32
|
-
"settings.mapStyle.traffic": "
|
|
33
|
-
"settings.mapStyle.trafficRequiresRoads": "
|
|
32
|
+
"settings.mapStyle.traffic": "Tráfego",
|
|
33
|
+
"settings.mapStyle.trafficRequiresRoads": "Ative as Estradas para mostrar o tráfego"
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
exports.default = translation;
|
package/translation11.esm.js
CHANGED
|
@@ -11,24 +11,24 @@ var translation = {
|
|
|
11
11
|
"controls.stepper.decrease": "Diminuir",
|
|
12
12
|
"controls.stepper.increase": "Aumentar",
|
|
13
13
|
"controls.zoom": "Ampliar",
|
|
14
|
-
"draw.clear": "
|
|
15
|
-
"draw.limitReached": "
|
|
16
|
-
"draw.polygon": "
|
|
17
|
-
"draw.select": "
|
|
18
|
-
"draw.selectDisabled": "
|
|
14
|
+
"draw.clear": "Apagar desenho",
|
|
15
|
+
"draw.limitReached": "Limite de polígono atingido. Apague o desenho para desenhar novamente",
|
|
16
|
+
"draw.polygon": "Desenhar polígono",
|
|
17
|
+
"draw.select": "Editar polígono",
|
|
18
|
+
"draw.selectDisabled": "Desenhe um polígono primeiro",
|
|
19
19
|
"map.loading": "Carregar mapa",
|
|
20
20
|
"map.loadingData": "Loading map data",
|
|
21
21
|
"map.loadingErrorMessage": "Não foi possível carregar o mapa. Tente novamente mais tarde.",
|
|
22
22
|
"multiGeometry.badge.tooltip": "Parte de uma forma de várias partes",
|
|
23
23
|
"settings.mapStyle.dark": "Escuro",
|
|
24
|
-
"settings.mapStyle.disabledWhileDrawing": "
|
|
24
|
+
"settings.mapStyle.disabledWhileDrawing": "Termine o desenho para alterar o estilo do mapa",
|
|
25
25
|
"settings.mapStyle.light": "Claro",
|
|
26
26
|
"settings.mapStyle.roadmap": "Mapa de estrada",
|
|
27
27
|
"settings.mapStyle.roads": "Estradas",
|
|
28
28
|
"settings.mapStyle.satellite": "Satélite",
|
|
29
29
|
"settings.mapStyle.title": "Estilo do mapa",
|
|
30
|
-
"settings.mapStyle.traffic": "
|
|
31
|
-
"settings.mapStyle.trafficRequiresRoads": "
|
|
30
|
+
"settings.mapStyle.traffic": "Tráfego",
|
|
31
|
+
"settings.mapStyle.trafficRequiresRoads": "Ative as Estradas para mostrar o tráfego"
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
export { translation as default };
|
package/translation12.cjs.js
CHANGED
|
@@ -13,24 +13,24 @@ var translation = {
|
|
|
13
13
|
"controls.stepper.decrease": "Уменьшить",
|
|
14
14
|
"controls.stepper.increase": "Увеличить",
|
|
15
15
|
"controls.zoom": "Масштаб",
|
|
16
|
-
"draw.clear": "
|
|
17
|
-
"draw.limitReached": "
|
|
18
|
-
"draw.polygon": "
|
|
19
|
-
"draw.select": "
|
|
20
|
-
"draw.selectDisabled": "
|
|
16
|
+
"draw.clear": "Очистить рисунок",
|
|
17
|
+
"draw.limitReached": "Достигнут предел для многоугольника. Очистите рисунок, чтобы нарисовать заново",
|
|
18
|
+
"draw.polygon": "Нарисовать многоугольник",
|
|
19
|
+
"draw.select": "Редактировать многоугольник",
|
|
20
|
+
"draw.selectDisabled": "Сначала нарисуйте многоугольник",
|
|
21
21
|
"map.loading": "Загрузка карты",
|
|
22
22
|
"map.loadingData": "Loading map data",
|
|
23
23
|
"map.loadingErrorMessage": "Не удается загрузить карту. Повторите попытку позже.",
|
|
24
24
|
"multiGeometry.badge.tooltip": "Часть составной фигуры",
|
|
25
25
|
"settings.mapStyle.dark": "Темная",
|
|
26
|
-
"settings.mapStyle.disabledWhileDrawing": "
|
|
26
|
+
"settings.mapStyle.disabledWhileDrawing": "Завершите рисование, чтобы изменить стиль карты",
|
|
27
27
|
"settings.mapStyle.light": "Светлая",
|
|
28
28
|
"settings.mapStyle.roadmap": "Карта маршрута",
|
|
29
29
|
"settings.mapStyle.roads": "Дороги",
|
|
30
30
|
"settings.mapStyle.satellite": "Спутник",
|
|
31
31
|
"settings.mapStyle.title": "Стиль карты",
|
|
32
|
-
"settings.mapStyle.traffic": "
|
|
33
|
-
"settings.mapStyle.trafficRequiresRoads": "
|
|
32
|
+
"settings.mapStyle.traffic": "Пробки",
|
|
33
|
+
"settings.mapStyle.trafficRequiresRoads": "Включите «Дороги», чтобы показать пробки"
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
exports.default = translation;
|
package/translation12.esm.js
CHANGED
|
@@ -11,24 +11,24 @@ var translation = {
|
|
|
11
11
|
"controls.stepper.decrease": "Уменьшить",
|
|
12
12
|
"controls.stepper.increase": "Увеличить",
|
|
13
13
|
"controls.zoom": "Масштаб",
|
|
14
|
-
"draw.clear": "
|
|
15
|
-
"draw.limitReached": "
|
|
16
|
-
"draw.polygon": "
|
|
17
|
-
"draw.select": "
|
|
18
|
-
"draw.selectDisabled": "
|
|
14
|
+
"draw.clear": "Очистить рисунок",
|
|
15
|
+
"draw.limitReached": "Достигнут предел для многоугольника. Очистите рисунок, чтобы нарисовать заново",
|
|
16
|
+
"draw.polygon": "Нарисовать многоугольник",
|
|
17
|
+
"draw.select": "Редактировать многоугольник",
|
|
18
|
+
"draw.selectDisabled": "Сначала нарисуйте многоугольник",
|
|
19
19
|
"map.loading": "Загрузка карты",
|
|
20
20
|
"map.loadingData": "Loading map data",
|
|
21
21
|
"map.loadingErrorMessage": "Не удается загрузить карту. Повторите попытку позже.",
|
|
22
22
|
"multiGeometry.badge.tooltip": "Часть составной фигуры",
|
|
23
23
|
"settings.mapStyle.dark": "Темная",
|
|
24
|
-
"settings.mapStyle.disabledWhileDrawing": "
|
|
24
|
+
"settings.mapStyle.disabledWhileDrawing": "Завершите рисование, чтобы изменить стиль карты",
|
|
25
25
|
"settings.mapStyle.light": "Светлая",
|
|
26
26
|
"settings.mapStyle.roadmap": "Карта маршрута",
|
|
27
27
|
"settings.mapStyle.roads": "Дороги",
|
|
28
28
|
"settings.mapStyle.satellite": "Спутник",
|
|
29
29
|
"settings.mapStyle.title": "Стиль карты",
|
|
30
|
-
"settings.mapStyle.traffic": "
|
|
31
|
-
"settings.mapStyle.trafficRequiresRoads": "
|
|
30
|
+
"settings.mapStyle.traffic": "Пробки",
|
|
31
|
+
"settings.mapStyle.trafficRequiresRoads": "Включите «Дороги», чтобы показать пробки"
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
export { translation as default };
|