@orbat-mapper/tactical-draw 0.2.0 → 0.3.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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as PointerEventInfo, S as PointerCallback, _ as HatchPattern, a as LayerId, b as makeFillPatternImage, c as MapEvent, d as PickHandler, f as PickOptions, g as HATCH_PATTERNS, h as TextStyleOptions, i as ImageOverlayResource, l as MapEventHandler, m as StyleOptions, n as HandleStyle, o as MapAdapter, p as PixelCoordinate, r as IconResource, s as MapCursor, t as FeatureGroup, u as PickEvent, v as fillPatternImageDimension, x as EditPointerDriver, y as fillPatternImageId } from "./map-adapter-DfIb57kQ.mjs";
|
|
2
2
|
import { AmplifierPlacement, AmplifierPlacements, ControlMeasure, ControlMeasureKind, ControlMeasureRender, ControlMeasureStyle, TextAmplifiers } from "@orbat-mapper/control-measures";
|
|
3
3
|
import { Feature, Position } from "geojson";
|
|
4
4
|
|
|
@@ -419,13 +419,73 @@ declare function clonePointSymbol(symbol: PointSymbol): PointSymbol;
|
|
|
419
419
|
*/
|
|
420
420
|
declare function resizePointSymbolSize(size: PointSymbolSize, value: number): PointSymbolSize;
|
|
421
421
|
//#endregion
|
|
422
|
+
//#region src/image-graphic.d.ts
|
|
423
|
+
type ImageSize = {
|
|
424
|
+
value: number;
|
|
425
|
+
unit: "meters";
|
|
426
|
+
};
|
|
427
|
+
interface ImageIntrinsicSize {
|
|
428
|
+
width: number;
|
|
429
|
+
height: number;
|
|
430
|
+
}
|
|
431
|
+
interface ImageGraphicStyle {
|
|
432
|
+
opacity?: number;
|
|
433
|
+
}
|
|
434
|
+
/** Persisted, host-resource-backed Image graphic. */
|
|
435
|
+
interface ImageGraphic {
|
|
436
|
+
id: string;
|
|
437
|
+
kind: "image";
|
|
438
|
+
resourceId: string;
|
|
439
|
+
intrinsicSize: ImageIntrinsicSize;
|
|
440
|
+
position: Position;
|
|
441
|
+
/** Normalized radians clockwise from geographic north. */
|
|
442
|
+
rotation: number;
|
|
443
|
+
/** Displayed width; height is derived from `intrinsicSize`. */
|
|
444
|
+
size: ImageSize;
|
|
445
|
+
name?: string;
|
|
446
|
+
style?: ImageGraphicStyle;
|
|
447
|
+
properties?: Record<string, unknown>;
|
|
448
|
+
schemaVersion: 1;
|
|
449
|
+
}
|
|
450
|
+
/** Prepared, synchronous display resource supplied and owned by the host. */
|
|
451
|
+
interface ImageResource {
|
|
452
|
+
id: string;
|
|
453
|
+
/** Self-contained raster URL prepared by the host for native image overlays. */
|
|
454
|
+
overlayUrl: string;
|
|
455
|
+
width: number;
|
|
456
|
+
height: number;
|
|
457
|
+
}
|
|
458
|
+
interface ImageCapability {
|
|
459
|
+
resolve(resourceId: string): ImageResource | undefined;
|
|
460
|
+
/** Monotonic host-owned revision for resource availability changes. */
|
|
461
|
+
readonly generation?: number;
|
|
462
|
+
}
|
|
463
|
+
interface ImageRender {
|
|
464
|
+
resourceId: string;
|
|
465
|
+
width: number;
|
|
466
|
+
height: number;
|
|
467
|
+
overlayUrl?: string;
|
|
468
|
+
available: boolean;
|
|
469
|
+
}
|
|
470
|
+
declare function isImageGraphic(graphic: unknown): graphic is ImageGraphic;
|
|
471
|
+
declare function cloneImageGraphic(image: ImageGraphic): ImageGraphic;
|
|
472
|
+
declare function normalizeImageGraphic(image: ImageGraphic): ImageGraphic;
|
|
473
|
+
declare function imageOpacity(image: ImageGraphic): number;
|
|
474
|
+
declare function validateImageGraphic(image: ImageGraphic): void;
|
|
475
|
+
//#endregion
|
|
422
476
|
//#region src/graphic.d.ts
|
|
423
|
-
type Graphic = ControlMeasure | PointSymbol;
|
|
424
|
-
type GraphicRender = ControlMeasureRender | PointSymbolRender;
|
|
477
|
+
type Graphic = ControlMeasure | PointSymbol | ImageGraphic;
|
|
478
|
+
type GraphicRender = ControlMeasureRender | PointSymbolRender | ImageRender;
|
|
425
479
|
interface GraphicSnapshot<G extends Graphic = Graphic> {
|
|
426
480
|
graphic: G;
|
|
427
|
-
render: G extends PointSymbol ? PointSymbolRender : ControlMeasureRender;
|
|
481
|
+
render: G extends PointSymbol ? PointSymbolRender : G extends ImageGraphic ? ImageRender : ControlMeasureRender;
|
|
428
482
|
}
|
|
483
|
+
/**
|
|
484
|
+
* A graphic whose identity is one geographic anchor + size + rotation,
|
|
485
|
+
* rather than a control-point geometry: `PointSymbol` or `ImageGraphic`.
|
|
486
|
+
*/
|
|
487
|
+
type AnchoredGraphic = PointSymbol | ImageGraphic;
|
|
488
|
+
declare function isAnchoredGraphic(graphic: Graphic): graphic is AnchoredGraphic;
|
|
429
489
|
//#endregion
|
|
430
490
|
//#region src/tactical-draw/abort.d.ts
|
|
431
491
|
/**
|
|
@@ -1213,6 +1273,9 @@ interface SnappingOptions {
|
|
|
1213
1273
|
//#region src/tactical-draw/point-symbol-draw-controller.d.ts
|
|
1214
1274
|
type DrawPointSymbolDraft = Pick<PointSymbol, "kind" | "sidc"> & Partial<Omit<PointSymbol, "kind" | "sidc">>;
|
|
1215
1275
|
//#endregion
|
|
1276
|
+
//#region src/tactical-draw/image-draw-controller.d.ts
|
|
1277
|
+
type DrawImageDraft = Pick<ImageGraphic, "kind" | "resourceId" | "intrinsicSize"> & Partial<Omit<ImageGraphic, "kind" | "resourceId" | "intrinsicSize">>;
|
|
1278
|
+
//#endregion
|
|
1216
1279
|
//#region src/tactical-draw/tactical-draw.d.ts
|
|
1217
1280
|
/**
|
|
1218
1281
|
* Host-supplied layer slot ids. Any omitted slot is allocated by the façade and
|
|
@@ -1246,6 +1309,8 @@ interface TacticalDrawOptions {
|
|
|
1246
1309
|
layers?: TacticalDrawLayerOptions;
|
|
1247
1310
|
/** Optional renderer capability for first-class point symbols (ADR-0029). */
|
|
1248
1311
|
pointSymbols?: PointSymbolCapability;
|
|
1312
|
+
/** Synchronous host-supplied resolver for first-class Image resources. */
|
|
1313
|
+
images?: ImageCapability;
|
|
1249
1314
|
/**
|
|
1250
1315
|
* Façade-level default style passed through to `renderControlMeasure` as the
|
|
1251
1316
|
* third (lowest priority) style layer per StyleResolver (#44). Shallow-merged
|
|
@@ -1275,7 +1340,7 @@ interface EditOptions {
|
|
|
1275
1340
|
* Called synchronously once when the edit starts, before any pointer event
|
|
1276
1341
|
* is processed. Lets a host wire commit / cancel buttons to the active edit.
|
|
1277
1342
|
*/
|
|
1278
|
-
onSession?: (session: EditSession | GraphicEditSession<PointSymbol>) => void;
|
|
1343
|
+
onSession?: (session: EditSession | GraphicEditSession<PointSymbol> | GraphicEditSession<ImageGraphic>) => void;
|
|
1279
1344
|
/**
|
|
1280
1345
|
* Default `true`. When `true`, a click on empty map (or on another graphics
|
|
1281
1346
|
* layer measure) closes the active edit. Clicks on preview / handle
|
|
@@ -1421,6 +1486,7 @@ declare class TacticalDraw {
|
|
|
1421
1486
|
private readonly defaultInteractionStyle;
|
|
1422
1487
|
private readonly generateId;
|
|
1423
1488
|
private readonly pointSymbols;
|
|
1489
|
+
private readonly images;
|
|
1424
1490
|
private snappingOptions;
|
|
1425
1491
|
private readonly resolveSnap;
|
|
1426
1492
|
private readonly graphicStack;
|
|
@@ -1487,6 +1553,7 @@ declare class TacticalDraw {
|
|
|
1487
1553
|
* there is no capability, or the capability doesn't expose `generation`.
|
|
1488
1554
|
*/
|
|
1489
1555
|
private lastSeenPointSymbolGeneration;
|
|
1556
|
+
private lastSeenImageGeneration;
|
|
1490
1557
|
/**
|
|
1491
1558
|
* Ids of graphics currently carrying a passive selection-highlight outline
|
|
1492
1559
|
* ({@link setHighlightedGraphics}). Declarative set-replace, no session —
|
|
@@ -1534,6 +1601,8 @@ declare class TacticalDraw {
|
|
|
1534
1601
|
* the point-symbol capability's `generation`.
|
|
1535
1602
|
*/
|
|
1536
1603
|
private invalidateGraphicGroupCache;
|
|
1604
|
+
/** Refresh capability-dependent renders before any caller-visible state is mutated. */
|
|
1605
|
+
private refreshCapabilityGenerations;
|
|
1537
1606
|
/** Submit one complete grouped desired state for the host stack plus overrides. */
|
|
1538
1607
|
private reconcileGraphicsStack;
|
|
1539
1608
|
/** Atomically publish several live renders into their host-owned Graphic slots. */
|
|
@@ -1668,6 +1737,7 @@ declare class TacticalDraw {
|
|
|
1668
1737
|
* kinds of session.
|
|
1669
1738
|
*/
|
|
1670
1739
|
draw(draft: DrawPointSymbolDraft, options?: DrawOptions): Promise<GraphicSnapshot<PointSymbol>>;
|
|
1740
|
+
draw(draft: DrawImageDraft, options?: DrawOptions): Promise<GraphicSnapshot<ImageGraphic>>;
|
|
1671
1741
|
draw<K extends ControlMeasureKind>(draft: DrawMeasureDraft<K>, options?: DrawOptions): Promise<GraphicSnapshot<ControlMeasure<K>>>;
|
|
1672
1742
|
/**
|
|
1673
1743
|
* Start an interactive edit on a single control measure. Returns a Promise
|
|
@@ -1685,6 +1755,7 @@ declare class TacticalDraw {
|
|
|
1685
1755
|
* non-load-bearing for hosts that adopt them.
|
|
1686
1756
|
*/
|
|
1687
1757
|
edit(graphic: PointSymbol, options?: EditOptions): Promise<GraphicSnapshot<PointSymbol>>;
|
|
1758
|
+
edit(graphic: ImageGraphic, options?: EditOptions): Promise<GraphicSnapshot<ImageGraphic>>;
|
|
1688
1759
|
edit(measure: ControlMeasure, options?: EditOptions): Promise<GraphicSnapshot<ControlMeasure>>;
|
|
1689
1760
|
/**
|
|
1690
1761
|
* Start an interactive group transform (multi-select) over `measures`
|
|
@@ -1828,7 +1899,7 @@ declare class TacticalDraw {
|
|
|
1828
1899
|
* The live variable-draw or edit session, or `null` while idle and during
|
|
1829
1900
|
* fixed-length draws. Safe to read after `destroy()`.
|
|
1830
1901
|
*/
|
|
1831
|
-
get activeSession(): DrawSession | EditSession | GraphicEditSession
|
|
1902
|
+
get activeSession(): DrawSession | EditSession | GraphicEditSession | null;
|
|
1832
1903
|
/**
|
|
1833
1904
|
* The live `editMany` group-transform session, or `null` while idle (and
|
|
1834
1905
|
* during any other interaction). Separate from `activeSession` because
|
|
@@ -1902,6 +1973,9 @@ declare class TacticalDrawDestroyedError extends Error {
|
|
|
1902
1973
|
declare class PointSymbolCapabilityRequiredError extends Error {
|
|
1903
1974
|
constructor();
|
|
1904
1975
|
}
|
|
1976
|
+
declare class ImageCapabilityRequiredError extends Error {
|
|
1977
|
+
constructor();
|
|
1978
|
+
}
|
|
1905
1979
|
//#endregion
|
|
1906
1980
|
//#region src/tactical-draw/transform-box.d.ts
|
|
1907
1981
|
/**
|
|
@@ -1946,6 +2020,13 @@ declare function effectivePointSymbolPixelSize(symbol: PointSymbol, resolution:
|
|
|
1946
2020
|
/** Complete rotated logical footprint for selection and transform chrome. */
|
|
1947
2021
|
declare function pointSymbolFootprint(symbol: PointSymbol, render: PointSymbolRender, adapter: Pick<MapAdapter, "getBearing" | "getPixelFromCoordinate" | "getResolution">): PointSymbolFootprint | null;
|
|
1948
2022
|
//#endregion
|
|
2023
|
+
//#region src/tactical-draw/image-rendering.d.ts
|
|
2024
|
+
interface ImageFootprint {
|
|
2025
|
+
box: TransformBox;
|
|
2026
|
+
corners: PixelCoordinate[];
|
|
2027
|
+
}
|
|
2028
|
+
declare function imageFootprint(image: ImageGraphic, render: ImageRender, adapter: Pick<MapAdapter, "getBearing" | "getPixelFromCoordinate" | "getResolution">): ImageFootprint | null;
|
|
2029
|
+
//#endregion
|
|
1949
2030
|
//#region src/world-wrap.d.ts
|
|
1950
2031
|
/**
|
|
1951
2032
|
* Shift `lng` by whole world widths (360°) onto the copy nearest `refLng`.
|
|
@@ -1960,4 +2041,4 @@ declare function nearestWorldCopyLng(lng: number, refLng: number): number;
|
|
|
1960
2041
|
/** `nearestWorldCopyLng` applied to a lon/lat position. */
|
|
1961
2042
|
declare function nearestWorldCopyPosition(position: Position, refLng: number): Position;
|
|
1962
2043
|
//#endregion
|
|
1963
|
-
export { BaseMapAdapter, type CombinedAbort, DEFAULT_LABEL_SIZE_PIXELS, DEFAULT_TEXT_SIZE_MAX_PIXELS, DEFAULT_TEXT_SIZE_MIN_PIXELS, type DrawMeasureDraft, type DrawOptions, type DrawPointSymbolDraft, type DrawSession, type EditChangeEvent, type EditManyOptions, type EditMode, type EditOptions, type EditPointerDriver, type EditSession, type FeatureGroup, type Graphic, type GraphicEditChangeEvent, type GraphicEditSession, type GraphicGeometrySnappingOptions, type GraphicRender, type GraphicSnapshot, type GuideStyle, HATCH_PATTERNS, type HandleStyle, type HatchPattern, type IconResource, type InteractionHit, type InteractionStyle, type LabelExtent, type LayerId, type MapAdapter, type MapCursor, type MapEvent, type MapEventHandler, type MergedPickFeature, type NativeEventEntry, type PickCandidate, type PickCandidateHit, type PickCandidateHitKind, type PickCandidateInput, type PickEvaluationContext, type PickEvent, type PickHandler, type PickOptions, type PickPointerType, type PixelCoordinate, type PointSymbol, type PointSymbolAnchor, type PointSymbolCapability, PointSymbolCapabilityRequiredError, type PointSymbolColors, type PointSymbolFootprint, type PointSymbolGraphicModifiers, type PointSymbolRender, type PointSymbolSize, type PointSymbolStyle, type PointerCallback, PointerCallbackHub, type PointerEventInfo, type ResolvedPickPresentation, type RotatedScreenBounds, type ScreenBounds, type SessionChangeSource, type SessionHistory, type SessionHistoryState, type SettleReason, type SizeAnchor, type SnapCandidate, type SnapCandidateProvider, type SnapCandidateRequest, type SnapInteraction, type SnapResult, type SnappingOptions, type StyleOptions, TEXT_HALO_COLOR, TOUCH_HIT_TOLERANCE_PX, TacticalDraw, TacticalDrawAbortError, type TacticalDrawAbortReason, TacticalDrawDestroyedError, type TacticalDrawLayerOptions, type TacticalDrawOptions, type TextSizeProps, type TextStyleOptions, type ToPixel, type TransformBox, type TransformChangeEvent, type TransformSession, type TransientChangeEvent, type TransientPhase, bindAbortable, clonePointSymbol, coerceHandleStyle, combineWithHostSignal, effectivePointSymbolPixelSize, evaluatePickCandidates, fillPatternImageDimension, fillPatternImageId, getSizeAnchor, hitTestFeature, hitTestIconFeature, ignoreAbort, isPointSymbol, isTacticalDrawAbortError, makeFillPatternImage, mergeNativeAndCachedPickFeatures, nearestWorldCopyLng, nearestWorldCopyPosition, pickHitTolerance, pickPointerType, pointSymbolFootprint, renderOrderToVisualOrder, resizePointSymbolSize, resolveGroundTextSizePixels, resolvePickPresentation, resolveTextHaloWidth, resolveTextSizePixels, tryControlMeasureIdFromFeature };
|
|
2044
|
+
export { type AnchoredGraphic, BaseMapAdapter, type CombinedAbort, DEFAULT_LABEL_SIZE_PIXELS, DEFAULT_TEXT_SIZE_MAX_PIXELS, DEFAULT_TEXT_SIZE_MIN_PIXELS, type DrawImageDraft, type DrawMeasureDraft, type DrawOptions, type DrawPointSymbolDraft, type DrawSession, type EditChangeEvent, type EditManyOptions, type EditMode, type EditOptions, type EditPointerDriver, type EditSession, type FeatureGroup, type Graphic, type GraphicEditChangeEvent, type GraphicEditSession, type GraphicGeometrySnappingOptions, type GraphicRender, type GraphicSnapshot, type GuideStyle, HATCH_PATTERNS, type HandleStyle, type HatchPattern, type IconResource, type ImageCapability, ImageCapabilityRequiredError, type ImageFootprint, type ImageGraphic, type ImageGraphicStyle, type ImageIntrinsicSize, type ImageOverlayResource, type ImageRender, type ImageResource, type ImageSize, type InteractionHit, type InteractionStyle, type LabelExtent, type LayerId, type MapAdapter, type MapCursor, type MapEvent, type MapEventHandler, type MergedPickFeature, type NativeEventEntry, type PickCandidate, type PickCandidateHit, type PickCandidateHitKind, type PickCandidateInput, type PickEvaluationContext, type PickEvent, type PickHandler, type PickOptions, type PickPointerType, type PixelCoordinate, type PointSymbol, type PointSymbolAnchor, type PointSymbolCapability, PointSymbolCapabilityRequiredError, type PointSymbolColors, type PointSymbolFootprint, type PointSymbolGraphicModifiers, type PointSymbolRender, type PointSymbolSize, type PointSymbolStyle, type PointerCallback, PointerCallbackHub, type PointerEventInfo, type ResolvedPickPresentation, type RotatedScreenBounds, type ScreenBounds, type SessionChangeSource, type SessionHistory, type SessionHistoryState, type SettleReason, type SizeAnchor, type SnapCandidate, type SnapCandidateProvider, type SnapCandidateRequest, type SnapInteraction, type SnapResult, type SnappingOptions, type StyleOptions, TEXT_HALO_COLOR, TOUCH_HIT_TOLERANCE_PX, TacticalDraw, TacticalDrawAbortError, type TacticalDrawAbortReason, TacticalDrawDestroyedError, type TacticalDrawLayerOptions, type TacticalDrawOptions, type TextSizeProps, type TextStyleOptions, type ToPixel, type TransformBox, type TransformChangeEvent, type TransformSession, type TransientChangeEvent, type TransientPhase, bindAbortable, cloneImageGraphic, clonePointSymbol, coerceHandleStyle, combineWithHostSignal, effectivePointSymbolPixelSize, evaluatePickCandidates, fillPatternImageDimension, fillPatternImageId, getSizeAnchor, hitTestFeature, hitTestIconFeature, ignoreAbort, imageFootprint, imageOpacity, isAnchoredGraphic, isImageGraphic, isPointSymbol, isTacticalDrawAbortError, makeFillPatternImage, mergeNativeAndCachedPickFeatures, nearestWorldCopyLng, nearestWorldCopyPosition, normalizeImageGraphic, pickHitTolerance, pickPointerType, pointSymbolFootprint, renderOrderToVisualOrder, resizePointSymbolSize, resolveGroundTextSizePixels, resolvePickPresentation, resolveTextHaloWidth, resolveTextSizePixels, tryControlMeasureIdFromFeature, validateImageGraphic };
|
package/dist/index.mjs
CHANGED
|
@@ -220,11 +220,11 @@ function evaluateGeometry(feature, presentation, context) {
|
|
|
220
220
|
distance
|
|
221
221
|
} : null;
|
|
222
222
|
}
|
|
223
|
-
if (geometry.type === "Polygon") return evaluatePolygon(pixel, geometry.coordinates, presentation, context);
|
|
224
|
-
if (geometry.type === "MultiPolygon") return bestPolygonHit(geometry.coordinates.map((polygon) => evaluatePolygon(pixel, polygon, presentation, context)).filter((hit) => hit !== null));
|
|
223
|
+
if (geometry.type === "Polygon") return evaluatePolygon(pixel, geometry.coordinates, presentation, context, feature.properties?.pickInterior === true);
|
|
224
|
+
if (geometry.type === "MultiPolygon") return bestPolygonHit(geometry.coordinates.map((polygon) => evaluatePolygon(pixel, polygon, presentation, context, feature.properties?.pickInterior === true)).filter((hit) => hit !== null));
|
|
225
225
|
return null;
|
|
226
226
|
}
|
|
227
|
-
function evaluatePolygon(pixel, rings, presentation, context) {
|
|
227
|
+
function evaluatePolygon(pixel, rings, presentation, context, pickInterior) {
|
|
228
228
|
const { tolerance, toPixel, viewport } = context;
|
|
229
229
|
const projectedRings = rings.map((ring) => ring.map(toPixel));
|
|
230
230
|
const distance = hasVisibleBoundary(presentation) ? minimum(projectedRings.map((points) => minVisibleSegmentDistance(pixel, points, viewport))) : null;
|
|
@@ -235,7 +235,7 @@ function evaluatePolygon(pixel, rings, presentation, context) {
|
|
|
235
235
|
if (!(projectedRings.length > 0 && pointInProjectedRing(pixel, projectedRings[0]) && !projectedRings.slice(1).some((points) => pointInProjectedRing(pixel, points)))) return null;
|
|
236
236
|
const visiblyFilled = (presentation.fill?.opacity ?? 0) > 0;
|
|
237
237
|
const inwardReach = context.pointerType === "touch" ? 36 : 24;
|
|
238
|
-
if (visiblyFilled || distance !== null && distance <= inwardReach) return {
|
|
238
|
+
if (pickInterior || visiblyFilled || distance !== null && distance <= inwardReach) return {
|
|
239
239
|
kind: "polygon-interior",
|
|
240
240
|
distance
|
|
241
241
|
};
|
|
@@ -487,6 +487,7 @@ var BaseMapAdapter = class {
|
|
|
487
487
|
id: group.id,
|
|
488
488
|
features: [...group.features],
|
|
489
489
|
iconResources: [...group.iconResources],
|
|
490
|
+
...group.imageOverlays ? { imageOverlays: [...group.imageOverlays] } : {},
|
|
490
491
|
revision: group.revision
|
|
491
492
|
}));
|
|
492
493
|
const nextFeatures = nextGroups.flatMap((group) => group.features);
|
|
@@ -615,6 +616,7 @@ function indexFeatureGroupOrder(groups) {
|
|
|
615
616
|
function validateFeatureGroups(groups) {
|
|
616
617
|
const groupIds = /* @__PURE__ */ new Set();
|
|
617
618
|
const featureIds = /* @__PURE__ */ new Set();
|
|
619
|
+
const overlayIds = /* @__PURE__ */ new Set();
|
|
618
620
|
for (const group of groups) {
|
|
619
621
|
if (typeof group.id !== "string" || group.id.trim().length === 0) throw new Error("Feature group id must be a non-empty string");
|
|
620
622
|
if (groupIds.has(group.id)) throw new Error(`Duplicate feature group id: ${group.id}`);
|
|
@@ -624,6 +626,12 @@ function validateFeatureGroups(groups) {
|
|
|
624
626
|
if (featureIds.has(feature.id)) throw new Error(`Duplicate feature id: ${String(feature.id)}`);
|
|
625
627
|
featureIds.add(feature.id);
|
|
626
628
|
}
|
|
629
|
+
for (const overlay of group.imageOverlays ?? []) {
|
|
630
|
+
if (!overlay.id) throw new Error(`Image overlay in group "${group.id}" is missing an id`);
|
|
631
|
+
if (overlayIds.has(overlay.id)) throw new Error(`Duplicate image overlay id: ${overlay.id}`);
|
|
632
|
+
if (overlay.coordinates.length !== 4) throw new Error(`Image overlay "${overlay.id}" must have four coordinates`);
|
|
633
|
+
overlayIds.add(overlay.id);
|
|
634
|
+
}
|
|
627
635
|
}
|
|
628
636
|
}
|
|
629
637
|
//#endregion
|
|
@@ -849,6 +857,50 @@ function resizePointSymbolSize(size, value) {
|
|
|
849
857
|
};
|
|
850
858
|
}
|
|
851
859
|
//#endregion
|
|
860
|
+
//#region src/image-graphic.ts
|
|
861
|
+
function isImageGraphic(graphic) {
|
|
862
|
+
return typeof graphic === "object" && graphic !== null && "kind" in graphic && graphic.kind === "image";
|
|
863
|
+
}
|
|
864
|
+
function cloneImageGraphic(image) {
|
|
865
|
+
return structuredClone(image);
|
|
866
|
+
}
|
|
867
|
+
function normalizeImageGraphic(image) {
|
|
868
|
+
validateImageGraphic(image);
|
|
869
|
+
const next = cloneImageGraphic(image);
|
|
870
|
+
next.rotation = normalizeImageRotation(next.rotation);
|
|
871
|
+
if (next.style?.opacity !== void 0) next.style.opacity = Math.max(0, Math.min(1, next.style.opacity));
|
|
872
|
+
return next;
|
|
873
|
+
}
|
|
874
|
+
function imageOpacity(image) {
|
|
875
|
+
const opacity = image.style?.opacity ?? 1;
|
|
876
|
+
if (!Number.isFinite(opacity)) throw new TypeError("ImageGraphic.style.opacity must be finite");
|
|
877
|
+
return Math.max(0, Math.min(1, opacity));
|
|
878
|
+
}
|
|
879
|
+
function validateImageGraphic(image) {
|
|
880
|
+
if (!image.id) throw new TypeError("ImageGraphic.id must not be empty");
|
|
881
|
+
if (!image.resourceId) throw new TypeError("ImageGraphic.resourceId must not be empty");
|
|
882
|
+
if (!isFinitePositive(image.intrinsicSize.width)) throw new TypeError("ImageGraphic.intrinsicSize.width must be a positive finite number");
|
|
883
|
+
if (!isFinitePositive(image.intrinsicSize.height)) throw new TypeError("ImageGraphic.intrinsicSize.height must be a positive finite number");
|
|
884
|
+
if (!isFinitePositive(image.size.value)) throw new TypeError("ImageGraphic.size.value must be a positive finite number");
|
|
885
|
+
if (image.size.unit !== "meters") throw new TypeError("ImageGraphic.size.unit must be \"meters\"");
|
|
886
|
+
if (!Number.isFinite(image.rotation)) throw new TypeError("ImageGraphic.rotation must be finite");
|
|
887
|
+
if (image.schemaVersion !== 1) throw new TypeError("ImageGraphic.schemaVersion must be 1");
|
|
888
|
+
imageOpacity(image);
|
|
889
|
+
if (!Array.isArray(image.position) || image.position.length < 2 || !Number.isFinite(image.position[0]) || !Number.isFinite(image.position[1])) throw new TypeError("ImageGraphic.position must be a finite geographic position");
|
|
890
|
+
}
|
|
891
|
+
function isFinitePositive(value) {
|
|
892
|
+
return Number.isFinite(value) && value > 0;
|
|
893
|
+
}
|
|
894
|
+
function normalizeImageRotation(value) {
|
|
895
|
+
const turn = Math.PI * 2;
|
|
896
|
+
return (value % turn + turn) % turn;
|
|
897
|
+
}
|
|
898
|
+
//#endregion
|
|
899
|
+
//#region src/graphic.ts
|
|
900
|
+
function isAnchoredGraphic(graphic) {
|
|
901
|
+
return isPointSymbol(graphic) || isImageGraphic(graphic);
|
|
902
|
+
}
|
|
903
|
+
//#endregion
|
|
852
904
|
//#region src/tactical-draw/active-interaction.ts
|
|
853
905
|
/**
|
|
854
906
|
* Owns the facade's public interaction state: the abort handle used by
|
|
@@ -1441,7 +1493,7 @@ const DEFAULT_TOLERANCE_PIXELS = 12;
|
|
|
1441
1493
|
function graphicCandidates(graphics) {
|
|
1442
1494
|
const candidates = [];
|
|
1443
1495
|
for (const graphic of graphics) {
|
|
1444
|
-
if (
|
|
1496
|
+
if (isAnchoredGraphic(graphic)) {
|
|
1445
1497
|
candidates.push({
|
|
1446
1498
|
id: `${graphic.id}:anchor`,
|
|
1447
1499
|
coordinate: graphic.position,
|
|
@@ -4953,6 +5005,13 @@ var PointSymbolCapabilityRequiredError = class extends Error {
|
|
|
4953
5005
|
this.name = "PointSymbolCapabilityRequiredError";
|
|
4954
5006
|
}
|
|
4955
5007
|
};
|
|
5008
|
+
var ImageCapabilityRequiredError = class ImageCapabilityRequiredError extends Error {
|
|
5009
|
+
constructor() {
|
|
5010
|
+
super("TacticalDraw: image capability is not configured");
|
|
5011
|
+
this.name = "ImageCapabilityRequiredError";
|
|
5012
|
+
Object.setPrototypeOf(this, ImageCapabilityRequiredError.prototype);
|
|
5013
|
+
}
|
|
5014
|
+
};
|
|
4956
5015
|
//#endregion
|
|
4957
5016
|
//#region src/tactical-draw/point-symbol-rendering.ts
|
|
4958
5017
|
function effectivePointSymbolPixelSize(symbol, resolution) {
|
|
@@ -5037,6 +5096,117 @@ function boundProperty(key, value) {
|
|
|
5037
5096
|
return value !== void 0 && Number.isFinite(value) && value > 0 ? { [key]: value } : {};
|
|
5038
5097
|
}
|
|
5039
5098
|
//#endregion
|
|
5099
|
+
//#region src/tactical-draw/image-rendering.ts
|
|
5100
|
+
function effectiveImagePixelWidth(image, resolution) {
|
|
5101
|
+
if (resolution === void 0 || resolution <= 0) return image.size.value;
|
|
5102
|
+
return image.size.value / resolution;
|
|
5103
|
+
}
|
|
5104
|
+
function imagePixelScale(image, render, resolution) {
|
|
5105
|
+
return effectiveImagePixelWidth(image, resolution) / render.width;
|
|
5106
|
+
}
|
|
5107
|
+
function imageFootprint(image, render, adapter) {
|
|
5108
|
+
const center = adapter.getPixelFromCoordinate(image.position);
|
|
5109
|
+
if (!center) return null;
|
|
5110
|
+
const scale = imagePixelScale(image, render, adapter.getResolution());
|
|
5111
|
+
const box = {
|
|
5112
|
+
center,
|
|
5113
|
+
halfWidth: render.width * scale / 2,
|
|
5114
|
+
halfHeight: render.height * scale / 2,
|
|
5115
|
+
angle: image.rotation - adapter.getBearing()
|
|
5116
|
+
};
|
|
5117
|
+
return {
|
|
5118
|
+
box,
|
|
5119
|
+
corners: boxCorners(box)
|
|
5120
|
+
};
|
|
5121
|
+
}
|
|
5122
|
+
function renderImageForAdapter(adapter, capability, image) {
|
|
5123
|
+
validateImageGraphic(image);
|
|
5124
|
+
const resolved = capability.resolve(image.resourceId);
|
|
5125
|
+
const source = resolved ? validateResolvedResource(image, resolved) : missingResource(image);
|
|
5126
|
+
const render = {
|
|
5127
|
+
resourceId: source.id,
|
|
5128
|
+
width: source.width,
|
|
5129
|
+
height: source.height,
|
|
5130
|
+
...resolved ? { overlayUrl: source.overlayUrl } : {},
|
|
5131
|
+
available: resolved !== void 0
|
|
5132
|
+
};
|
|
5133
|
+
const coordinates = imageOverlayCoordinates(adapter, image, render);
|
|
5134
|
+
return {
|
|
5135
|
+
render,
|
|
5136
|
+
...render.overlayUrl ? { overlay: {
|
|
5137
|
+
id: `${image.id}:image-overlay`,
|
|
5138
|
+
url: render.overlayUrl,
|
|
5139
|
+
width: render.width,
|
|
5140
|
+
height: render.height,
|
|
5141
|
+
coordinates,
|
|
5142
|
+
opacity: imageOpacity(image)
|
|
5143
|
+
} } : {},
|
|
5144
|
+
feature: imageOverlayFeature(image, coordinates, render.available)
|
|
5145
|
+
};
|
|
5146
|
+
}
|
|
5147
|
+
function imageOverlayCoordinates(adapter, image, render) {
|
|
5148
|
+
const [centerX, centerY] = adapter.fromLonLat(image.position);
|
|
5149
|
+
const halfWidth = image.size.value / 2;
|
|
5150
|
+
const halfHeight = image.size.value * render.height / render.width / 2;
|
|
5151
|
+
const cos = Math.cos(-image.rotation);
|
|
5152
|
+
const sin = Math.sin(-image.rotation);
|
|
5153
|
+
const rotate = (x, y) => adapter.toLonLat([centerX + x * cos - y * sin, centerY + x * sin + y * cos]);
|
|
5154
|
+
return [
|
|
5155
|
+
rotate(-halfWidth, halfHeight),
|
|
5156
|
+
rotate(halfWidth, halfHeight),
|
|
5157
|
+
rotate(halfWidth, -halfHeight),
|
|
5158
|
+
rotate(-halfWidth, -halfHeight)
|
|
5159
|
+
];
|
|
5160
|
+
}
|
|
5161
|
+
function imageOverlayFeature(image, coordinates, available) {
|
|
5162
|
+
return {
|
|
5163
|
+
type: "Feature",
|
|
5164
|
+
id: `${image.id}:image`,
|
|
5165
|
+
geometry: {
|
|
5166
|
+
type: "Polygon",
|
|
5167
|
+
coordinates: [[...coordinates.map((coordinate) => [...coordinate]), [...coordinates[0]]]]
|
|
5168
|
+
},
|
|
5169
|
+
properties: {
|
|
5170
|
+
...image.properties ?? {},
|
|
5171
|
+
graphicId: image.id,
|
|
5172
|
+
graphicKind: "image",
|
|
5173
|
+
imageOverlayId: `${image.id}:image-overlay`,
|
|
5174
|
+
imageAvailable: available,
|
|
5175
|
+
pickInterior: true,
|
|
5176
|
+
style: available ? {
|
|
5177
|
+
fillColor: "rgba(0,0,0,0)",
|
|
5178
|
+
strokeColor: "rgba(0,0,0,0)",
|
|
5179
|
+
strokeWidth: 0
|
|
5180
|
+
} : {
|
|
5181
|
+
fillColor: "rgba(243,244,246,0.85)",
|
|
5182
|
+
strokeColor: "#6b7280",
|
|
5183
|
+
strokeWidth: 2
|
|
5184
|
+
}
|
|
5185
|
+
}
|
|
5186
|
+
};
|
|
5187
|
+
}
|
|
5188
|
+
function validateResolvedResource(image, resource) {
|
|
5189
|
+
if (resource.id !== image.resourceId) throw new TypeError("ImageCapability returned a resource with a mismatched id");
|
|
5190
|
+
if (!isSelfContainedRasterDataUrl(resource.overlayUrl)) throw new TypeError("ImageResource.overlayUrl must be a self-contained raster data URL");
|
|
5191
|
+
if (!Number.isFinite(resource.width) || resource.width <= 0) throw new TypeError("ImageResource.width must be a positive finite number");
|
|
5192
|
+
if (!Number.isFinite(resource.height) || resource.height <= 0) throw new TypeError("ImageResource.height must be a positive finite number");
|
|
5193
|
+
if (resource.width !== image.intrinsicSize.width || resource.height !== image.intrinsicSize.height) throw new TypeError("ImageResource dimensions must match ImageGraphic.intrinsicSize");
|
|
5194
|
+
return resource;
|
|
5195
|
+
}
|
|
5196
|
+
function isSelfContainedRasterDataUrl(value) {
|
|
5197
|
+
const match = /^data:(image\/[a-z0-9.+-]+)(?:;[^,]*)?,.+$/is.exec(value);
|
|
5198
|
+
return match !== null && match[1].toLowerCase() !== "image/svg+xml";
|
|
5199
|
+
}
|
|
5200
|
+
function missingResource(image) {
|
|
5201
|
+
const { width, height } = image.intrinsicSize;
|
|
5202
|
+
return {
|
|
5203
|
+
id: `__td_missing_image__:${width}x${height}`,
|
|
5204
|
+
overlayUrl: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=",
|
|
5205
|
+
width,
|
|
5206
|
+
height
|
|
5207
|
+
};
|
|
5208
|
+
}
|
|
5209
|
+
//#endregion
|
|
5040
5210
|
//#region src/tactical-draw/frame-coalescer.ts
|
|
5041
5211
|
/**
|
|
5042
5212
|
* @param run Callback invoked with the latest scheduled args, at most once per frame.
|
|
@@ -5106,20 +5276,32 @@ function scalePointSymbolStates(pre, scale, rotation) {
|
|
|
5106
5276
|
* a live session without a session boundary
|
|
5107
5277
|
*/
|
|
5108
5278
|
function runGroupTransform(opts) {
|
|
5109
|
-
const { adapter, capability, graphics, graphicsLayer, previewLayer, handlesLayer, graphicsStyle, signal, closeOnClickAway = true, interactionStyle, onSession, handleIdPrefix, publishWorkingGraphics, settleWorkingGraphics, isOnGraphicsLayer, onSettled, onClickAwayGraphicsPick } = opts;
|
|
5279
|
+
const { adapter, capability, imageCapability, graphics, graphicsLayer, previewLayer, handlesLayer, graphicsStyle, signal, closeOnClickAway = true, interactionStyle, onSession, handleIdPrefix, publishWorkingGraphics, settleWorkingGraphics, isOnGraphicsLayer, onSettled, onClickAwayGraphicsPick } = opts;
|
|
5110
5280
|
assertCapabilityFor(graphics);
|
|
5281
|
+
validateImageResources(graphics);
|
|
5111
5282
|
const renderOpts = graphicsStyle ? { graphicsStyle } : void 0;
|
|
5112
5283
|
let sizeAnchor = opts.sizeAnchor ?? "ground";
|
|
5113
5284
|
/** Throw synchronously if any graphic in `list` is a point symbol and no capability was supplied. */
|
|
5114
5285
|
function assertCapabilityFor(list) {
|
|
5115
5286
|
if (!capability && list.some(isPointSymbol)) throw new PointSymbolCapabilityRequiredError();
|
|
5287
|
+
if (!imageCapability && list.some(isImageGraphic)) throw new ImageCapabilityRequiredError();
|
|
5288
|
+
}
|
|
5289
|
+
/** Validate host integration before listeners, layers, or interaction state are created. */
|
|
5290
|
+
function validateImageResources(list) {
|
|
5291
|
+
for (const graphic of list) if (isImageGraphic(graphic)) renderImageForAdapter(adapter, imageCapability, graphic);
|
|
5116
5292
|
}
|
|
5117
5293
|
function isPointSymbolMember(member) {
|
|
5118
5294
|
return isPointSymbol(member.graphic);
|
|
5119
5295
|
}
|
|
5296
|
+
function isImageMember(member) {
|
|
5297
|
+
return isImageGraphic(member.graphic);
|
|
5298
|
+
}
|
|
5299
|
+
function isAnchoredMember(member) {
|
|
5300
|
+
return isAnchoredGraphic(member.graphic);
|
|
5301
|
+
}
|
|
5120
5302
|
/** Build a fresh working record for `graphic`, snapshotting its edit-start state. */
|
|
5121
5303
|
function createMemberState(graphic) {
|
|
5122
|
-
if (
|
|
5304
|
+
if (isAnchoredGraphic(graphic)) {
|
|
5123
5305
|
const editStartPoints = [[...graphic.position]];
|
|
5124
5306
|
return {
|
|
5125
5307
|
graphic,
|
|
@@ -5175,6 +5357,16 @@ function runGroupTransform(opts) {
|
|
|
5175
5357
|
symbol.rotation = member.workingRotation;
|
|
5176
5358
|
return symbol;
|
|
5177
5359
|
}
|
|
5360
|
+
function buildWorkingImage(member) {
|
|
5361
|
+
const image = cloneImageGraphic(member.graphic);
|
|
5362
|
+
image.position = [...member.workingPoints[0]];
|
|
5363
|
+
image.size = {
|
|
5364
|
+
value: member.workingSize,
|
|
5365
|
+
unit: "meters"
|
|
5366
|
+
};
|
|
5367
|
+
image.rotation = member.workingRotation;
|
|
5368
|
+
return image;
|
|
5369
|
+
}
|
|
5178
5370
|
/** Build the working measure for member `i` with a given options override. */
|
|
5179
5371
|
function buildWorkingMeasureWith(member, override) {
|
|
5180
5372
|
const measure = member.graphic;
|
|
@@ -5195,6 +5387,13 @@ function runGroupTransform(opts) {
|
|
|
5195
5387
|
render: capability.render(symbol)
|
|
5196
5388
|
};
|
|
5197
5389
|
}
|
|
5390
|
+
if (isImageMember(member)) {
|
|
5391
|
+
const image = buildWorkingImage(member);
|
|
5392
|
+
return {
|
|
5393
|
+
graphic: cloneImageGraphic(image),
|
|
5394
|
+
render: renderImageForAdapter(adapter, imageCapability, image).render
|
|
5395
|
+
};
|
|
5396
|
+
}
|
|
5198
5397
|
const working = buildWorkingMeasureWith(member, override);
|
|
5199
5398
|
const committed = sizeAnchor === "screen" ? working : bakePixelSizeToGround(working, adapter);
|
|
5200
5399
|
return {
|
|
@@ -5206,6 +5405,7 @@ function runGroupTransform(opts) {
|
|
|
5206
5405
|
function workingGraphicFor(i) {
|
|
5207
5406
|
const member = members[i];
|
|
5208
5407
|
if (isPointSymbolMember(member)) return buildWorkingPointSymbol(member);
|
|
5408
|
+
if (isImageMember(member)) return buildWorkingImage(member);
|
|
5209
5409
|
return buildWorkingMeasureWith(member, member.optionsOverride);
|
|
5210
5410
|
}
|
|
5211
5411
|
let dirty = false;
|
|
@@ -5288,7 +5488,7 @@ function runGroupTransform(opts) {
|
|
|
5288
5488
|
const { scale, rotation } = boxScaleRotation(kind, box, fromBox);
|
|
5289
5489
|
if (scale === 1 && rotation === 0) return;
|
|
5290
5490
|
members.forEach((member, i) => {
|
|
5291
|
-
if (
|
|
5491
|
+
if (isAnchoredMember(member)) return;
|
|
5292
5492
|
const base = baseOverrides[i] ?? null;
|
|
5293
5493
|
const effective = mergeOptions(member.graphic.options, base);
|
|
5294
5494
|
const patch = applyBoxTransformOptions(member.graphic.kind, effective, {
|
|
@@ -5331,8 +5531,16 @@ function runGroupTransform(opts) {
|
|
|
5331
5531
|
members.forEach((member, i) => {
|
|
5332
5532
|
let features;
|
|
5333
5533
|
let iconResources = [];
|
|
5534
|
+
let imageOverlays;
|
|
5334
5535
|
let boxPixels = [];
|
|
5335
|
-
|
|
5536
|
+
if (isImageMember(member)) {
|
|
5537
|
+
const image = buildWorkingImage(member);
|
|
5538
|
+
const plan = renderImageForAdapter(adapter, imageCapability, image);
|
|
5539
|
+
imageOverlays = plan.overlay ? [plan.overlay] : void 0;
|
|
5540
|
+
features = [plan.feature];
|
|
5541
|
+
const footprint = imageFootprint(image, plan.render, adapter);
|
|
5542
|
+
if (footprint) boxPixels = footprint.corners;
|
|
5543
|
+
} else try {
|
|
5336
5544
|
if (isPointSymbolMember(member)) {
|
|
5337
5545
|
const symbol = buildWorkingPointSymbol(member);
|
|
5338
5546
|
const plan = renderPointSymbolForAdapter(adapter, capability, symbol);
|
|
@@ -5353,12 +5561,14 @@ function runGroupTransform(opts) {
|
|
|
5353
5561
|
if (member.usesGraphicStack) workingGroups.push({
|
|
5354
5562
|
id: member.graphic.id,
|
|
5355
5563
|
features,
|
|
5356
|
-
iconResources
|
|
5564
|
+
iconResources,
|
|
5565
|
+
...imageOverlays ? { imageOverlays } : {}
|
|
5357
5566
|
});
|
|
5358
5567
|
else previewGroups.push({
|
|
5359
5568
|
id: member.graphic.id,
|
|
5360
5569
|
features,
|
|
5361
|
-
iconResources
|
|
5570
|
+
iconResources,
|
|
5571
|
+
...imageOverlays ? { imageOverlays } : {}
|
|
5362
5572
|
});
|
|
5363
5573
|
});
|
|
5364
5574
|
publishWorkingGraphics(workingGroups);
|
|
@@ -5367,7 +5577,7 @@ function runGroupTransform(opts) {
|
|
|
5367
5577
|
}
|
|
5368
5578
|
function rescaleOnViewChange() {
|
|
5369
5579
|
if (ctx.settled) return;
|
|
5370
|
-
if (members.some((m) =>
|
|
5580
|
+
if (members.some((m) => isAnchoredMember(m) || measureRendersFromViewState({
|
|
5371
5581
|
kind: m.graphic.kind,
|
|
5372
5582
|
options: m.graphic.options
|
|
5373
5583
|
}))) renderAllPreviews();
|
|
@@ -5403,7 +5613,7 @@ function runGroupTransform(opts) {
|
|
|
5403
5613
|
return members.map((member) => buildMemberSnapshot(member, member.optionsOverride));
|
|
5404
5614
|
}
|
|
5405
5615
|
function recomputeDirty() {
|
|
5406
|
-
dirty = nonGeometryDirty || members.some((m) => !pointsEqualWithinTolerance(m.workingPoints, m.editStartPoints, 1e-9) ||
|
|
5616
|
+
dirty = nonGeometryDirty || members.some((m) => !pointsEqualWithinTolerance(m.workingPoints, m.editStartPoints, 1e-9) || isAnchoredMember(m) && (m.workingSize !== m.editStartSize || m.workingRotation !== m.editStartRotation));
|
|
5407
5617
|
}
|
|
5408
5618
|
/** Split `points` (the concatenation of every member's anchor points) back per member. */
|
|
5409
5619
|
function applyConcatenatedPoints(points) {
|
|
@@ -5431,7 +5641,7 @@ function runGroupTransform(opts) {
|
|
|
5431
5641
|
}
|
|
5432
5642
|
/** Snapshot each point-symbol member's working size/rotation (`null` for measures). */
|
|
5433
5643
|
function clonePointSymbolStateByMember() {
|
|
5434
|
-
return members.map((m) =>
|
|
5644
|
+
return members.map((m) => isAnchoredMember(m) ? {
|
|
5435
5645
|
size: m.workingSize,
|
|
5436
5646
|
rotation: m.workingRotation
|
|
5437
5647
|
} : null);
|
|
@@ -5440,7 +5650,7 @@ function runGroupTransform(opts) {
|
|
|
5440
5650
|
function applyPointSymbolStateByMember(states) {
|
|
5441
5651
|
members.forEach((member, i) => {
|
|
5442
5652
|
const state = states[i];
|
|
5443
|
-
if (state &&
|
|
5653
|
+
if (state && isAnchoredMember(member)) {
|
|
5444
5654
|
member.workingSize = state.size;
|
|
5445
5655
|
member.workingRotation = state.rotation;
|
|
5446
5656
|
}
|
|
@@ -5480,7 +5690,7 @@ function runGroupTransform(opts) {
|
|
|
5480
5690
|
*/
|
|
5481
5691
|
function freezeOrientationForRotate() {
|
|
5482
5692
|
members.forEach((member, i) => {
|
|
5483
|
-
if (
|
|
5693
|
+
if (isAnchoredMember(member)) return;
|
|
5484
5694
|
const patch = freezeOrientationOptions(member.graphic.kind, member.workingPoints.map((p) => [...p]), effectiveOptions(i));
|
|
5485
5695
|
if (patch) member.optionsOverride = {
|
|
5486
5696
|
...member.optionsOverride ?? {},
|
|
@@ -5696,7 +5906,7 @@ function runGroupTransform(opts) {
|
|
|
5696
5906
|
},
|
|
5697
5907
|
controlPointsFor(graphicId) {
|
|
5698
5908
|
const member = members.find((m) => m.graphic.id === graphicId);
|
|
5699
|
-
if (!member ||
|
|
5909
|
+
if (!member || isAnchoredMember(member)) return void 0;
|
|
5700
5910
|
return member.workingPoints.map((p) => [...p]);
|
|
5701
5911
|
},
|
|
5702
5912
|
get dirty() {
|
|
@@ -5818,7 +6028,7 @@ function runGroupTransform(opts) {
|
|
|
5818
6028
|
applyConcatenatedPoints(preDragPoints);
|
|
5819
6029
|
applyPointSymbolStateByMember(preDragPointSymbolStateByMember);
|
|
5820
6030
|
applyAmplifierPlacementsByMember(preDragAmplifierPlacementsByMember);
|
|
5821
|
-
if (members.some(
|
|
6031
|
+
if (members.some(isAnchoredMember)) shell.suppressNextClickAway();
|
|
5822
6032
|
if (fsm.kind === "rotate") boxAngle += finalSnapshot.box.angle - preDragBox.angle;
|
|
5823
6033
|
applyMeasureTransformForBox(finalSnapshot.box, preDragBox, fsm.kind, preDragOptionsOverrideByMember);
|
|
5824
6034
|
commitGesture(finalSnapshot.points, preDragOptionsOverrideByMember, preDragAmplifierPlacementsByMember.map((placements) => transformAmplifierPlacements(placements, preDragBox, finalSnapshot.box, driver)), preDragBox.angle, nextPointSymbolStateByMember);
|
|
@@ -5885,7 +6095,7 @@ function runGroupTransform(opts) {
|
|
|
5885
6095
|
}
|
|
5886
6096
|
//#endregion
|
|
5887
6097
|
//#region src/tactical-draw/point-symbol-draw-controller.ts
|
|
5888
|
-
const PREVIEW_ID = "__td_point_symbol_preview__";
|
|
6098
|
+
const PREVIEW_ID$1 = "__td_point_symbol_preview__";
|
|
5889
6099
|
function runPointSymbolDraw(options) {
|
|
5890
6100
|
const { adapter, capability, draft, previewLayer, generateId, signal, onSettled, snap } = options;
|
|
5891
6101
|
let latestPosition = draft.position;
|
|
@@ -5902,9 +6112,9 @@ function runPointSymbolDraw(options) {
|
|
|
5902
6112
|
});
|
|
5903
6113
|
const renderPreview = () => {
|
|
5904
6114
|
if (!latestPosition) return;
|
|
5905
|
-
const plan = renderPointSymbolForAdapter(adapter, capability, build(PREVIEW_ID, latestPosition));
|
|
6115
|
+
const plan = renderPointSymbolForAdapter(adapter, capability, build(PREVIEW_ID$1, latestPosition));
|
|
5906
6116
|
ctx.writeLayer(previewLayer, [{
|
|
5907
|
-
id: PREVIEW_ID,
|
|
6117
|
+
id: PREVIEW_ID$1,
|
|
5908
6118
|
features: [plan.feature],
|
|
5909
6119
|
iconResources: [plan.resource]
|
|
5910
6120
|
}]);
|
|
@@ -6191,6 +6401,338 @@ function runPointSymbolEdit(opts) {
|
|
|
6191
6401
|
return usesGraphicStack;
|
|
6192
6402
|
},
|
|
6193
6403
|
measureId: symbol.id,
|
|
6404
|
+
graphicKind: "point-symbol",
|
|
6405
|
+
abort: handle.abort,
|
|
6406
|
+
syncHostMembership(present) {
|
|
6407
|
+
if (handle.settled || usesGraphicStack === present) return;
|
|
6408
|
+
const previous = usesGraphicStack;
|
|
6409
|
+
usesGraphicStack = present;
|
|
6410
|
+
try {
|
|
6411
|
+
render();
|
|
6412
|
+
} catch (error) {
|
|
6413
|
+
usesGraphicStack = previous;
|
|
6414
|
+
throw error;
|
|
6415
|
+
}
|
|
6416
|
+
}
|
|
6417
|
+
};
|
|
6418
|
+
}
|
|
6419
|
+
//#endregion
|
|
6420
|
+
//#region src/tactical-draw/image-draw-controller.ts
|
|
6421
|
+
const PREVIEW_ID = "__td_image_preview__";
|
|
6422
|
+
const DEFAULT_IMAGE_WIDTH_PIXELS = 128;
|
|
6423
|
+
function runImageDraw(options) {
|
|
6424
|
+
const { adapter, capability, draft, previewLayer, generateId, signal, onSettled, snap } = options;
|
|
6425
|
+
let latestPosition = draft.position;
|
|
6426
|
+
let ctx;
|
|
6427
|
+
const savedCursor = "";
|
|
6428
|
+
const build = (id, position) => ({
|
|
6429
|
+
...structuredClone(draft),
|
|
6430
|
+
id,
|
|
6431
|
+
kind: "image",
|
|
6432
|
+
resourceId: draft.resourceId,
|
|
6433
|
+
intrinsicSize: structuredClone(draft.intrinsicSize),
|
|
6434
|
+
position: [...position],
|
|
6435
|
+
rotation: normalizeRotation(draft.rotation ?? 0),
|
|
6436
|
+
schemaVersion: 1,
|
|
6437
|
+
size: structuredClone(draft.size ?? {
|
|
6438
|
+
value: DEFAULT_IMAGE_WIDTH_PIXELS * positiveResolution(adapter.getResolution()),
|
|
6439
|
+
unit: "meters"
|
|
6440
|
+
}),
|
|
6441
|
+
...draft.style ? { style: {
|
|
6442
|
+
...draft.style,
|
|
6443
|
+
opacity: Math.max(0, Math.min(1, draft.style.opacity ?? 1))
|
|
6444
|
+
} } : {}
|
|
6445
|
+
});
|
|
6446
|
+
const planFor = (id, position) => renderImageForAdapter(adapter, capability, build(id, position));
|
|
6447
|
+
const renderPreview = () => {
|
|
6448
|
+
if (!latestPosition) return;
|
|
6449
|
+
const plan = planFor(PREVIEW_ID, latestPosition);
|
|
6450
|
+
ctx.writeLayer(previewLayer, [{
|
|
6451
|
+
id: PREVIEW_ID,
|
|
6452
|
+
features: [plan.feature],
|
|
6453
|
+
iconResources: [],
|
|
6454
|
+
...plan.overlay ? { imageOverlays: [plan.overlay] } : {}
|
|
6455
|
+
}]);
|
|
6456
|
+
};
|
|
6457
|
+
const handlePointerMove = (event) => {
|
|
6458
|
+
latestPosition = snappedDrawPosition(snap, event);
|
|
6459
|
+
renderPreview();
|
|
6460
|
+
};
|
|
6461
|
+
const handleClick = (event) => {
|
|
6462
|
+
latestPosition = snappedDrawPosition(snap, event);
|
|
6463
|
+
ctx.commit(() => {
|
|
6464
|
+
const graphic = build(draft.id ?? generateId(), latestPosition);
|
|
6465
|
+
return {
|
|
6466
|
+
graphic: cloneImageGraphic(graphic),
|
|
6467
|
+
render: planFor(graphic.id, graphic.position).render
|
|
6468
|
+
};
|
|
6469
|
+
});
|
|
6470
|
+
};
|
|
6471
|
+
return runInteraction({
|
|
6472
|
+
adapter,
|
|
6473
|
+
signal,
|
|
6474
|
+
layers: [previewLayer],
|
|
6475
|
+
onViewChange: renderPreview,
|
|
6476
|
+
onSettled,
|
|
6477
|
+
attach(interaction) {
|
|
6478
|
+
ctx = interaction;
|
|
6479
|
+
interaction.onTeardown(() => {
|
|
6480
|
+
adapter.off("pointermove", handlePointerMove);
|
|
6481
|
+
adapter.off("click", handleClick);
|
|
6482
|
+
adapter.setCursor(savedCursor);
|
|
6483
|
+
});
|
|
6484
|
+
adapter.setCursor("crosshair");
|
|
6485
|
+
adapter.on("pointermove", handlePointerMove);
|
|
6486
|
+
adapter.on("click", handleClick);
|
|
6487
|
+
renderPreview();
|
|
6488
|
+
}
|
|
6489
|
+
});
|
|
6490
|
+
}
|
|
6491
|
+
function positiveResolution(resolution) {
|
|
6492
|
+
return resolution !== void 0 && resolution > 0 ? resolution : 1;
|
|
6493
|
+
}
|
|
6494
|
+
//#endregion
|
|
6495
|
+
//#region src/tactical-draw/image-edit-controller.ts
|
|
6496
|
+
function normaliseImageModes(input) {
|
|
6497
|
+
const modes = input ?? ["transform"];
|
|
6498
|
+
for (const mode of modes) if (mode !== "transform" && mode !== "delete") throw new TypeError(`Image editing does not support mode "${mode}"`);
|
|
6499
|
+
return modes.includes("delete") ? ["delete"] : [...new Set(modes)];
|
|
6500
|
+
}
|
|
6501
|
+
function runImageEdit(opts) {
|
|
6502
|
+
const { adapter, capability, image, graphicsLayer, previewLayer, handlesLayer, signal, closeOnClickAway = true, interactionStyle, onSession, handleIdPrefix, settleToGraphics, publishWorkingGraphic, wasOnGraphicsLayer, onSettled, onClickAwayGraphicsPick, snap } = opts;
|
|
6503
|
+
validateImageGraphic(image);
|
|
6504
|
+
let modes = normaliseImageModes(opts.modes);
|
|
6505
|
+
let usesGraphicStack = wasOnGraphicsLayer;
|
|
6506
|
+
let working = cloneImageGraphic(image);
|
|
6507
|
+
let dirty = false;
|
|
6508
|
+
let box = null;
|
|
6509
|
+
let drag = null;
|
|
6510
|
+
let ctx;
|
|
6511
|
+
let driver;
|
|
6512
|
+
let shell;
|
|
6513
|
+
const changeEmitter = createChangeEmitter({
|
|
6514
|
+
listenerErrorsMessage: "GraphicEditSession.onChange errors",
|
|
6515
|
+
isSettled: () => ctx.settled,
|
|
6516
|
+
abort: () => ctx.fail(new TacticalDrawAbortError("session")),
|
|
6517
|
+
close: () => ctx.commit(snapshot)
|
|
6518
|
+
});
|
|
6519
|
+
const commitEmitter = createCommitEmitter("GraphicEditSession.onCommit listener errors");
|
|
6520
|
+
const settleEmitter = createSettleEmitter("GraphicEditSession.onSettled listener errors");
|
|
6521
|
+
const captureHistory = () => ({ working: cloneImageGraphic(working) });
|
|
6522
|
+
const snapshot = () => ({
|
|
6523
|
+
graphic: cloneImageGraphic(working),
|
|
6524
|
+
render: renderImageForAdapter(adapter, capability, working).render
|
|
6525
|
+
});
|
|
6526
|
+
const render = (publishGraphic = true) => {
|
|
6527
|
+
if (ctx.settled) return;
|
|
6528
|
+
const plan = renderImageForAdapter(adapter, capability, working);
|
|
6529
|
+
const footprint = imageFootprint(working, plan.render, adapter);
|
|
6530
|
+
const nextBox = footprint ? {
|
|
6531
|
+
...footprint.box,
|
|
6532
|
+
halfWidth: Math.max(1, footprint.box.halfWidth) + (interactionStyle?.boxPadding ?? 0),
|
|
6533
|
+
halfHeight: Math.max(1, footprint.box.halfHeight) + (interactionStyle?.boxPadding ?? 0)
|
|
6534
|
+
} : null;
|
|
6535
|
+
const handles = [];
|
|
6536
|
+
if (modes.includes("transform") && nextBox) handles.push(boxOutlineFeature(nextBox, (pixel) => driver.fromPixel(pixel), `${handleIdPrefix}:box-outline`, interactionStyle?.boxOutline), ...toFeatures(boxToHandles(nextBox, (pixel) => driver.fromPixel(pixel)), handleIdPrefix, interactionStyle));
|
|
6537
|
+
const group = {
|
|
6538
|
+
id: working.id,
|
|
6539
|
+
features: [plan.feature],
|
|
6540
|
+
iconResources: [],
|
|
6541
|
+
...plan.overlay ? { imageOverlays: [plan.overlay] } : {}
|
|
6542
|
+
};
|
|
6543
|
+
if (publishGraphic) {
|
|
6544
|
+
publishWorkingGraphic(group);
|
|
6545
|
+
ctx.writeLayer(previewLayer, usesGraphicStack ? [] : [group]);
|
|
6546
|
+
}
|
|
6547
|
+
box = nextBox;
|
|
6548
|
+
ctx.writeLayer(handlesLayer, [{
|
|
6549
|
+
id: `__td_image_edit_handles__:${working.id}`,
|
|
6550
|
+
features: handles,
|
|
6551
|
+
iconResources: []
|
|
6552
|
+
}]);
|
|
6553
|
+
};
|
|
6554
|
+
const emitChange = (previousState, source, onAccepted) => {
|
|
6555
|
+
const previous = {
|
|
6556
|
+
graphic: cloneImageGraphic(previousState.working),
|
|
6557
|
+
render: renderImageForAdapter(adapter, capability, previousState.working).render
|
|
6558
|
+
};
|
|
6559
|
+
return changeEmitter.emit({
|
|
6560
|
+
source,
|
|
6561
|
+
graphic: snapshot(),
|
|
6562
|
+
previous,
|
|
6563
|
+
session
|
|
6564
|
+
}, {
|
|
6565
|
+
rollback() {
|
|
6566
|
+
working = cloneImageGraphic(previousState.working);
|
|
6567
|
+
dirty = !deepEqual(working, image);
|
|
6568
|
+
render();
|
|
6569
|
+
},
|
|
6570
|
+
onAccepted
|
|
6571
|
+
});
|
|
6572
|
+
};
|
|
6573
|
+
const history = createSessionHistory({
|
|
6574
|
+
initial: captureHistory(),
|
|
6575
|
+
clone: (value) => ({ working: cloneImageGraphic(value.working) }),
|
|
6576
|
+
equals: (a, b) => deepEqual(a.working, b.working),
|
|
6577
|
+
isCurrent: (value) => deepEqual(working, value.working),
|
|
6578
|
+
apply(from, to, source) {
|
|
6579
|
+
working = cloneImageGraphic(to.working);
|
|
6580
|
+
dirty = !deepEqual(working, image);
|
|
6581
|
+
render();
|
|
6582
|
+
return emitChange(from, source);
|
|
6583
|
+
}
|
|
6584
|
+
});
|
|
6585
|
+
const apply = (next, source, label) => {
|
|
6586
|
+
const previous = captureHistory();
|
|
6587
|
+
working = cloneImageGraphic(next);
|
|
6588
|
+
dirty = !deepEqual(working, image);
|
|
6589
|
+
render();
|
|
6590
|
+
emitChange(previous, source, () => history.record(captureHistory(), label));
|
|
6591
|
+
};
|
|
6592
|
+
const session = {
|
|
6593
|
+
history,
|
|
6594
|
+
graphic: cloneImageGraphic(image),
|
|
6595
|
+
get workingGraphic() {
|
|
6596
|
+
return cloneImageGraphic(working);
|
|
6597
|
+
},
|
|
6598
|
+
get dirty() {
|
|
6599
|
+
return dirty;
|
|
6600
|
+
},
|
|
6601
|
+
get modes() {
|
|
6602
|
+
return modes;
|
|
6603
|
+
},
|
|
6604
|
+
close: () => ctx.commit(snapshot),
|
|
6605
|
+
abort: () => ctx.fail(new TacticalDrawAbortError("session")),
|
|
6606
|
+
setModes(next) {
|
|
6607
|
+
if (ctx.settled) return;
|
|
6608
|
+
modes = normaliseImageModes(next);
|
|
6609
|
+
render();
|
|
6610
|
+
},
|
|
6611
|
+
updateGraphic(updater) {
|
|
6612
|
+
if (ctx.settled) return;
|
|
6613
|
+
const next = normalizeImageGraphic(updater(cloneImageGraphic(working)));
|
|
6614
|
+
if (next.kind !== "image" || next.id !== image.id) throw new TypeError("updateGraphic must preserve image kind and id");
|
|
6615
|
+
validateImageGraphic(next);
|
|
6616
|
+
renderImageForAdapter(adapter, capability, next);
|
|
6617
|
+
apply(next, "programmatic", "Update graphic");
|
|
6618
|
+
},
|
|
6619
|
+
onChange(listener) {
|
|
6620
|
+
if (ctx.settled) return () => {};
|
|
6621
|
+
return changeEmitter.register(listener);
|
|
6622
|
+
},
|
|
6623
|
+
onCommit(listener) {
|
|
6624
|
+
if (ctx.settled) return () => {};
|
|
6625
|
+
return commitEmitter.register(listener);
|
|
6626
|
+
},
|
|
6627
|
+
onSettled(listener) {
|
|
6628
|
+
return settleEmitter.register(listener);
|
|
6629
|
+
}
|
|
6630
|
+
};
|
|
6631
|
+
const transformed = (pixel, info) => {
|
|
6632
|
+
if (!drag) return null;
|
|
6633
|
+
const next = cloneImageGraphic(drag.start);
|
|
6634
|
+
const result = drag.fsm.move(pixel, { constrainRotation: info?.shiftKey });
|
|
6635
|
+
next.position = [...result.points[0]];
|
|
6636
|
+
const delta = boxScaleRotation(drag.kind, result.box, drag.startBox);
|
|
6637
|
+
if (drag.kind === "scale") next.size = {
|
|
6638
|
+
value: Math.max(.1, next.size.value * delta.scale),
|
|
6639
|
+
unit: "meters"
|
|
6640
|
+
};
|
|
6641
|
+
else if (drag.kind === "rotate") next.rotation = normalizeRotation(next.rotation + delta.rotation);
|
|
6642
|
+
else {
|
|
6643
|
+
const anchorPixel = driver.toPixel(next.position) ?? pixel;
|
|
6644
|
+
const snapped = snap?.({
|
|
6645
|
+
coordinate: next.position,
|
|
6646
|
+
pixel: anchorPixel,
|
|
6647
|
+
interaction: "translate",
|
|
6648
|
+
graphicId: image.id,
|
|
6649
|
+
originalEvent: info?.native
|
|
6650
|
+
});
|
|
6651
|
+
if (snapped) next.position = snapped.coordinate;
|
|
6652
|
+
}
|
|
6653
|
+
return next;
|
|
6654
|
+
};
|
|
6655
|
+
const onDown = (pixel, info) => {
|
|
6656
|
+
if (ctx.settled || !box || !modes.includes("transform")) return;
|
|
6657
|
+
const hit = pickBoxHandle(box, pixel, info?.hitTolerance ?? 12);
|
|
6658
|
+
if (!hit) return;
|
|
6659
|
+
drag = {
|
|
6660
|
+
fsm: beginBoxDrag({
|
|
6661
|
+
kind: hit.kind,
|
|
6662
|
+
downPixel: pixel,
|
|
6663
|
+
points: [[...working.position]],
|
|
6664
|
+
projection: {
|
|
6665
|
+
toPixel: (position) => driver.toPixel(position),
|
|
6666
|
+
fromPixel: (coordinate) => driver.fromPixel(coordinate)
|
|
6667
|
+
},
|
|
6668
|
+
box,
|
|
6669
|
+
cornerIndex: hit.kind === "scale" ? hit.index : void 0
|
|
6670
|
+
}),
|
|
6671
|
+
kind: hit.kind,
|
|
6672
|
+
down: [...pixel],
|
|
6673
|
+
start: cloneImageGraphic(working),
|
|
6674
|
+
startBox: box
|
|
6675
|
+
};
|
|
6676
|
+
driver.setDragPanEnabled(false);
|
|
6677
|
+
};
|
|
6678
|
+
const onMove = (pixel, info) => {
|
|
6679
|
+
const next = transformed(pixel, info);
|
|
6680
|
+
if (!next) return;
|
|
6681
|
+
working = next;
|
|
6682
|
+
render();
|
|
6683
|
+
};
|
|
6684
|
+
const onUp = (pixel, info) => {
|
|
6685
|
+
if (!drag) return;
|
|
6686
|
+
const current = drag;
|
|
6687
|
+
const next = transformed(pixel, info);
|
|
6688
|
+
drag = null;
|
|
6689
|
+
shell.suppressNextClickAway();
|
|
6690
|
+
driver.setDragPanEnabled(true);
|
|
6691
|
+
working = cloneImageGraphic(current.start);
|
|
6692
|
+
if (!next) return;
|
|
6693
|
+
if (current.kind === "body" && withinClickSlop(pixel, current.down)) {
|
|
6694
|
+
render();
|
|
6695
|
+
return;
|
|
6696
|
+
}
|
|
6697
|
+
apply(next, "gesture", `${current.kind[0].toUpperCase()}${current.kind.slice(1)}`);
|
|
6698
|
+
};
|
|
6699
|
+
const handle = runEditInteraction({
|
|
6700
|
+
adapter,
|
|
6701
|
+
signal,
|
|
6702
|
+
layers: [previewLayer, handlesLayer],
|
|
6703
|
+
graphicsLayer,
|
|
6704
|
+
previewLayer,
|
|
6705
|
+
handlesLayer,
|
|
6706
|
+
closeOnClickAway,
|
|
6707
|
+
onViewChange: () => render(false),
|
|
6708
|
+
onBeforeTeardown: (settlement) => settleToGraphics(settlement.status === "committed" ? settlement.value.graphic : void 0),
|
|
6709
|
+
onDown,
|
|
6710
|
+
onMove,
|
|
6711
|
+
onUp,
|
|
6712
|
+
ownsGraphic: (id) => id === image.id,
|
|
6713
|
+
close: () => ctx.commit(snapshot),
|
|
6714
|
+
onForeignPick: onClickAwayGraphicsPick,
|
|
6715
|
+
historySettle: () => history.settle(),
|
|
6716
|
+
facadeOnSettled: onSettled,
|
|
6717
|
+
emitSettle: (settlement) => settleFromInteraction(settlement, commitEmitter, settleEmitter),
|
|
6718
|
+
attach(interaction, createdDriver, createdShell) {
|
|
6719
|
+
ctx = interaction;
|
|
6720
|
+
driver = createdDriver;
|
|
6721
|
+
shell = createdShell;
|
|
6722
|
+
render();
|
|
6723
|
+
onSession?.(session);
|
|
6724
|
+
}
|
|
6725
|
+
});
|
|
6726
|
+
return {
|
|
6727
|
+
promise: handle.promise,
|
|
6728
|
+
get settled() {
|
|
6729
|
+
return handle.settled;
|
|
6730
|
+
},
|
|
6731
|
+
get usesGraphicStack() {
|
|
6732
|
+
return usesGraphicStack;
|
|
6733
|
+
},
|
|
6734
|
+
measureId: image.id,
|
|
6735
|
+
graphicKind: "image",
|
|
6194
6736
|
abort: handle.abort,
|
|
6195
6737
|
syncHostMembership(present) {
|
|
6196
6738
|
if (handle.settled || usesGraphicStack === present) return;
|
|
@@ -6267,6 +6809,7 @@ var TacticalDraw = class {
|
|
|
6267
6809
|
defaultInteractionStyle;
|
|
6268
6810
|
generateId;
|
|
6269
6811
|
pointSymbols;
|
|
6812
|
+
images;
|
|
6270
6813
|
snappingOptions;
|
|
6271
6814
|
resolveSnap;
|
|
6272
6815
|
graphicStack = new GraphicStackCoordinator();
|
|
@@ -6333,6 +6876,7 @@ var TacticalDraw = class {
|
|
|
6333
6876
|
* there is no capability, or the capability doesn't expose `generation`.
|
|
6334
6877
|
*/
|
|
6335
6878
|
lastSeenPointSymbolGeneration;
|
|
6879
|
+
lastSeenImageGeneration;
|
|
6336
6880
|
/**
|
|
6337
6881
|
* Ids of graphics currently carrying a passive selection-highlight outline
|
|
6338
6882
|
* ({@link setHighlightedGraphics}). Declarative set-replace, no session —
|
|
@@ -6353,7 +6897,9 @@ var TacticalDraw = class {
|
|
|
6353
6897
|
this.defaultInteractionStyle = options?.interactionStyle;
|
|
6354
6898
|
this.generateId = options?.generateId ?? (() => `td-${++this.idCounter}`);
|
|
6355
6899
|
this.pointSymbols = options?.pointSymbols;
|
|
6900
|
+
this.images = options?.images;
|
|
6356
6901
|
this.lastSeenPointSymbolGeneration = this.pointSymbols?.generation;
|
|
6902
|
+
this.lastSeenImageGeneration = this.images?.generation;
|
|
6357
6903
|
this.snappingOptions = options?.snapping;
|
|
6358
6904
|
this.resolveSnap = createSnapResolver(adapter, () => this.lastRenderedMeasures, () => this.snapGeometryFeatures, () => this.snappingOptions);
|
|
6359
6905
|
const owned = /* @__PURE__ */ new Set();
|
|
@@ -6420,6 +6966,17 @@ var TacticalDraw = class {
|
|
|
6420
6966
|
revision
|
|
6421
6967
|
};
|
|
6422
6968
|
}
|
|
6969
|
+
if (isImageGraphic(graphic)) {
|
|
6970
|
+
if (!this.images) throw new ImageCapabilityRequiredError();
|
|
6971
|
+
const plan = renderImageForAdapter(this.adapter, this.images, graphic);
|
|
6972
|
+
return {
|
|
6973
|
+
id: graphic.id,
|
|
6974
|
+
features: [plan.feature],
|
|
6975
|
+
iconResources: [],
|
|
6976
|
+
...plan.overlay ? { imageOverlays: [plan.overlay] } : {},
|
|
6977
|
+
revision
|
|
6978
|
+
};
|
|
6979
|
+
}
|
|
6423
6980
|
const render = renderMeasureForAdapter(this.adapter, graphic, { graphicsStyle: this.graphicsStyle });
|
|
6424
6981
|
return {
|
|
6425
6982
|
id: graphic.id,
|
|
@@ -6436,13 +6993,19 @@ var TacticalDraw = class {
|
|
|
6436
6993
|
invalidateGraphicGroupCache() {
|
|
6437
6994
|
this.graphicGroupCache = /* @__PURE__ */ new WeakMap();
|
|
6438
6995
|
}
|
|
6439
|
-
/**
|
|
6440
|
-
|
|
6441
|
-
const
|
|
6442
|
-
|
|
6996
|
+
/** Refresh capability-dependent renders before any caller-visible state is mutated. */
|
|
6997
|
+
refreshCapabilityGenerations() {
|
|
6998
|
+
const currentPointSymbolGeneration = this.pointSymbols?.generation;
|
|
6999
|
+
const currentImageGeneration = this.images?.generation;
|
|
7000
|
+
if (currentPointSymbolGeneration !== this.lastSeenPointSymbolGeneration || currentImageGeneration !== this.lastSeenImageGeneration) {
|
|
6443
7001
|
this.invalidateGraphicGroupCache();
|
|
6444
|
-
this.lastSeenPointSymbolGeneration =
|
|
7002
|
+
this.lastSeenPointSymbolGeneration = currentPointSymbolGeneration;
|
|
7003
|
+
this.lastSeenImageGeneration = currentImageGeneration;
|
|
6445
7004
|
}
|
|
7005
|
+
}
|
|
7006
|
+
/** Submit one complete grouped desired state for the host stack plus overrides. */
|
|
7007
|
+
reconcileGraphicsStack(graphics = this.lastRenderedMeasures) {
|
|
7008
|
+
this.refreshCapabilityGenerations();
|
|
6446
7009
|
const groups = this.graphicStack.desiredGroups(graphics, (graphic) => this.renderGraphicGroup(graphic));
|
|
6447
7010
|
this.adapter.setLayerFeatureGroups(this.graphicsLayer, groups);
|
|
6448
7011
|
this.snapGeometryFeatures = groups.flatMap((group) => group.features);
|
|
@@ -6475,8 +7038,8 @@ var TacticalDraw = class {
|
|
|
6475
7038
|
this.renderHighlights();
|
|
6476
7039
|
const excluded = this.graphicsStackExcludedIds();
|
|
6477
7040
|
const visible = excluded.size > 0 ? this.lastRenderedMeasures.filter((m) => !excluded.has(m.id)) : this.lastRenderedMeasures;
|
|
6478
|
-
const
|
|
6479
|
-
if (!visible.some((g) => graphicRendersFromViewState(g,
|
|
7041
|
+
const nativePointSymbolScaling = this.adapter.scalesGroundPointSymbolsNatively === true;
|
|
7042
|
+
if (!visible.some((g) => graphicRendersFromViewState(g, nativePointSymbolScaling))) return;
|
|
6480
7043
|
this.reconcileGraphicsStack(visible);
|
|
6481
7044
|
};
|
|
6482
7045
|
/**
|
|
@@ -6541,6 +7104,8 @@ var TacticalDraw = class {
|
|
|
6541
7104
|
if (seen.has(m.id)) throw new Error(`TacticalDraw.render: duplicate graphic id "${m.id}"`);
|
|
6542
7105
|
seen.add(m.id);
|
|
6543
7106
|
}
|
|
7107
|
+
this.refreshCapabilityGenerations();
|
|
7108
|
+
for (const graphic of measures) if (isImageGraphic(graphic)) this.renderGraphicGroup(graphic);
|
|
6544
7109
|
const activeEdit = this.activeEdit;
|
|
6545
7110
|
const constructingSession = activeEdit ? null : this.activeInteraction.session;
|
|
6546
7111
|
const constructingGraphic = constructingSession && "workingGraphic" in constructingSession ? constructingSession.workingGraphic : void 0;
|
|
@@ -6549,14 +7114,17 @@ var TacticalDraw = class {
|
|
|
6549
7114
|
let editedRemoved = false;
|
|
6550
7115
|
if (editedId !== void 0) {
|
|
6551
7116
|
const candidate = measures.find((m) => m.id === editedId);
|
|
6552
|
-
if (activeEdit && "notifyExternalMeasure" in activeEdit || constructingGraphic !== void 0 && !
|
|
6553
|
-
externalEdited = candidate && !
|
|
7117
|
+
if (activeEdit && "notifyExternalMeasure" in activeEdit || constructingGraphic !== void 0 && !isAnchoredGraphic(constructingGraphic)) {
|
|
7118
|
+
externalEdited = candidate && !isAnchoredGraphic(candidate) ? candidate : void 0;
|
|
6554
7119
|
editedRemoved = externalEdited === void 0;
|
|
6555
|
-
} else
|
|
7120
|
+
} else {
|
|
7121
|
+
const expectedKind = activeEdit && "graphicKind" in activeEdit ? activeEdit.graphicKind : constructingGraphic?.kind;
|
|
7122
|
+
editedRemoved = candidate === void 0 || candidate.kind !== expectedKind;
|
|
7123
|
+
}
|
|
6556
7124
|
}
|
|
6557
7125
|
this.lastRenderedMeasures = measures.slice();
|
|
6558
7126
|
this.graphicStack.acknowledgeHostRender(measures);
|
|
6559
|
-
if (activeEdit && "syncHostMembership" in activeEdit && measures.some((graphic) => graphic.id === activeEdit.measureId &&
|
|
7127
|
+
if (activeEdit && "syncHostMembership" in activeEdit && measures.some((graphic) => graphic.id === activeEdit.measureId && graphic.kind === activeEdit.graphicKind)) activeEdit.syncHostMembership(true);
|
|
6560
7128
|
(this.activeTransform ?? this.activeTransformSessionRef)?.syncHostGraphics(measures);
|
|
6561
7129
|
const excluded = this.graphicsStackExcludedIds();
|
|
6562
7130
|
const visible = excluded.size > 0 ? measures.filter((m) => !excluded.has(m.id)) : measures;
|
|
@@ -6645,6 +7213,10 @@ var TacticalDraw = class {
|
|
|
6645
7213
|
if (!this.pointSymbols) return null;
|
|
6646
7214
|
return pointSymbolFootprint(graphic, this.pointSymbols.render(graphic), this.adapter)?.box ?? null;
|
|
6647
7215
|
}
|
|
7216
|
+
if (isImageGraphic(graphic)) {
|
|
7217
|
+
if (!this.images) return null;
|
|
7218
|
+
return imageFootprint(graphic, renderImageForAdapter(this.adapter, this.images, graphic).render, this.adapter)?.box ?? null;
|
|
7219
|
+
}
|
|
6648
7220
|
const render = renderMeasureForAdapter(this.adapter, graphic, { graphicsStyle: this.graphicsStyle });
|
|
6649
7221
|
if (graphic.kind === "text") return fitTextFootprintFromFeatures(render.features, (lonLat) => this.adapter.getPixelFromCoordinate(lonLat), {
|
|
6650
7222
|
resolution: this.adapter.getResolution(),
|
|
@@ -6756,6 +7328,21 @@ var TacticalDraw = class {
|
|
|
6756
7328
|
}
|
|
6757
7329
|
draw(draft, options) {
|
|
6758
7330
|
this.assertAlive();
|
|
7331
|
+
if (draft.kind === "image") {
|
|
7332
|
+
if (!this.images) throw new ImageCapabilityRequiredError();
|
|
7333
|
+
const preempt = this.guardAndPreempt();
|
|
7334
|
+
if (preempt) return preempt;
|
|
7335
|
+
return this.runWithSlot((onSettled) => runImageDraw({
|
|
7336
|
+
adapter: this.adapter,
|
|
7337
|
+
capability: this.images,
|
|
7338
|
+
draft,
|
|
7339
|
+
previewLayer: this.previewLayer,
|
|
7340
|
+
generateId: this.generateId,
|
|
7341
|
+
signal: options?.signal,
|
|
7342
|
+
onSettled,
|
|
7343
|
+
snap: this.resolveSnap
|
|
7344
|
+
}), null);
|
|
7345
|
+
}
|
|
6759
7346
|
if (draft.kind === "point-symbol") {
|
|
6760
7347
|
if (!this.pointSymbols) throw new PointSymbolCapabilityRequiredError();
|
|
6761
7348
|
const preempt = this.guardAndPreempt();
|
|
@@ -6827,6 +7414,43 @@ var TacticalDraw = class {
|
|
|
6827
7414
|
}
|
|
6828
7415
|
edit(measure, options) {
|
|
6829
7416
|
this.assertAlive();
|
|
7417
|
+
if (isImageGraphic(measure)) {
|
|
7418
|
+
normaliseImageModes(options?.modes);
|
|
7419
|
+
if (!this.images) throw new ImageCapabilityRequiredError();
|
|
7420
|
+
const preempt = this.guardAndPreempt();
|
|
7421
|
+
if (preempt) return preempt;
|
|
7422
|
+
const wasOnGraphicsLayer = this.lastRenderedMeasures.some((g) => g.id === measure.id);
|
|
7423
|
+
const handleIdPrefix = `__td_edit_${++this.editCounter}__`;
|
|
7424
|
+
return this.runWithSlot((onSettled) => runImageEdit({
|
|
7425
|
+
adapter: this.adapter,
|
|
7426
|
+
capability: this.images,
|
|
7427
|
+
image: measure,
|
|
7428
|
+
graphicsLayer: this.graphicsLayer,
|
|
7429
|
+
previewLayer: this.previewLayer,
|
|
7430
|
+
handlesLayer: this.handlesLayer,
|
|
7431
|
+
signal: options?.signal,
|
|
7432
|
+
closeOnClickAway: options?.closeOnClickAway,
|
|
7433
|
+
modes: options?.modes,
|
|
7434
|
+
interactionStyle: this.resolveInteractionStyle(options?.interactionStyle),
|
|
7435
|
+
onSession: this.trackSession(options?.onSession),
|
|
7436
|
+
handleIdPrefix,
|
|
7437
|
+
settleToGraphics: (settled) => this.settleWorkingGraphics([{
|
|
7438
|
+
id: measure.id,
|
|
7439
|
+
committed: settled
|
|
7440
|
+
}]),
|
|
7441
|
+
publishWorkingGraphic: (group) => this.publishWorkingGraphics([group]),
|
|
7442
|
+
wasOnGraphicsLayer,
|
|
7443
|
+
onSettled,
|
|
7444
|
+
onClickAwayGraphicsPick: (event) => this.dispatchHostPick(this.graphicsLayer, event),
|
|
7445
|
+
snap: this.resolveSnap
|
|
7446
|
+
}), (handle) => {
|
|
7447
|
+
handle.syncHostMembership(this.lastRenderedMeasures.some((graphic) => graphic.id === handle.measureId && isImageGraphic(graphic)));
|
|
7448
|
+
this.activeEdit = handle;
|
|
7449
|
+
return () => {
|
|
7450
|
+
if (this.activeEdit === handle) this.activeEdit = null;
|
|
7451
|
+
};
|
|
7452
|
+
});
|
|
7453
|
+
}
|
|
6830
7454
|
if (isPointSymbol(measure)) {
|
|
6831
7455
|
normalisePointEditModes(options?.modes);
|
|
6832
7456
|
if (!this.pointSymbols) throw new PointSymbolCapabilityRequiredError();
|
|
@@ -6923,6 +7547,7 @@ var TacticalDraw = class {
|
|
|
6923
7547
|
seenIds.add(m.id);
|
|
6924
7548
|
}
|
|
6925
7549
|
if (measures.some(isPointSymbol) && !this.pointSymbols) throw new PointSymbolCapabilityRequiredError();
|
|
7550
|
+
if (measures.some(isImageGraphic) && !this.images) throw new ImageCapabilityRequiredError();
|
|
6926
7551
|
const preempt = this.guardAndPreempt();
|
|
6927
7552
|
if (preempt) return preempt;
|
|
6928
7553
|
const isOnGraphicsLayer = (id) => this.lastRenderedMeasures.some((m) => m.id === id);
|
|
@@ -6937,6 +7562,7 @@ var TacticalDraw = class {
|
|
|
6937
7562
|
return this.runWithSlot((onSettled) => runGroupTransform({
|
|
6938
7563
|
adapter: this.adapter,
|
|
6939
7564
|
capability: this.pointSymbols,
|
|
7565
|
+
imageCapability: this.images,
|
|
6940
7566
|
graphics: measures,
|
|
6941
7567
|
graphicsLayer: this.graphicsLayer,
|
|
6942
7568
|
previewLayer: this.previewLayer,
|
|
@@ -7311,8 +7937,10 @@ var TacticalDraw = class {
|
|
|
7311
7937
|
if (this.destroyed) throw new TacticalDrawDestroyedError();
|
|
7312
7938
|
}
|
|
7313
7939
|
};
|
|
7314
|
-
function graphicRendersFromViewState(graphic,
|
|
7315
|
-
|
|
7940
|
+
function graphicRendersFromViewState(graphic, nativePointSymbolScaling) {
|
|
7941
|
+
if (isPointSymbol(graphic)) return graphic.size.unit === "meters" && !nativePointSymbolScaling;
|
|
7942
|
+
if (isImageGraphic(graphic)) return false;
|
|
7943
|
+
return measureRendersFromViewState(graphic);
|
|
7316
7944
|
}
|
|
7317
7945
|
function normalisePointEditModes(modes) {
|
|
7318
7946
|
for (const mode of modes ?? ["transform"]) if (mode !== "transform" && mode !== "delete") throw new TypeError(`Point-symbol editing does not support mode "${mode}"`);
|
|
@@ -7628,4 +8256,4 @@ function nearestWorldCopyPosition(position, refLng) {
|
|
|
7628
8256
|
return [nearestWorldCopyLng(position[0], refLng), ...position.slice(1)];
|
|
7629
8257
|
}
|
|
7630
8258
|
//#endregion
|
|
7631
|
-
export { BaseMapAdapter, DEFAULT_LABEL_SIZE_PIXELS, DEFAULT_TEXT_SIZE_MAX_PIXELS, DEFAULT_TEXT_SIZE_MIN_PIXELS, HATCH_PATTERNS, PointSymbolCapabilityRequiredError, PointerCallbackHub, TEXT_HALO_COLOR, TOUCH_HIT_TOLERANCE_PX, TacticalDraw, TacticalDrawAbortError, TacticalDrawDestroyedError, bindAbortable, clonePointSymbol, coerceHandleStyle, combineWithHostSignal, effectivePointSymbolPixelSize, evaluatePickCandidates, fillPatternImageDimension, fillPatternImageId, getSizeAnchor, hitTestFeature, hitTestIconFeature, ignoreAbort, isPointSymbol, isTacticalDrawAbortError, makeFillPatternImage, mergeNativeAndCachedPickFeatures, nearestWorldCopyLng, nearestWorldCopyPosition, pickHitTolerance, pickPointerType, pointSymbolFootprint, renderOrderToVisualOrder, resizePointSymbolSize, resolveGroundTextSizePixels, resolvePickPresentation, resolveTextHaloWidth, resolveTextSizePixels, tryControlMeasureIdFromFeature };
|
|
8259
|
+
export { BaseMapAdapter, DEFAULT_LABEL_SIZE_PIXELS, DEFAULT_TEXT_SIZE_MAX_PIXELS, DEFAULT_TEXT_SIZE_MIN_PIXELS, HATCH_PATTERNS, ImageCapabilityRequiredError, PointSymbolCapabilityRequiredError, PointerCallbackHub, TEXT_HALO_COLOR, TOUCH_HIT_TOLERANCE_PX, TacticalDraw, TacticalDrawAbortError, TacticalDrawDestroyedError, bindAbortable, cloneImageGraphic, clonePointSymbol, coerceHandleStyle, combineWithHostSignal, effectivePointSymbolPixelSize, evaluatePickCandidates, fillPatternImageDimension, fillPatternImageId, getSizeAnchor, hitTestFeature, hitTestIconFeature, ignoreAbort, imageFootprint, imageOpacity, isAnchoredGraphic, isImageGraphic, isPointSymbol, isTacticalDrawAbortError, makeFillPatternImage, mergeNativeAndCachedPickFeatures, nearestWorldCopyLng, nearestWorldCopyPosition, normalizeImageGraphic, pickHitTolerance, pickPointerType, pointSymbolFootprint, renderOrderToVisualOrder, resizePointSymbolSize, resolveGroundTextSizePixels, resolvePickPresentation, resolveTextHaloWidth, resolveTextSizePixels, tryControlMeasureIdFromFeature, validateImageGraphic };
|
|
@@ -180,6 +180,15 @@ interface IconResource {
|
|
|
180
180
|
height: number;
|
|
181
181
|
};
|
|
182
182
|
}
|
|
183
|
+
/** A self-contained image fixed to four geographic corners, ordered TL/TR/BR/BL. */
|
|
184
|
+
interface ImageOverlayResource {
|
|
185
|
+
id: string;
|
|
186
|
+
url: string;
|
|
187
|
+
width: number;
|
|
188
|
+
height: number;
|
|
189
|
+
coordinates: readonly [Position, Position, Position, Position];
|
|
190
|
+
opacity: number;
|
|
191
|
+
}
|
|
183
192
|
/**
|
|
184
193
|
* One stable, atomic unit in a logical layer's bottom-to-top paint stack.
|
|
185
194
|
*
|
|
@@ -190,6 +199,8 @@ interface FeatureGroup {
|
|
|
190
199
|
id: string;
|
|
191
200
|
features: readonly Feature[];
|
|
192
201
|
iconResources: readonly IconResource[];
|
|
202
|
+
/** Ground-anchored rasters painted atomically with this Graphic. */
|
|
203
|
+
imageOverlays?: readonly ImageOverlayResource[];
|
|
193
204
|
/**
|
|
194
205
|
* Monotonic stamp identifying this group's rendered content, when the
|
|
195
206
|
* producer supplies one. Two groups with the same `id` and the same
|
|
@@ -369,4 +380,4 @@ interface MapAdapter {
|
|
|
369
380
|
getLayerFeatures(layerId: LayerId): readonly Feature[];
|
|
370
381
|
}
|
|
371
382
|
//#endregion
|
|
372
|
-
export { PointerEventInfo as S,
|
|
383
|
+
export { PointerEventInfo as C, PointerCallback as S, HatchPattern as _, LayerId as a, makeFillPatternImage as b, MapEvent as c, PickHandler as d, PickOptions as f, HATCH_PATTERNS as g, TextStyleOptions as h, ImageOverlayResource as i, MapEventHandler as l, StyleOptions as m, HandleStyle as n, MapAdapter as o, PixelCoordinate as p, IconResource as r, MapCursor as s, FeatureGroup as t, PickEvent as u, fillPatternImageDimension as v, EditPointerDriver as x, fillPatternImageId as y };
|
package/dist/testing.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as LayerId, o as MapAdapter, p as PixelCoordinate } from "./map-adapter-DfIb57kQ.mjs";
|
|
2
2
|
import { Feature } from "geojson";
|
|
3
3
|
|
|
4
4
|
//#region src/testing/feature-group-conformance.d.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orbat-mapper/tactical-draw",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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.3.1"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"vitest": ">=4.0.0"
|