@orbat-mapper/tactical-draw-adapter-maplibre 0.4.2 → 0.4.4

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 +28 -24
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -439,6 +439,7 @@ function shader(gl, type, source) {
439
439
  }
440
440
  return s;
441
441
  }
442
+ const elevationOrSeaLevel = (value) => Number.isFinite(value) ? value : 0;
442
443
  /**
443
444
  * Appends one instance's worth of vertex-shader input to `data` and extends `ranges`
444
445
  * accordingly. Hoisted out of rebuild()'s per-pin loop (ADR n/a) so pushing 10k+ pins
@@ -471,7 +472,7 @@ function arrowSegmentPoint(center, position, elevationAt, from, to, t) {
471
472
  return [
472
473
  mc.x - center.x,
473
474
  mc.y - center.y,
474
- elevationAt(ll) + 1,
475
+ elevationOrSeaLevel(elevationAt(ll)) + 1,
475
476
  0
476
477
  ];
477
478
  }
@@ -524,21 +525,25 @@ var PinLayer = class {
524
525
  const key = `${position[0]}/${position[1]}`;
525
526
  const cached = this.elevationCache.get(key);
526
527
  if (cached !== void 0) return cached;
527
- const terrain = this.map.terrain;
528
- const manager = terrain.tileManager ?? terrain.sourceCache;
529
- const source = terrain.tileManager ? terrain.tileManager.getSource() : terrain.sourceCache.sourceCache.getSource();
530
- const { tileID, mercatorX, mercatorY } = terrain._getOverscaledTileIDFromLngLatZoom(new LngLat(position[0], position[1]), Math.min(manager.maxzoom, source.maxzoom + manager.deltaZoom));
531
- const x = mercatorX % 8192;
532
- const y = mercatorY % 8192;
533
- const getSampler = terrain.getElevationSampler ?? terrain._getElevationSampler;
534
528
  let value;
535
- if (getSampler) {
536
- const sampler = getSampler.call(terrain, tileID);
537
- if (!sampler) return NaN;
538
- value = sampler(x, y, 8192) * terrain.exaggeration;
539
- } else {
540
- if (!manager.getSourceTile(tileID, true)?.dem) return NaN;
541
- value = terrain.getElevation(tileID, x, y, 8192);
529
+ try {
530
+ const terrain = this.map.terrain;
531
+ const manager = terrain.tileManager ?? terrain.sourceCache;
532
+ const source = terrain.tileManager ? terrain.tileManager.getSource() : terrain.sourceCache.sourceCache.getSource();
533
+ const { tileID, mercatorX, mercatorY } = terrain._getOverscaledTileIDFromLngLatZoom(new LngLat(position[0], position[1]), Math.min(manager.maxzoom, source.maxzoom + manager.deltaZoom));
534
+ const x = mercatorX % 8192;
535
+ const y = mercatorY % 8192;
536
+ const getSampler = terrain.getElevationSampler ?? terrain._getElevationSampler;
537
+ if (getSampler) {
538
+ const sampler = getSampler.call(terrain, tileID);
539
+ if (!sampler) return NaN;
540
+ value = sampler(x, y, 8192) * terrain.exaggeration;
541
+ } else {
542
+ if (!manager.getSourceTile(tileID, true)?.dem) return NaN;
543
+ value = terrain.getElevation(tileID, x, y, 8192);
544
+ }
545
+ } catch {
546
+ return NaN;
542
547
  }
543
548
  this.elevationCache.set(key, value);
544
549
  return value;
@@ -677,13 +682,12 @@ var PinLayer = class {
677
682
  const pin = this.pins[i], p = pin.presentation;
678
683
  const anchor = pinMercator(pin.position);
679
684
  anchor.x += Math.round(center.x - anchor.x);
680
- const elevation = this.elevation(pin.position);
685
+ const sampledElevation = this.elevation(pin.position);
686
+ const hasElevation = Number.isFinite(sampledElevation);
687
+ const elevation = elevationOrSeaLevel(sampledElevation);
681
688
  this.elevations[i] = elevation;
682
- if (!Number.isFinite(elevation)) {
683
- this.pendingElevation.add(pin.id);
684
- return;
685
- }
686
- this.pendingElevation.delete(pin.id);
689
+ if (hasElevation) this.pendingElevation.delete(pin.id);
690
+ else this.pendingElevation.add(pin.id);
687
691
  const a = [
688
692
  anchor.x - center.x,
689
693
  anchor.y - center.y,
@@ -700,7 +704,7 @@ var PinLayer = class {
700
704
  const opacity = pin.opacity;
701
705
  const highlightOnly = pin.highlightOnly;
702
706
  const instanceId = i + 1;
703
- const occlusionFlag = p.occlusion === "terrain" ? 1 : 0;
707
+ const occlusionFlag = hasElevation && p.occlusion === "terrain" ? 1 : 0;
704
708
  const worldMode = p.mode === "world" ? 1 : 0;
705
709
  const haloColor = rgba(p.halo.color, p.halo.opacity * opacity);
706
710
  const stemColor = rgba(p.stem.color, p.stem.opacity * opacity);
@@ -824,7 +828,7 @@ var PinLayer = class {
824
828
  this.buildPin(i, center, data, []);
825
829
  const slice = this.slices[i];
826
830
  const page = this.atlas.entries.get(this.pins[i].resource.id)?.page;
827
- if (data.length !== slice.length || page !== slice.page) {
831
+ if (data.length !== slice.length || page !== slice.page || previousPending.has(this.pins[i].id) !== this.pendingElevation.has(this.pins[i].id)) {
828
832
  this.pendingElevation = previousPending;
829
833
  this.dirty = true;
830
834
  break;
@@ -1026,7 +1030,7 @@ var PinLayer = class {
1026
1030
  const c = pinMercator(ll);
1027
1031
  c.x += Math.round(this.origin[0] - c.x);
1028
1032
  const world = 512 * 2 ** this.map.getZoom();
1029
- const [px, py] = this.projectToPixel((c.x - this.origin[0]) * world, (c.y - this.origin[1]) * world, this.elevation(ll) + (p.mode === "world" ? p.heightMeters : 0));
1033
+ const [px, py] = this.projectToPixel((c.x - this.origin[0]) * world, (c.y - this.origin[1]) * world, elevationOrSeaLevel(this.elevation(ll)) + (p.mode === "world" ? p.heightMeters : 0));
1030
1034
  return [px, py - (p.mode === "screen" ? p.liftPixels : 0)];
1031
1035
  };
1032
1036
  return invertPinProjection(project, pin.position, attachment, this.map.getProjection()?.type === "globe" ? 90 : void 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbat-mapper/tactical-draw-adapter-maplibre",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
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",