@orbat-mapper/tactical-draw 0.23.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +89 -6
- package/dist/index.mjs +758 -336
- package/dist/{map-adapter-Btuz2FLI.d.mts → map-adapter-DoB8tiCc.d.mts} +92 -46
- package/dist/testing.d.mts +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DEFAULT_HIGHLIGHT_WIDTH, DEFAULT_LABEL_HEIGHT_CSS_PIXELS, DEFAULT_SYMBOL_COLOR, FILL_PATTERN_DEFINITIONS, LABEL_FADE_END_RATIO, NON_SOLID_FILL_PATTERNS, applyBoxTransformOptions, canonicalTextAmplifierKey, cloneControlMeasure, controlMeasureIdFromFeature, dragControlMeasureOptionHandle, foldsBoxTransformOptions, freezeOrientationOptions, getControlMeasureMetadata, getControlMeasureOptionHandles, getDefaultOptions, labelSizeBandHideThreshold, normalizeTextAmplifiers, remapVertexAlignedOptions, renderControlMeasure, resetControlMeasureOptionHandle, resolveAmplifierPlacement, resolveSizePair, resolveStyleHints, resolveSymbolColor, roundToFixed, switchSizePairUnit } from "@orbat-mapper/control-measures";
|
|
1
|
+
import { DEFAULT_HIGHLIGHT_WIDTH, DEFAULT_LABEL_HEIGHT_CSS_PIXELS, DEFAULT_SYMBOL_COLOR, FILL_PATTERN_DEFINITIONS, LABEL_FADE_END_RATIO, NON_SOLID_FILL_PATTERNS, applyBoxTransformOptions, canDeleteControlMeasureVertex, canonicalTextAmplifierKey, cloneControlMeasure, controlMeasureIdFromFeature, dragControlMeasureOptionHandle, foldsBoxTransformOptions, freezeOrientationOptions, getControlMeasureMetadata, getControlMeasureModifierDrag, getControlMeasureOptionHandles, getControlMeasurePartOf, getControlMeasureSegments, getDefaultOptions, labelSizeBandHideThreshold, normalizeTextAmplifiers, remapVertexAlignedOptions, renderControlMeasure, resetControlMeasureOptionHandle, resolveAmplifierPlacement, resolveSizePair, resolveStyleHints, resolveSymbolColor, roundToFixed, switchSizePairUnit } from "@orbat-mapper/control-measures";
|
|
2
2
|
function pickPointerType(originalEvent) {
|
|
3
3
|
if (typeof PointerEvent !== "undefined" && originalEvent instanceof PointerEvent) {
|
|
4
4
|
if (originalEvent.pointerType === "touch") return "touch";
|
|
@@ -350,13 +350,20 @@ function clipSegmentToBounds(a, b, bounds) {
|
|
|
350
350
|
}
|
|
351
351
|
return [[a[0] + start * dx, a[1] + start * dy], [a[0] + end * dx, a[1] + end * dy]];
|
|
352
352
|
}
|
|
353
|
+
/** Pixel distance from `pixel` to segment `a`–`b`; `null` for a zero-length segment. */
|
|
353
354
|
function distanceToSegment(pixel, a, b) {
|
|
355
|
+
if (a[0] === b[0] && a[1] === b[1]) return null;
|
|
356
|
+
return pixelSegmentDistance(pixel, a, b);
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Pixel distance from `pixel` to the segment `a`–`b`, clamped to its ends; a
|
|
360
|
+
* zero-length segment measures to its point.
|
|
361
|
+
*/
|
|
362
|
+
function pixelSegmentDistance(pixel, a, b) {
|
|
354
363
|
const dx = b[0] - a[0];
|
|
355
364
|
const dy = b[1] - a[1];
|
|
356
365
|
const lengthSq = dx * dx + dy * dy;
|
|
357
|
-
|
|
358
|
-
const unclamped = ((pixel[0] - a[0]) * dx + (pixel[1] - a[1]) * dy) / lengthSq;
|
|
359
|
-
const t = Math.max(0, Math.min(1, unclamped));
|
|
366
|
+
const t = lengthSq > 0 ? Math.max(0, Math.min(1, ((pixel[0] - a[0]) * dx + (pixel[1] - a[1]) * dy) / lengthSq)) : 0;
|
|
360
367
|
return Math.hypot(pixel[0] - (a[0] + t * dx), pixel[1] - (a[1] + t * dy));
|
|
361
368
|
}
|
|
362
369
|
/**
|
|
@@ -2008,6 +2015,272 @@ function isPinnableGraphic(graphic) {
|
|
|
2008
2015
|
return isPointSymbol(graphic) || isMarker(graphic);
|
|
2009
2016
|
}
|
|
2010
2017
|
//#endregion
|
|
2018
|
+
//#region src/tactical-draw/run-interaction.ts
|
|
2019
|
+
function runInteraction(spec) {
|
|
2020
|
+
const { adapter, signal, layers, onViewChange, onSettled, attach } = spec;
|
|
2021
|
+
if (signal?.aborted) {
|
|
2022
|
+
const error = new TacticalDrawAbortError("signal", { cause: signal.reason });
|
|
2023
|
+
const promise = Promise.reject(error);
|
|
2024
|
+
promise.catch(() => {});
|
|
2025
|
+
return {
|
|
2026
|
+
promise,
|
|
2027
|
+
settled: true,
|
|
2028
|
+
abort: () => {}
|
|
2029
|
+
};
|
|
2030
|
+
}
|
|
2031
|
+
let settled = false;
|
|
2032
|
+
const combined = combineWithHostSignal(signal);
|
|
2033
|
+
let resolveFn;
|
|
2034
|
+
let rejectFn;
|
|
2035
|
+
const promise = new Promise((resolve, reject) => {
|
|
2036
|
+
resolveFn = resolve;
|
|
2037
|
+
rejectFn = reject;
|
|
2038
|
+
});
|
|
2039
|
+
const ownedLayers = new Set(layers);
|
|
2040
|
+
let controllerDetach = null;
|
|
2041
|
+
let controllerOnAbort = null;
|
|
2042
|
+
function writeLayer(layer, groups) {
|
|
2043
|
+
if (!ownedLayers.has(layer)) return;
|
|
2044
|
+
adapter.setLayerFeatureGroups(layer, groups);
|
|
2045
|
+
}
|
|
2046
|
+
function clearLayers() {
|
|
2047
|
+
for (const layer of ownedLayers) adapter.setLayerFeatureGroups(layer, []);
|
|
2048
|
+
}
|
|
2049
|
+
const handleKeydown = (event) => {
|
|
2050
|
+
if (settled) return;
|
|
2051
|
+
if (event.key !== "Escape") return;
|
|
2052
|
+
fail(new TacticalDrawAbortError("escape"));
|
|
2053
|
+
};
|
|
2054
|
+
function teardown() {
|
|
2055
|
+
if (controllerDetach) controllerDetach();
|
|
2056
|
+
if (onViewChange) adapter.offViewChange(onViewChange);
|
|
2057
|
+
if (typeof window !== "undefined") window.removeEventListener("keydown", handleKeydown);
|
|
2058
|
+
combined.dispose();
|
|
2059
|
+
clearLayers();
|
|
2060
|
+
}
|
|
2061
|
+
function commit(produce) {
|
|
2062
|
+
if (settled) return void 0;
|
|
2063
|
+
let value;
|
|
2064
|
+
try {
|
|
2065
|
+
value = produce();
|
|
2066
|
+
} catch (err) {
|
|
2067
|
+
settled = true;
|
|
2068
|
+
teardown();
|
|
2069
|
+
rejectFn(err);
|
|
2070
|
+
if (onSettled) onSettled({
|
|
2071
|
+
status: "rejected",
|
|
2072
|
+
error: err
|
|
2073
|
+
});
|
|
2074
|
+
return;
|
|
2075
|
+
}
|
|
2076
|
+
settled = true;
|
|
2077
|
+
teardown();
|
|
2078
|
+
resolveFn(value);
|
|
2079
|
+
if (onSettled) onSettled({
|
|
2080
|
+
status: "committed",
|
|
2081
|
+
value
|
|
2082
|
+
});
|
|
2083
|
+
return value;
|
|
2084
|
+
}
|
|
2085
|
+
function fail(error) {
|
|
2086
|
+
if (settled) return;
|
|
2087
|
+
settled = true;
|
|
2088
|
+
teardown();
|
|
2089
|
+
if (controllerOnAbort) try {
|
|
2090
|
+
controllerOnAbort();
|
|
2091
|
+
} catch {}
|
|
2092
|
+
rejectFn(error);
|
|
2093
|
+
if (onSettled) onSettled({
|
|
2094
|
+
status: "rejected",
|
|
2095
|
+
error
|
|
2096
|
+
});
|
|
2097
|
+
}
|
|
2098
|
+
const ctx = {
|
|
2099
|
+
get settled() {
|
|
2100
|
+
return settled;
|
|
2101
|
+
},
|
|
2102
|
+
commit,
|
|
2103
|
+
fail,
|
|
2104
|
+
writeLayer,
|
|
2105
|
+
onTeardown(detach, onAbort) {
|
|
2106
|
+
controllerDetach = detach;
|
|
2107
|
+
controllerOnAbort = onAbort ?? null;
|
|
2108
|
+
}
|
|
2109
|
+
};
|
|
2110
|
+
combined.signal.addEventListener("abort", () => {
|
|
2111
|
+
if (settled) return;
|
|
2112
|
+
const reason = combined.signal.reason;
|
|
2113
|
+
if (reason instanceof TacticalDrawAbortError) fail(reason);
|
|
2114
|
+
else fail(new TacticalDrawAbortError("signal", { cause: reason }));
|
|
2115
|
+
}, { once: true });
|
|
2116
|
+
if (onViewChange) adapter.onViewChange(onViewChange);
|
|
2117
|
+
if (typeof window !== "undefined") window.addEventListener("keydown", handleKeydown);
|
|
2118
|
+
attach(ctx);
|
|
2119
|
+
return {
|
|
2120
|
+
promise,
|
|
2121
|
+
get settled() {
|
|
2122
|
+
return settled;
|
|
2123
|
+
},
|
|
2124
|
+
abort(reason, cause) {
|
|
2125
|
+
combined.abort(reason, cause);
|
|
2126
|
+
}
|
|
2127
|
+
};
|
|
2128
|
+
}
|
|
2129
|
+
/** Whether `b` lands within {@link CLICK_SLOP_PX} of `a` — a click, not a drag. */
|
|
2130
|
+
function withinClickSlop(a, b) {
|
|
2131
|
+
return Math.hypot(a[0] - b[0], a[1] - b[1]) <= 3;
|
|
2132
|
+
}
|
|
2133
|
+
function runEditInteraction(spec) {
|
|
2134
|
+
const { adapter, signal, layers, graphicsLayer, previewLayer, handlesLayer, closeOnClickAway } = spec;
|
|
2135
|
+
let ctx;
|
|
2136
|
+
let driver;
|
|
2137
|
+
let previewPick;
|
|
2138
|
+
let handlesPick;
|
|
2139
|
+
let graphicsPick;
|
|
2140
|
+
/**
|
|
2141
|
+
* Consume exactly one trailing click without closing — set through
|
|
2142
|
+
* `shell.suppressNextClickAway()` on delete / label-drag / post-drag paths.
|
|
2143
|
+
*
|
|
2144
|
+
* The suppression is scoped to the pointer cycle that armed it: it is cleared
|
|
2145
|
+
* again on the next `pointerdown` (see the `onDown` wrapper below). Hosts do
|
|
2146
|
+
* not agree on whether a completed drag is followed by a `click` at all —
|
|
2147
|
+
* MapLibre swallows its `click` when the pointer moved beyond its 3px
|
|
2148
|
+
* `clickTolerance`, while Leaflet delivers one. Without the reset, a
|
|
2149
|
+
* suppression armed after a real drag on MapLibre survives into the *next*
|
|
2150
|
+
* pointer cycle and eats the user's first genuine click-away, so exiting the
|
|
2151
|
+
* edit takes two clicks instead of one.
|
|
2152
|
+
*/
|
|
2153
|
+
let suppressClickAway = false;
|
|
2154
|
+
/** A zero-movement body drag released this pointer cycle — set through `shell.noteBodyClick()`. */
|
|
2155
|
+
let bodyClickPending = false;
|
|
2156
|
+
const shell = {
|
|
2157
|
+
suppressNextClickAway() {
|
|
2158
|
+
suppressClickAway = true;
|
|
2159
|
+
},
|
|
2160
|
+
noteBodyClick() {
|
|
2161
|
+
bodyClickPending = true;
|
|
2162
|
+
}
|
|
2163
|
+
};
|
|
2164
|
+
const onPreviewPick = (event) => {
|
|
2165
|
+
previewPick = event;
|
|
2166
|
+
};
|
|
2167
|
+
const onHandlesPick = (event) => {
|
|
2168
|
+
handlesPick = event;
|
|
2169
|
+
};
|
|
2170
|
+
const onGraphicsPick = (event) => {
|
|
2171
|
+
graphicsPick = event;
|
|
2172
|
+
};
|
|
2173
|
+
const onClick = () => {
|
|
2174
|
+
const localPreview = previewPick;
|
|
2175
|
+
const localHandles = handlesPick;
|
|
2176
|
+
const localGraphics = graphicsPick;
|
|
2177
|
+
const wasBodyClick = bodyClickPending;
|
|
2178
|
+
previewPick = void 0;
|
|
2179
|
+
handlesPick = void 0;
|
|
2180
|
+
graphicsPick = void 0;
|
|
2181
|
+
bodyClickPending = false;
|
|
2182
|
+
if (ctx.settled) return;
|
|
2183
|
+
if (!closeOnClickAway) return;
|
|
2184
|
+
if (suppressClickAway) {
|
|
2185
|
+
suppressClickAway = false;
|
|
2186
|
+
return;
|
|
2187
|
+
}
|
|
2188
|
+
if (localHandles) return;
|
|
2189
|
+
if (localGraphics && !spec.ownsGraphic(localGraphics.id)) {
|
|
2190
|
+
spec.close();
|
|
2191
|
+
spec.onForeignPick?.(localGraphics);
|
|
2192
|
+
return;
|
|
2193
|
+
}
|
|
2194
|
+
if (localGraphics && spec.ownsGraphic(localGraphics.id)) {
|
|
2195
|
+
spec.onOwnClick?.(localGraphics);
|
|
2196
|
+
return;
|
|
2197
|
+
}
|
|
2198
|
+
if (localPreview) {
|
|
2199
|
+
spec.onOwnClick?.(localPreview);
|
|
2200
|
+
return;
|
|
2201
|
+
}
|
|
2202
|
+
if (wasBodyClick) return;
|
|
2203
|
+
spec.close();
|
|
2204
|
+
};
|
|
2205
|
+
return runInteraction({
|
|
2206
|
+
adapter,
|
|
2207
|
+
signal,
|
|
2208
|
+
layers,
|
|
2209
|
+
onViewChange: spec.onViewChange,
|
|
2210
|
+
onSettled: (settlement) => {
|
|
2211
|
+
try {
|
|
2212
|
+
spec.historySettle();
|
|
2213
|
+
} finally {
|
|
2214
|
+
spec.facadeOnSettled?.();
|
|
2215
|
+
spec.emitSettle(settlement);
|
|
2216
|
+
}
|
|
2217
|
+
},
|
|
2218
|
+
attach(interaction) {
|
|
2219
|
+
ctx = interaction;
|
|
2220
|
+
driver = adapter.createEditPointerDriver();
|
|
2221
|
+
let beforeTeardownRan = false;
|
|
2222
|
+
const runBeforeTeardown = (settlement) => {
|
|
2223
|
+
if (beforeTeardownRan) return;
|
|
2224
|
+
beforeTeardownRan = true;
|
|
2225
|
+
try {
|
|
2226
|
+
spec.onBeforeTeardown?.(settlement);
|
|
2227
|
+
} catch {}
|
|
2228
|
+
};
|
|
2229
|
+
const controllerContext = {
|
|
2230
|
+
get settled() {
|
|
2231
|
+
return interaction.settled;
|
|
2232
|
+
},
|
|
2233
|
+
commit(produce) {
|
|
2234
|
+
return interaction.commit(() => {
|
|
2235
|
+
const value = produce();
|
|
2236
|
+
runBeforeTeardown({
|
|
2237
|
+
status: "committed",
|
|
2238
|
+
value
|
|
2239
|
+
});
|
|
2240
|
+
return value;
|
|
2241
|
+
});
|
|
2242
|
+
},
|
|
2243
|
+
fail(error) {
|
|
2244
|
+
if (!interaction.settled) runBeforeTeardown({
|
|
2245
|
+
status: "rejected",
|
|
2246
|
+
error
|
|
2247
|
+
});
|
|
2248
|
+
interaction.fail(error);
|
|
2249
|
+
},
|
|
2250
|
+
writeLayer: interaction.writeLayer,
|
|
2251
|
+
onTeardown: interaction.onTeardown
|
|
2252
|
+
};
|
|
2253
|
+
const onDown = (pixel, info) => {
|
|
2254
|
+
suppressClickAway = false;
|
|
2255
|
+
spec.onDown(pixel, info);
|
|
2256
|
+
};
|
|
2257
|
+
const unsubDown = driver.onPointerDown(onDown);
|
|
2258
|
+
const unsubMove = driver.onPointerMove(spec.onMove);
|
|
2259
|
+
const unsubUp = driver.onPointerUp(spec.onUp);
|
|
2260
|
+
const unsubPreview = adapter.onPick(previewLayer, onPreviewPick);
|
|
2261
|
+
const unsubHandles = adapter.onPick(handlesLayer, onHandlesPick);
|
|
2262
|
+
const unsubGraphics = adapter.onPick(graphicsLayer, onGraphicsPick);
|
|
2263
|
+
adapter.on("click", onClick);
|
|
2264
|
+
interaction.onTeardown(() => {
|
|
2265
|
+
runBeforeTeardown({
|
|
2266
|
+
status: "rejected",
|
|
2267
|
+
error: void 0
|
|
2268
|
+
});
|
|
2269
|
+
adapter.off("click", onClick);
|
|
2270
|
+
unsubPreview();
|
|
2271
|
+
unsubHandles();
|
|
2272
|
+
unsubGraphics();
|
|
2273
|
+
unsubDown();
|
|
2274
|
+
unsubMove();
|
|
2275
|
+
unsubUp();
|
|
2276
|
+
spec.extraTeardown?.();
|
|
2277
|
+
driver.dispose();
|
|
2278
|
+
}, spec.onAbort);
|
|
2279
|
+
spec.attach(controllerContext, driver, shell);
|
|
2280
|
+
}
|
|
2281
|
+
});
|
|
2282
|
+
}
|
|
2283
|
+
//#endregion
|
|
2011
2284
|
//#region src/tactical-draw/active-interaction.ts
|
|
2012
2285
|
/**
|
|
2013
2286
|
* Owns the facade's public interaction state: the abort handle used by
|
|
@@ -2086,25 +2359,37 @@ function sizeOptionSpecs(kind) {
|
|
|
2086
2359
|
}
|
|
2087
2360
|
/**
|
|
2088
2361
|
* Whether `kind` has at least one size that can be restored to its normal
|
|
2089
|
-
* pixel-authored appearance at the
|
|
2362
|
+
* pixel-authored appearance at the given resolution. Kept inside
|
|
2090
2363
|
* tactical-draw using the core metadata catalog so hosts never need to
|
|
2091
2364
|
* infer option names or special-case captured labels.
|
|
2365
|
+
*
|
|
2366
|
+
* `scale` only needs `getResolution()` (Web Mercator meters per CSS pixel), so
|
|
2367
|
+
* a host without a live map can pass a fixed one:
|
|
2368
|
+
* `canResetGroundSizes(measure, { getResolution: () => resolution })`.
|
|
2092
2369
|
*/
|
|
2093
|
-
function canResetGroundSizes(measure,
|
|
2094
|
-
return hasUsableResolution(
|
|
2370
|
+
function canResetGroundSizes(measure, scale) {
|
|
2371
|
+
return hasUsableResolution(scale.getResolution()) && sizeOptionSpecs(measure.kind).length > 0;
|
|
2095
2372
|
}
|
|
2096
2373
|
/**
|
|
2097
2374
|
* Return the complete option record produced by resetting every known size
|
|
2098
|
-
* pair to its default on-screen appearance at the
|
|
2099
|
-
*
|
|
2100
|
-
*
|
|
2101
|
-
*
|
|
2375
|
+
* pair to its default on-screen appearance at the given resolution. Pixel
|
|
2376
|
+
* keys are removed and meter keys are written, so the result remains
|
|
2377
|
+
* ground-anchored. A pair that inherits another pair's size is cleared so it
|
|
2378
|
+
* follows again. Unrelated options are preserved. This is the rule
|
|
2379
|
+
* `EditSession.resetGroundSizes()` applies; hosts resetting graphics outside
|
|
2380
|
+
* an edit session call it directly, passing a fixed resolution such as
|
|
2381
|
+
* `{ getResolution: () => resolution }`.
|
|
2102
2382
|
*
|
|
2103
|
-
*
|
|
2104
|
-
*
|
|
2383
|
+
* A pair's default is its own `defaultValue` when its `defaultUnit` is `"px"`,
|
|
2384
|
+
* else the kind's default pixel option.
|
|
2385
|
+
*
|
|
2386
|
+
* Returns options for any kind with size pairs, even when nothing changes;
|
|
2387
|
+
* compare with the input (e.g. structurally) to detect a no-op. Returns
|
|
2388
|
+
* `undefined` when the kind has no resettable sizes or the resolution is not
|
|
2389
|
+
* usable.
|
|
2105
2390
|
*/
|
|
2106
|
-
function resetGroundSizeOptions(measure,
|
|
2107
|
-
const mpp =
|
|
2391
|
+
function resetGroundSizeOptions(measure, scale) {
|
|
2392
|
+
const mpp = scale.getResolution();
|
|
2108
2393
|
const specs = sizeOptionSpecs(measure.kind);
|
|
2109
2394
|
if (!hasUsableResolution(mpp) || specs.length === 0) return void 0;
|
|
2110
2395
|
const defaults = getDefaultOptions(measure.kind);
|
|
@@ -2299,118 +2584,6 @@ function geographicMidpointLatitude(points) {
|
|
|
2299
2584
|
}
|
|
2300
2585
|
return (min + max) / 2;
|
|
2301
2586
|
}
|
|
2302
|
-
//#endregion
|
|
2303
|
-
//#region src/tactical-draw/run-interaction.ts
|
|
2304
|
-
function runInteraction(spec) {
|
|
2305
|
-
const { adapter, signal, layers, onViewChange, onSettled, attach } = spec;
|
|
2306
|
-
if (signal?.aborted) {
|
|
2307
|
-
const error = new TacticalDrawAbortError("signal", { cause: signal.reason });
|
|
2308
|
-
const promise = Promise.reject(error);
|
|
2309
|
-
promise.catch(() => {});
|
|
2310
|
-
return {
|
|
2311
|
-
promise,
|
|
2312
|
-
settled: true,
|
|
2313
|
-
abort: () => {}
|
|
2314
|
-
};
|
|
2315
|
-
}
|
|
2316
|
-
let settled = false;
|
|
2317
|
-
const combined = combineWithHostSignal(signal);
|
|
2318
|
-
let resolveFn;
|
|
2319
|
-
let rejectFn;
|
|
2320
|
-
const promise = new Promise((resolve, reject) => {
|
|
2321
|
-
resolveFn = resolve;
|
|
2322
|
-
rejectFn = reject;
|
|
2323
|
-
});
|
|
2324
|
-
const ownedLayers = new Set(layers);
|
|
2325
|
-
let controllerDetach = null;
|
|
2326
|
-
let controllerOnAbort = null;
|
|
2327
|
-
function writeLayer(layer, groups) {
|
|
2328
|
-
if (!ownedLayers.has(layer)) return;
|
|
2329
|
-
adapter.setLayerFeatureGroups(layer, groups);
|
|
2330
|
-
}
|
|
2331
|
-
function clearLayers() {
|
|
2332
|
-
for (const layer of ownedLayers) adapter.setLayerFeatureGroups(layer, []);
|
|
2333
|
-
}
|
|
2334
|
-
const handleKeydown = (event) => {
|
|
2335
|
-
if (settled) return;
|
|
2336
|
-
if (event.key !== "Escape") return;
|
|
2337
|
-
fail(new TacticalDrawAbortError("escape"));
|
|
2338
|
-
};
|
|
2339
|
-
function teardown() {
|
|
2340
|
-
if (controllerDetach) controllerDetach();
|
|
2341
|
-
if (onViewChange) adapter.offViewChange(onViewChange);
|
|
2342
|
-
if (typeof window !== "undefined") window.removeEventListener("keydown", handleKeydown);
|
|
2343
|
-
combined.dispose();
|
|
2344
|
-
clearLayers();
|
|
2345
|
-
}
|
|
2346
|
-
function commit(produce) {
|
|
2347
|
-
if (settled) return void 0;
|
|
2348
|
-
let value;
|
|
2349
|
-
try {
|
|
2350
|
-
value = produce();
|
|
2351
|
-
} catch (err) {
|
|
2352
|
-
settled = true;
|
|
2353
|
-
teardown();
|
|
2354
|
-
rejectFn(err);
|
|
2355
|
-
if (onSettled) onSettled({
|
|
2356
|
-
status: "rejected",
|
|
2357
|
-
error: err
|
|
2358
|
-
});
|
|
2359
|
-
return;
|
|
2360
|
-
}
|
|
2361
|
-
settled = true;
|
|
2362
|
-
teardown();
|
|
2363
|
-
resolveFn(value);
|
|
2364
|
-
if (onSettled) onSettled({
|
|
2365
|
-
status: "committed",
|
|
2366
|
-
value
|
|
2367
|
-
});
|
|
2368
|
-
return value;
|
|
2369
|
-
}
|
|
2370
|
-
function fail(error) {
|
|
2371
|
-
if (settled) return;
|
|
2372
|
-
settled = true;
|
|
2373
|
-
teardown();
|
|
2374
|
-
if (controllerOnAbort) try {
|
|
2375
|
-
controllerOnAbort();
|
|
2376
|
-
} catch {}
|
|
2377
|
-
rejectFn(error);
|
|
2378
|
-
if (onSettled) onSettled({
|
|
2379
|
-
status: "rejected",
|
|
2380
|
-
error
|
|
2381
|
-
});
|
|
2382
|
-
}
|
|
2383
|
-
const ctx = {
|
|
2384
|
-
get settled() {
|
|
2385
|
-
return settled;
|
|
2386
|
-
},
|
|
2387
|
-
commit,
|
|
2388
|
-
fail,
|
|
2389
|
-
writeLayer,
|
|
2390
|
-
onTeardown(detach, onAbort) {
|
|
2391
|
-
controllerDetach = detach;
|
|
2392
|
-
controllerOnAbort = onAbort ?? null;
|
|
2393
|
-
}
|
|
2394
|
-
};
|
|
2395
|
-
combined.signal.addEventListener("abort", () => {
|
|
2396
|
-
if (settled) return;
|
|
2397
|
-
const reason = combined.signal.reason;
|
|
2398
|
-
if (reason instanceof TacticalDrawAbortError) fail(reason);
|
|
2399
|
-
else fail(new TacticalDrawAbortError("signal", { cause: reason }));
|
|
2400
|
-
}, { once: true });
|
|
2401
|
-
if (onViewChange) adapter.onViewChange(onViewChange);
|
|
2402
|
-
if (typeof window !== "undefined") window.addEventListener("keydown", handleKeydown);
|
|
2403
|
-
attach(ctx);
|
|
2404
|
-
return {
|
|
2405
|
-
promise,
|
|
2406
|
-
get settled() {
|
|
2407
|
-
return settled;
|
|
2408
|
-
},
|
|
2409
|
-
abort(reason, cause) {
|
|
2410
|
-
combined.abort(reason, cause);
|
|
2411
|
-
}
|
|
2412
|
-
};
|
|
2413
|
-
}
|
|
2414
2587
|
/**
|
|
2415
2588
|
* Round every component of a single position to {@link CONTROL_POINT_PRECISION}
|
|
2416
2589
|
* places. Handles optional altitude (any trailing components) too.
|
|
@@ -2467,7 +2640,8 @@ function shouldSuppressGuide(metadata) {
|
|
|
2467
2640
|
* Callers are responsible for the opt-out (`guide: false`) and the suppression
|
|
2468
2641
|
* check via [[shouldSuppressGuide]] — this function only emits geometry.
|
|
2469
2642
|
*/
|
|
2470
|
-
function buildGuideFeatures(points, isAreaKind, trailingFixedSlots = 0) {
|
|
2643
|
+
function buildGuideFeatures(points, isAreaKind, trailingFixedSlots = 0, segments) {
|
|
2644
|
+
if (segments) return segmentGuideFeatures(points, segments);
|
|
2471
2645
|
const features = [];
|
|
2472
2646
|
const spine = trailingFixedSlots > 0 ? points.slice(0, points.length - trailingFixedSlots) : points;
|
|
2473
2647
|
if (spine.length >= 2) {
|
|
@@ -2501,7 +2675,101 @@ function buildGuideFeatures(points, isAreaKind, trailingFixedSlots = 0) {
|
|
|
2501
2675
|
};
|
|
2502
2676
|
features.push(closing);
|
|
2503
2677
|
}
|
|
2504
|
-
return features;
|
|
2678
|
+
return features;
|
|
2679
|
+
}
|
|
2680
|
+
/**
|
|
2681
|
+
* The open guide along a definition topology's real segments (ADR-0065):
|
|
2682
|
+
* consecutive segments that join end to start chain into one line. A single
|
|
2683
|
+
* chain stays a LineString, as the plain guide is; several become one
|
|
2684
|
+
* MultiLineString under the same id.
|
|
2685
|
+
*/
|
|
2686
|
+
function segmentGuideFeatures(points, segments) {
|
|
2687
|
+
const chains = [];
|
|
2688
|
+
let lastEnd = null;
|
|
2689
|
+
for (const { from, to } of segments) {
|
|
2690
|
+
const a = points[from];
|
|
2691
|
+
const b = points[to];
|
|
2692
|
+
if (!a || !b) continue;
|
|
2693
|
+
if (lastEnd === from && chains.length > 0) chains[chains.length - 1].push(b);
|
|
2694
|
+
else chains.push([a, b]);
|
|
2695
|
+
lastEnd = to;
|
|
2696
|
+
}
|
|
2697
|
+
if (chains.length === 0) return [];
|
|
2698
|
+
return [{
|
|
2699
|
+
type: "Feature",
|
|
2700
|
+
id: PREVIEW_GUIDE_OPEN_ID,
|
|
2701
|
+
geometry: chains.length === 1 ? {
|
|
2702
|
+
type: "LineString",
|
|
2703
|
+
coordinates: chains[0]
|
|
2704
|
+
} : {
|
|
2705
|
+
type: "MultiLineString",
|
|
2706
|
+
coordinates: chains
|
|
2707
|
+
},
|
|
2708
|
+
properties: {
|
|
2709
|
+
part: "guide",
|
|
2710
|
+
segment: "open"
|
|
2711
|
+
}
|
|
2712
|
+
}];
|
|
2713
|
+
}
|
|
2714
|
+
//#endregion
|
|
2715
|
+
//#region src/tactical-draw/edit-modifiers.ts
|
|
2716
|
+
const KEY_PROPS = {
|
|
2717
|
+
alt: "altKey",
|
|
2718
|
+
shift: "shiftKey",
|
|
2719
|
+
ctrl: "ctrlKey",
|
|
2720
|
+
meta: "metaKey"
|
|
2721
|
+
};
|
|
2722
|
+
const MODIFIER_KEYS = Object.keys(KEY_PROPS);
|
|
2723
|
+
const DEFAULT_EDIT_MODIFIERS = Object.freeze({
|
|
2724
|
+
modifierDrag: Object.freeze(["ctrl", "meta"]),
|
|
2725
|
+
deleteOrReset: "alt",
|
|
2726
|
+
constrain: "shift"
|
|
2727
|
+
});
|
|
2728
|
+
function checkKey(role, key) {
|
|
2729
|
+
if (key === false) return false;
|
|
2730
|
+
if (!MODIFIER_KEYS.includes(key)) throw new RangeError(`editModifiers.${role}: ${JSON.stringify(key)} is not one of ${MODIFIER_KEYS.join(", ")} or false`);
|
|
2731
|
+
return key;
|
|
2732
|
+
}
|
|
2733
|
+
/**
|
|
2734
|
+
* Lay `patch` over `base`, validating every key. Throws a `RangeError` for an
|
|
2735
|
+
* unknown key, or when `deleteOrReset` shares a key with `modifierDrag` — both
|
|
2736
|
+
* act on the same vertex press, so the delete would silently win.
|
|
2737
|
+
*/
|
|
2738
|
+
function resolveEditModifiers(base, patch) {
|
|
2739
|
+
let modifierDrag = base.modifierDrag;
|
|
2740
|
+
if (patch?.modifierDrag !== void 0) {
|
|
2741
|
+
const raw = patch.modifierDrag;
|
|
2742
|
+
const keys = (raw === false ? [] : typeof raw === "string" ? [raw] : raw).map((key) => checkKey("modifierDrag", key));
|
|
2743
|
+
const unique = [...new Set(keys)];
|
|
2744
|
+
modifierDrag = unique.length > 0 ? Object.freeze(unique) : false;
|
|
2745
|
+
}
|
|
2746
|
+
const deleteOrReset = patch?.deleteOrReset !== void 0 ? checkKey("deleteOrReset", patch.deleteOrReset) : base.deleteOrReset;
|
|
2747
|
+
const constrain = patch?.constrain !== void 0 ? checkKey("constrain", patch.constrain) : base.constrain;
|
|
2748
|
+
if (deleteOrReset && modifierDrag && modifierDrag.includes(deleteOrReset)) throw new RangeError(`editModifiers: deleteOrReset and modifierDrag both use "${deleteOrReset}"; they act on the same vertex press, so give them different keys`);
|
|
2749
|
+
return Object.freeze({
|
|
2750
|
+
modifierDrag,
|
|
2751
|
+
deleteOrReset,
|
|
2752
|
+
constrain
|
|
2753
|
+
});
|
|
2754
|
+
}
|
|
2755
|
+
/** Whether `info` reports any of `keys` held; never when the role is off. */
|
|
2756
|
+
function modifierHeld(info, keys) {
|
|
2757
|
+
if (!info || keys === false) return false;
|
|
2758
|
+
if (typeof keys === "string") return info[KEY_PROPS[keys]] === true;
|
|
2759
|
+
return keys.some((key) => info[KEY_PROPS[key]] === true);
|
|
2760
|
+
}
|
|
2761
|
+
/** Read `key` through engine event wrappers without assuming a DOM event type. */
|
|
2762
|
+
function eventModifierHeld(originalEvent, key) {
|
|
2763
|
+
if (key === false) return false;
|
|
2764
|
+
const prop = KEY_PROPS[key];
|
|
2765
|
+
let event = originalEvent;
|
|
2766
|
+
for (let depth = 0; depth < 4; depth += 1) {
|
|
2767
|
+
if (typeof event !== "object" || event === null) return false;
|
|
2768
|
+
if (prop in event && event[prop] === true) return true;
|
|
2769
|
+
if (!("originalEvent" in event)) return false;
|
|
2770
|
+
event = event.originalEvent;
|
|
2771
|
+
}
|
|
2772
|
+
return false;
|
|
2505
2773
|
}
|
|
2506
2774
|
//#endregion
|
|
2507
2775
|
//#region src/tactical-draw/snapping.ts
|
|
@@ -2597,24 +2865,14 @@ function snappedDrawPosition(snap, event) {
|
|
|
2597
2865
|
originalEvent: event.originalEvent
|
|
2598
2866
|
})?.coordinate ?? event.coordinate;
|
|
2599
2867
|
}
|
|
2600
|
-
/** Read Shift through engine event wrappers without assuming a DOM event type. */
|
|
2601
|
-
function shiftKeyPressed(originalEvent) {
|
|
2602
|
-
let event = originalEvent;
|
|
2603
|
-
for (let depth = 0; depth < 4; depth += 1) {
|
|
2604
|
-
if (typeof event !== "object" || event === null) return false;
|
|
2605
|
-
if ("shiftKey" in event && event.shiftKey === true) return true;
|
|
2606
|
-
if (!("originalEvent" in event)) return false;
|
|
2607
|
-
event = event.originalEvent;
|
|
2608
|
-
}
|
|
2609
|
-
return false;
|
|
2610
|
-
}
|
|
2611
2868
|
/**
|
|
2612
2869
|
* Apply a rule's angular constraint to `points` when the gesture asks for it
|
|
2613
|
-
* (Shift
|
|
2614
|
-
* so callers can use the result
|
|
2870
|
+
* (the `constrain` key held, Shift by default) and the rule defines one.
|
|
2871
|
+
* Returns `points` unchanged otherwise, so callers can use the result
|
|
2872
|
+
* unconditionally.
|
|
2615
2873
|
*/
|
|
2616
|
-
function constrainedDrawPoints(rule, points, activePointIndex, originalEvent) {
|
|
2617
|
-
if (!rule?.constrainAngles || !
|
|
2874
|
+
function constrainedDrawPoints(rule, points, activePointIndex, originalEvent, constrainKey) {
|
|
2875
|
+
if (!rule?.constrainAngles || !eventModifierHeld(originalEvent, constrainKey)) return points;
|
|
2618
2876
|
return rule.constrainAngles(points, activePointIndex);
|
|
2619
2877
|
}
|
|
2620
2878
|
const DEFAULT_TOLERANCE_PIXELS = 12;
|
|
@@ -2807,6 +3065,7 @@ const PREVIEW_CURSOR$1 = "crosshair";
|
|
|
2807
3065
|
* kinds need no host UI.
|
|
2808
3066
|
*/
|
|
2809
3067
|
function runFixedLengthDraw(options) {
|
|
3068
|
+
const constrainKey = () => options.editModifiers().constrain;
|
|
2810
3069
|
const { adapter, kind, previewLayer, guideLayer, renderOptions: renderOpts, generateId, signal, measureOptions, measureStyle, measureProperties, measureTextAmplifiers, guide: guideOpt, sizeAnchor, onSettled, onSession, seed, snap } = options;
|
|
2811
3070
|
const metadata = getControlMeasureMetadata(kind);
|
|
2812
3071
|
const rule = metadata.rule;
|
|
@@ -2903,7 +3162,7 @@ function runFixedLengthDraw(options) {
|
|
|
2903
3162
|
}
|
|
2904
3163
|
const activePointIndex = committed.length;
|
|
2905
3164
|
committed.push(position);
|
|
2906
|
-
committed.splice(0, committed.length, ...constrainedDrawPoints(rule, committed, activePointIndex, event.originalEvent));
|
|
3165
|
+
committed.splice(0, committed.length, ...constrainedDrawPoints(rule, committed, activePointIndex, event.originalEvent, constrainKey()));
|
|
2907
3166
|
rubberBand = void 0;
|
|
2908
3167
|
if (committed.length >= required) {
|
|
2909
3168
|
ctx.commit(buildSnapshot);
|
|
@@ -2920,7 +3179,7 @@ function runFixedLengthDraw(options) {
|
|
|
2920
3179
|
if (ctx.settled) return;
|
|
2921
3180
|
if (committed.length === 0) return;
|
|
2922
3181
|
rubberBand = snappedDrawPosition(snap, event);
|
|
2923
|
-
const points = constrainedDrawPoints(rule, [...committed, rubberBand], committed.length, event.originalEvent);
|
|
3182
|
+
const points = constrainedDrawPoints(rule, [...committed, rubberBand], committed.length, event.originalEvent, constrainKey());
|
|
2924
3183
|
rubberBand = points[committed.length] ?? rubberBand;
|
|
2925
3184
|
renderPreview();
|
|
2926
3185
|
const phase = transientStarted ? "move" : "start";
|
|
@@ -3084,6 +3343,7 @@ const PREVIEW_CURSOR = "crosshair";
|
|
|
3084
3343
|
* added point again" as additional gesture-level commit triggers.
|
|
3085
3344
|
*/
|
|
3086
3345
|
function runVariableLengthDraw(options) {
|
|
3346
|
+
const constrainKey = () => options.editModifiers().constrain;
|
|
3087
3347
|
const { adapter, kind, previewLayer, guideLayer, renderOptions: renderOpts, generateId, signal, onSession, seed, measureOptions, measureStyle, measureProperties, measureTextAmplifiers, guide: guideOpt, sizeAnchor, onSettled, snap } = options;
|
|
3088
3348
|
const metadata = getControlMeasureMetadata(kind);
|
|
3089
3349
|
if (typeof metadata.minCoordinates !== "number") throw new Error(`runVariableLengthDraw: kind "${kind}" has no minCoordinates metadata`);
|
|
@@ -3209,7 +3469,7 @@ function runVariableLengthDraw(options) {
|
|
|
3209
3469
|
const idx = insertionIndex(committed.length);
|
|
3210
3470
|
committed.splice(idx, 0, [...pos]);
|
|
3211
3471
|
if (rule) {
|
|
3212
|
-
const derived = rule.derive(constrainedDrawPoints(rule, committed, idx, event.originalEvent));
|
|
3472
|
+
const derived = rule.derive(constrainedDrawPoints(rule, committed, idx, event.originalEvent, constrainKey()));
|
|
3213
3473
|
committed.splice(0, committed.length, ...derived);
|
|
3214
3474
|
}
|
|
3215
3475
|
committed.splice(0, committed.length, ...roundControlPoints(committed));
|
|
@@ -3232,7 +3492,7 @@ function runVariableLengthDraw(options) {
|
|
|
3232
3492
|
const idx = insertionIndex(committed.length);
|
|
3233
3493
|
const spine = [...committed];
|
|
3234
3494
|
spine.splice(idx, 0, rubberBand);
|
|
3235
|
-
const points = constrainedDrawPoints(rule, spine, idx, event.originalEvent);
|
|
3495
|
+
const points = constrainedDrawPoints(rule, spine, idx, event.originalEvent, constrainKey());
|
|
3236
3496
|
rubberBand = points[idx] ?? rubberBand;
|
|
3237
3497
|
renderPreview();
|
|
3238
3498
|
const phase = transientStarted ? "move" : "start";
|
|
@@ -3373,154 +3633,6 @@ function outlinePreview(points) {
|
|
|
3373
3633
|
}
|
|
3374
3634
|
return features;
|
|
3375
3635
|
}
|
|
3376
|
-
/** Whether `b` lands within {@link CLICK_SLOP_PX} of `a` — a click, not a drag. */
|
|
3377
|
-
function withinClickSlop(a, b) {
|
|
3378
|
-
return Math.hypot(a[0] - b[0], a[1] - b[1]) <= 3;
|
|
3379
|
-
}
|
|
3380
|
-
function runEditInteraction(spec) {
|
|
3381
|
-
const { adapter, signal, layers, graphicsLayer, previewLayer, handlesLayer, closeOnClickAway } = spec;
|
|
3382
|
-
let ctx;
|
|
3383
|
-
let driver;
|
|
3384
|
-
let previewPick;
|
|
3385
|
-
let handlesPick;
|
|
3386
|
-
let graphicsPick;
|
|
3387
|
-
/**
|
|
3388
|
-
* Consume exactly one trailing click without closing — set through
|
|
3389
|
-
* `shell.suppressNextClickAway()` on delete / label-drag / post-drag paths.
|
|
3390
|
-
*
|
|
3391
|
-
* The suppression is scoped to the pointer cycle that armed it: it is cleared
|
|
3392
|
-
* again on the next `pointerdown` (see the `onDown` wrapper below). Hosts do
|
|
3393
|
-
* not agree on whether a completed drag is followed by a `click` at all —
|
|
3394
|
-
* MapLibre swallows its `click` when the pointer moved beyond its 3px
|
|
3395
|
-
* `clickTolerance`, while Leaflet delivers one. Without the reset, a
|
|
3396
|
-
* suppression armed after a real drag on MapLibre survives into the *next*
|
|
3397
|
-
* pointer cycle and eats the user's first genuine click-away, so exiting the
|
|
3398
|
-
* edit takes two clicks instead of one.
|
|
3399
|
-
*/
|
|
3400
|
-
let suppressClickAway = false;
|
|
3401
|
-
/** A zero-movement body drag released this pointer cycle — set through `shell.noteBodyClick()`. */
|
|
3402
|
-
let bodyClickPending = false;
|
|
3403
|
-
const shell = {
|
|
3404
|
-
suppressNextClickAway() {
|
|
3405
|
-
suppressClickAway = true;
|
|
3406
|
-
},
|
|
3407
|
-
noteBodyClick() {
|
|
3408
|
-
bodyClickPending = true;
|
|
3409
|
-
}
|
|
3410
|
-
};
|
|
3411
|
-
const onPreviewPick = (event) => {
|
|
3412
|
-
previewPick = event;
|
|
3413
|
-
};
|
|
3414
|
-
const onHandlesPick = (event) => {
|
|
3415
|
-
handlesPick = event;
|
|
3416
|
-
};
|
|
3417
|
-
const onGraphicsPick = (event) => {
|
|
3418
|
-
graphicsPick = event;
|
|
3419
|
-
};
|
|
3420
|
-
const onClick = () => {
|
|
3421
|
-
const localPreview = previewPick;
|
|
3422
|
-
const localHandles = handlesPick;
|
|
3423
|
-
const localGraphics = graphicsPick;
|
|
3424
|
-
const wasBodyClick = bodyClickPending;
|
|
3425
|
-
previewPick = void 0;
|
|
3426
|
-
handlesPick = void 0;
|
|
3427
|
-
graphicsPick = void 0;
|
|
3428
|
-
bodyClickPending = false;
|
|
3429
|
-
if (ctx.settled) return;
|
|
3430
|
-
if (!closeOnClickAway) return;
|
|
3431
|
-
if (suppressClickAway) {
|
|
3432
|
-
suppressClickAway = false;
|
|
3433
|
-
return;
|
|
3434
|
-
}
|
|
3435
|
-
if (localHandles) return;
|
|
3436
|
-
if (localGraphics && !spec.ownsGraphic(localGraphics.id)) {
|
|
3437
|
-
spec.close();
|
|
3438
|
-
spec.onForeignPick?.(localGraphics);
|
|
3439
|
-
return;
|
|
3440
|
-
}
|
|
3441
|
-
if (localGraphics && spec.ownsGraphic(localGraphics.id)) return;
|
|
3442
|
-
if (localPreview) return;
|
|
3443
|
-
if (wasBodyClick) return;
|
|
3444
|
-
spec.close();
|
|
3445
|
-
};
|
|
3446
|
-
return runInteraction({
|
|
3447
|
-
adapter,
|
|
3448
|
-
signal,
|
|
3449
|
-
layers,
|
|
3450
|
-
onViewChange: spec.onViewChange,
|
|
3451
|
-
onSettled: (settlement) => {
|
|
3452
|
-
try {
|
|
3453
|
-
spec.historySettle();
|
|
3454
|
-
} finally {
|
|
3455
|
-
spec.facadeOnSettled?.();
|
|
3456
|
-
spec.emitSettle(settlement);
|
|
3457
|
-
}
|
|
3458
|
-
},
|
|
3459
|
-
attach(interaction) {
|
|
3460
|
-
ctx = interaction;
|
|
3461
|
-
driver = adapter.createEditPointerDriver();
|
|
3462
|
-
let beforeTeardownRan = false;
|
|
3463
|
-
const runBeforeTeardown = (settlement) => {
|
|
3464
|
-
if (beforeTeardownRan) return;
|
|
3465
|
-
beforeTeardownRan = true;
|
|
3466
|
-
try {
|
|
3467
|
-
spec.onBeforeTeardown?.(settlement);
|
|
3468
|
-
} catch {}
|
|
3469
|
-
};
|
|
3470
|
-
const controllerContext = {
|
|
3471
|
-
get settled() {
|
|
3472
|
-
return interaction.settled;
|
|
3473
|
-
},
|
|
3474
|
-
commit(produce) {
|
|
3475
|
-
return interaction.commit(() => {
|
|
3476
|
-
const value = produce();
|
|
3477
|
-
runBeforeTeardown({
|
|
3478
|
-
status: "committed",
|
|
3479
|
-
value
|
|
3480
|
-
});
|
|
3481
|
-
return value;
|
|
3482
|
-
});
|
|
3483
|
-
},
|
|
3484
|
-
fail(error) {
|
|
3485
|
-
if (!interaction.settled) runBeforeTeardown({
|
|
3486
|
-
status: "rejected",
|
|
3487
|
-
error
|
|
3488
|
-
});
|
|
3489
|
-
interaction.fail(error);
|
|
3490
|
-
},
|
|
3491
|
-
writeLayer: interaction.writeLayer,
|
|
3492
|
-
onTeardown: interaction.onTeardown
|
|
3493
|
-
};
|
|
3494
|
-
const onDown = (pixel, info) => {
|
|
3495
|
-
suppressClickAway = false;
|
|
3496
|
-
spec.onDown(pixel, info);
|
|
3497
|
-
};
|
|
3498
|
-
const unsubDown = driver.onPointerDown(onDown);
|
|
3499
|
-
const unsubMove = driver.onPointerMove(spec.onMove);
|
|
3500
|
-
const unsubUp = driver.onPointerUp(spec.onUp);
|
|
3501
|
-
const unsubPreview = adapter.onPick(previewLayer, onPreviewPick);
|
|
3502
|
-
const unsubHandles = adapter.onPick(handlesLayer, onHandlesPick);
|
|
3503
|
-
const unsubGraphics = adapter.onPick(graphicsLayer, onGraphicsPick);
|
|
3504
|
-
adapter.on("click", onClick);
|
|
3505
|
-
interaction.onTeardown(() => {
|
|
3506
|
-
runBeforeTeardown({
|
|
3507
|
-
status: "rejected",
|
|
3508
|
-
error: void 0
|
|
3509
|
-
});
|
|
3510
|
-
adapter.off("click", onClick);
|
|
3511
|
-
unsubPreview();
|
|
3512
|
-
unsubHandles();
|
|
3513
|
-
unsubGraphics();
|
|
3514
|
-
unsubDown();
|
|
3515
|
-
unsubMove();
|
|
3516
|
-
unsubUp();
|
|
3517
|
-
spec.extraTeardown?.();
|
|
3518
|
-
driver.dispose();
|
|
3519
|
-
}, spec.onAbort);
|
|
3520
|
-
spec.attach(controllerContext, driver, shell);
|
|
3521
|
-
}
|
|
3522
|
-
});
|
|
3523
|
-
}
|
|
3524
3636
|
//#endregion
|
|
3525
3637
|
//#region src/tactical-draw/handles.ts
|
|
3526
3638
|
/** Size of a `compact` option handle relative to its slot's style. */
|
|
@@ -3563,7 +3675,7 @@ function segmentMidpoint(a, b) {
|
|
|
3563
3675
|
* an empty control-point list.
|
|
3564
3676
|
*/
|
|
3565
3677
|
function buildHandleSet(controlPoints, modes, options = {}) {
|
|
3566
|
-
const { includeMidpoints = true, hiddenControlPointIndices = [], trailingFixedSlots = 0, closedRing = false } = options;
|
|
3678
|
+
const { includeMidpoints = true, hiddenControlPointIndices = [], trailingFixedSlots = 0, closedRing = false, segments } = options;
|
|
3567
3679
|
const handles = [];
|
|
3568
3680
|
const wantsReshape = modes.includes("reshape");
|
|
3569
3681
|
if (wantsReshape || modes.includes("delete")) {
|
|
@@ -3575,7 +3687,18 @@ function buildHandleSet(controlPoints, modes, options = {}) {
|
|
|
3575
3687
|
position: [...controlPoints[i]]
|
|
3576
3688
|
});
|
|
3577
3689
|
}
|
|
3578
|
-
if (wantsReshape && includeMidpoints) {
|
|
3690
|
+
if (wantsReshape && includeMidpoints && segments) segments.forEach((segment, index) => {
|
|
3691
|
+
const a = controlPoints[segment.from];
|
|
3692
|
+
const b = controlPoints[segment.to];
|
|
3693
|
+
if (!a || !b) return;
|
|
3694
|
+
handles.push({
|
|
3695
|
+
kind: "midpoint",
|
|
3696
|
+
index,
|
|
3697
|
+
position: segmentMidpoint(a, b),
|
|
3698
|
+
segment: { ...segment }
|
|
3699
|
+
});
|
|
3700
|
+
});
|
|
3701
|
+
else if (wantsReshape && includeMidpoints) {
|
|
3579
3702
|
const edgeCount = closedRing && trailingFixedSlots === 0 && controlPoints.length >= 3 ? controlPoints.length : controlPoints.length - 1 - trailingFixedSlots;
|
|
3580
3703
|
for (let i = 0; i < edgeCount; i++) {
|
|
3581
3704
|
const end = (i + 1) % controlPoints.length;
|
|
@@ -3597,10 +3720,12 @@ function handleFeatureId(prefix, kind, index) {
|
|
|
3597
3720
|
case "geometry": return `${prefix}:handle-geometry:${index}`;
|
|
3598
3721
|
case "scale": return `${prefix}:handle-scale:${index}`;
|
|
3599
3722
|
case "rotate": return `${prefix}:handle-rotate`;
|
|
3723
|
+
case "snap": return `${prefix}:handle-snap:${index}`;
|
|
3600
3724
|
}
|
|
3601
3725
|
}
|
|
3602
|
-
function handleStyleFor(kind, interactionStyle, unset = false) {
|
|
3726
|
+
function handleStyleFor(kind, interactionStyle, unset = false, active = false) {
|
|
3603
3727
|
if (kind === "option" && unset && interactionStyle?.unsetOptionHandle) return interactionStyle.unsetOptionHandle;
|
|
3728
|
+
if (kind === "snap" && active && interactionStyle?.activeSnapTargetHandle) return interactionStyle.activeSnapTargetHandle;
|
|
3604
3729
|
switch (kind) {
|
|
3605
3730
|
case "vertex": return interactionStyle?.vertexHandle;
|
|
3606
3731
|
case "midpoint": return interactionStyle?.midpointHandle;
|
|
@@ -3608,6 +3733,7 @@ function handleStyleFor(kind, interactionStyle, unset = false) {
|
|
|
3608
3733
|
case "geometry": return interactionStyle?.geometryHandle;
|
|
3609
3734
|
case "scale": return interactionStyle?.scaleHandle;
|
|
3610
3735
|
case "rotate": return interactionStyle?.rotateHandle;
|
|
3736
|
+
case "snap": return interactionStyle?.snapTargetHandle;
|
|
3611
3737
|
}
|
|
3612
3738
|
}
|
|
3613
3739
|
/**
|
|
@@ -3621,7 +3747,7 @@ function handleStyleFor(kind, interactionStyle, unset = false) {
|
|
|
3621
3747
|
*/
|
|
3622
3748
|
function toFeatures(handles, featureIdPrefix, interactionStyle) {
|
|
3623
3749
|
return handles.map((handle) => {
|
|
3624
|
-
const slotStyle = handleStyleFor(handle.kind, interactionStyle, handle.unset);
|
|
3750
|
+
const slotStyle = handleStyleFor(handle.kind, interactionStyle, handle.unset, handle.active);
|
|
3625
3751
|
const style = slotStyle && handle.compact ? compactHandleStyle(slotStyle) : slotStyle;
|
|
3626
3752
|
return {
|
|
3627
3753
|
type: "Feature",
|
|
@@ -3660,6 +3786,10 @@ function pickHandle(handles, pixel, tolerance, toPixel) {
|
|
|
3660
3786
|
}
|
|
3661
3787
|
//#endregion
|
|
3662
3788
|
//#region src/tactical-draw/handle-drag.ts
|
|
3789
|
+
/** The control-point index a midpoint handle's grab inserts its new vertex at. */
|
|
3790
|
+
function midpointInsertIndex(handle) {
|
|
3791
|
+
return handle.segment?.insertAt ?? handle.index + 1;
|
|
3792
|
+
}
|
|
3663
3793
|
function clonePoints(points) {
|
|
3664
3794
|
return points.map((p) => [...p]);
|
|
3665
3795
|
}
|
|
@@ -3784,9 +3914,10 @@ function beginHandleDrag(args) {
|
|
|
3784
3914
|
}) }));
|
|
3785
3915
|
}
|
|
3786
3916
|
if (hit.kind !== "midpoint") throw new TypeError(`Unsupported control-point handle kind: ${hit.kind}`);
|
|
3787
|
-
const insertIndex = hit
|
|
3788
|
-
const
|
|
3789
|
-
const
|
|
3917
|
+
const insertIndex = midpointInsertIndex(hit);
|
|
3918
|
+
const segmentStartIndex = hit.segment?.from ?? hit.index;
|
|
3919
|
+
const segmentEndIndex = hit.segment?.to ?? (hit.index + 1) % preDragPoints.length;
|
|
3920
|
+
const mid = segmentMidpoint(preDragPoints[segmentStartIndex], preDragPoints[segmentEndIndex]);
|
|
3790
3921
|
const insertedBase = [
|
|
3791
3922
|
...preDragPoints.slice(0, insertIndex),
|
|
3792
3923
|
mid,
|
|
@@ -3879,6 +4010,154 @@ function beginBoxDrag(args) {
|
|
|
3879
4010
|
};
|
|
3880
4011
|
}
|
|
3881
4012
|
//#endregion
|
|
4013
|
+
//#region src/tactical-draw/modifier-drag.ts
|
|
4014
|
+
/**
|
|
4015
|
+
* The modifier-drag state machine: a Ctrl/⌘ + drag from a vertex handed to a
|
|
4016
|
+
* definition's `modifierDrag` hook (ADR-0065), lifted out of `runEdit`
|
|
4017
|
+
* (`edit-controller.ts`) beside `handle-drag.ts`. The hook plans the drag once
|
|
4018
|
+
* from the pre-drag graphic and computes every frame from that plan, so this
|
|
4019
|
+
* module keeps the plan, the pre-drag graphic for the single commit, and the
|
|
4020
|
+
* snap target under the pointer.
|
|
4021
|
+
*
|
|
4022
|
+
* It is pure and projection-injected. It does not render, commit, toggle
|
|
4023
|
+
* drag-pan or track `dragInFlight`: those stay in the controller.
|
|
4024
|
+
*/
|
|
4025
|
+
/** A Ctrl/⌘ + drag snaps onto a target within this multiple of the hit tolerance. */
|
|
4026
|
+
const MODIFIER_SNAP_SCALE = 1.5;
|
|
4027
|
+
/**
|
|
4028
|
+
* Start the hook's drag from vertex `index`; `null` when the hook declines
|
|
4029
|
+
* this point, so the press becomes a plain drag.
|
|
4030
|
+
*/
|
|
4031
|
+
function beginModifierDrag(args) {
|
|
4032
|
+
const { hook, index, downPixel, projection } = args;
|
|
4033
|
+
const preDragPoints = args.controlPoints.map((p) => [...p]);
|
|
4034
|
+
const preDragOptions = args.options;
|
|
4035
|
+
const hookOptions = preDragOptions ?? {};
|
|
4036
|
+
const plan = hook.start({
|
|
4037
|
+
controlPoints: preDragPoints,
|
|
4038
|
+
options: hookOptions,
|
|
4039
|
+
index
|
|
4040
|
+
});
|
|
4041
|
+
if (!plan) return null;
|
|
4042
|
+
const { targets } = plan;
|
|
4043
|
+
const snapTolerance = args.tolerance * MODIFIER_SNAP_SCALE;
|
|
4044
|
+
/** The snap target the pointer is on, as an index into `targets`. */
|
|
4045
|
+
let target;
|
|
4046
|
+
function snapTarget(pixel) {
|
|
4047
|
+
let best;
|
|
4048
|
+
let bestDistance = snapTolerance;
|
|
4049
|
+
targets.forEach((position, k) => {
|
|
4050
|
+
const at = projection.toPixel(position);
|
|
4051
|
+
const distance = at ? pixelDistance$1(at, pixel) : Infinity;
|
|
4052
|
+
if (distance <= bestDistance) {
|
|
4053
|
+
best = k;
|
|
4054
|
+
bestDistance = distance;
|
|
4055
|
+
}
|
|
4056
|
+
});
|
|
4057
|
+
return best;
|
|
4058
|
+
}
|
|
4059
|
+
/** The pointer's lon/lat; updates the snap target. */
|
|
4060
|
+
function pointer(pixel) {
|
|
4061
|
+
target = snapTarget(pixel);
|
|
4062
|
+
return projection.fromPixel(pixel);
|
|
4063
|
+
}
|
|
4064
|
+
return {
|
|
4065
|
+
preDragPoints,
|
|
4066
|
+
preDragOptions,
|
|
4067
|
+
first: plan.first,
|
|
4068
|
+
move: (pixel) => plan.move(pointer(pixel), target),
|
|
4069
|
+
end(pixel) {
|
|
4070
|
+
const position = pointer(pixel);
|
|
4071
|
+
return target === void 0 && withinClickSlop(pixel, downPixel) ? void 0 : plan.end(position, target);
|
|
4072
|
+
},
|
|
4073
|
+
snapHandles: () => targets.map((position, k) => ({
|
|
4074
|
+
kind: "snap",
|
|
4075
|
+
index: k,
|
|
4076
|
+
position: [...position],
|
|
4077
|
+
...k === target ? { active: true } : {}
|
|
4078
|
+
}))
|
|
4079
|
+
};
|
|
4080
|
+
}
|
|
4081
|
+
//#endregion
|
|
4082
|
+
//#region src/tactical-draw/part-selection.ts
|
|
4083
|
+
/**
|
|
4084
|
+
* Bind `kind`'s topology to a working graphic. `points` is the live working
|
|
4085
|
+
* array (mutated in place by the controller); `options` reads the current
|
|
4086
|
+
* working options.
|
|
4087
|
+
*/
|
|
4088
|
+
function bindWorkingTopology(kind, points, options) {
|
|
4089
|
+
let cached = null;
|
|
4090
|
+
const segments = () => {
|
|
4091
|
+
const current = options();
|
|
4092
|
+
if (cached && cached.options === current && samePoints(cached.points, points)) return cached.segments;
|
|
4093
|
+
const result = getControlMeasureSegments(kind, points, current) ?? void 0;
|
|
4094
|
+
cached = {
|
|
4095
|
+
options: current,
|
|
4096
|
+
points: points.map((p) => [...p]),
|
|
4097
|
+
segments: result
|
|
4098
|
+
};
|
|
4099
|
+
return result;
|
|
4100
|
+
};
|
|
4101
|
+
return {
|
|
4102
|
+
segments,
|
|
4103
|
+
partOf: (index) => getControlMeasurePartOf(kind, points, options(), index),
|
|
4104
|
+
parts() {
|
|
4105
|
+
const parts = /* @__PURE__ */ new Set();
|
|
4106
|
+
for (const segment of segments() ?? []) if (segment.part !== void 0) parts.add(segment.part);
|
|
4107
|
+
return parts;
|
|
4108
|
+
},
|
|
4109
|
+
canDeleteVertex: (index) => canDeleteControlMeasureVertex(kind, points, options(), index)
|
|
4110
|
+
};
|
|
4111
|
+
}
|
|
4112
|
+
function samePoints(a, b) {
|
|
4113
|
+
return a.length === b.length && a.every((p, i) => p.length === b[i].length && p.every((c, k) => c === b[i][k]));
|
|
4114
|
+
}
|
|
4115
|
+
function createPartSelection(opts) {
|
|
4116
|
+
const { topology, isSettled, repaint } = opts;
|
|
4117
|
+
let selected = topology.parts().has(0) ? 0 : void 0;
|
|
4118
|
+
const listeners = createCommitEmitter("EditSession.onPartSelect listener errors");
|
|
4119
|
+
function select(part, repaintAfter = true) {
|
|
4120
|
+
if (isSettled() || part === selected) return;
|
|
4121
|
+
if (part === void 0 || !topology.parts().has(part)) return;
|
|
4122
|
+
selected = part;
|
|
4123
|
+
if (repaintAfter) repaint();
|
|
4124
|
+
listeners.emit(part);
|
|
4125
|
+
}
|
|
4126
|
+
return {
|
|
4127
|
+
get selected() {
|
|
4128
|
+
return selected;
|
|
4129
|
+
},
|
|
4130
|
+
select,
|
|
4131
|
+
reconcile() {
|
|
4132
|
+
if (selected === void 0 || topology.parts().has(selected)) return;
|
|
4133
|
+
select(0, false);
|
|
4134
|
+
},
|
|
4135
|
+
onSelect(listener) {
|
|
4136
|
+
if (isSettled()) return () => {};
|
|
4137
|
+
return listeners.register(listener);
|
|
4138
|
+
}
|
|
4139
|
+
};
|
|
4140
|
+
}
|
|
4141
|
+
/**
|
|
4142
|
+
* The part of the segment nearest `pixel` (for a click on the graphic's
|
|
4143
|
+
* body), or `undefined` when no projectable segment carries a part.
|
|
4144
|
+
*/
|
|
4145
|
+
function partNearestPixel(pixel, segments, points, toPixel) {
|
|
4146
|
+
let best;
|
|
4147
|
+
let bestDistance = Infinity;
|
|
4148
|
+
for (const segment of segments ?? []) {
|
|
4149
|
+
const a = points[segment.from] && toPixel(points[segment.from]);
|
|
4150
|
+
const b = points[segment.to] && toPixel(points[segment.to]);
|
|
4151
|
+
if (!a || !b || segment.part === void 0) continue;
|
|
4152
|
+
const distance = pixelSegmentDistance(pixel, a, b);
|
|
4153
|
+
if (distance < bestDistance) {
|
|
4154
|
+
best = segment.part;
|
|
4155
|
+
bestDistance = distance;
|
|
4156
|
+
}
|
|
4157
|
+
}
|
|
4158
|
+
return best;
|
|
4159
|
+
}
|
|
4160
|
+
//#endregion
|
|
3882
4161
|
//#region src/tactical-draw/deep-equal.ts
|
|
3883
4162
|
/**
|
|
3884
4163
|
* @internal
|
|
@@ -4780,6 +5059,8 @@ const ALLOWED_EDIT_MODES = new Set([
|
|
|
4780
5059
|
* - close / abort / signal / preempt / destroy paths
|
|
4781
5060
|
*/
|
|
4782
5061
|
function runEdit(opts) {
|
|
5062
|
+
const keys = opts.editModifiers;
|
|
5063
|
+
const constrainHeld = (info) => modifierHeld(info, keys().constrain);
|
|
4783
5064
|
const { adapter, measure, graphicsLayer, previewLayer, guideLayer, handlesLayer, renderOptions: renderOpts, signal, closeOnClickAway = true, modes: initialModes, interactionStyle, onSession, handleIdPrefix, guide: guideOpt, settleToGraphics, publishWorkingGraphic, onSettled, onClickAwayGraphicsPick, snap, deferredSnap } = opts;
|
|
4784
5065
|
let sizeAnchor = opts.sizeAnchor ?? defaultSizeAnchor(measure);
|
|
4785
5066
|
let detailHandles = opts.detailHandles ?? false;
|
|
@@ -4798,6 +5079,12 @@ function runEdit(opts) {
|
|
|
4798
5079
|
const editStartPoints = measure.controlPoints.map((p) => [...p]);
|
|
4799
5080
|
const workingPoints = editStartPoints.map((p) => [...p]);
|
|
4800
5081
|
let workingOptions = { ...measure.options ?? {} };
|
|
5082
|
+
const topology = bindWorkingTopology(measure.kind, workingPoints, () => workingOptions);
|
|
5083
|
+
const parts = createPartSelection({
|
|
5084
|
+
topology,
|
|
5085
|
+
isSettled: () => ctx.settled,
|
|
5086
|
+
repaint: () => renderHandlesLayer()
|
|
5087
|
+
});
|
|
4801
5088
|
let workingTextAmplifiers = measure.textAmplifiers && Object.keys(measure.textAmplifiers).length > 0 ? { ...measure.textAmplifiers } : void 0;
|
|
4802
5089
|
let workingAmplifierPlacements = measure.amplifierPlacements && Object.keys(measure.amplifierPlacements).length > 0 ? structuredClone(measure.amplifierPlacements) : void 0;
|
|
4803
5090
|
let workingProperties = measure.properties ? structuredClone(measure.properties) : void 0;
|
|
@@ -4976,7 +5263,7 @@ function runEdit(opts) {
|
|
|
4976
5263
|
lastWorkingFeatures = features;
|
|
4977
5264
|
refitBox();
|
|
4978
5265
|
const guidePoints = rule?.guidePoints ? rule.guidePoints(workingPoints) : workingPoints;
|
|
4979
|
-
const guideFeatures = guideEnabled ? buildGuideFeatures(guidePoints, isAreaKind, trailingFixedSlots) : [];
|
|
5266
|
+
const guideFeatures = guideEnabled ? buildGuideFeatures(guidePoints, isAreaKind, trailingFixedSlots, topology.segments()) : [];
|
|
4980
5267
|
ctx.writeLayer(guideLayer, [{
|
|
4981
5268
|
id: `__td_edit_guide__:${measure.id}`,
|
|
4982
5269
|
features: guideFeatures,
|
|
@@ -4995,7 +5282,8 @@ function runEdit(opts) {
|
|
|
4995
5282
|
}
|
|
4996
5283
|
function renderHandlesLayer() {
|
|
4997
5284
|
if (ctx.settled) return;
|
|
4998
|
-
|
|
5285
|
+
parts.reconcile();
|
|
5286
|
+
const features = toFeatures([...buildCurrentHandleSet(), ...activeModifierDrag?.snapHandles() ?? []], handleIdPrefix, interactionStyle);
|
|
4999
5287
|
if (modes.includes("labeldrag")) features.push(...labels.handleFeatures());
|
|
5000
5288
|
if (modes.includes("transform")) {
|
|
5001
5289
|
const liveBox = activeBoxDrag && !anchoredOptionTransformInFlight() ? activeBoxDrag.lastSnapshot.box : box;
|
|
@@ -5018,6 +5306,7 @@ function runEdit(opts) {
|
|
|
5018
5306
|
function buildCurrentHandleSet() {
|
|
5019
5307
|
const handles = buildHandleSet(workingPoints, modes, {
|
|
5020
5308
|
includeMidpoints: midpointHandlesEnabled,
|
|
5309
|
+
segments: topology.segments(),
|
|
5021
5310
|
hiddenControlPointIndices,
|
|
5022
5311
|
trailingFixedSlots,
|
|
5023
5312
|
closedRing
|
|
@@ -5032,6 +5321,7 @@ function runEdit(opts) {
|
|
|
5032
5321
|
})));
|
|
5033
5322
|
const optionHandles = getControlMeasureOptionHandles(measure.kind, workingPoints, workingOptions, {
|
|
5034
5323
|
detail: detailHandles,
|
|
5324
|
+
...parts.selected !== void 0 ? { part: parts.selected } : {},
|
|
5035
5325
|
...optionHandleContext()
|
|
5036
5326
|
});
|
|
5037
5327
|
for (let index = 0; index < optionHandles.length; index++) {
|
|
@@ -5489,6 +5779,15 @@ function runEdit(opts) {
|
|
|
5489
5779
|
get detailHandles() {
|
|
5490
5780
|
return detailHandles;
|
|
5491
5781
|
},
|
|
5782
|
+
get selectedPart() {
|
|
5783
|
+
return parts.selected;
|
|
5784
|
+
},
|
|
5785
|
+
selectPart(part) {
|
|
5786
|
+
parts.select(part);
|
|
5787
|
+
},
|
|
5788
|
+
onPartSelect(listener) {
|
|
5789
|
+
return parts.onSelect(listener);
|
|
5790
|
+
},
|
|
5492
5791
|
setDetailHandles(visible) {
|
|
5493
5792
|
if (ctx.settled || visible === detailHandles) return;
|
|
5494
5793
|
detailHandles = visible;
|
|
@@ -5562,6 +5861,40 @@ function runEdit(opts) {
|
|
|
5562
5861
|
};
|
|
5563
5862
|
let activeDrag = null;
|
|
5564
5863
|
let activeOptionDrag = null;
|
|
5864
|
+
let activeModifierDrag = null;
|
|
5865
|
+
/**
|
|
5866
|
+
* Start the definition's Ctrl/⌘ + drag from vertex `index`; `false` when it
|
|
5867
|
+
* has none or declines this point, so the press becomes a plain drag.
|
|
5868
|
+
*/
|
|
5869
|
+
function startModifierDrag(index, pixel, tolerance) {
|
|
5870
|
+
const hook = getControlMeasureModifierDrag(measure.kind);
|
|
5871
|
+
if (!hook) return false;
|
|
5872
|
+
const drag = beginModifierDrag({
|
|
5873
|
+
hook,
|
|
5874
|
+
controlPoints: workingPoints,
|
|
5875
|
+
options: workingOptions,
|
|
5876
|
+
index,
|
|
5877
|
+
downPixel: pixel,
|
|
5878
|
+
tolerance,
|
|
5879
|
+
projection: driver
|
|
5880
|
+
});
|
|
5881
|
+
if (!drag) return false;
|
|
5882
|
+
activeModifierDrag = drag;
|
|
5883
|
+
transient.emit("start", drag.preDragPoints, index);
|
|
5884
|
+
showModifierFrame(drag.first);
|
|
5885
|
+
dragInFlight = true;
|
|
5886
|
+
driver.setDragPanEnabled(false);
|
|
5887
|
+
return true;
|
|
5888
|
+
}
|
|
5889
|
+
/** Show a modifier-drag frame, selecting the part it names (e.g. a new flow pulled out). */
|
|
5890
|
+
function showModifierFrame(frame) {
|
|
5891
|
+
replaceWorkingPoints(frame.controlPoints);
|
|
5892
|
+
replaceWorkingOptions(frame.options);
|
|
5893
|
+
renderWorkingGraphic();
|
|
5894
|
+
renderHandlesLayer();
|
|
5895
|
+
recomputeDirty();
|
|
5896
|
+
if (frame.part !== void 0) parts.select(frame.part);
|
|
5897
|
+
}
|
|
5565
5898
|
function optionsForOptionHandle(position, drag) {
|
|
5566
5899
|
const patch = dragControlMeasureOptionHandle(measure.kind, workingPoints, drag.preDragOptions, drag.handleId, position, optionHandleContext());
|
|
5567
5900
|
return patch ? {
|
|
@@ -5673,7 +6006,8 @@ function runEdit(opts) {
|
|
|
5673
6006
|
const spineCount = workingPoints.length - trailingFixedSlots;
|
|
5674
6007
|
if (index < 0 || index >= spineCount) return false;
|
|
5675
6008
|
const minimum = rule?.minimumUserPoints ?? (isAreaKind ? 3 : 2);
|
|
5676
|
-
|
|
6009
|
+
if (spineCount - 1 < minimum) return false;
|
|
6010
|
+
return topology.canDeleteVertex(index);
|
|
5677
6011
|
}
|
|
5678
6012
|
/**
|
|
5679
6013
|
* Remove the vertex at `index` and commit through the normal gesture path so
|
|
@@ -5730,12 +6064,16 @@ function runEdit(opts) {
|
|
|
5730
6064
|
}
|
|
5731
6065
|
return;
|
|
5732
6066
|
}
|
|
5733
|
-
|
|
6067
|
+
const deleteOrReset = modifierHeld(info, keys().deleteOrReset);
|
|
6068
|
+
if (hit.kind === "vertex" && deleteOrReset && canDeleteVertex(hit.index)) {
|
|
5734
6069
|
deleteVertex(hit.index);
|
|
5735
6070
|
shell.suppressNextClickAway();
|
|
5736
6071
|
return;
|
|
5737
6072
|
}
|
|
5738
|
-
if (hit.kind === "
|
|
6073
|
+
if (hit.kind === "vertex") parts.select(topology.partOf(hit.index));
|
|
6074
|
+
else if (hit.kind === "midpoint") parts.select(hit.segment?.part);
|
|
6075
|
+
if (hit.kind === "vertex" && modifierHeld(info, keys().modifierDrag) && startModifierDrag(hit.index, pixel, tol)) return;
|
|
6076
|
+
if (hit.kind === "option" && hit.optionId && deleteOrReset) {
|
|
5739
6077
|
const patch = resetControlMeasureOptionHandle(measure.kind, workingPoints, workingOptions, hit.optionId, optionHandleContext());
|
|
5740
6078
|
if (patch) {
|
|
5741
6079
|
setOptions(patch, "gesture", "Reset option handle");
|
|
@@ -5766,13 +6104,14 @@ function runEdit(opts) {
|
|
|
5766
6104
|
fsm,
|
|
5767
6105
|
preDragPoints,
|
|
5768
6106
|
preDragOptions: workingOptions,
|
|
5769
|
-
controlPointIndex: hit.kind === "geometry" ? null : hit.kind === "midpoint" ? hit
|
|
6107
|
+
controlPointIndex: hit.kind === "geometry" ? null : hit.kind === "midpoint" ? midpointInsertIndex(hit) : hit.index
|
|
5770
6108
|
};
|
|
5771
6109
|
transient.emit("start", fsm.kind === "midpoint" ? initialPoints : preDragPoints, activeDrag.controlPointIndex);
|
|
5772
6110
|
if (fsm.kind === "midpoint") {
|
|
5773
6111
|
followVertexChange({
|
|
5774
6112
|
type: "insert",
|
|
5775
|
-
index: hit
|
|
6113
|
+
index: midpointInsertIndex(hit),
|
|
6114
|
+
...hit.segment ? { segment: hit.index } : {}
|
|
5776
6115
|
});
|
|
5777
6116
|
workingPoints.splice(0, workingPoints.length, ...initialPoints);
|
|
5778
6117
|
renderWorkingGraphic();
|
|
@@ -5825,7 +6164,7 @@ function runEdit(opts) {
|
|
|
5825
6164
|
}
|
|
5826
6165
|
function paintDragAt(resolvedPixel, info) {
|
|
5827
6166
|
if (!activeDrag) return;
|
|
5828
|
-
const snapshot = activeDrag.fsm.move(resolvedPixel, { constrainAngles: info
|
|
6167
|
+
const snapshot = activeDrag.fsm.move(resolvedPixel, { constrainAngles: constrainHeld(info) });
|
|
5829
6168
|
workingPoints.splice(0, workingPoints.length, ...snapshot.points);
|
|
5830
6169
|
renderWorkingGraphic();
|
|
5831
6170
|
renderHandlesLayer();
|
|
@@ -5915,8 +6254,11 @@ function runEdit(opts) {
|
|
|
5915
6254
|
renderHandlesLayer();
|
|
5916
6255
|
}
|
|
5917
6256
|
} else if (activeOptionDrag) paintOptionDragSnapshot(pixel);
|
|
5918
|
-
else if (
|
|
5919
|
-
|
|
6257
|
+
else if (activeModifierDrag) {
|
|
6258
|
+
showModifierFrame(activeModifierDrag.move(pixel));
|
|
6259
|
+
transient.emit("move", workingPoints, null);
|
|
6260
|
+
} else if (activeDrag) paintDragSnapshot(pixel, info);
|
|
6261
|
+
else if (activeBoxDrag) paintBoxDragSnapshot(pixel, info, constrainHeld(info));
|
|
5920
6262
|
};
|
|
5921
6263
|
/** Reset drag-in-flight bookkeeping shared by every "gesture ended" path. */
|
|
5922
6264
|
function endDragBookkeeping() {
|
|
@@ -5956,6 +6298,32 @@ function runEdit(opts) {
|
|
|
5956
6298
|
}
|
|
5957
6299
|
return;
|
|
5958
6300
|
}
|
|
6301
|
+
if (activeModifierDrag) {
|
|
6302
|
+
const drag = activeModifierDrag;
|
|
6303
|
+
if (ctx.settled) {
|
|
6304
|
+
transient.emit("end", workingPoints, null);
|
|
6305
|
+
activeModifierDrag = null;
|
|
6306
|
+
dragInFlight = false;
|
|
6307
|
+
driver.setDragPanEnabled(true);
|
|
6308
|
+
return;
|
|
6309
|
+
}
|
|
6310
|
+
const frame = drag.end(pixel);
|
|
6311
|
+
activeModifierDrag = null;
|
|
6312
|
+
transient.emit("end", frame?.controlPoints ?? drag.preDragPoints, null);
|
|
6313
|
+
replaceWorkingPoints(drag.preDragPoints);
|
|
6314
|
+
replaceWorkingOptions(drag.preDragOptions);
|
|
6315
|
+
endDragBookkeeping();
|
|
6316
|
+
shell.suppressNextClickAway();
|
|
6317
|
+
if (frame) {
|
|
6318
|
+
replaceWorkingOptions(frame.options);
|
|
6319
|
+
commitGesture(frame.controlPoints, drag.preDragOptions);
|
|
6320
|
+
if (frame.part !== void 0) parts.select(frame.part);
|
|
6321
|
+
} else showModifierFrame({
|
|
6322
|
+
controlPoints: drag.preDragPoints,
|
|
6323
|
+
options: drag.preDragOptions
|
|
6324
|
+
});
|
|
6325
|
+
return;
|
|
6326
|
+
}
|
|
5959
6327
|
if (activeDrag) {
|
|
5960
6328
|
if (ctx.settled) {
|
|
5961
6329
|
transient.emit("end", workingPoints, activeDrag.controlPointIndex);
|
|
@@ -5969,7 +6337,7 @@ function runEdit(opts) {
|
|
|
5969
6337
|
driver.setDragPanEnabled(true);
|
|
5970
6338
|
const snapped = snapDrag(pixel, (at) => reshapeTarget(at, info, controlPointIndex));
|
|
5971
6339
|
deferred.finish(releaseDeferred(snapped.pixel, snapped.target), (finalPixel) => {
|
|
5972
|
-
const next = fsm.end(finalPixel, { constrainAngles: info
|
|
6340
|
+
const next = fsm.end(finalPixel, { constrainAngles: constrainHeld(info) });
|
|
5973
6341
|
transient.emit("end", next, controlPointIndex);
|
|
5974
6342
|
replaceWorkingPoints(preDragPoints);
|
|
5975
6343
|
commitGesture(next, preDragOptions);
|
|
@@ -6006,7 +6374,7 @@ function runEdit(opts) {
|
|
|
6006
6374
|
};
|
|
6007
6375
|
const snapped = snapDrag(pixel, (at) => translateTarget(at, info, drag));
|
|
6008
6376
|
deferred.finish(releaseDeferred(snapped.pixel, snapped.target), (finalPixel) => {
|
|
6009
|
-
const finalSnapshot = fsm.move(finalPixel, { constrainRotation: info
|
|
6377
|
+
const finalSnapshot = fsm.move(finalPixel, { constrainRotation: constrainHeld(info) });
|
|
6010
6378
|
replaceWorkingPoints(preDragPoints);
|
|
6011
6379
|
workingAmplifierPlacements = preDragAmplifierPlacements;
|
|
6012
6380
|
const optionFold = foldsTransformIntoOptions && (fsm.kind === "rotate" || fsm.kind === "scale");
|
|
@@ -6040,6 +6408,7 @@ function runEdit(opts) {
|
|
|
6040
6408
|
onMove: onDriverMove,
|
|
6041
6409
|
onUp: onDriverUp,
|
|
6042
6410
|
ownsGraphic: (id) => id === measure.id,
|
|
6411
|
+
onOwnClick: (event) => parts.select(partNearestPixel(event.pixel, topology.segments(), workingPoints, (p) => driver.toPixel(p))),
|
|
6043
6412
|
close: () => {
|
|
6044
6413
|
ctx.commit(rebuildRendered);
|
|
6045
6414
|
},
|
|
@@ -6048,11 +6417,12 @@ function runEdit(opts) {
|
|
|
6048
6417
|
facadeOnSettled: onSettled,
|
|
6049
6418
|
emitSettle: (settlement) => settleFromInteraction(settlement, commitEmitter, settleEmitter),
|
|
6050
6419
|
extraTeardown: () => {
|
|
6051
|
-
if (activeDrag !== null || activeOptionDrag !== null || activeBoxDrag !== null || labels.dragging) {
|
|
6420
|
+
if (activeDrag !== null || activeOptionDrag !== null || activeModifierDrag !== null || activeBoxDrag !== null || labels.dragging) {
|
|
6052
6421
|
transient.emit("end", workingPoints, activeDrag?.controlPointIndex ?? null);
|
|
6053
6422
|
driver.setDragPanEnabled(true);
|
|
6054
6423
|
activeDrag = null;
|
|
6055
6424
|
activeOptionDrag = null;
|
|
6425
|
+
activeModifierDrag = null;
|
|
6056
6426
|
activeBoxDrag = null;
|
|
6057
6427
|
labels.endDrag();
|
|
6058
6428
|
dragInFlight = false;
|
|
@@ -6610,6 +6980,7 @@ function defaultGroupSizeAnchor(graphics) {
|
|
|
6610
6980
|
* a live session without a session boundary
|
|
6611
6981
|
*/
|
|
6612
6982
|
function runGroupTransform(opts) {
|
|
6983
|
+
const constrainKey = () => opts.editModifiers().constrain;
|
|
6613
6984
|
const { adapter, capability, imageCapability, markerCapability, graphics, graphicsLayer, previewLayer, handlesLayer, renderOptions: renderOpts, signal, closeOnClickAway = true, interactionStyle, onSession, handleIdPrefix, publishWorkingGraphics, settleWorkingGraphics, isOnGraphicsLayer, onSettled, onClickAwayGraphicsPick } = opts;
|
|
6614
6985
|
assertCapabilityFor(graphics);
|
|
6615
6986
|
validateHostResources(graphics);
|
|
@@ -7408,7 +7779,7 @@ function runGroupTransform(opts) {
|
|
|
7408
7779
|
const boxDragPaintCoalescer = createFrameCoalescer(paintBoxDragSnapshot);
|
|
7409
7780
|
const onDriverMove = (pixel, info) => {
|
|
7410
7781
|
if (ctx.settled) return;
|
|
7411
|
-
if (activeBoxDrag) boxDragPaintCoalescer.schedule(pixel, info
|
|
7782
|
+
if (activeBoxDrag) boxDragPaintCoalescer.schedule(pixel, modifierHeld(info, constrainKey()));
|
|
7412
7783
|
};
|
|
7413
7784
|
const onDriverUp = (pixel, info) => {
|
|
7414
7785
|
if (!activeBoxDrag) return;
|
|
@@ -7433,7 +7804,7 @@ function runGroupTransform(opts) {
|
|
|
7433
7804
|
shell.noteBodyClick();
|
|
7434
7805
|
return;
|
|
7435
7806
|
}
|
|
7436
|
-
const finalSnapshot = fsm.move(pixel, { constrainRotation: info
|
|
7807
|
+
const finalSnapshot = fsm.move(pixel, { constrainRotation: modifierHeld(info, constrainKey()) });
|
|
7437
7808
|
const { scale, rotation } = boxScaleRotation(fsm.kind, finalSnapshot.box, preDragBox);
|
|
7438
7809
|
const nextPointSymbolStateByMember = scalePointSymbolStates(preDragPointSymbolStateByMember, scale, rotation);
|
|
7439
7810
|
applyConcatenatedPoints(preDragPoints);
|
|
@@ -7591,6 +7962,7 @@ function symbolBox(adapter, symbol, rendered, padding = 0) {
|
|
|
7591
7962
|
};
|
|
7592
7963
|
}
|
|
7593
7964
|
function runPointSymbolEdit(opts) {
|
|
7965
|
+
const constrainKey = () => opts.editModifiers().constrain;
|
|
7594
7966
|
const { adapter, capability, symbol, graphicsLayer, previewLayer, handlesLayer, signal, closeOnClickAway = true, interactionStyle, onSession, handleIdPrefix, settleToGraphics, publishWorkingGraphic, wasOnGraphicsLayer, onSettled, onClickAwayGraphicsPick, snap, deferredSnap } = opts;
|
|
7595
7967
|
let modes = normalisePointModes(opts.modes ?? (symbol.offset ? ["transform", "offset"] : ["transform"]));
|
|
7596
7968
|
let usesGraphicStack = wasOnGraphicsLayer;
|
|
@@ -7846,7 +8218,7 @@ function runPointSymbolEdit(opts) {
|
|
|
7846
8218
|
}
|
|
7847
8219
|
const render = capability.render(working);
|
|
7848
8220
|
const modifier = opts.offsetDragModifier?.();
|
|
7849
|
-
if (kind === "body" && modifier
|
|
8221
|
+
if (kind === "body" && modifierHeld(info, modifier ?? false) && currentLayout.status !== "unsupported-presentation" && render.offset) offsetMode = true;
|
|
7850
8222
|
if (!kind || offsetMode && !render.offset) return;
|
|
7851
8223
|
const anchor = kind === "body" || kind === "location" || !working.offset ? currentLayout.actual : currentLayout.display;
|
|
7852
8224
|
drag = {
|
|
@@ -7914,7 +8286,7 @@ function runPointSymbolEdit(opts) {
|
|
|
7914
8286
|
}
|
|
7915
8287
|
} else if (drag.kind === "rotate") {
|
|
7916
8288
|
const rotation = drag.start.rotation + pointerAngle(pixel, drag.anchor) - drag.startPointerAngle;
|
|
7917
|
-
next.rotation = normalizeRotation(info
|
|
8289
|
+
next.rotation = normalizeRotation(modifierHeld(info, constrainKey()) ? constrainRotation(rotation) : rotation);
|
|
7918
8290
|
} else {
|
|
7919
8291
|
const distance = pixelDistance$1(pixel, drag.anchor);
|
|
7920
8292
|
next.size = resizePointSymbolSize(drag.start.size, Math.max(.1, drag.start.size.value * (distance / drag.startDistance)));
|
|
@@ -8107,6 +8479,7 @@ function normaliseImageModes(input) {
|
|
|
8107
8479
|
return modes.includes("delete") ? ["delete"] : [...new Set(modes)];
|
|
8108
8480
|
}
|
|
8109
8481
|
function runImageEdit(opts) {
|
|
8482
|
+
const constrainKey = () => opts.editModifiers().constrain;
|
|
8110
8483
|
const { adapter, capability, image, graphicsLayer, previewLayer, handlesLayer, signal, closeOnClickAway = true, interactionStyle, onSession, handleIdPrefix, settleToGraphics, publishWorkingGraphic, wasOnGraphicsLayer, onSettled, onClickAwayGraphicsPick, snap } = opts;
|
|
8111
8484
|
validateImageGraphic(image);
|
|
8112
8485
|
let modes = normaliseImageModes(opts.modes);
|
|
@@ -8239,7 +8612,7 @@ function runImageEdit(opts) {
|
|
|
8239
8612
|
const transformed = (pixel, info) => {
|
|
8240
8613
|
if (!drag) return null;
|
|
8241
8614
|
const next = cloneImageGraphic(drag.start);
|
|
8242
|
-
const result = drag.fsm.move(pixel, { constrainRotation: info
|
|
8615
|
+
const result = drag.fsm.move(pixel, { constrainRotation: modifierHeld(info, constrainKey()) });
|
|
8243
8616
|
next.position = [...result.points[0]];
|
|
8244
8617
|
const delta = boxScaleRotation(drag.kind, result.box, drag.startBox);
|
|
8245
8618
|
if (drag.kind === "scale") next.size = {
|
|
@@ -8431,6 +8804,7 @@ function normaliseMarkerModes(input) {
|
|
|
8431
8804
|
return modes.includes("delete") ? ["delete"] : [...new Set(modes)];
|
|
8432
8805
|
}
|
|
8433
8806
|
function runMarkerEdit(opts) {
|
|
8807
|
+
const constrainKey = () => opts.editModifiers().constrain;
|
|
8434
8808
|
const { adapter, capability, marker, graphicsLayer, previewLayer, handlesLayer, signal, closeOnClickAway = true, interactionStyle, onSession, handleIdPrefix, settleToGraphics, publishWorkingGraphic, wasOnGraphicsLayer, onSettled, onClickAwayGraphicsPick, snap } = opts;
|
|
8435
8809
|
validateMarker(marker);
|
|
8436
8810
|
let modes = normaliseMarkerModes(opts.modes);
|
|
@@ -8608,7 +8982,7 @@ function runMarkerEdit(opts) {
|
|
|
8608
8982
|
next.position = snapTranslate(position, driver.toPixel(position) ?? pixel, info);
|
|
8609
8983
|
} else if (drag.kind === "rotate") {
|
|
8610
8984
|
const rotation = drag.start.rotation + pointerAngle(pixel, drag.anchor) - drag.startPointerAngle;
|
|
8611
|
-
next.rotation = normalizeRotation(info
|
|
8985
|
+
next.rotation = normalizeRotation(modifierHeld(info, constrainKey()) ? constrainRotation(rotation) : rotation);
|
|
8612
8986
|
} else {
|
|
8613
8987
|
const distance = pixelDistance$1(pixel, drag.anchor);
|
|
8614
8988
|
next.size = resizePointSymbolSize(drag.start.size, Math.max(.1, drag.start.size.value * (distance / drag.startDistance)));
|
|
@@ -8801,6 +9175,9 @@ var TacticalDraw = class {
|
|
|
8801
9175
|
defaultInteractionStyle;
|
|
8802
9176
|
generateId;
|
|
8803
9177
|
offsetDragModifier;
|
|
9178
|
+
editModifiers;
|
|
9179
|
+
/** Live read of the editor's modifier keys, so a change applies mid-edit. */
|
|
9180
|
+
currentEditModifiers = () => this.editModifiers;
|
|
8804
9181
|
pointSymbols;
|
|
8805
9182
|
images;
|
|
8806
9183
|
markers;
|
|
@@ -8915,6 +9292,7 @@ var TacticalDraw = class {
|
|
|
8915
9292
|
constructor(adapter, options) {
|
|
8916
9293
|
this.adapter = adapter;
|
|
8917
9294
|
this.offsetDragModifier = options?.offsetDragModifier ?? false;
|
|
9295
|
+
this.editModifiers = resolveEditModifiers(DEFAULT_EDIT_MODIFIERS, options?.editModifiers);
|
|
8918
9296
|
this.symbolColors = options?.symbolColors ? { ...options.symbolColors } : void 0;
|
|
8919
9297
|
this.labelSizeBand = options?.labelSizeBand ? { ...options.labelSizeBand } : void 0;
|
|
8920
9298
|
this.labelFit = options?.labelFit ?? "shrink";
|
|
@@ -9017,6 +9395,20 @@ var TacticalDraw = class {
|
|
|
9017
9395
|
graphicUsesPinPresentation(graphic, presentation) {
|
|
9018
9396
|
return (presentation ?? this.pins.resolve(graphic.id)).enabled && this.adapter.getPinPresentationCapability?.().status === "supported";
|
|
9019
9397
|
}
|
|
9398
|
+
/**
|
|
9399
|
+
* Change the editor's modifier keys (see {@link TacticalDrawOptions.editModifiers}).
|
|
9400
|
+
* Roles the patch omits keep their current key. Applies from the next
|
|
9401
|
+
* pointer event, including in an active draw or edit. Throws a `RangeError`,
|
|
9402
|
+
* leaving the keys unchanged, when the result would be invalid.
|
|
9403
|
+
*/
|
|
9404
|
+
setEditModifiers(modifiers) {
|
|
9405
|
+
this.assertAlive();
|
|
9406
|
+
this.editModifiers = resolveEditModifiers(this.editModifiers, modifiers);
|
|
9407
|
+
}
|
|
9408
|
+
/** The editor's current modifier keys, every role filled in (e.g. for hint text). */
|
|
9409
|
+
getEditModifiers() {
|
|
9410
|
+
return this.editModifiers;
|
|
9411
|
+
}
|
|
9020
9412
|
/** Change the default shortcut for subsequent drags, including in an active edit. */
|
|
9021
9413
|
setOffsetDragModifier(modifier) {
|
|
9022
9414
|
this.assertAlive();
|
|
@@ -9656,7 +10048,8 @@ var TacticalDraw = class {
|
|
|
9656
10048
|
onSettled,
|
|
9657
10049
|
onSession: this.trackSession(options?.onSession),
|
|
9658
10050
|
seed: measureDraft.controlPoints,
|
|
9659
|
-
snap: this.resolveSnap
|
|
10051
|
+
snap: this.resolveSnap,
|
|
10052
|
+
editModifiers: this.currentEditModifiers
|
|
9660
10053
|
}) : runVariableLengthDraw({
|
|
9661
10054
|
adapter: this.adapter,
|
|
9662
10055
|
kind,
|
|
@@ -9674,7 +10067,8 @@ var TacticalDraw = class {
|
|
|
9674
10067
|
guide: options?.guide,
|
|
9675
10068
|
sizeAnchor: options?.sizeAnchor,
|
|
9676
10069
|
onSettled,
|
|
9677
|
-
snap: this.resolveSnap
|
|
10070
|
+
snap: this.resolveSnap,
|
|
10071
|
+
editModifiers: this.currentEditModifiers
|
|
9678
10072
|
}), null, extraSettle);
|
|
9679
10073
|
}
|
|
9680
10074
|
edit(measure, options) {
|
|
@@ -9711,7 +10105,8 @@ var TacticalDraw = class {
|
|
|
9711
10105
|
wasOnGraphicsLayer,
|
|
9712
10106
|
onSettled,
|
|
9713
10107
|
onClickAwayGraphicsPick: (event) => this.dispatchHostPick(this.graphicsLayer, event),
|
|
9714
|
-
snap: this.resolveSnap
|
|
10108
|
+
snap: this.resolveSnap,
|
|
10109
|
+
editModifiers: this.currentEditModifiers
|
|
9715
10110
|
}), (handle) => {
|
|
9716
10111
|
handle.syncHostMembership(this.lastRenderedMeasures.some((graphic) => graphic.id === handle.measureId && isMarker(graphic)));
|
|
9717
10112
|
this.activeEdit = handle;
|
|
@@ -9748,7 +10143,8 @@ var TacticalDraw = class {
|
|
|
9748
10143
|
wasOnGraphicsLayer,
|
|
9749
10144
|
onSettled,
|
|
9750
10145
|
onClickAwayGraphicsPick: (event) => this.dispatchHostPick(this.graphicsLayer, event),
|
|
9751
|
-
snap: this.resolveSnap
|
|
10146
|
+
snap: this.resolveSnap,
|
|
10147
|
+
editModifiers: this.currentEditModifiers
|
|
9752
10148
|
}), (handle) => {
|
|
9753
10149
|
handle.syncHostMembership(this.lastRenderedMeasures.some((graphic) => graphic.id === handle.measureId && isImageGraphic(graphic)));
|
|
9754
10150
|
this.activeEdit = handle;
|
|
@@ -9794,6 +10190,7 @@ var TacticalDraw = class {
|
|
|
9794
10190
|
onSettled,
|
|
9795
10191
|
onClickAwayGraphicsPick: (event) => this.dispatchHostPick(this.graphicsLayer, event),
|
|
9796
10192
|
snap: this.resolveSnap,
|
|
10193
|
+
editModifiers: this.currentEditModifiers,
|
|
9797
10194
|
deferredSnap: this.resolveDeferredSnap
|
|
9798
10195
|
}), (handle) => {
|
|
9799
10196
|
handle.syncHostMembership(this.lastRenderedMeasures.some((graphic) => graphic.id === handle.measureId && isPointSymbol(graphic)));
|
|
@@ -9845,6 +10242,7 @@ var TacticalDraw = class {
|
|
|
9845
10242
|
onSettled,
|
|
9846
10243
|
onClickAwayGraphicsPick,
|
|
9847
10244
|
snap: this.resolveSnap,
|
|
10245
|
+
editModifiers: this.currentEditModifiers,
|
|
9848
10246
|
deferredSnap: this.resolveDeferredSnap
|
|
9849
10247
|
}), (handle) => {
|
|
9850
10248
|
this.activeEdit = handle;
|
|
@@ -9896,7 +10294,8 @@ var TacticalDraw = class {
|
|
|
9896
10294
|
settleWorkingGraphics: (settlements) => this.settleWorkingGraphics(settlements),
|
|
9897
10295
|
isOnGraphicsLayer,
|
|
9898
10296
|
onSettled,
|
|
9899
|
-
onClickAwayGraphicsPick
|
|
10297
|
+
onClickAwayGraphicsPick,
|
|
10298
|
+
editModifiers: this.currentEditModifiers
|
|
9900
10299
|
}), (handle) => {
|
|
9901
10300
|
this.activeTransform = handle;
|
|
9902
10301
|
return () => {
|
|
@@ -10025,10 +10424,13 @@ var TacticalDraw = class {
|
|
|
10025
10424
|
* This matters most for the active preview, since a click can land
|
|
10026
10425
|
* anywhere across a rotated/offset label during an edit.
|
|
10027
10426
|
*
|
|
10028
|
-
* `tolerance` defaults
|
|
10029
|
-
*
|
|
10030
|
-
*
|
|
10031
|
-
*
|
|
10427
|
+
* `tolerance` defaults per layer and by pointer type — pass the host's raw
|
|
10428
|
+
* click event as `originalEvent` to get the right one: edit handles take
|
|
10429
|
+
* the edit session's own handle tolerance (12px mouse/pen, 22px touch), so
|
|
10430
|
+
* a pixel the edit would press as a handle is owned by `handles`; preview
|
|
10431
|
+
* and graphics take `pickHitTolerance` (4px mouse/pen, 12px touch), as
|
|
10432
|
+
* `onPick` does. Pass an explicit `tolerance` to override it for every
|
|
10433
|
+
* layer.
|
|
10032
10434
|
*
|
|
10033
10435
|
* `measureId` is set when the hit feature resolves to a control-measure id
|
|
10034
10436
|
* via `tryControlMeasureIdFromFeature` — present for graphics/preview
|
|
@@ -10041,7 +10443,9 @@ var TacticalDraw = class {
|
|
|
10041
10443
|
*/
|
|
10042
10444
|
ownsInteractionAt(pixel, options) {
|
|
10043
10445
|
this.assertAlive();
|
|
10044
|
-
const
|
|
10446
|
+
const pointerType = pickPointerType(options?.originalEvent);
|
|
10447
|
+
const pickTolerance = options?.tolerance ?? pickHitTolerance(options?.originalEvent);
|
|
10448
|
+
const handleTolerance = options?.tolerance ?? (pointerType === "touch" ? 22 : 12);
|
|
10045
10449
|
const toPixel = (lonLat) => this.adapter.getPixelFromCoordinate(lonLat);
|
|
10046
10450
|
const layers = [
|
|
10047
10451
|
{
|
|
@@ -10061,10 +10465,10 @@ var TacticalDraw = class {
|
|
|
10061
10465
|
}
|
|
10062
10466
|
];
|
|
10063
10467
|
const size = this.adapter.getViewportSize();
|
|
10064
|
-
const
|
|
10468
|
+
const pickContext = {
|
|
10065
10469
|
pixel,
|
|
10066
|
-
pointerType
|
|
10067
|
-
tolerance,
|
|
10470
|
+
pointerType,
|
|
10471
|
+
tolerance: pickTolerance,
|
|
10068
10472
|
toPixel,
|
|
10069
10473
|
viewport: {
|
|
10070
10474
|
minX: 0,
|
|
@@ -10075,6 +10479,10 @@ var TacticalDraw = class {
|
|
|
10075
10479
|
bearing: this.adapter.getBearing()
|
|
10076
10480
|
};
|
|
10077
10481
|
for (const { layer, layerId, labelFallback } of layers) {
|
|
10482
|
+
const context = layer === "handles" ? {
|
|
10483
|
+
...pickContext,
|
|
10484
|
+
tolerance: handleTolerance
|
|
10485
|
+
} : pickContext;
|
|
10078
10486
|
const features = this.adapter.getLayerFeatures(layerId);
|
|
10079
10487
|
const geometryCandidate = evaluatePickCandidates(features.map((feature, index) => ({
|
|
10080
10488
|
feature,
|
|
@@ -10368,6 +10776,18 @@ const BUILT_IN_INTERACTION_STYLE = {
|
|
|
10368
10776
|
strokeColor: "#ffffff",
|
|
10369
10777
|
strokeWidth: 2
|
|
10370
10778
|
},
|
|
10779
|
+
snapTargetHandle: {
|
|
10780
|
+
pointRadius: 10,
|
|
10781
|
+
fillColor: "rgba(22, 163, 74, 0.12)",
|
|
10782
|
+
strokeColor: "#16a34a",
|
|
10783
|
+
strokeWidth: 1.5
|
|
10784
|
+
},
|
|
10785
|
+
activeSnapTargetHandle: {
|
|
10786
|
+
pointRadius: 13,
|
|
10787
|
+
fillColor: "rgba(22, 163, 74, 0.25)",
|
|
10788
|
+
strokeColor: "#16a34a",
|
|
10789
|
+
strokeWidth: 3
|
|
10790
|
+
},
|
|
10371
10791
|
scaleHandle: {
|
|
10372
10792
|
pointRadius: 5,
|
|
10373
10793
|
fillColor: "#ffffff",
|
|
@@ -10388,6 +10808,8 @@ const HANDLE_SLOTS = [
|
|
|
10388
10808
|
"unsetOptionHandle",
|
|
10389
10809
|
"geometryHandle",
|
|
10390
10810
|
"labelHandle",
|
|
10811
|
+
"snapTargetHandle",
|
|
10812
|
+
"activeSnapTargetHandle",
|
|
10391
10813
|
"scaleHandle",
|
|
10392
10814
|
"rotateHandle"
|
|
10393
10815
|
];
|
|
@@ -10693,4 +11115,4 @@ function nearestWorldCopyPosition(position, refLng) {
|
|
|
10693
11115
|
return [nearestWorldCopyLng(position[0], refLng), ...position.slice(1)];
|
|
10694
11116
|
}
|
|
10695
11117
|
//#endregion
|
|
10696
|
-
export { BaseMapAdapter, DEFAULT_LABEL_SIZE_PIXELS, DEFAULT_MARKER_SIZE, DEFAULT_PIN_PRESENTATION, DEFAULT_TEXT_SIZE_MAX_PIXELS, DEFAULT_TEXT_SIZE_MIN_PIXELS, HATCH_PATTERNS, HIGHLIGHT_BAND_SLOTS, HIGHLIGHT_CASING_OUTSET_CSS_PIXELS, HIGHLIGHT_GLOW_BANDS, ImageCapabilityRequiredError, MINE_PATTERN_TILE_SIZE, MarkerCapabilityRequiredError, PinPresentationStore, PointSymbolCapabilityRequiredError, PointerCallbackHub, TEXT_FADE_END_RATIO, TEXT_HALO_BREAKPOINT_PIXELS, TEXT_HALO_COLOR, TOUCH_HIT_TOLERANCE_PX, TacticalDraw, TacticalDrawAbortError, TacticalDrawDestroyedError, alignPointSymbolIndicator, bindAbortable, cloneImageGraphic, cloneMarker, clonePointSymbol, coerceHandleStyle, combinePinScale, combineWithHostSignal, convertPointSymbolPlacement, effectivePointSymbolPixelSize, evaluatePickCandidates, fillPatternImageDimension, fillPatternImageId, getSizeAnchor, hasHighlightCasing, highlightBandsForStyle, highlightBandsInPaintOrder, highlightCasingWidth, hitTestFeature, hitTestIconFeature, ignoreAbort, imageFootprint, imageOpacity, isAnchoredGraphic, isImageGraphic, isMarker, isMinePattern, isPinnableGraphic, isPointSymbol, isTacticalDrawAbortError, isValidPinNumber, makeFillPatternImage, markerFootprint, markerOpacity, mergeNativeAndCachedPickFeatures, movePointSymbolLocation, nearestWorldCopyLng, nearestWorldCopyPosition, normalizeImageGraphic, normalizeMarker, parseColor, pickHitTolerance, pickPointerType, pinDistanceScale, pinZoomScale, placePointSymbol, pointSymbolFootprint, pointSymbolResource, renderOrderToVisualOrder, resizePointSymbolSize, resolveGroundTextSizePixels, resolveHighlightBands, resolveHighlightCasing, resolveMarkerRender, resolvePickPresentation, resolvePinPresentation, resolvePointSymbolOffset, resolveTextAppearance, resolveTextHaloWidth, resolveTextSizePixels, scalePointSymbolLayout, tryControlMeasureIdFromFeature, validateImageGraphic, validateMarker };
|
|
11118
|
+
export { BaseMapAdapter, DEFAULT_EDIT_MODIFIERS, DEFAULT_LABEL_SIZE_PIXELS, DEFAULT_MARKER_SIZE, DEFAULT_PIN_PRESENTATION, DEFAULT_TEXT_SIZE_MAX_PIXELS, DEFAULT_TEXT_SIZE_MIN_PIXELS, HATCH_PATTERNS, HIGHLIGHT_BAND_SLOTS, HIGHLIGHT_CASING_OUTSET_CSS_PIXELS, HIGHLIGHT_GLOW_BANDS, ImageCapabilityRequiredError, MINE_PATTERN_TILE_SIZE, MarkerCapabilityRequiredError, PinPresentationStore, PointSymbolCapabilityRequiredError, PointerCallbackHub, TEXT_FADE_END_RATIO, TEXT_HALO_BREAKPOINT_PIXELS, TEXT_HALO_COLOR, TOUCH_HIT_TOLERANCE_PX, TacticalDraw, TacticalDrawAbortError, TacticalDrawDestroyedError, alignPointSymbolIndicator, bindAbortable, canResetGroundSizes, cloneImageGraphic, cloneMarker, clonePointSymbol, coerceHandleStyle, combinePinScale, combineWithHostSignal, convertPointSymbolPlacement, effectivePointSymbolPixelSize, evaluatePickCandidates, fillPatternImageDimension, fillPatternImageId, getSizeAnchor, hasHighlightCasing, highlightBandsForStyle, highlightBandsInPaintOrder, highlightCasingWidth, hitTestFeature, hitTestIconFeature, ignoreAbort, imageFootprint, imageOpacity, isAnchoredGraphic, isImageGraphic, isMarker, isMinePattern, isPinnableGraphic, isPointSymbol, isTacticalDrawAbortError, isValidPinNumber, makeFillPatternImage, markerFootprint, markerOpacity, mergeNativeAndCachedPickFeatures, movePointSymbolLocation, nearestWorldCopyLng, nearestWorldCopyPosition, normalizeImageGraphic, normalizeMarker, parseColor, pickHitTolerance, pickPointerType, pinDistanceScale, pinZoomScale, placePointSymbol, pointSymbolFootprint, pointSymbolResource, renderOrderToVisualOrder, resetGroundSizeOptions, resizePointSymbolSize, resolveGroundTextSizePixels, resolveHighlightBands, resolveHighlightCasing, resolveMarkerRender, resolvePickPresentation, resolvePinPresentation, resolvePointSymbolOffset, resolveTextAppearance, resolveTextHaloWidth, resolveTextSizePixels, scalePointSymbolLayout, tryControlMeasureIdFromFeature, validateImageGraphic, validateMarker };
|