@ingissa/navcore-google-maps 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,87 @@
1
+ import { MapRendererAdapter, Coordinate, NavCoreState, VehicleStyle, RouteStyle, CameraOptions } from '@ingissa/navcore-core';
2
+
3
+ /**
4
+ * GoogleMapsAdapter — NavCore renderer adapter for Google Maps JS API v3.
5
+ * Peer dependency: @types/google.maps (type-only)
6
+ */
7
+
8
+ declare namespace google {
9
+ namespace maps {
10
+ class Map {
11
+ panTo(p: {
12
+ lat: number;
13
+ lng: number;
14
+ }): void;
15
+ setZoom(z: number): void;
16
+ }
17
+ class Marker {
18
+ constructor(opts?: {
19
+ position?: {
20
+ lat: number;
21
+ lng: number;
22
+ };
23
+ map?: Map;
24
+ icon?: unknown;
25
+ optimized?: boolean;
26
+ });
27
+ setPosition(p: {
28
+ lat: number;
29
+ lng: number;
30
+ }): void;
31
+ setIcon(i: unknown): void;
32
+ setMap(m: Map | null): void;
33
+ }
34
+ class Polyline {
35
+ constructor(opts?: {
36
+ path?: {
37
+ lat: number;
38
+ lng: number;
39
+ }[];
40
+ map?: Map;
41
+ strokeColor?: string;
42
+ strokeWeight?: number;
43
+ strokeOpacity?: number;
44
+ icons?: unknown[];
45
+ });
46
+ setPath(path: {
47
+ lat: number;
48
+ lng: number;
49
+ }[]): void;
50
+ setMap(m: Map | null): void;
51
+ }
52
+ class Point {
53
+ constructor(x: number, y: number);
54
+ }
55
+ enum SymbolPath {
56
+ FORWARD_CLOSED_ARROW = 1
57
+ }
58
+ interface Symbol {
59
+ path: SymbolPath;
60
+ scale: number;
61
+ fillColor: string;
62
+ fillOpacity: number;
63
+ strokeColor: string;
64
+ strokeWeight: number;
65
+ rotation: number;
66
+ anchor: Point;
67
+ }
68
+ }
69
+ }
70
+ interface GoogleMapsAdapterOptions {
71
+ vehicleIconScale?: number;
72
+ }
73
+ declare class GoogleMapsAdapter implements MapRendererAdapter {
74
+ private readonly map;
75
+ private polyline;
76
+ private marker;
77
+ private readonly opts;
78
+ constructor(map: google.maps.Map, options?: GoogleMapsAdapterOptions);
79
+ updateVehicle(coord: Coordinate, bearing: number, _state: NavCoreState, _style?: VehicleStyle): void;
80
+ drawRoute(coords: Coordinate[], style?: RouteStyle): void;
81
+ clearRoute(): void;
82
+ panCamera(coord: Coordinate, bearing: number, options?: CameraOptions): void;
83
+ destroy(): void;
84
+ private buildIcon;
85
+ }
86
+
87
+ export { GoogleMapsAdapter, type GoogleMapsAdapterOptions };
@@ -0,0 +1,87 @@
1
+ import { MapRendererAdapter, Coordinate, NavCoreState, VehicleStyle, RouteStyle, CameraOptions } from '@ingissa/navcore-core';
2
+
3
+ /**
4
+ * GoogleMapsAdapter — NavCore renderer adapter for Google Maps JS API v3.
5
+ * Peer dependency: @types/google.maps (type-only)
6
+ */
7
+
8
+ declare namespace google {
9
+ namespace maps {
10
+ class Map {
11
+ panTo(p: {
12
+ lat: number;
13
+ lng: number;
14
+ }): void;
15
+ setZoom(z: number): void;
16
+ }
17
+ class Marker {
18
+ constructor(opts?: {
19
+ position?: {
20
+ lat: number;
21
+ lng: number;
22
+ };
23
+ map?: Map;
24
+ icon?: unknown;
25
+ optimized?: boolean;
26
+ });
27
+ setPosition(p: {
28
+ lat: number;
29
+ lng: number;
30
+ }): void;
31
+ setIcon(i: unknown): void;
32
+ setMap(m: Map | null): void;
33
+ }
34
+ class Polyline {
35
+ constructor(opts?: {
36
+ path?: {
37
+ lat: number;
38
+ lng: number;
39
+ }[];
40
+ map?: Map;
41
+ strokeColor?: string;
42
+ strokeWeight?: number;
43
+ strokeOpacity?: number;
44
+ icons?: unknown[];
45
+ });
46
+ setPath(path: {
47
+ lat: number;
48
+ lng: number;
49
+ }[]): void;
50
+ setMap(m: Map | null): void;
51
+ }
52
+ class Point {
53
+ constructor(x: number, y: number);
54
+ }
55
+ enum SymbolPath {
56
+ FORWARD_CLOSED_ARROW = 1
57
+ }
58
+ interface Symbol {
59
+ path: SymbolPath;
60
+ scale: number;
61
+ fillColor: string;
62
+ fillOpacity: number;
63
+ strokeColor: string;
64
+ strokeWeight: number;
65
+ rotation: number;
66
+ anchor: Point;
67
+ }
68
+ }
69
+ }
70
+ interface GoogleMapsAdapterOptions {
71
+ vehicleIconScale?: number;
72
+ }
73
+ declare class GoogleMapsAdapter implements MapRendererAdapter {
74
+ private readonly map;
75
+ private polyline;
76
+ private marker;
77
+ private readonly opts;
78
+ constructor(map: google.maps.Map, options?: GoogleMapsAdapterOptions);
79
+ updateVehicle(coord: Coordinate, bearing: number, _state: NavCoreState, _style?: VehicleStyle): void;
80
+ drawRoute(coords: Coordinate[], style?: RouteStyle): void;
81
+ clearRoute(): void;
82
+ panCamera(coord: Coordinate, bearing: number, options?: CameraOptions): void;
83
+ destroy(): void;
84
+ private buildIcon;
85
+ }
86
+
87
+ export { GoogleMapsAdapter, type GoogleMapsAdapterOptions };
package/dist/index.js ADDED
@@ -0,0 +1,72 @@
1
+ 'use strict';
2
+
3
+ // src/GoogleMapsAdapter.ts
4
+ var GoogleMapsAdapter = class {
5
+ constructor(map, options) {
6
+ this.polyline = null;
7
+ this.marker = null;
8
+ this.map = map;
9
+ this.opts = { vehicleIconScale: options?.vehicleIconScale ?? 1 };
10
+ }
11
+ updateVehicle(coord, bearing, _state, _style) {
12
+ const position = { lat: coord[1], lng: coord[0] };
13
+ if (!this.marker) {
14
+ this.marker = new google.maps.Marker({
15
+ position,
16
+ map: this.map,
17
+ icon: this.buildIcon(bearing),
18
+ optimized: false
19
+ });
20
+ } else {
21
+ this.marker.setPosition(position);
22
+ this.marker.setIcon(this.buildIcon(bearing));
23
+ }
24
+ }
25
+ drawRoute(coords, style) {
26
+ const path = coords.map((c) => ({ lat: c[1], lng: c[0] }));
27
+ if (this.polyline) {
28
+ this.polyline.setPath(path);
29
+ } else {
30
+ this.polyline = new google.maps.Polyline({
31
+ path,
32
+ map: this.map,
33
+ strokeColor: style?.color ?? "#7c3aed",
34
+ strokeWeight: style?.width ?? 4,
35
+ strokeOpacity: style?.opacity ?? 0.9,
36
+ icons: style?.dashArray ? [{
37
+ icon: { path: "M 0,-1 0,1", strokeOpacity: 1, scale: 2 },
38
+ offset: "0",
39
+ repeat: `${style.dashArray[0] ?? 10}px`
40
+ }] : void 0
41
+ });
42
+ }
43
+ }
44
+ clearRoute() {
45
+ this.polyline?.setMap(null);
46
+ this.polyline = null;
47
+ }
48
+ panCamera(coord, bearing, options) {
49
+ this.map.panTo({ lat: coord[1], lng: coord[0] });
50
+ if (options?.zoom !== void 0) this.map.setZoom(options.zoom);
51
+ this.map.__navcoreBearing = bearing;
52
+ }
53
+ destroy() {
54
+ this.clearRoute();
55
+ this.marker?.setMap(null);
56
+ this.marker = null;
57
+ }
58
+ buildIcon(bearing) {
59
+ return {
60
+ path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
61
+ scale: 5 * this.opts.vehicleIconScale,
62
+ fillColor: "#7c3aed",
63
+ fillOpacity: 1,
64
+ strokeColor: "#ffffff",
65
+ strokeWeight: 2,
66
+ rotation: bearing,
67
+ anchor: new google.maps.Point(0, 2.5)
68
+ };
69
+ }
70
+ };
71
+
72
+ exports.GoogleMapsAdapter = GoogleMapsAdapter;
package/dist/index.mjs ADDED
@@ -0,0 +1,70 @@
1
+ // src/GoogleMapsAdapter.ts
2
+ var GoogleMapsAdapter = class {
3
+ constructor(map, options) {
4
+ this.polyline = null;
5
+ this.marker = null;
6
+ this.map = map;
7
+ this.opts = { vehicleIconScale: options?.vehicleIconScale ?? 1 };
8
+ }
9
+ updateVehicle(coord, bearing, _state, _style) {
10
+ const position = { lat: coord[1], lng: coord[0] };
11
+ if (!this.marker) {
12
+ this.marker = new google.maps.Marker({
13
+ position,
14
+ map: this.map,
15
+ icon: this.buildIcon(bearing),
16
+ optimized: false
17
+ });
18
+ } else {
19
+ this.marker.setPosition(position);
20
+ this.marker.setIcon(this.buildIcon(bearing));
21
+ }
22
+ }
23
+ drawRoute(coords, style) {
24
+ const path = coords.map((c) => ({ lat: c[1], lng: c[0] }));
25
+ if (this.polyline) {
26
+ this.polyline.setPath(path);
27
+ } else {
28
+ this.polyline = new google.maps.Polyline({
29
+ path,
30
+ map: this.map,
31
+ strokeColor: style?.color ?? "#7c3aed",
32
+ strokeWeight: style?.width ?? 4,
33
+ strokeOpacity: style?.opacity ?? 0.9,
34
+ icons: style?.dashArray ? [{
35
+ icon: { path: "M 0,-1 0,1", strokeOpacity: 1, scale: 2 },
36
+ offset: "0",
37
+ repeat: `${style.dashArray[0] ?? 10}px`
38
+ }] : void 0
39
+ });
40
+ }
41
+ }
42
+ clearRoute() {
43
+ this.polyline?.setMap(null);
44
+ this.polyline = null;
45
+ }
46
+ panCamera(coord, bearing, options) {
47
+ this.map.panTo({ lat: coord[1], lng: coord[0] });
48
+ if (options?.zoom !== void 0) this.map.setZoom(options.zoom);
49
+ this.map.__navcoreBearing = bearing;
50
+ }
51
+ destroy() {
52
+ this.clearRoute();
53
+ this.marker?.setMap(null);
54
+ this.marker = null;
55
+ }
56
+ buildIcon(bearing) {
57
+ return {
58
+ path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
59
+ scale: 5 * this.opts.vehicleIconScale,
60
+ fillColor: "#7c3aed",
61
+ fillOpacity: 1,
62
+ strokeColor: "#ffffff",
63
+ strokeWeight: 2,
64
+ rotation: bearing,
65
+ anchor: new google.maps.Point(0, 2.5)
66
+ };
67
+ }
68
+ };
69
+
70
+ export { GoogleMapsAdapter };
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@ingissa/navcore-google-maps",
3
+ "version": "1.0.4",
4
+ "description": "NavCore renderer adapter for Google Maps JS API",
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
+ "@types/google.maps": ">=3.0.0"
30
+ },
31
+ "dependencies": {}
32
+ }