@ingissa/navcore-leaflet 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.
@@ -0,0 +1,37 @@
1
+ import { MapRendererAdapter, Coordinate, NavCoreState, VehicleStyle, RouteStyle, CameraOptions } from '@ingissa/navcore-core';
2
+
3
+ /**
4
+ * LeafletAdapter — NavCore renderer adapter for Leaflet.js.
5
+ * Peer dependency: leaflet >= 1.9.0
6
+ */
7
+
8
+ interface LeafletMap {
9
+ panTo(coord: [number, number], options?: {
10
+ animate?: boolean;
11
+ duration?: number;
12
+ }): void;
13
+ setView(coord: [number, number], zoom: number, options?: {
14
+ animate?: boolean;
15
+ }): void;
16
+ }
17
+ interface LeafletAdapterOptions {
18
+ vehicleIconHtml?: string;
19
+ iconSize?: [number, number];
20
+ }
21
+ declare class LeafletAdapter implements MapRendererAdapter {
22
+ private readonly map;
23
+ private polyline;
24
+ private marker;
25
+ private markerEl;
26
+ private readonly opts;
27
+ constructor(map: LeafletMap, options?: LeafletAdapterOptions);
28
+ updateVehicle(coord: Coordinate, bearing: number, _state: NavCoreState, _style?: VehicleStyle): void;
29
+ drawRoute(coords: Coordinate[], style?: RouteStyle): void;
30
+ clearRoute(): void;
31
+ panCamera(coord: Coordinate, _bearing: number, options?: CameraOptions): void;
32
+ destroy(): void;
33
+ private createMarker;
34
+ private getLeaflet;
35
+ }
36
+
37
+ export { LeafletAdapter, type LeafletAdapterOptions };
@@ -0,0 +1,37 @@
1
+ import { MapRendererAdapter, Coordinate, NavCoreState, VehicleStyle, RouteStyle, CameraOptions } from '@ingissa/navcore-core';
2
+
3
+ /**
4
+ * LeafletAdapter — NavCore renderer adapter for Leaflet.js.
5
+ * Peer dependency: leaflet >= 1.9.0
6
+ */
7
+
8
+ interface LeafletMap {
9
+ panTo(coord: [number, number], options?: {
10
+ animate?: boolean;
11
+ duration?: number;
12
+ }): void;
13
+ setView(coord: [number, number], zoom: number, options?: {
14
+ animate?: boolean;
15
+ }): void;
16
+ }
17
+ interface LeafletAdapterOptions {
18
+ vehicleIconHtml?: string;
19
+ iconSize?: [number, number];
20
+ }
21
+ declare class LeafletAdapter implements MapRendererAdapter {
22
+ private readonly map;
23
+ private polyline;
24
+ private marker;
25
+ private markerEl;
26
+ private readonly opts;
27
+ constructor(map: LeafletMap, options?: LeafletAdapterOptions);
28
+ updateVehicle(coord: Coordinate, bearing: number, _state: NavCoreState, _style?: VehicleStyle): void;
29
+ drawRoute(coords: Coordinate[], style?: RouteStyle): void;
30
+ clearRoute(): void;
31
+ panCamera(coord: Coordinate, _bearing: number, options?: CameraOptions): void;
32
+ destroy(): void;
33
+ private createMarker;
34
+ private getLeaflet;
35
+ }
36
+
37
+ export { LeafletAdapter, type LeafletAdapterOptions };
package/dist/index.js ADDED
@@ -0,0 +1,88 @@
1
+ 'use strict';
2
+
3
+ // src/LeafletAdapter.ts
4
+ var DEFAULT_ICON_HTML = `
5
+ <div style="width:32px;height:32px;transform-origin:center center;">
6
+ <svg width="32" height="32" viewBox="0 0 32 32" fill="none">
7
+ <circle cx="16" cy="16" r="12" fill="#7c3aed" stroke="white" stroke-width="3"/>
8
+ <path d="M16 8 L20 20 L16 17 L12 20 Z" fill="white"/>
9
+ </svg>
10
+ </div>`;
11
+ var LeafletAdapter = class {
12
+ constructor(map, options) {
13
+ this.polyline = null;
14
+ this.marker = null;
15
+ this.markerEl = null;
16
+ this.map = map;
17
+ this.opts = {
18
+ vehicleIconHtml: options?.vehicleIconHtml ?? DEFAULT_ICON_HTML,
19
+ iconSize: options?.iconSize ?? [32, 32]
20
+ };
21
+ }
22
+ updateVehicle(coord, bearing, _state, _style) {
23
+ const latlng = [coord[1], coord[0]];
24
+ if (!this.marker) {
25
+ this.marker = this.createMarker(latlng);
26
+ } else {
27
+ this.marker.setLatLng(latlng);
28
+ }
29
+ if (this.markerEl) {
30
+ this.markerEl.style.transform = `rotate(${bearing}deg)`;
31
+ this.markerEl.style.transformOrigin = "center center";
32
+ }
33
+ }
34
+ drawRoute(coords, style) {
35
+ const L = this.getLeaflet();
36
+ const latlngs = coords.map((c) => [c[1], c[0]]);
37
+ if (this.polyline) {
38
+ this.polyline.setLatLngs(latlngs);
39
+ } else {
40
+ this.polyline = L.polyline(latlngs, {
41
+ color: style?.color ?? "#7c3aed",
42
+ weight: style?.width ?? 4,
43
+ opacity: style?.opacity ?? 0.9,
44
+ dashArray: style?.dashArray?.join(",")
45
+ }).addTo(this.map);
46
+ }
47
+ }
48
+ clearRoute() {
49
+ this.polyline?.remove();
50
+ this.polyline = null;
51
+ }
52
+ panCamera(coord, _bearing, options) {
53
+ const latlng = [coord[1], coord[0]];
54
+ const animate = options?.animate !== false;
55
+ if (options?.zoom !== void 0) {
56
+ this.map.setView(latlng, options.zoom, { animate });
57
+ } else {
58
+ this.map.panTo(latlng, { animate, duration: (options?.animationDurationMs ?? 300) / 1e3 });
59
+ }
60
+ }
61
+ destroy() {
62
+ this.clearRoute();
63
+ this.marker?.remove();
64
+ this.marker = null;
65
+ this.markerEl = null;
66
+ }
67
+ createMarker(latlng) {
68
+ const L = this.getLeaflet();
69
+ const [w, h] = this.opts.iconSize;
70
+ const el = document.createElement("div");
71
+ el.innerHTML = this.opts.vehicleIconHtml;
72
+ this.markerEl = el.firstElementChild ?? el;
73
+ const icon = L.divIcon({
74
+ html: el,
75
+ iconSize: [w, h],
76
+ iconAnchor: [w / 2, h / 2],
77
+ className: "navcore-vehicle-marker"
78
+ });
79
+ return L.marker(latlng, { icon }).addTo(this.map);
80
+ }
81
+ getLeaflet() {
82
+ const L = globalThis.L ?? globalThis.leaflet;
83
+ if (!L) throw new Error("[LeafletAdapter] Leaflet not found on globalThis");
84
+ return L;
85
+ }
86
+ };
87
+
88
+ exports.LeafletAdapter = LeafletAdapter;
package/dist/index.mjs ADDED
@@ -0,0 +1,86 @@
1
+ // src/LeafletAdapter.ts
2
+ var DEFAULT_ICON_HTML = `
3
+ <div style="width:32px;height:32px;transform-origin:center center;">
4
+ <svg width="32" height="32" viewBox="0 0 32 32" fill="none">
5
+ <circle cx="16" cy="16" r="12" fill="#7c3aed" stroke="white" stroke-width="3"/>
6
+ <path d="M16 8 L20 20 L16 17 L12 20 Z" fill="white"/>
7
+ </svg>
8
+ </div>`;
9
+ var LeafletAdapter = class {
10
+ constructor(map, options) {
11
+ this.polyline = null;
12
+ this.marker = null;
13
+ this.markerEl = null;
14
+ this.map = map;
15
+ this.opts = {
16
+ vehicleIconHtml: options?.vehicleIconHtml ?? DEFAULT_ICON_HTML,
17
+ iconSize: options?.iconSize ?? [32, 32]
18
+ };
19
+ }
20
+ updateVehicle(coord, bearing, _state, _style) {
21
+ const latlng = [coord[1], coord[0]];
22
+ if (!this.marker) {
23
+ this.marker = this.createMarker(latlng);
24
+ } else {
25
+ this.marker.setLatLng(latlng);
26
+ }
27
+ if (this.markerEl) {
28
+ this.markerEl.style.transform = `rotate(${bearing}deg)`;
29
+ this.markerEl.style.transformOrigin = "center center";
30
+ }
31
+ }
32
+ drawRoute(coords, style) {
33
+ const L = this.getLeaflet();
34
+ const latlngs = coords.map((c) => [c[1], c[0]]);
35
+ if (this.polyline) {
36
+ this.polyline.setLatLngs(latlngs);
37
+ } else {
38
+ this.polyline = L.polyline(latlngs, {
39
+ color: style?.color ?? "#7c3aed",
40
+ weight: style?.width ?? 4,
41
+ opacity: style?.opacity ?? 0.9,
42
+ dashArray: style?.dashArray?.join(",")
43
+ }).addTo(this.map);
44
+ }
45
+ }
46
+ clearRoute() {
47
+ this.polyline?.remove();
48
+ this.polyline = null;
49
+ }
50
+ panCamera(coord, _bearing, options) {
51
+ const latlng = [coord[1], coord[0]];
52
+ const animate = options?.animate !== false;
53
+ if (options?.zoom !== void 0) {
54
+ this.map.setView(latlng, options.zoom, { animate });
55
+ } else {
56
+ this.map.panTo(latlng, { animate, duration: (options?.animationDurationMs ?? 300) / 1e3 });
57
+ }
58
+ }
59
+ destroy() {
60
+ this.clearRoute();
61
+ this.marker?.remove();
62
+ this.marker = null;
63
+ this.markerEl = null;
64
+ }
65
+ createMarker(latlng) {
66
+ const L = this.getLeaflet();
67
+ const [w, h] = this.opts.iconSize;
68
+ const el = document.createElement("div");
69
+ el.innerHTML = this.opts.vehicleIconHtml;
70
+ this.markerEl = el.firstElementChild ?? el;
71
+ const icon = L.divIcon({
72
+ html: el,
73
+ iconSize: [w, h],
74
+ iconAnchor: [w / 2, h / 2],
75
+ className: "navcore-vehicle-marker"
76
+ });
77
+ return L.marker(latlng, { icon }).addTo(this.map);
78
+ }
79
+ getLeaflet() {
80
+ const L = globalThis.L ?? globalThis.leaflet;
81
+ if (!L) throw new Error("[LeafletAdapter] Leaflet not found on globalThis");
82
+ return L;
83
+ }
84
+ };
85
+
86
+ export { LeafletAdapter };
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@ingissa/navcore-leaflet",
3
+ "version": "1.0.4",
4
+ "description": "NavCore renderer adapter for Leaflet.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
+ "leaflet": ">=1.9.0"
30
+ },
31
+ "dependencies": {}
32
+ }