@orbat-mapper/tactical-draw-adapter-maplibre 0.2.0-alpha.16 → 0.2.0-alpha.17

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 +41 -13
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -1,8 +1,10 @@
1
1
  import { project, unproject } from "@orbat-mapper/control-measures";
2
- import { BaseMapAdapter, DEFAULT_TEXT_SIZE_MAX_PIXELS, DEFAULT_TEXT_SIZE_MIN_PIXELS, HATCH_PATTERNS, PointerCallbackHub, TOUCH_HIT_TOLERANCE_PX, bindAbortable, fillPatternImageId, makeFillPatternImage, nearestWorldCopyLng, pickHitTolerance, tryControlMeasureIdFromFeature } from "@orbat-mapper/tactical-draw";
2
+ import { BaseMapAdapter, DEFAULT_TEXT_SIZE_MAX_PIXELS, DEFAULT_TEXT_SIZE_MIN_PIXELS, HATCH_PATTERNS, PointerCallbackHub, TOUCH_HIT_TOLERANCE_PX, bindAbortable, evaluatePickCandidates, fillPatternImageId, makeFillPatternImage, mergeNativeAndCachedPickFeatures, nearestWorldCopyLng, pickHitTolerance, pickPointerType } from "@orbat-mapper/tactical-draw";
3
3
  //#region src/ml-adapter.ts
4
4
  /** Feature property key for the resolved hatch-pattern image id (see `promoteFeature`). */
5
5
  const FILL_PATTERN_IMAGE_ID_PROPERTY = "_fillPatternImageId";
6
+ const DEFAULT_LINE_COLOR = "#000";
7
+ const DEFAULT_LINE_WIDTH = 2;
6
8
  function isHatchPattern(value) {
7
9
  return HATCH_PATTERNS.includes(value);
8
10
  }
@@ -489,8 +491,8 @@ const FILL_PATTERN_PAINT = {
489
491
  "fill-opacity": 1
490
492
  };
491
493
  function buildLinePaint(style) {
492
- const colorDefault = style?.strokeColor ?? "#000";
493
- const widthDefault = style?.strokeWidth ?? 2;
494
+ const colorDefault = style?.strokeColor ?? DEFAULT_LINE_COLOR;
495
+ const widthDefault = style?.strokeWidth ?? DEFAULT_LINE_WIDTH;
494
496
  const styleObj = [
495
497
  "coalesce",
496
498
  ["get", "style"],
@@ -973,20 +975,46 @@ var MapLibreAdapter = class extends BaseMapAdapter {
973
975
  const tol = pickHitTolerance(originalEvent);
974
976
  const { x, y } = e.point;
975
977
  const bbox = [[x - tol, y - tol], [x + tol, y + tol]];
976
- const features = this.map.queryRenderedFeatures(bbox, { layers: handle.mlLayerIds });
977
- if (features.length === 0) return;
978
- const f = features[0];
979
- const geojson = {
978
+ const relevantFeatures = mergeNativeAndCachedPickFeatures(this.map.queryRenderedFeatures(bbox, { layers: handle.mlLayerIds }).map((feature) => ({
980
979
  type: "Feature",
981
- id: f.id,
982
- geometry: f.geometry,
983
- properties: f.properties
984
- };
985
- const cmId = tryControlMeasureIdFromFeature(geojson);
980
+ id: feature.id,
981
+ geometry: feature.geometry,
982
+ properties: feature.properties
983
+ })), this.featureCache.get(layerId) ?? []);
984
+ const size = this.getViewportSize();
985
+ const candidate = evaluatePickCandidates(relevantFeatures.map(({ feature, nativeHit, visualOrder }) => {
986
+ const iconId = feature.properties?.iconId;
987
+ const icon = typeof iconId === "string" ? this.getIconResource(iconId) : void 0;
988
+ return {
989
+ feature,
990
+ visualOrder,
991
+ nativeHit,
992
+ ...icon ? { icon } : {},
993
+ layerStyle: {
994
+ ...handle.style,
995
+ strokeColor: handle.style?.strokeColor ?? DEFAULT_LINE_COLOR,
996
+ strokeWidth: handle.style?.strokeWidth ?? DEFAULT_LINE_WIDTH
997
+ }
998
+ };
999
+ }), {
1000
+ pixel: [x, y],
1001
+ pointerType: pickPointerType(originalEvent),
1002
+ tolerance: tol,
1003
+ toPixel: (position) => this.getPixelFromCoordinate(position),
1004
+ viewport: {
1005
+ minX: 0,
1006
+ minY: 0,
1007
+ maxX: size.width,
1008
+ maxY: size.height
1009
+ },
1010
+ bearing: this.getBearing()
1011
+ });
1012
+ if (!candidate) return;
1013
+ const cmId = candidate.graphicId;
986
1014
  if (cmId == null) return;
987
1015
  handler({
988
1016
  id: cmId,
989
- feature: geojson,
1017
+ feature: candidate.feature,
990
1018
  pixel: [x, y],
991
1019
  coordinate: [this.toContinuousLng(e.lngLat.lng), e.lngLat.lat],
992
1020
  originalEvent
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbat-mapper/tactical-draw-adapter-maplibre",
3
- "version": "0.2.0-alpha.16",
3
+ "version": "0.2.0-alpha.17",
4
4
  "description": "MapLibre GL JS engine adapter for @orbat-mapper/tactical-draw. Draw and edit tactical control measures (MIL-STD-2525 / APP-6) on a MapLibre map.",
5
5
  "license": "MIT",
6
6
  "author": "Orbat Mapper",
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@orbat-mapper/control-measures": "^0.2.0-alpha.24",
41
- "@orbat-mapper/tactical-draw": "^0.2.0-alpha.31"
41
+ "@orbat-mapper/tactical-draw": "^0.2.0-alpha.32"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "maplibre-gl": ">=4.0.0 <6.0.0"