@orbat-mapper/tactical-draw 0.22.0 → 0.22.1

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.
Files changed (2) hide show
  1. package/dist/index.mjs +72 -21
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -3651,6 +3651,31 @@ function translatePoints(base, dx, dy) {
3651
3651
  return out;
3652
3652
  });
3653
3653
  }
3654
+ /**
3655
+ * Carry a pixel-space box by a ground (lon/lat) delta: unproject each corner,
3656
+ * shift it, re-project, and re-fit the box (same angle) around the landed
3657
+ * corners. Untilted this is the plain pixel translate (up to the small
3658
+ * Mercator-latitude term); pitched, the box also shrinks or grows with depth so
3659
+ * it keeps framing geometry moved by the same delta. Falls back to
3660
+ * `pixelDelta` when a corner can't be projected.
3661
+ */
3662
+ function translateBoxOnGround(box, [dLon, dLat], pixelDelta, projection) {
3663
+ const pixelTranslated = () => ({
3664
+ ...box,
3665
+ center: [box.center[0] + pixelDelta[0], box.center[1] + pixelDelta[1]]
3666
+ });
3667
+ const landed = [];
3668
+ for (const corner of boxCorners(box)) {
3669
+ const ground = projection.fromPixel(corner);
3670
+ const moved = projection.toPixel([ground[0] + dLon, ground[1] + dLat]);
3671
+ if (!moved || !Number.isFinite(moved[0]) || !Number.isFinite(moved[1])) return pixelTranslated();
3672
+ landed.push(moved);
3673
+ }
3674
+ const fitted = fitTransformBox(landed, box.angle);
3675
+ return Math.max(fitted.halfWidth / box.halfWidth, fitted.halfHeight / box.halfHeight) > MAX_GROUND_BOX_GROWTH ? pixelTranslated() : fitted;
3676
+ }
3677
+ /** Above this size ratio a ground-translated box is treated as unprojectable. */
3678
+ const MAX_GROUND_BOX_GROWTH = 10;
3654
3679
  function pixelDistance(a, b) {
3655
3680
  return Math.hypot(a[0] - b[0], a[1] - b[1]);
3656
3681
  }
