@orbat-mapper/tactical-draw-adapter-maplibre 0.2.0-alpha.1 → 0.2.0-alpha.3
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 +1 -0
- package/dist/index.mjs +27 -6
- package/package.json +3 -3
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 {
|
|
@@ -136,6 +136,22 @@ function buildSymbolLayer(symbolId, sourceId, text) {
|
|
|
136
136
|
],
|
|
137
137
|
"#000"
|
|
138
138
|
];
|
|
139
|
+
const textAnchor = text.labelProperty ? [
|
|
140
|
+
"case",
|
|
141
|
+
[
|
|
142
|
+
"==",
|
|
143
|
+
["get", "textAnchor"],
|
|
144
|
+
"start"
|
|
145
|
+
],
|
|
146
|
+
"left",
|
|
147
|
+
[
|
|
148
|
+
"==",
|
|
149
|
+
["get", "textAnchor"],
|
|
150
|
+
"end"
|
|
151
|
+
],
|
|
152
|
+
"right",
|
|
153
|
+
"center"
|
|
154
|
+
] : "center";
|
|
139
155
|
return {
|
|
140
156
|
id: symbolId,
|
|
141
157
|
type: "symbol",
|
|
@@ -145,6 +161,7 @@ function buildSymbolLayer(symbolId, sourceId, text) {
|
|
|
145
161
|
"text-font": ["Open Sans Regular"],
|
|
146
162
|
"text-size": buildTextSizeExpression(),
|
|
147
163
|
"text-rotate": textRotate,
|
|
164
|
+
"text-anchor": textAnchor,
|
|
148
165
|
"text-rotation-alignment": "map",
|
|
149
166
|
"text-pitch-alignment": "map",
|
|
150
167
|
"text-allow-overlap": true
|
|
@@ -212,6 +229,9 @@ var MapLibreAdapter = class extends BaseMapAdapter {
|
|
|
212
229
|
super();
|
|
213
230
|
this.map = map;
|
|
214
231
|
}
|
|
232
|
+
toContinuousLng(lng) {
|
|
233
|
+
return nearestWorldCopyLng(lng, this.map.getCenter().lng);
|
|
234
|
+
}
|
|
215
235
|
createLayer(layerId, style) {
|
|
216
236
|
const sourceId = `${layerId}-src`;
|
|
217
237
|
this.map.addSource(sourceId, {
|
|
@@ -302,7 +322,7 @@ var MapLibreAdapter = class extends BaseMapAdapter {
|
|
|
302
322
|
attachNativeEvent(type, onEvent) {
|
|
303
323
|
const mlEvent = type === "pointermove" ? "mousemove" : type === "dblclick" ? "dblclick" : "click";
|
|
304
324
|
const fn = (e) => {
|
|
305
|
-
onEvent([e.lngLat.lng, e.lngLat.lat], [e.point.x, e.point.y], e);
|
|
325
|
+
onEvent([this.toContinuousLng(e.lngLat.lng), e.lngLat.lat], [e.point.x, e.point.y], e);
|
|
306
326
|
};
|
|
307
327
|
this.map.on(mlEvent, fn);
|
|
308
328
|
return {
|
|
@@ -329,6 +349,7 @@ var MapLibreAdapter = class extends BaseMapAdapter {
|
|
|
329
349
|
}
|
|
330
350
|
createEditPointerDriver() {
|
|
331
351
|
const map = this.map;
|
|
352
|
+
const toContinuousLng = (lng) => this.toContinuousLng(lng);
|
|
332
353
|
const hub = new PointerCallbackHub();
|
|
333
354
|
let dragPanWasEnabled = false;
|
|
334
355
|
let disposed = false;
|
|
@@ -403,12 +424,12 @@ var MapLibreAdapter = class extends BaseMapAdapter {
|
|
|
403
424
|
}
|
|
404
425
|
},
|
|
405
426
|
toPixel(lonLat) {
|
|
406
|
-
const p = map.project(lonLat);
|
|
427
|
+
const p = map.project([toContinuousLng(lonLat[0]), lonLat[1]]);
|
|
407
428
|
return [p.x, p.y];
|
|
408
429
|
},
|
|
409
430
|
fromPixel(pixel) {
|
|
410
431
|
const ll = map.unproject(pixel);
|
|
411
|
-
return [ll.lng, ll.lat];
|
|
432
|
+
return [toContinuousLng(ll.lng), ll.lat];
|
|
412
433
|
},
|
|
413
434
|
dispose() {
|
|
414
435
|
if (disposed) return;
|
|
@@ -472,7 +493,7 @@ var MapLibreAdapter = class extends BaseMapAdapter {
|
|
|
472
493
|
return project(position[0], position[1]);
|
|
473
494
|
}
|
|
474
495
|
getPixelFromCoordinate(position) {
|
|
475
|
-
const point = this.map.project(position);
|
|
496
|
+
const point = this.map.project([this.toContinuousLng(position[0]), position[1]]);
|
|
476
497
|
return [point.x, point.y];
|
|
477
498
|
}
|
|
478
499
|
getViewportSize() {
|
|
@@ -534,7 +555,7 @@ var MapLibreAdapter = class extends BaseMapAdapter {
|
|
|
534
555
|
id: cmId,
|
|
535
556
|
feature: geojson,
|
|
536
557
|
pixel: [x, y],
|
|
537
|
-
coordinate: [e.lngLat.lng, e.lngLat.lat],
|
|
558
|
+
coordinate: [this.toContinuousLng(e.lngLat.lng), e.lngLat.lat],
|
|
538
559
|
originalEvent
|
|
539
560
|
});
|
|
540
561
|
};
|
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.3",
|
|
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.9",
|
|
41
|
+
"@orbat-mapper/tactical-draw": "^0.2.0-alpha.12"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"maplibre-gl": ">=4.0.0 <6.0.0"
|