@orbat-mapper/tactical-draw 0.22.0 → 0.23.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.mjs +106 -31
- package/package.json +4 -3
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, NON_SOLID_FILL_PATTERNS, applyBoxTransformOptions, canonicalTextAmplifierKey, cloneControlMeasure, controlMeasureIdFromFeature, dragControlMeasureOptionHandle, foldsBoxTransformOptions, freezeOrientationOptions, getControlMeasureMetadata, getControlMeasureOptionHandles, getDefaultOptions, 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, 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";
|
|
2
2
|
function pickPointerType(originalEvent) {
|
|
3
3
|
if (typeof PointerEvent !== "undefined" && originalEvent instanceof PointerEvent) {
|
|
4
4
|
if (originalEvent.pointerType === "touch") return "touch";
|
|
@@ -776,7 +776,7 @@ const DEFAULT_TEXT_SIZE_MAX_PIXELS = 24;
|
|
|
776
776
|
* Share of the band minimum at which a fading ground label reaches zero
|
|
777
777
|
* opacity and hides (ADR-0060): 4 px fades out to nothing at 3.2 px.
|
|
778
778
|
*/
|
|
779
|
-
const TEXT_FADE_END_RATIO =
|
|
779
|
+
const TEXT_FADE_END_RATIO = LABEL_FADE_END_RATIO;
|
|
780
780
|
/**
|
|
781
781
|
* Ground label size `textSizeMeters / resolution`, pinned to both edges of
|
|
782
782
|
* the band. The fixed-scale rule behind [[resolveTextAppearance]]'s
|
|
@@ -789,6 +789,19 @@ function resolveGroundTextSizePixels(textSizeMeters, resolution, text) {
|
|
|
789
789
|
return Math.min(max, Math.max(min, textSizeMeters / resolution));
|
|
790
790
|
}
|
|
791
791
|
/**
|
|
792
|
+
* `band` as the render context's label size band (ADR-0064): how an
|
|
793
|
+
* interactive map draws ground labels, pinned at the maximum and hiding below
|
|
794
|
+
* the minimum. Generators then size knockouts to the text on screen and drop
|
|
795
|
+
* them once the text hides.
|
|
796
|
+
*/
|
|
797
|
+
function interactiveLabelSizeBand(band) {
|
|
798
|
+
return {
|
|
799
|
+
min: band?.textSizeMinPixels ?? 4,
|
|
800
|
+
max: band?.textSizeMaxPixels ?? 24,
|
|
801
|
+
belowMin: "hide"
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
792
805
|
* Resolve how a label renders on an interactive map at `resolution`, or
|
|
793
806
|
* `null` when it should render nothing this frame:
|
|
794
807
|
*
|
|
@@ -828,7 +841,7 @@ function resolveTextAppearance(props, resolution, policy) {
|
|
|
828
841
|
sizePixels: Math.min(max, px),
|
|
829
842
|
opacity: 1
|
|
830
843
|
};
|
|
831
|
-
const fadeEnd =
|
|
844
|
+
const fadeEnd = labelSizeBandHideThreshold(interactiveLabelSizeBand(props));
|
|
832
845
|
if (px <= fadeEnd) return null;
|
|
833
846
|
return {
|
|
834
847
|
sizePixels: px,
|
|
@@ -2084,7 +2097,8 @@ function canResetGroundSizes(measure, adapter) {
|
|
|
2084
2097
|
* Return the complete option record produced by resetting every known size
|
|
2085
2098
|
* pair to its default on-screen appearance at the adapter's current
|
|
2086
2099
|
* resolution. Pixel keys are removed and meter keys are written, so the
|
|
2087
|
-
* result remains ground-anchored.
|
|
2100
|
+
* result remains ground-anchored. A pair that inherits another pair's size is
|
|
2101
|
+
* cleared so it follows again. Unrelated options are preserved.
|
|
2088
2102
|
*
|
|
2089
2103
|
* Returns `undefined` when the kind has no resettable sizes or the adapter has
|
|
2090
2104
|
* no usable resolution.
|
|
@@ -2096,6 +2110,11 @@ function resetGroundSizeOptions(measure, adapter) {
|
|
|
2096
2110
|
const defaults = getDefaultOptions(measure.kind);
|
|
2097
2111
|
const next = { ...measure.options ?? {} };
|
|
2098
2112
|
for (const spec of specs) {
|
|
2113
|
+
if (spec.inheritsFrom !== void 0) {
|
|
2114
|
+
delete next[spec.pixels];
|
|
2115
|
+
delete next[spec.meters];
|
|
2116
|
+
continue;
|
|
2117
|
+
}
|
|
2099
2118
|
const defaultPixels = spec.defaultUnit === "px" && spec.defaultValue !== void 0 ? spec.defaultValue : defaults[spec.pixels];
|
|
2100
2119
|
if (typeof defaultPixels !== "number") continue;
|
|
2101
2120
|
const result = switchSizePairUnit({
|
|
@@ -2129,7 +2148,7 @@ function measureUsesAdapterResolution(measure) {
|
|
|
2129
2148
|
return sizeOptionSpecs(measure.kind).some((spec) => {
|
|
2130
2149
|
if (options?.[spec.pixels] !== void 0) return true;
|
|
2131
2150
|
if (options?.[spec.meters] !== void 0) return false;
|
|
2132
|
-
return !spec.captureOnDraw && spec.defaultUnit === "px";
|
|
2151
|
+
return !spec.captureOnDraw && spec.inheritsFrom === void 0 && spec.defaultUnit === "px";
|
|
2133
2152
|
});
|
|
2134
2153
|
}
|
|
2135
2154
|
/**
|
|
@@ -2175,14 +2194,15 @@ function defaultSizeAnchor(measure) {
|
|
|
2175
2194
|
}
|
|
2176
2195
|
/**
|
|
2177
2196
|
* Materialize uncaptured pixel authoring defaults before commit, so the ground
|
|
2178
|
-
* bake sees an explicit value. Meter-default dimensions
|
|
2179
|
-
* remain unchanged; captured labels
|
|
2197
|
+
* bake sees an explicit value. Meter-default dimensions, pairs that inherit
|
|
2198
|
+
* another pair's size, and authored values remain unchanged; captured labels
|
|
2199
|
+
* have their separate render/commit seam.
|
|
2180
2200
|
*/
|
|
2181
2201
|
function withDefaultAuthoringSize(measure) {
|
|
2182
2202
|
let options = measure.options ?? {};
|
|
2183
2203
|
let changed = false;
|
|
2184
2204
|
for (const spec of sizeOptionSpecs(measure.kind)) {
|
|
2185
|
-
if (spec.captureOnDraw || spec.defaultUnit !== "px") continue;
|
|
2205
|
+
if (spec.captureOnDraw || spec.inheritsFrom !== void 0 || spec.defaultUnit !== "px") continue;
|
|
2186
2206
|
if (options[spec.pixels] !== void 0 || options[spec.meters] !== void 0) continue;
|
|
2187
2207
|
const resolved = resolveSizePair({
|
|
2188
2208
|
kind: measure.kind,
|
|
@@ -3651,6 +3671,31 @@ function translatePoints(base, dx, dy) {
|
|
|
3651
3671
|
return out;
|
|
3652
3672
|
});
|
|
3653
3673
|
}
|
|
3674
|
+
/**
|
|
3675
|
+
* Carry a pixel-space box by a ground (lon/lat) delta: unproject each corner,
|
|
3676
|
+
* shift it, re-project, and re-fit the box (same angle) around the landed
|
|
3677
|
+
* corners. Untilted this is the plain pixel translate (up to the small
|
|
3678
|
+
* Mercator-latitude term); pitched, the box also shrinks or grows with depth so
|
|
3679
|
+
* it keeps framing geometry moved by the same delta. Falls back to
|
|
3680
|
+
* `pixelDelta` when a corner can't be projected.
|
|
3681
|
+
*/
|
|
3682
|
+
function translateBoxOnGround(box, [dLon, dLat], pixelDelta, projection) {
|
|
3683
|
+
const pixelTranslated = () => ({
|
|
3684
|
+
...box,
|
|
3685
|
+
center: [box.center[0] + pixelDelta[0], box.center[1] + pixelDelta[1]]
|
|
3686
|
+
});
|
|
3687
|
+
const landed = [];
|
|
3688
|
+
for (const corner of boxCorners(box)) {
|
|
3689
|
+
const ground = projection.fromPixel(corner);
|
|
3690
|
+
const moved = projection.toPixel([ground[0] + dLon, ground[1] + dLat]);
|
|
3691
|
+
if (!moved || !Number.isFinite(moved[0]) || !Number.isFinite(moved[1])) return pixelTranslated();
|
|
3692
|
+
landed.push(moved);
|
|
3693
|
+
}
|
|
3694
|
+
const fitted = fitTransformBox(landed, box.angle);
|
|
3695
|
+
return Math.max(fitted.halfWidth / box.halfWidth, fitted.halfHeight / box.halfHeight) > MAX_GROUND_BOX_GROWTH ? pixelTranslated() : fitted;
|
|
3696
|
+
}
|
|
3697
|
+
/** Above this size ratio a ground-translated box is treated as unprojectable. */
|
|
3698
|
+
const MAX_GROUND_BOX_GROWTH = 10;
|
|
3654
3699
|
function pixelDistance(a, b) {
|
|
3655
3700
|
return Math.hypot(a[0] - b[0], a[1] - b[1]);
|
|
3656
3701
|
}
|
|
@@ -3819,12 +3864,12 @@ function beginBoxDrag(args) {
|
|
|
3819
3864
|
const origin = fromPixel(downPixel);
|
|
3820
3865
|
const move = (pixel) => {
|
|
3821
3866
|
const cur = fromPixel(pixel);
|
|
3867
|
+
const translation = [cur[0] - origin[0], cur[1] - origin[1]];
|
|
3868
|
+
const pixelDelta = [pixel[0] - downPixel[0], pixel[1] - downPixel[1]];
|
|
3822
3869
|
return {
|
|
3823
|
-
points: translatePoints(preDragPoints,
|
|
3824
|
-
box:
|
|
3825
|
-
|
|
3826
|
-
center: [box.center[0] + (pixel[0] - downPixel[0]), box.center[1] + (pixel[1] - downPixel[1])]
|
|
3827
|
-
}
|
|
3870
|
+
points: translatePoints(preDragPoints, translation[0], translation[1]),
|
|
3871
|
+
box: translateBoxOnGround(box, translation, pixelDelta, projection),
|
|
3872
|
+
translation
|
|
3828
3873
|
};
|
|
3829
3874
|
};
|
|
3830
3875
|
return {
|
|
@@ -4375,27 +4420,50 @@ function transformAmplifierPlacements(placements, from, to, projection) {
|
|
|
4375
4420
|
if (!placements) return void 0;
|
|
4376
4421
|
const scaleX = to.halfWidth / from.halfWidth;
|
|
4377
4422
|
const scaleY = to.halfHeight / from.halfHeight;
|
|
4378
|
-
|
|
4379
|
-
|
|
4423
|
+
return mapAmplifierPlacements(placements, (position) => {
|
|
4424
|
+
const pixel = projection.toPixel(position);
|
|
4425
|
+
if (!pixel) return [...position];
|
|
4426
|
+
const [localX, localY] = rotate(pixel[0] - from.center[0], pixel[1] - from.center[1], -from.angle);
|
|
4427
|
+
const [outX, outY] = rotate(localX * scaleX, localY * scaleY, to.angle);
|
|
4428
|
+
return projection.fromPixel([to.center[0] + outX, to.center[1] + outY]);
|
|
4429
|
+
}, to.angle - from.angle);
|
|
4430
|
+
}
|
|
4431
|
+
/**
|
|
4432
|
+
* Rebuild `placements` with every anchor passed through `movePosition` and
|
|
4433
|
+
* every rotation override shifted by `-angleDelta`, keeping each entry's
|
|
4434
|
+
* storage shape (bare `Position` vs object form) and rotation-only entries.
|
|
4435
|
+
*/
|
|
4436
|
+
function mapAmplifierPlacements(placements, movePosition, angleDelta) {
|
|
4437
|
+
const mapped = {};
|
|
4380
4438
|
for (const [field, raw] of Object.entries(placements)) {
|
|
4381
4439
|
const resolved = resolveAmplifierPlacement(raw);
|
|
4382
4440
|
const rotation = resolved.rotation !== void 0 ? resolved.rotation - angleDelta : void 0;
|
|
4383
4441
|
if (!resolved.position) {
|
|
4384
|
-
if (rotation !== void 0)
|
|
4442
|
+
if (rotation !== void 0) mapped[field] = { rotation };
|
|
4385
4443
|
continue;
|
|
4386
4444
|
}
|
|
4387
|
-
const
|
|
4388
|
-
|
|
4389
|
-
const [localX, localY] = rotate(pixel[0] - from.center[0], pixel[1] - from.center[1], -from.angle);
|
|
4390
|
-
const [outX, outY] = rotate(localX * scaleX, localY * scaleY, to.angle);
|
|
4391
|
-
return projection.fromPixel([to.center[0] + outX, to.center[1] + outY]);
|
|
4392
|
-
})() : [...resolved.position];
|
|
4393
|
-
transformed[field] = rotation !== void 0 ? {
|
|
4445
|
+
const position = movePosition(resolved.position);
|
|
4446
|
+
mapped[field] = rotation !== void 0 ? {
|
|
4394
4447
|
position,
|
|
4395
4448
|
rotation
|
|
4396
4449
|
} : position;
|
|
4397
4450
|
}
|
|
4398
|
-
return
|
|
4451
|
+
return mapped;
|
|
4452
|
+
}
|
|
4453
|
+
/**
|
|
4454
|
+
* Carry placement overrides through one box-drag snapshot. A body drag moves
|
|
4455
|
+
* the control points by a lon/lat delta (`snapshot.translation`), so the
|
|
4456
|
+
* anchors move by that same delta and stay glued to the geometry; going
|
|
4457
|
+
* through the box's pixel delta instead would drift on a pitched view, where
|
|
4458
|
+
* equal pixel offsets cover different ground distances at different screen
|
|
4459
|
+
* depths. Scale and rotate share the pixel-space affine with the points, so
|
|
4460
|
+
* they go through {@link transformAmplifierPlacements}.
|
|
4461
|
+
*/
|
|
4462
|
+
function carryAmplifierPlacements(placements, from, snapshot, projection) {
|
|
4463
|
+
if (!snapshot.translation) return transformAmplifierPlacements(placements, from, snapshot.box, projection);
|
|
4464
|
+
if (!placements) return void 0;
|
|
4465
|
+
const [dLon, dLat] = snapshot.translation;
|
|
4466
|
+
return mapAmplifierPlacements(placements, (p) => [p[0] + dLon, p[1] + dLat], 0);
|
|
4399
4467
|
}
|
|
4400
4468
|
/**
|
|
4401
4469
|
* Field-wise merge of one `amplifierPlacements` entry: fields present in
|
|
@@ -5535,7 +5603,10 @@ function runEdit(opts) {
|
|
|
5535
5603
|
graphicId: measure.id,
|
|
5536
5604
|
originalEvent: info?.native
|
|
5537
5605
|
},
|
|
5538
|
-
toDragPixel: (landed) =>
|
|
5606
|
+
toDragPixel: (landed) => {
|
|
5607
|
+
const at = driver.fromPixel(landed);
|
|
5608
|
+
return driver.toPixel([origin[0] + at[0] - first[0], origin[1] + at[1] - first[1]]) ?? [pixel[0] + landed[0] - anchorPixel[0], pixel[1] + landed[1] - anchorPixel[1]];
|
|
5609
|
+
}
|
|
5539
5610
|
};
|
|
5540
5611
|
}
|
|
5541
5612
|
/**
|
|
@@ -5824,7 +5895,7 @@ function runEdit(opts) {
|
|
|
5824
5895
|
return;
|
|
5825
5896
|
}
|
|
5826
5897
|
workingPoints.splice(0, workingPoints.length, ...snapshot.points);
|
|
5827
|
-
workingAmplifierPlacements =
|
|
5898
|
+
workingAmplifierPlacements = carryAmplifierPlacements(activeBoxDrag.preDragAmplifierPlacements, activeBoxDrag.preDragBox, snapshot, driver);
|
|
5828
5899
|
renderWorkingGraphic();
|
|
5829
5900
|
renderHandlesLayer();
|
|
5830
5901
|
recomputeDirty();
|
|
@@ -5947,7 +6018,7 @@ function runEdit(opts) {
|
|
|
5947
6018
|
}
|
|
5948
6019
|
const committedPoints = optionFold && holdsAnchorOnFold ? preDragPoints : finalSnapshot.points;
|
|
5949
6020
|
transient.emit("end", committedPoints, null);
|
|
5950
|
-
commitGesture(committedPoints, preDragOptions,
|
|
6021
|
+
commitGesture(committedPoints, preDragOptions, carryAmplifierPlacements(preDragAmplifierPlacements, preDragBox, finalSnapshot, driver), preDragBox.angle);
|
|
5951
6022
|
});
|
|
5952
6023
|
return;
|
|
5953
6024
|
}
|
|
@@ -7329,7 +7400,7 @@ function runGroupTransform(opts) {
|
|
|
7329
7400
|
applyConcatenatedPoints(snapshot.points);
|
|
7330
7401
|
applyPointSymbolStateByMember(pointSymbolStateForBox(snapshot.box));
|
|
7331
7402
|
applyMeasureTransformForBox(snapshot.box, activeBoxDrag.preDragBox, activeBoxDrag.fsm.kind, activeBoxDrag.preDragOptionsOverrideByMember);
|
|
7332
|
-
applyAmplifierPlacementsByMember(activeBoxDrag.preDragAmplifierPlacementsByMember.map((placements) =>
|
|
7403
|
+
applyAmplifierPlacementsByMember(activeBoxDrag.preDragAmplifierPlacementsByMember.map((placements) => carryAmplifierPlacements(placements, activeBoxDrag.preDragBox, snapshot, driver)));
|
|
7333
7404
|
renderAllPreviews();
|
|
7334
7405
|
renderHandlesLayer();
|
|
7335
7406
|
recomputeDirty();
|
|
@@ -7371,7 +7442,7 @@ function runGroupTransform(opts) {
|
|
|
7371
7442
|
if (members.some(isAnchoredMember)) shell.suppressNextClickAway();
|
|
7372
7443
|
if (fsm.kind === "rotate") boxAngle += finalSnapshot.box.angle - preDragBox.angle;
|
|
7373
7444
|
applyMeasureTransformForBox(finalSnapshot.box, preDragBox, fsm.kind, preDragOptionsOverrideByMember);
|
|
7374
|
-
commitGesture(finalSnapshot.points, preDragOptionsOverrideByMember, preDragAmplifierPlacementsByMember.map((placements) =>
|
|
7445
|
+
commitGesture(finalSnapshot.points, preDragOptionsOverrideByMember, preDragAmplifierPlacementsByMember.map((placements) => carryAmplifierPlacements(placements, preDragBox, finalSnapshot, driver)), preDragBox.angle, nextPointSymbolStateByMember);
|
|
7375
7446
|
};
|
|
7376
7447
|
const core = runEditInteraction({
|
|
7377
7448
|
adapter,
|
|
@@ -8852,7 +8923,8 @@ var TacticalDraw = class {
|
|
|
8852
8923
|
this.sessionRenderOptions = {
|
|
8853
8924
|
graphicsStyle: this.graphicsStyle,
|
|
8854
8925
|
symbolColors: this.symbolColors,
|
|
8855
|
-
highlightAppearance: { ...options?.highlightAppearance }
|
|
8926
|
+
highlightAppearance: { ...options?.highlightAppearance },
|
|
8927
|
+
context: { labelSizeBand: interactiveLabelSizeBand(this.labelSizeBand) }
|
|
8856
8928
|
};
|
|
8857
8929
|
this.defaultInteractionStyle = options?.interactionStyle;
|
|
8858
8930
|
this.generateId = options?.generateId ?? (() => `td-${++this.idCounter}`);
|
|
@@ -9099,7 +9171,10 @@ var TacticalDraw = class {
|
|
|
9099
9171
|
}
|
|
9100
9172
|
const render = renderMeasureForAdapter(this.adapter, graphic, {
|
|
9101
9173
|
...this.sessionRenderOptions,
|
|
9102
|
-
context: {
|
|
9174
|
+
context: {
|
|
9175
|
+
...this.sessionRenderOptions.context,
|
|
9176
|
+
labelFit: this.labelFit
|
|
9177
|
+
}
|
|
9103
9178
|
});
|
|
9104
9179
|
return {
|
|
9105
9180
|
id: graphic.id,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orbat-mapper/tactical-draw",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "Engine-agnostic draw/edit core for tactical control measures (MIL-STD-2525 / APP-6). The MapAdapter ABI and bring-your-own-engine entry point for the tactical-draw package family.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Orbat Mapper",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@orbat-mapper/control-measures": "^0.
|
|
42
|
+
"@orbat-mapper/control-measures": "^0.39.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"vitest": ">=4.0.0"
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "tsdown",
|
|
64
64
|
"test": "vitest run",
|
|
65
|
-
"lint": "eslint . --fix"
|
|
65
|
+
"lint": "eslint . --fix",
|
|
66
|
+
"typecheck": "tsc --noEmit"
|
|
66
67
|
}
|
|
67
68
|
}
|