@@ -3819,12 +3844,12 @@ function beginBoxDrag(args) {
3819
3844
  const origin = fromPixel(downPixel);
3820
3845
  const move = (pixel) => {
3821
3846
  const cur = fromPixel(pixel);
3847
+ const translation = [cur[0] - origin[0], cur[1] - origin[1]];
3848
+ const pixelDelta = [pixel[0] - downPixel[0], pixel[1] - downPixel[1]];
3822
3849
  return {
3823
- points: translatePoints(preDragPoints, cur[0] - origin[0], cur[1] - origin[1]),
3824
- box: {
3825
- ...box,
3826
- center: [box.center[0] + (pixel[0] - downPixel[0]), box.center[1] + (pixel[1] - downPixel[1])]
3827
- }
3850
+ points: translatePoints(preDragPoints, translation[0], translation[1]),
3851
+ box: translateBoxOnGround(box, translation, pixelDelta, projection),
3852
+ translation
3828
3853
  };
3829
3854
  };
3830
3855
  return {
@@ -4375,27 +4400,50 @@ function transformAmplifierPlacements(placements, from, to, projection) {
4375
4400
  if (!placements) return void 0;
4376
4401
  const scaleX = to.halfWidth / from.halfWidth;
4377
4402
  const scaleY = to.halfHeight / from.halfHeight;
4378
- const angleDelta = to.angle - from.angle;
4379
- const transformed = {};
4403
+ return mapAmplifierPlacements(placements, (position) => {
4404
+ const pixel = projection.toPixel(position);
4405
+ if (!pixel) return [...position];
4406
+ const [localX, localY] = rotate(pixel[0] - from.center[0], pixel[1] - from.center[1], -from.angle);
4407
+ const [outX, outY] = rotate(localX * scaleX, localY * scaleY, to.angle);
4408
+ return projection.fromPixel([to.center[0] + outX, to.center[1] + outY]);
4409
+ }, to.angle - from.angle);
4410
+ }
4411
+ /**
4412
+ * Rebuild `placements` with every anchor passed through `movePosition` and
4413
+ * every rotation override shifted by `-angleDelta`, keeping each entry's
4414
+ * storage shape (bare `Position` vs object form) and rotation-only entries.
4415
+ */
4416
+ function mapAmplifierPlacements(placements, movePosition, angleDelta) {
4417
+ const mapped = {};
4380
4418
  for (const [field, raw] of Object.entries(placements)) {
4381
4419
  const resolved = resolveAmplifierPlacement(raw);
4382
4420
  const rotation = resolved.rotation !== void 0 ? resolved.rotation - angleDelta : void 0;
4383
4421
  if (!resolved.position) {
4384
- if (rotation !== void 0) transformed[field] = { rotation };
4422
+ if (rotation !== void 0) mapped[field] = { rotation };
4385
4423
  continue;
4386
4424
  }
4387
- const pixel = projection.toPixel(resolved.position);
4388
- const position = pixel ? (() => {
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 ? {
4425
+ const position = movePosition(resolved.position);
4426
+ mapped[field] = rotation !== void 0 ? {
4394
4427
  position,
4395
4428
  rotation
4396
4429
  } : position;
4397
4430
  }
4398
- return transformed;
4431
+ return mapped;
4432
+ }
4433
+ /**
4434
+ * Carry placement overrides through one box-drag snapshot. A body drag moves
4435
+ * the control points by a lon/lat delta (`snapshot.translation`), so the
4436
+ * anchors move by that same delta and stay glued to the geometry; going
4437
+ * through the box's pixel delta instead would drift on a pitched view, where
4438
+ * equal pixel offsets cover different ground distances at different screen
4439
+ * depths. Scale and rotate share the pixel-space affine with the points, so
4440
+ * they go through {@link transformAmplifierPlacements}.
4441
+ */
4442
+ function carryAmplifierPlacements(placements, from, snapshot, projection) {
4443
+ if (!snapshot.translation) return transformAmplifierPlacements(placements, from, snapshot.box, projection);
4444
+ if (!placements) return void 0;
4445
+ const [dLon, dLat] = snapshot.translation;
4446
+ return mapAmplifierPlacements(placements, (p) => [p[0] + dLon, p[1] + dLat], 0);
4399
4447
  }
4400
4448
  /**
4401
4449
  * Field-wise merge of one `amplifierPlacements` entry: fields present in
@@ -5535,7 +5583,10 @@ function runEdit(opts) {
5535
5583
  graphicId: measure.id,
5536
5584
  originalEvent: info?.native
5537
5585
  },
5538
- toDragPixel: (landed) => [pixel[0] + landed[0] - anchorPixel[0], pixel[1] + landed[1] - anchorPixel[1]]
5586
+ toDragPixel: (landed) => {
5587
+ const at = driver.fromPixel(landed);
5588
+ 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]];
5589
+ }
5539
5590
  };
5540
5591
  }
5541
5592
  /**
@@ -5824,7 +5875,7 @@ function runEdit(opts) {
5824
5875
  return;
5825
5876
  }
5826
5877
  workingPoints.splice(0, workingPoints.length, ...snapshot.points);
5827
- workingAmplifierPlacements = transformAmplifierPlacements(activeBoxDrag.preDragAmplifierPlacements, activeBoxDrag.preDragBox, snapshot.box, driver);
5878
+ workingAmplifierPlacements = carryAmplifierPlacements(activeBoxDrag.preDragAmplifierPlacements, activeBoxDrag.preDragBox, snapshot, driver);
5828
5879
  renderWorkingGraphic();
5829
5880
  renderHandlesLayer();
5830
5881
  recomputeDirty();
@@ -5947,7 +5998,7 @@ function runEdit(opts) {
5947
5998
  }
5948
5999
  const committedPoints = optionFold && holdsAnchorOnFold ? preDragPoints : finalSnapshot.points;
5949
6000
  transient.emit("end", committedPoints, null);
5950
- commitGesture(committedPoints, preDragOptions, transformAmplifierPlacements(preDragAmplifierPlacements, preDragBox, finalSnapshot.box, driver), preDragBox.angle);
6001
+ commitGesture(committedPoints, preDragOptions, carryAmplifierPlacements(preDragAmplifierPlacements, preDragBox, finalSnapshot, driver), preDragBox.angle);
5951
6002
  });
5952
6003
  return;
5953
6004
  }
@@ -7329,7 +7380,7 @@ function runGroupTransform(opts) {
7329
7380
  applyConcatenatedPoints(snapshot.points);
7330
7381
  applyPointSymbolStateByMember(pointSymbolStateForBox(snapshot.box));
7331
7382
  applyMeasureTransformForBox(snapshot.box, activeBoxDrag.preDragBox, activeBoxDrag.fsm.kind, activeBoxDrag.preDragOptionsOverrideByMember);
7332
- applyAmplifierPlacementsByMember(activeBoxDrag.preDragAmplifierPlacementsByMember.map((placements) => transformAmplifierPlacements(placements, activeBoxDrag.preDragBox, snapshot.box, driver)));
7383
+ applyAmplifierPlacementsByMember(activeBoxDrag.preDragAmplifierPlacementsByMember.map((placements) => carryAmplifierPlacements(placements, activeBoxDrag.preDragBox, snapshot, driver)));
7333
7384
  renderAllPreviews();
7334
7385
  renderHandlesLayer();
7335
7386
  recomputeDirty();
@@ -7371,7 +7422,7 @@ function runGroupTransform(opts) {
7371
7422
  if (members.some(isAnchoredMember)) shell.suppressNextClickAway();
7372
7423
  if (fsm.kind === "rotate") boxAngle += finalSnapshot.box.angle - preDragBox.angle;
7373
7424
  applyMeasureTransformForBox(finalSnapshot.box, preDragBox, fsm.kind, preDragOptionsOverrideByMember);
7374
- commitGesture(finalSnapshot.points, preDragOptionsOverrideByMember, preDragAmplifierPlacementsByMember.map((placements) => transformAmplifierPlacements(placements, preDragBox, finalSnapshot.box, driver)), preDragBox.angle, nextPointSymbolStateByMember);
7425
+ commitGesture(finalSnapshot.points, preDragOptionsOverrideByMember, preDragAmplifierPlacementsByMember.map((placements) => carryAmplifierPlacements(placements, preDragBox, finalSnapshot, driver)), preDragBox.angle, nextPointSymbolStateByMember);
7375
7426
  };
7376
7427
  const core = runEditInteraction({
7377
7428
  adapter,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbat-mapper/tactical-draw",
3
- "version": "0.22.0",
3
+ "version": "0.22.1",
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",