@ingissa/navcore-maplibre 1.0.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.
- package/dist/index.d.mts +41 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +84 -0
- package/dist/index.mjs +82 -0
- package/package.json +32 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { MapRendererAdapter, Coordinate, NavCoreState, VehicleStyle, RouteStyle, CameraOptions } from '@ingissa/navcore-core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* MapLibreAdapter — NavCore renderer adapter for MapLibre GL JS.
|
|
5
|
+
* Peer dependency: maplibre-gl >= 3.0.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
interface MapLibreMap {
|
|
9
|
+
getSource(id: string): unknown;
|
|
10
|
+
addSource(id: string, source: unknown): void;
|
|
11
|
+
removeSource(id: string): void;
|
|
12
|
+
getLayer(id: string): unknown;
|
|
13
|
+
addLayer(layer: unknown): void;
|
|
14
|
+
removeLayer(id: string): void;
|
|
15
|
+
easeTo(options: {
|
|
16
|
+
center?: [number, number];
|
|
17
|
+
bearing?: number;
|
|
18
|
+
zoom?: number;
|
|
19
|
+
pitch?: number;
|
|
20
|
+
duration?: number;
|
|
21
|
+
}): void;
|
|
22
|
+
}
|
|
23
|
+
interface MapLibreAdapterOptions {
|
|
24
|
+
vehicleRotationOrigin?: string;
|
|
25
|
+
vehicleHtml?: string;
|
|
26
|
+
}
|
|
27
|
+
declare class MapLibreAdapter implements MapRendererAdapter {
|
|
28
|
+
private readonly map;
|
|
29
|
+
private marker;
|
|
30
|
+
private routeInitialized;
|
|
31
|
+
private readonly opts;
|
|
32
|
+
constructor(map: MapLibreMap, options?: MapLibreAdapterOptions);
|
|
33
|
+
updateVehicle(coord: Coordinate, bearing: number, _state: NavCoreState, _style?: VehicleStyle): void;
|
|
34
|
+
drawRoute(coords: Coordinate[], style?: RouteStyle): void;
|
|
35
|
+
clearRoute(): void;
|
|
36
|
+
panCamera(coord: Coordinate, bearing: number, options?: CameraOptions): void;
|
|
37
|
+
destroy(): void;
|
|
38
|
+
private createMarker;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { MapLibreAdapter, type MapLibreAdapterOptions };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { MapRendererAdapter, Coordinate, NavCoreState, VehicleStyle, RouteStyle, CameraOptions } from '@ingissa/navcore-core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* MapLibreAdapter — NavCore renderer adapter for MapLibre GL JS.
|
|
5
|
+
* Peer dependency: maplibre-gl >= 3.0.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
interface MapLibreMap {
|
|
9
|
+
getSource(id: string): unknown;
|
|
10
|
+
addSource(id: string, source: unknown): void;
|
|
11
|
+
removeSource(id: string): void;
|
|
12
|
+
getLayer(id: string): unknown;
|
|
13
|
+
addLayer(layer: unknown): void;
|
|
14
|
+
removeLayer(id: string): void;
|
|
15
|
+
easeTo(options: {
|
|
16
|
+
center?: [number, number];
|
|
17
|
+
bearing?: number;
|
|
18
|
+
zoom?: number;
|
|
19
|
+
pitch?: number;
|
|
20
|
+
duration?: number;
|
|
21
|
+
}): void;
|
|
22
|
+
}
|
|
23
|
+
interface MapLibreAdapterOptions {
|
|
24
|
+
vehicleRotationOrigin?: string;
|
|
25
|
+
vehicleHtml?: string;
|
|
26
|
+
}
|
|
27
|
+
declare class MapLibreAdapter implements MapRendererAdapter {
|
|
28
|
+
private readonly map;
|
|
29
|
+
private marker;
|
|
30
|
+
private routeInitialized;
|
|
31
|
+
private readonly opts;
|
|
32
|
+
constructor(map: MapLibreMap, options?: MapLibreAdapterOptions);
|
|
33
|
+
updateVehicle(coord: Coordinate, bearing: number, _state: NavCoreState, _style?: VehicleStyle): void;
|
|
34
|
+
drawRoute(coords: Coordinate[], style?: RouteStyle): void;
|
|
35
|
+
clearRoute(): void;
|
|
36
|
+
panCamera(coord: Coordinate, bearing: number, options?: CameraOptions): void;
|
|
37
|
+
destroy(): void;
|
|
38
|
+
private createMarker;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { MapLibreAdapter, type MapLibreAdapterOptions };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/MapLibreAdapter.ts
|
|
4
|
+
var SOURCE_ID = "navcore-route";
|
|
5
|
+
var LAYER_ID = "navcore-route-line";
|
|
6
|
+
var DEFAULT_VEHICLE_HTML = `
|
|
7
|
+
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
8
|
+
<circle cx="16" cy="16" r="12" fill="#7c3aed" stroke="white" stroke-width="3"/>
|
|
9
|
+
<path d="M16 8 L20 20 L16 17 L12 20 Z" fill="white"/>
|
|
10
|
+
</svg>`;
|
|
11
|
+
var MapLibreAdapter = class {
|
|
12
|
+
constructor(map, options) {
|
|
13
|
+
this.marker = null;
|
|
14
|
+
this.routeInitialized = false;
|
|
15
|
+
this.map = map;
|
|
16
|
+
this.opts = {
|
|
17
|
+
vehicleRotationOrigin: options?.vehicleRotationOrigin ?? "center center",
|
|
18
|
+
vehicleHtml: options?.vehicleHtml ?? DEFAULT_VEHICLE_HTML
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
updateVehicle(coord, bearing, _state, _style) {
|
|
22
|
+
if (!this.marker) this.marker = this.createMarker(coord);
|
|
23
|
+
this.marker.setLngLat(coord);
|
|
24
|
+
const el = this.marker.getElement();
|
|
25
|
+
el.style.transform = `rotate(${bearing}deg)`;
|
|
26
|
+
el.style.transformOrigin = this.opts.vehicleRotationOrigin;
|
|
27
|
+
}
|
|
28
|
+
drawRoute(coords, style) {
|
|
29
|
+
const geojson = {
|
|
30
|
+
type: "FeatureCollection",
|
|
31
|
+
features: [{
|
|
32
|
+
type: "Feature",
|
|
33
|
+
properties: {},
|
|
34
|
+
geometry: { type: "LineString", coordinates: coords }
|
|
35
|
+
}]
|
|
36
|
+
};
|
|
37
|
+
if (this.routeInitialized && this.map.getSource(SOURCE_ID)) {
|
|
38
|
+
this.map.getSource(SOURCE_ID).setData(geojson);
|
|
39
|
+
} else {
|
|
40
|
+
this.map.addSource(SOURCE_ID, { type: "geojson", data: geojson });
|
|
41
|
+
this.map.addLayer({
|
|
42
|
+
id: LAYER_ID,
|
|
43
|
+
type: "line",
|
|
44
|
+
source: SOURCE_ID,
|
|
45
|
+
layout: { "line-join": "round", "line-cap": "round" },
|
|
46
|
+
paint: {
|
|
47
|
+
"line-color": style?.color ?? "#7c3aed",
|
|
48
|
+
"line-width": style?.width ?? 4,
|
|
49
|
+
"line-opacity": style?.opacity ?? 0.9,
|
|
50
|
+
...style?.dashArray ? { "line-dasharray": style.dashArray } : {}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
this.routeInitialized = true;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
clearRoute() {
|
|
57
|
+
if (this.map.getLayer(LAYER_ID)) this.map.removeLayer(LAYER_ID);
|
|
58
|
+
if (this.map.getSource(SOURCE_ID)) this.map.removeSource(SOURCE_ID);
|
|
59
|
+
this.routeInitialized = false;
|
|
60
|
+
}
|
|
61
|
+
panCamera(coord, bearing, options) {
|
|
62
|
+
this.map.easeTo({
|
|
63
|
+
center: coord,
|
|
64
|
+
bearing,
|
|
65
|
+
zoom: options?.zoom,
|
|
66
|
+
pitch: options?.pitch ?? 0,
|
|
67
|
+
duration: options?.animate !== false ? options?.animationDurationMs ?? 300 : 0
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
destroy() {
|
|
71
|
+
this.clearRoute();
|
|
72
|
+
this.marker?.remove();
|
|
73
|
+
this.marker = null;
|
|
74
|
+
}
|
|
75
|
+
createMarker(coord) {
|
|
76
|
+
const el = document.createElement("div");
|
|
77
|
+
el.innerHTML = this.opts.vehicleHtml;
|
|
78
|
+
const ML = globalThis.maplibregl;
|
|
79
|
+
if (!ML) throw new Error("[MapLibreAdapter] maplibregl not found on globalThis");
|
|
80
|
+
return new ML.Marker({ element: el }).setLngLat(coord).addTo(this.map);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
exports.MapLibreAdapter = MapLibreAdapter;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// src/MapLibreAdapter.ts
|
|
2
|
+
var SOURCE_ID = "navcore-route";
|
|
3
|
+
var LAYER_ID = "navcore-route-line";
|
|
4
|
+
var DEFAULT_VEHICLE_HTML = `
|
|
5
|
+
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
6
|
+
<circle cx="16" cy="16" r="12" fill="#7c3aed" stroke="white" stroke-width="3"/>
|
|
7
|
+
<path d="M16 8 L20 20 L16 17 L12 20 Z" fill="white"/>
|
|
8
|
+
</svg>`;
|
|
9
|
+
var MapLibreAdapter = class {
|
|
10
|
+
constructor(map, options) {
|
|
11
|
+
this.marker = null;
|
|
12
|
+
this.routeInitialized = false;
|
|
13
|
+
this.map = map;
|
|
14
|
+
this.opts = {
|
|
15
|
+
vehicleRotationOrigin: options?.vehicleRotationOrigin ?? "center center",
|
|
16
|
+
vehicleHtml: options?.vehicleHtml ?? DEFAULT_VEHICLE_HTML
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
updateVehicle(coord, bearing, _state, _style) {
|
|
20
|
+
if (!this.marker) this.marker = this.createMarker(coord);
|
|
21
|
+
this.marker.setLngLat(coord);
|
|
22
|
+
const el = this.marker.getElement();
|
|
23
|
+
el.style.transform = `rotate(${bearing}deg)`;
|
|
24
|
+
el.style.transformOrigin = this.opts.vehicleRotationOrigin;
|
|
25
|
+
}
|
|
26
|
+
drawRoute(coords, style) {
|
|
27
|
+
const geojson = {
|
|
28
|
+
type: "FeatureCollection",
|
|
29
|
+
features: [{
|
|
30
|
+
type: "Feature",
|
|
31
|
+
properties: {},
|
|
32
|
+
geometry: { type: "LineString", coordinates: coords }
|
|
33
|
+
}]
|
|
34
|
+
};
|
|
35
|
+
if (this.routeInitialized && this.map.getSource(SOURCE_ID)) {
|
|
36
|
+
this.map.getSource(SOURCE_ID).setData(geojson);
|
|
37
|
+
} else {
|
|
38
|
+
this.map.addSource(SOURCE_ID, { type: "geojson", data: geojson });
|
|
39
|
+
this.map.addLayer({
|
|
40
|
+
id: LAYER_ID,
|
|
41
|
+
type: "line",
|
|
42
|
+
source: SOURCE_ID,
|
|
43
|
+
layout: { "line-join": "round", "line-cap": "round" },
|
|
44
|
+
paint: {
|
|
45
|
+
"line-color": style?.color ?? "#7c3aed",
|
|
46
|
+
"line-width": style?.width ?? 4,
|
|
47
|
+
"line-opacity": style?.opacity ?? 0.9,
|
|
48
|
+
...style?.dashArray ? { "line-dasharray": style.dashArray } : {}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
this.routeInitialized = true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
clearRoute() {
|
|
55
|
+
if (this.map.getLayer(LAYER_ID)) this.map.removeLayer(LAYER_ID);
|
|
56
|
+
if (this.map.getSource(SOURCE_ID)) this.map.removeSource(SOURCE_ID);
|
|
57
|
+
this.routeInitialized = false;
|
|
58
|
+
}
|
|
59
|
+
panCamera(coord, bearing, options) {
|
|
60
|
+
this.map.easeTo({
|
|
61
|
+
center: coord,
|
|
62
|
+
bearing,
|
|
63
|
+
zoom: options?.zoom,
|
|
64
|
+
pitch: options?.pitch ?? 0,
|
|
65
|
+
duration: options?.animate !== false ? options?.animationDurationMs ?? 300 : 0
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
destroy() {
|
|
69
|
+
this.clearRoute();
|
|
70
|
+
this.marker?.remove();
|
|
71
|
+
this.marker = null;
|
|
72
|
+
}
|
|
73
|
+
createMarker(coord) {
|
|
74
|
+
const el = document.createElement("div");
|
|
75
|
+
el.innerHTML = this.opts.vehicleHtml;
|
|
76
|
+
const ML = globalThis.maplibregl;
|
|
77
|
+
if (!ML) throw new Error("[MapLibreAdapter] maplibregl not found on globalThis");
|
|
78
|
+
return new ML.Marker({ element: el }).setLngLat(coord).addTo(this.map);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export { MapLibreAdapter };
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ingissa/navcore-maplibre",
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"description": "NavCore renderer adapter for MapLibre GL JS",
|
|
5
|
+
"author": "Ingissa <8abnav@gmail.com>",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/index.mjs",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"require": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": ["dist"],
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"license": "Commercial",
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"engines": { "node": ">=16" },
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsup",
|
|
25
|
+
"prepublishOnly": "npm run build"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@ingissa/navcore-core": "^1.0.4",
|
|
29
|
+
"maplibre-gl": ">=3.0.0"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {}
|
|
32
|
+
}
|