@orbat-mapper/tactical-draw-adapter-maplibre 0.2.0-alpha.0 → 0.2.0-alpha.2
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/README.md +10 -9
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +16 -8
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
# @orbat-mapper/tactical-draw-adapter-maplibre
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
unchanged against a MapLibre map.
|
|
3
|
+
[MapLibre GL JS](https://maplibre.org/maplibre-gl-js/docs/) bindings for
|
|
4
|
+
`@orbat-mapper/tactical-draw`. `MapLibreAdapter` implements the `MapAdapter`
|
|
5
|
+
contract, so the draw/edit sessions, draw rules, gestures, and handle
|
|
6
|
+
rendering from `tactical-draw` run unchanged on a MapLibre map.
|
|
8
7
|
|
|
9
|
-
`maplibre-gl` is
|
|
10
|
-
copy and never install an engine you don't use.
|
|
8
|
+
`maplibre-gl` is a peer dependency — your app supplies the version.
|
|
11
9
|
|
|
12
10
|
## Installation
|
|
13
11
|
|
|
@@ -34,8 +32,11 @@ const adapter = new MapLibreAdapter(map);
|
|
|
34
32
|
const draw = new TacticalDraw(adapter);
|
|
35
33
|
```
|
|
36
34
|
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
## Quick Links
|
|
36
|
+
|
|
37
|
+
- [`@orbat-mapper/tactical-draw`](https://www.npmjs.com/package/@orbat-mapper/tactical-draw) — the draw/edit core this adapter plugs into
|
|
38
|
+
- [`@orbat-mapper/control-measures`](https://www.npmjs.com/package/@orbat-mapper/control-measures) — generates the control measures as GeoJSON
|
|
39
|
+
- [GitHub repository](https://github.com/orbat-mapper/tactical-graphics)
|
|
39
40
|
|
|
40
41
|
## License
|
|
41
42
|
|
package/dist/index.d.mts
CHANGED
|
@@ -16,6 +16,7 @@ interface MapLibreViewToken {
|
|
|
16
16
|
declare class MapLibreAdapter extends BaseMapAdapter<MapLibreLayerHandle, MapLibreEventToken, MapLibreViewToken> {
|
|
17
17
|
private map;
|
|
18
18
|
constructor(map: maplibregl.Map);
|
|
19
|
+
private toContinuousLng;
|
|
19
20
|
protected createLayer(layerId: LayerId, style?: StyleOptions): MapLibreLayerHandle;
|
|
20
21
|
protected destroyLayer(handle: MapLibreLayerHandle): void;
|
|
21
22
|
protected applyFeatureOps(layerId: LayerId, ops: FeatureOps): void;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { project, unproject } from "@orbat-mapper/control-measures";
|
|
2
|
-
import { BaseMapAdapter, PointerCallbackHub, TOUCH_HIT_TOLERANCE_PX, bindAbortable, pickHitTolerance, tryControlMeasureIdFromFeature } from "@orbat-mapper/tactical-draw";
|
|
2
|
+
import { BaseMapAdapter, PointerCallbackHub, TOUCH_HIT_TOLERANCE_PX, bindAbortable, nearestWorldCopyLng, pickHitTolerance, tryControlMeasureIdFromFeature } from "@orbat-mapper/tactical-draw";
|
|
3
3
|
//#region src/ml-adapter.ts
|
|
4
4
|
function emptyFC() {
|
|
5
5
|
return {
|
|
@@ -212,6 +212,9 @@ var MapLibreAdapter = class extends BaseMapAdapter {
|
|
|
212
212
|
super();
|
|
213
213
|
this.map = map;
|
|
214
214
|
}
|
|
215
|
+
toContinuousLng(lng) {
|
|
216
|
+
return nearestWorldCopyLng(lng, this.map.getCenter().lng);
|
|
217
|
+
}
|
|
215
218
|
createLayer(layerId, style) {
|
|
216
219
|
const sourceId = `${layerId}-src`;
|
|
217
220
|
this.map.addSource(sourceId, {
|
|
@@ -302,7 +305,7 @@ var MapLibreAdapter = class extends BaseMapAdapter {
|
|
|
302
305
|
attachNativeEvent(type, onEvent) {
|
|
303
306
|
const mlEvent = type === "pointermove" ? "mousemove" : type === "dblclick" ? "dblclick" : "click";
|
|
304
307
|
const fn = (e) => {
|
|
305
|
-
onEvent([e.lngLat.lng, e.lngLat.lat], [e.point.x, e.point.y], e);
|
|
308
|
+
onEvent([this.toContinuousLng(e.lngLat.lng), e.lngLat.lat], [e.point.x, e.point.y], e);
|
|
306
309
|
};
|
|
307
310
|
this.map.on(mlEvent, fn);
|
|
308
311
|
return {
|
|
@@ -315,16 +318,21 @@ var MapLibreAdapter = class extends BaseMapAdapter {
|
|
|
315
318
|
}
|
|
316
319
|
attachViewChange(handler) {
|
|
317
320
|
const fn = () => handler();
|
|
321
|
+
this.map.on("zoom", fn);
|
|
322
|
+
this.map.on("rotate", fn);
|
|
323
|
+
this.map.on("pitch", fn);
|
|
318
324
|
this.map.on("moveend", fn);
|
|
319
|
-
this.map.on("zoomend", fn);
|
|
320
325
|
return { fn };
|
|
321
326
|
}
|
|
322
327
|
detachViewChange(token) {
|
|
328
|
+
this.map.off("zoom", token.fn);
|
|
329
|
+
this.map.off("rotate", token.fn);
|
|
330
|
+
this.map.off("pitch", token.fn);
|
|
323
331
|
this.map.off("moveend", token.fn);
|
|
324
|
-
this.map.off("zoomend", token.fn);
|
|
325
332
|
}
|
|
326
333
|
createEditPointerDriver() {
|
|
327
334
|
const map = this.map;
|
|
335
|
+
const toContinuousLng = (lng) => this.toContinuousLng(lng);
|
|
328
336
|
const hub = new PointerCallbackHub();
|
|
329
337
|
let dragPanWasEnabled = false;
|
|
330
338
|
let disposed = false;
|
|
@@ -399,12 +407,12 @@ var MapLibreAdapter = class extends BaseMapAdapter {
|
|
|
399
407
|
}
|
|
400
408
|
},
|
|
401
409
|
toPixel(lonLat) {
|
|
402
|
-
const p = map.project(lonLat);
|
|
410
|
+
const p = map.project([toContinuousLng(lonLat[0]), lonLat[1]]);
|
|
403
411
|
return [p.x, p.y];
|
|
404
412
|
},
|
|
405
413
|
fromPixel(pixel) {
|
|
406
414
|
const ll = map.unproject(pixel);
|
|
407
|
-
return [ll.lng, ll.lat];
|
|
415
|
+
return [toContinuousLng(ll.lng), ll.lat];
|
|
408
416
|
},
|
|
409
417
|
dispose() {
|
|
410
418
|
if (disposed) return;
|
|
@@ -468,7 +476,7 @@ var MapLibreAdapter = class extends BaseMapAdapter {
|
|
|
468
476
|
return project(position[0], position[1]);
|
|
469
477
|
}
|
|
470
478
|
getPixelFromCoordinate(position) {
|
|
471
|
-
const point = this.map.project(position);
|
|
479
|
+
const point = this.map.project([this.toContinuousLng(position[0]), position[1]]);
|
|
472
480
|
return [point.x, point.y];
|
|
473
481
|
}
|
|
474
482
|
getViewportSize() {
|
|
@@ -530,7 +538,7 @@ var MapLibreAdapter = class extends BaseMapAdapter {
|
|
|
530
538
|
id: cmId,
|
|
531
539
|
feature: geojson,
|
|
532
540
|
pixel: [x, y],
|
|
533
|
-
coordinate: [e.lngLat.lng, e.lngLat.lat],
|
|
541
|
+
coordinate: [this.toContinuousLng(e.lngLat.lng), e.lngLat.lat],
|
|
534
542
|
originalEvent
|
|
535
543
|
});
|
|
536
544
|
};
|
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.
|
|
3
|
+
"version": "0.2.0-alpha.2",
|
|
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",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@orbat-mapper/control-measures": "^0.2.0-alpha.
|
|
41
|
-
"@orbat-mapper/tactical-draw": "^0.2.0-alpha.
|
|
40
|
+
"@orbat-mapper/control-measures": "^0.2.0-alpha.7",
|
|
41
|
+
"@orbat-mapper/tactical-draw": "^0.2.0-alpha.6"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"maplibre-gl": ">=4.0.0 <6.0.0"
|