@any-routing/leaflet-engine 1.0.0-rc.1
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 +11 -0
- package/eslint.config.mjs +22 -0
- package/package.json +14 -0
- package/project.json +21 -0
- package/src/index.ts +1 -0
- package/src/lib/leaflet-engine.spec.ts +7 -0
- package/src/lib/leaflet-engine.ts +3 -0
- package/src/lib/projector.leaflet-defaults.plugin.ts +108 -0
- package/src/lib/projector.leaflet.plugin.ts +992 -0
- package/src/lib/projector.leaflet.plugin.types.ts +137 -0
- package/src/lib/utils/debounce.util.ts +164 -0
- package/tsconfig.json +23 -0
- package/tsconfig.lib.json +23 -0
- package/tsconfig.spec.json +22 -0
- package/vite.config.mts +59 -0
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# leaflet-engine
|
|
2
|
+
|
|
3
|
+
This library was generated with [Nx](https://nx.dev).
|
|
4
|
+
|
|
5
|
+
## Building
|
|
6
|
+
|
|
7
|
+
Run `nx build leaflet-engine` to build the library.
|
|
8
|
+
|
|
9
|
+
## Running unit tests
|
|
10
|
+
|
|
11
|
+
Run `nx test leaflet-engine` to execute the unit tests via [Vitest](https://vitest.dev/).
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import baseConfig from '../../../../eslint.config.mjs';
|
|
2
|
+
|
|
3
|
+
export default [
|
|
4
|
+
...baseConfig,
|
|
5
|
+
{
|
|
6
|
+
files: ['**/*.json'],
|
|
7
|
+
rules: {
|
|
8
|
+
'@nx/dependency-checks': [
|
|
9
|
+
'error',
|
|
10
|
+
{
|
|
11
|
+
ignoredFiles: [
|
|
12
|
+
'{projectRoot}/eslint.config.{js,cjs,mjs,ts,cts,mts}',
|
|
13
|
+
'{projectRoot}/vite.config.{js,ts,mjs,mts}',
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
languageOptions: {
|
|
19
|
+
parser: await import('jsonc-eslint-parser'),
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
];
|
package/package.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@any-routing/leaflet-engine",
|
|
3
|
+
"version": "1.0.0-rc.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./index.js",
|
|
6
|
+
"types": "./index.d.ts",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@turf/bbox": "7.4.0",
|
|
9
|
+
"@turf/helpers": "7.4.0",
|
|
10
|
+
"@types/geojson": "7946.0.16",
|
|
11
|
+
"@types/leaflet": "^1.9.22",
|
|
12
|
+
"leaflet": "^1.9.4"
|
|
13
|
+
}
|
|
14
|
+
}
|
package/project.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "leaflet-engine",
|
|
3
|
+
"$schema": "../../../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"sourceRoot": "libs/line-loader/libs/leaflet-engine/src",
|
|
5
|
+
"projectType": "library",
|
|
6
|
+
"release": {
|
|
7
|
+
"version": {
|
|
8
|
+
"manifestRootsToUpdate": ["dist/{projectRoot}"],
|
|
9
|
+
"currentVersionResolver": "git-tag",
|
|
10
|
+
"fallbackCurrentVersionResolver": "disk"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"tags": [],
|
|
14
|
+
"targets": {
|
|
15
|
+
"nx-release-publish": {
|
|
16
|
+
"options": {
|
|
17
|
+
"packageRoot": "dist/{projectRoot}"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/leaflet-engine';
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { divIcon, Marker } from 'leaflet';
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
LeafletProjectorOptions,
|
|
5
|
+
MarkerFactoryContext,
|
|
6
|
+
} from './projector.leaflet.plugin.types';
|
|
7
|
+
|
|
8
|
+
export const defaultLeafletMarkerFactory = ({
|
|
9
|
+
waypoint,
|
|
10
|
+
routeHover,
|
|
11
|
+
}: MarkerFactoryContext): Marker => {
|
|
12
|
+
if ((waypoint && !waypoint.properties.isFirst && !waypoint.properties.isLast) || routeHover) {
|
|
13
|
+
const width = waypoint ? 16 : 12;
|
|
14
|
+
const height = waypoint ? 16 : 12;
|
|
15
|
+
const fill = waypoint ? '#2546fe' : '#e207ff';
|
|
16
|
+
const stroke = waypoint ? '#0b1e61' : '#ffffff';
|
|
17
|
+
|
|
18
|
+
const icon = divIcon({
|
|
19
|
+
className: 'marker-wrapper',
|
|
20
|
+
html: `
|
|
21
|
+
<div
|
|
22
|
+
class="marker"
|
|
23
|
+
style="
|
|
24
|
+
width: ${width}px;
|
|
25
|
+
height: ${height}px;
|
|
26
|
+
"
|
|
27
|
+
>
|
|
28
|
+
<svg width="${width}" height="${height}" viewBox="0 0 24 24" aria-hidden="true">
|
|
29
|
+
<circle cx="12" cy="12" r="8.5" fill="${fill}" stroke="${stroke}" stroke-width="2.5" />
|
|
30
|
+
<circle cx="9" cy="9" r="2.2" fill="#ffffff" opacity="0.75" />
|
|
31
|
+
</svg>
|
|
32
|
+
</div>
|
|
33
|
+
`,
|
|
34
|
+
iconSize: [width, height],
|
|
35
|
+
iconAnchor: [width / 2, height / 2],
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return new Marker([0, 0], {
|
|
39
|
+
icon,
|
|
40
|
+
draggable: !!waypoint,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const isFirst = waypoint?.properties.isFirst === true;
|
|
45
|
+
const isLast = waypoint?.properties.isLast === true;
|
|
46
|
+
const color = isFirst ? '#11a775' : '#e53935';
|
|
47
|
+
const label = isFirst ? 'A' : isLast ? 'B' : '';
|
|
48
|
+
const size = 48;
|
|
49
|
+
const icon = divIcon({
|
|
50
|
+
className: 'marker-wrapper',
|
|
51
|
+
html: `
|
|
52
|
+
<div class="marker marker-waypoint marker-waypoint-${isFirst ? 'start' : 'end'}">
|
|
53
|
+
<svg width="${size}" height="${size}" viewBox="0 0 24 24" aria-hidden="true">
|
|
54
|
+
<path
|
|
55
|
+
fill="${color}"
|
|
56
|
+
stroke="#ffffff"
|
|
57
|
+
stroke-width="1.5"
|
|
58
|
+
d="M12 21.7l-.7-.7a48 48 0 0 1-3.5-4C6.2 14.7 4 12 4 10a8 8 0 1 1 16 0c0 2-2.2 4.7-3.8 7a48 48 0 0 1-3.5 4l-.7.7Z"
|
|
59
|
+
/>
|
|
60
|
+
<circle cx="12" cy="10" r="3" fill="#ffffff" />
|
|
61
|
+
${label ? `<text x="12" y="11.5" text-anchor="middle" font-size="3.5" font-weight="700" fill="${color}">${label}</text>` : ''}
|
|
62
|
+
</svg>
|
|
63
|
+
</div>
|
|
64
|
+
`,
|
|
65
|
+
iconSize: [size, size],
|
|
66
|
+
iconAnchor: [size / 2, size],
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
return new Marker([0, 0], {
|
|
70
|
+
icon,
|
|
71
|
+
draggable: !!waypoint,
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const defaultLeafletProjectorOptions = {
|
|
76
|
+
markerFactory: defaultLeafletMarkerFactory,
|
|
77
|
+
|
|
78
|
+
routeStyle: {
|
|
79
|
+
color: '#33C9EB',
|
|
80
|
+
weight: 5,
|
|
81
|
+
opacity: 1,
|
|
82
|
+
lineCap: 'round',
|
|
83
|
+
lineJoin: 'round',
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
routeOutlineStyle: {
|
|
87
|
+
color: '#ffffff',
|
|
88
|
+
weight: 9,
|
|
89
|
+
opacity: 0.95,
|
|
90
|
+
lineCap: 'round',
|
|
91
|
+
lineJoin: 'round',
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
selectedRouteStyle: {
|
|
95
|
+
color: '#e207ff',
|
|
96
|
+
weight: 5,
|
|
97
|
+
opacity: 1,
|
|
98
|
+
lineCap: 'round',
|
|
99
|
+
lineJoin: 'round',
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
maxWaypoints: Infinity,
|
|
103
|
+
canAddWaypoints: true,
|
|
104
|
+
canDragWaypoints: true,
|
|
105
|
+
canSelectRoute: true,
|
|
106
|
+
routesWhileDragging: true,
|
|
107
|
+
waypointDragCommitDebounceTime: 150,
|
|
108
|
+
} satisfies Omit<LeafletProjectorOptions, 'map'>;
|