@orbat-mapper/tactical-draw 0.36.3 → 0.37.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 CHANGED
@@ -246,6 +246,12 @@ interface PickCandidateInput {
246
246
  /** The engine already reported this part as hit; retained as a fallback for engine-only marks. */
247
247
  nativeHit?: boolean;
248
248
  icon?: IconResource;
249
+ /**
250
+ * The scale `icon` is drawn at, when the engine sizes it itself rather than
251
+ * from the feature's `iconScale` snapshot: a ground-sized icon on an engine
252
+ * that scales those natively (`MapAdapter.scalesGroundPointSymbolsNatively`).
253
+ */
254
+ iconScale?: number;
249
255
  labelExtent?: LabelExtent;
250
256
  presentation?: ResolvedPickPresentation;
251
257
  layerStyle?: StyleOptions;
@@ -1788,7 +1794,10 @@ interface CollocationGroupRender {
1788
1794
  * resolution re-render of a ground-sized collocation mints no new image. When
1789
1795
  * its size has a `maxPixels` cap, every icon feature also carries the native
1790
1796
  * ground-size fields, so an engine that scales ground-sized point symbols
1791
- * natively tracks zoom animations itself.
1797
+ * natively tracks zoom animations itself. For such an engine
1798
+ * (`nativeGroundScaling`) those icons leave out the `iconScale` snapshot, so a
1799
+ * zoom that changes no image re-renders identical features and the engine
1800
+ * reloads nothing mid-animation (#791).
1792
1801
  */
1793
1802
  declare function renderCollocationGroup(collocation: Collocation, capabilities: CollocationMemberCapabilities, options: {
1794
1803
  resolution: number | undefined;
@@ -1806,6 +1815,12 @@ declare function renderCollocationGroup(collocation: Collocation, capabilities:
1806
1815
  * still draw.
1807
1816
  */
1808
1817
  hiddenMembers?: readonly string[];
1818
+ /**
1819
+ * The engine sizes ground-sized icons from their native fields
1820
+ * (`MapAdapter.scalesGroundPointSymbolsNatively`): icons that carry them
1821
+ * get no per-resolution `iconScale`.
1822
+ */
1823
+ nativeGroundScaling?: boolean;
1809
1824
  }): CollocationGroupRender;
1810
1825
  /** The view a live leader is drawn through. */
1811
1826
  interface LiveLeaderView {
package/dist/index.mjs CHANGED
@@ -312,7 +312,7 @@ function evaluateInput(input, presentation, context) {
312
312
  kind: "label",
313
313
  distance: 0
314
314
  } };
315
- if (input.icon) return evaluateIcon(input.feature, input.icon, context);
315
+ if (input.icon) return evaluateIcon(input.feature, input.icon, context, input.iconScale);
316
316
  const geometryHit = evaluateGeometry(input.feature, presentation, context);
317
317
  if (geometryHit) return { hit: geometryHit };
318
318
  if (input.feature.geometry.type === "Polygon" || input.feature.geometry.type === "MultiPolygon") return null;
@@ -381,11 +381,11 @@ function bestPolygonHit(hits) {
381
381
  if (boundary.length > 0) return boundary.reduce((best, hit) => (hit.distance ?? Infinity) < (best.distance ?? Infinity) ? hit : best);
382
382
  return hits[0];
383
383
  }
384
- function evaluateIcon(feature, resource, context) {
384
+ function evaluateIcon(feature, resource, context, iconScale) {
385
385
  if (feature.geometry.type !== "Point") return null;
386
386
  const anchor = context.toPixel(feature.geometry.coordinates);
387
387
  if (!anchor) return null;
388
- const rawScale = feature.properties?.iconScale;
388
+ const rawScale = iconScale ?? feature.properties?.iconScale;
389
389
  const scale = typeof rawScale === "number" ? rawScale : 1;
390
390
  if (!Number.isFinite(scale) || scale <= 0) return null;
391
391
  const rawRotation = feature.properties?.iconRotation;
@@ -11708,6 +11708,10 @@ let nextGraphicGroupRevision = 0;
11708
11708
  function sameFeatures(a, b) {
11709
11709
  return JSON.stringify(a) === JSON.stringify(b);
11710
11710
  }
11711
+ /** Icon resource ids hash their drawing, so equal ids in order mean equal resources. */
11712
+ function sameIconResourceIds(a, b) {
11713
+ return a.length === b.length && a.every((resource, i) => resource.id === b[i].id);
11714
+ }
11711
11715
  /**
11712
11716
  * `TacticalDraw` façade — slice #6 (issue #45).
11713
11717
  *
@@ -12066,7 +12070,11 @@ var TacticalDraw = class {
12066
12070
  const dependence = presentation && this.graphicUsesPinPresentation(graphic, presentation) ? "none" : graphicViewDependence(graphic, this.adapter.scalesGroundPointSymbolsNatively === true, this.collocationMembers, this.collocations);
12067
12071
  const resolution = dependence === "none" ? void 0 : this.adapter.getResolution();
12068
12072
  if (isCollocation(graphic)) {
12069
- const { group, layout } = this.buildCollocationGroup(graphic);
12073
+ const { group: built, layout } = this.buildCollocationGroup(graphic);
12074
+ const group = cached && sameFeatures(cached.group.features, built.features) && sameIconResourceIds(cached.group.iconResources, built.iconResources) ? {
12075
+ ...built,
12076
+ revision: cached.group.revision
12077
+ } : built;
12070
12078
  this.graphicGroupCache.set(graphic, {
12071
12079
  group,
12072
12080
  dependence,
@@ -12124,7 +12132,8 @@ var TacticalDraw = class {
12124
12132
  collocations.warn(graphic, capabilities);
12125
12133
  const drawn = collocations.renderGroup(graphic, capabilities, {
12126
12134
  resolution: this.adapter.getResolution(),
12127
- highlight: this.sessionRenderOptions.highlightAppearance
12135
+ highlight: this.sessionRenderOptions.highlightAppearance,
12136
+ nativeGroundScaling: this.adapter.scalesGroundPointSymbolsNatively === true
12128
12137
  });
12129
12138
  return {
12130
12139
  group: {
@@ -15266,7 +15275,10 @@ const COLLOCATION_MEMBER_PROPERTY = "collocationMemberId";
15266
15275
  * resolution re-render of a ground-sized collocation mints no new image. When
15267
15276
  * its size has a `maxPixels` cap, every icon feature also carries the native
15268
15277
  * ground-size fields, so an engine that scales ground-sized point symbols
15269
- * natively tracks zoom animations itself.
15278
+ * natively tracks zoom animations itself. For such an engine
15279
+ * (`nativeGroundScaling`) those icons leave out the `iconScale` snapshot, so a
15280
+ * zoom that changes no image re-renders identical features and the engine
15281
+ * reloads nothing mid-animation (#791).
15270
15282
  */
15271
15283
  function renderCollocationGroup(collocation, capabilities, options) {
15272
15284
  const hiddenIds = new Set(options.hiddenMembers);
@@ -15291,6 +15303,11 @@ function renderCollocationGroup(collocation, capabilities, options) {
15291
15303
  return resource.id;
15292
15304
  };
15293
15305
  const native = nativeGroundSizing(render.size);
15306
+ /** An icon's size: its native ground-size fields, plus the `iconScale` snapshot unless the engine needs none. */
15307
+ const iconSize = (iconScale, octagonSize) => native && octagonSize !== void 0 ? {
15308
+ ...options.nativeGroundScaling ? {} : { iconScale },
15309
+ ...groundSizeProperties(native, octagonSize)
15310
+ } : { iconScale };
15294
15311
  /**
15295
15312
  * A ground mark, laid out at its full size times the collocation scale: its
15296
15313
  * image is drawn at full size and the engine scales it, natively for a
@@ -15320,9 +15337,8 @@ function renderCollocationGroup(collocation, capabilities, options) {
15320
15337
  },
15321
15338
  properties: ground({
15322
15339
  iconId: addResource(markResource(full, highlighted ? highlight : void 0)),
15323
- iconScale: k,
15324
- [ICON_SCREEN_ROTATION_PROPERTY]: 0,
15325
- ...native && scaleMarks ? groundSizeProperties(native, native.maxPixels) : {}
15340
+ ...iconSize(k, scaleMarks ? native?.maxPixels : void 0),
15341
+ [ICON_SCREEN_ROTATION_PROPERTY]: 0
15326
15342
  })
15327
15343
  };
15328
15344
  };
@@ -15443,10 +15459,9 @@ function renderCollocationGroup(collocation, capabilities, options) {
15443
15459
  properties: base({
15444
15460
  [COLLOCATION_PART_PROPERTY]: part.part,
15445
15461
  iconId: addResource(resource),
15446
- iconScale: layout.scale / reference,
15462
+ ...iconSize(layout.scale / reference, native && native.maxPixels * reference),
15447
15463
  ...ox !== 0 || oy !== 0 ? { [ICON_OFFSET_PROPERTY]: [ox, oy] } : {},
15448
- [ICON_SCREEN_ROTATION_PROPERTY]: 0,
15449
- ...native ? groundSizeProperties(native, native.maxPixels * reference) : {}
15464
+ [ICON_SCREEN_ROTATION_PROPERTY]: 0
15450
15465
  })
15451
15466
  });
15452
15467
  }
@@ -15465,11 +15480,10 @@ function renderCollocationGroup(collocation, capabilities, options) {
15465
15480
  [COLLOCATION_PART_PROPERTY]: part.part,
15466
15481
  [COLLOCATION_MEMBER_PROPERTY]: member.memberId,
15467
15482
  iconId: addResource(memberResource(member)),
15468
- iconScale: member.iconScale,
15483
+ ...iconSize(member.iconScale, member.render.sizeReference),
15469
15484
  [ICON_SCREEN_ROTATION_PROPERTY]: 0,
15470
- [ICON_OFFSET_PROPERTY]: [...member.iconOffset],
15471
- iconOpacity: (style?.opacity ?? 1) * (style?.overallOpacity ?? 1),
15472
- ...native ? groundSizeProperties(native, member.render.sizeReference) : {}
15485
+ [ICON_OFFSET_PROPERTY]: member.iconOffset.map(snap),
15486
+ iconOpacity: (style?.opacity ?? 1) * (style?.overallOpacity ?? 1)
15473
15487
  })
15474
15488
  });
15475
15489
  }
@@ -16236,6 +16250,7 @@ function runCollocationEdit(opts) {
16236
16250
  const drawn = renderCollocationGroup(working, capabilities, {
16237
16251
  resolution: renderedResolution,
16238
16252
  highlight: appearance,
16253
+ nativeGroundScaling: adapter.scalesGroundPointSymbolsNatively === true,
16239
16254
  ...drag ? { liveLeaders: {
16240
16255
  toPixel: driver.toPixel,
16241
16256
  fromPixel: driver.fromPixel
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbat-mapper/tactical-draw",
3
- "version": "0.36.3",
3
+ "version": "0.37.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",