@tomtom-org/maps-sdk-plugin-route-dragging 0.0.2 → 0.0.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/CHANGELOG.md +30 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.es.js +1 -1
- package/package.json +3 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# @tomtom-org/maps-sdk-plugin-route-dragging
|
|
2
|
+
|
|
3
|
+
## 0.0.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#2823](https://github.com/tomtom-internal/maps-sdk-js/pull/2823) [`d1b906f`](https://github.com/tomtom-internal/maps-sdk-js/commit/d1b906f460c33607bf9789475ad85bff339b7c3b) Thanks [@DanielForniessoria-TomTom](https://github.com/DanielForniessoria-TomTom)! - The package ships its `CHANGELOG.md`, as the SDK does, so you can read what changed between two releases from `node_modules`
|
|
8
|
+
|
|
9
|
+
- [#2813](https://github.com/tomtom-internal/maps-sdk-js/pull/2813) [`c186703`](https://github.com/tomtom-internal/maps-sdk-js/commit/c1867038e9a38e300ea72e8812419204bf008e73) Thanks [@DanielForniessoria-TomTom](https://github.com/DanielForniessoria-TomTom)! - A pin drags from where it is drawn, and a drop after a failed plan plans again
|
|
10
|
+
|
|
11
|
+
- A clear drops the route plans still in flight, and nothing plans after `remove()`
|
|
12
|
+
- A line drag that can't extend the route keeps it as it was
|
|
13
|
+
|
|
14
|
+
## 0.0.2
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- [#2803](https://github.com/tomtom-internal/maps-sdk-js/pull/2803) [`1a62c72`](https://github.com/tomtom-internal/maps-sdk-js/commit/1a62c72eb372d037397bb88485ea731763f3e554) Thanks [@DanielForniessoria-TomTom](https://github.com/DanielForniessoria-TomTom)! - The README links the repository's security policy page, which sends a vulnerability report to TomTom's HackerOne program
|
|
19
|
+
|
|
20
|
+
## 0.0.1
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- [#2791](https://github.com/tomtom-internal/maps-sdk-js/pull/2791) [`968f63d`](https://github.com/tomtom-internal/maps-sdk-js/commit/968f63de577620c35c028f3481b7c33d2bcf2e3a) Thanks [@AlvaroGraca-TomTom](https://github.com/AlvaroGraca-TomTom)! - Installs beside `@tomtom-org/maps-sdk` 1.0.0 and every later 1.x release: the peer range on the SDK runs up to `<2.0.0` instead of stopping below 1.0.0
|
|
25
|
+
|
|
26
|
+
- [#2766](https://github.com/tomtom-internal/maps-sdk-js/pull/2766) [`22215a6`](https://github.com/tomtom-internal/maps-sdk-js/commit/22215a65286f7a6bd274c2aa6bb75cf81e5fee1e) Thanks [@DanielForniessoria-TomTom](https://github.com/DanielForniessoria-TomTom)! - New plugin: edit a route on a `RoutingModule` by dragging with `RouteDragging`, and watch the route re-plan as you drag
|
|
27
|
+
|
|
28
|
+
- Move a stop by its pin, or pull a new stop off a route line, between the two stops its detour fits best
|
|
29
|
+
- The route re-plans every `planIntervalMS` during the drag and once more on the drop, through your own `plan` if you pass one, and `onRoutes` gets the answers in order
|
|
30
|
+
- With `showOnMap: false`, it shows nothing itself and reports each change to `onWaypointsChange`, for an app that keeps its stops in its own state
|
package/dist/index.d.ts
CHANGED
|
@@ -124,7 +124,7 @@ type RouteDraggingOptions = {
|
|
|
124
124
|
*/
|
|
125
125
|
onRoutes?: (routes: Routes, waypoints: PlanningWaypoint[]) => void;
|
|
126
126
|
/**
|
|
127
|
-
* Called when planning fails.
|
|
127
|
+
* Called when planning fails, or showing the moved waypoints, or showing or clearing the routes on the map does.
|
|
128
128
|
*
|
|
129
129
|
* @defaultValue a `console.warn`
|
|
130
130
|
*/
|
|
@@ -167,6 +167,7 @@ export declare class RouteDragging {
|
|
|
167
167
|
private waypoints;
|
|
168
168
|
private plannedWaypoints?;
|
|
169
169
|
private activeDrag?;
|
|
170
|
+
private removed;
|
|
170
171
|
constructor(routing: RoutingModule, options?: RouteDraggingOptions);
|
|
171
172
|
/**
|
|
172
173
|
* Whether a waypoint is being dragged.
|
|
@@ -188,6 +189,7 @@ export declare class RouteDragging {
|
|
|
188
189
|
* Stops listening to the routing module, and drops the plans still in flight.
|
|
189
190
|
*/
|
|
190
191
|
remove(): void;
|
|
192
|
+
private drawnPosition;
|
|
191
193
|
private startMove;
|
|
192
194
|
private dragTo;
|
|
193
195
|
private planRoutes;
|
package/dist/index.es.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{findBestWaypointInsertionIndex,getPosition}from"@tomtom-org/maps-sdk/core";import{calculateRoute,createLatestRequest}from"@tomtom-org/maps-sdk/services";import{
|
|
1
|
+
import{findBestWaypointInsertionIndex,getPosition}from"@tomtom-org/maps-sdk/core";import{calculateRoute,createLatestRequest}from"@tomtom-org/maps-sdk/services";import{throttle}from"lodash-es";var waypointAt=(t,n)=>{const o="object"!=typeof(s=n)||null===s||Array.isArray(s)||"Feature"!==s.type?void 0:n;var s;const{pauseDurationSeconds:i,legCostModel:a}=o?.properties??{};return{type:"Feature",...void 0!==o?.id&&{id:o.id},geometry:{type:"Point",coordinates:t},properties:{...void 0!==i&&{pauseDurationSeconds:i},...a&&{legCostModel:a}}}},planWithCalculateRoute=(t,n)=>calculateRoute({locations:t,signal:n}),warn=t=>console.warn("Route dragging could not plan, show or clear the routes, or show the waypoints",t),RouteDragging=class{routing;plan;showOnMap;onWaypointsChange;onRoutes;onError;latestRoutes=createLatestRequest({supersede:"on-answer"});planWhileDragging;unsubscribes;waypoints;plannedWaypoints;activeDrag;removed=!1;constructor(t,n={}){this.routing=t,this.waypoints=(t=>{const n=[];for(const o of t.features){const{index:t,id:s,indexType:i,iconID:a,stopDisplayIndex:e,stopDisplayLabel:r,stopDuration:p,...h}=o.properties;for(;n.length<t;)n.push(null);n[t]={...o,properties:h}}return n})(t.getShown().waypoints),this.plan=!1===n.plan?void 0:n.plan??planWithCalculateRoute,this.showOnMap=n.showOnMap??!0,this.onWaypointsChange=n.onWaypointsChange,this.onRoutes=n.onRoutes,this.onError=n.onError??warn,this.planWhileDragging=throttle(()=>{this.planRoutes()},n.planIntervalMS??500);const{events:o}=t,s=t=>(n,o)=>this.dragTo(t,o.toArray());this.unsubscribes=[o.on("shown-features",t=>{"waypoints"in t&&(this.waypoints=Array.isArray(t.waypoints)?t.waypoints:t.waypoints.features)}),o.waypoints.on("dragstart",(t,n)=>this.startMove(t.properties.index,t.geometry.coordinates,n.toArray())),o.waypoints.on("drag",s("drag")),o.waypoints.on("dragend",s("dragend")),...n.insertFromRouteLines??!0?[o.mainLines.on("dragstart",(t,n)=>{const o=n.toArray(),s=((t,n,o)=>{const s=n.flatMap((t,n)=>t?[{waypoint:t,index:n}]:[]);if(s.length<2)return;const i=findBestWaypointInsertionIndex(t,s.map(({waypoint:t})=>t),o);return s[Math.min(Math.max(i,1),s.length-1)].index})(t,this.waypoints,o);void 0!==s&&(this.waypoints=[...this.waypoints.slice(0,s),waypointAt(o),...this.waypoints.slice(s)],this.activeDrag={kind:"insert",waypointIndex:s,offset:[0,0]},this.dragTo("dragstart",o))}),o.mainLines.on("drag",s("drag")),o.mainLines.on("dragend",s("dragend"))]:[]]}get dragging(){return void 0!==this.activeDrag}getWaypoints(){return this.waypoints}async setWaypoints(t){await this.routing.showWaypoints(t),this.plannedWaypoints=void 0,await this.planRoutes()}remove(){this.removed=!0;for(const t of this.unsubscribes)t();this.planWhileDragging.cancel(),this.latestRoutes.cancel(),this.activeDrag=void 0}drawnPosition(t){const n=this.routing.getConfig()?.waypoints?.entryPoints;return getPosition(this.waypoints[t]??void 0,{useEntryPoint:n})}startMove(t,n,o){const[s,i]=this.drawnPosition(t)??n;this.activeDrag={kind:"move",waypointIndex:t,offset:[s-o[0],i-o[1]]},this.dragTo("dragstart",o)}dragTo(t,n){const o=this.activeDrag;if(!o)return;const{kind:s,waypointIndex:i,offset:a}=o,e=[n[0]+a[0],n[1]+a[1]],r=this.drawnPosition(i);r?.[0]===e[0]&&r[1]===e[1]||(this.waypoints=this.waypoints.map((t,n)=>n===i?waypointAt(e,t):t)),"dragend"===t&&(this.activeDrag=void 0),this.showOnMap&&this.routing.showWaypoints(this.waypoints).catch(this.onError),this.onWaypointsChange?.(this.waypoints,{type:t,kind:s,waypointIndex:i,position:e}),"dragend"===t?(this.planWhileDragging.cancel(),this.planRoutes()):"drag"===t&&this.planWhileDragging()}async planRoutes(){const{plan:t,waypoints:n}=this;if(!t||this.removed||n===this.plannedWaypoints)return;this.plannedWaypoints=n;const o=n.filter(t=>null!==t);try{if(o.length<2)return this.latestRoutes.cancel(),void(this.showOnMap&&await this.routing.clearRoutes());const s=await this.latestRoutes.run(n=>t(o,n));if(!s.current)return;this.showOnMap&&await this.routing.showRoutes(s.value),this.onRoutes?.(s.value,n)}catch(s){this.plannedWaypoints===n&&(this.plannedWaypoints=void 0),this.onError(s)}}};export{RouteDragging};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tomtom-org/maps-sdk-plugin-route-dragging",
|
|
3
3
|
"author": "TomTom International B.V.",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.3",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"description": "Edit a route on a TomTomMap by dragging: move a waypoint's pin or pull a new stop off the route line, and the route re-plans as you drag, its answers shown in order",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
@@ -22,12 +22,13 @@
|
|
|
22
22
|
"typescript": "^6.0.3",
|
|
23
23
|
"vite": "^8.3.4",
|
|
24
24
|
"vitest": "^5.0.5",
|
|
25
|
-
"@tomtom-org/maps-sdk": "1.0.0-rc.
|
|
25
|
+
"@tomtom-org/maps-sdk": "1.0.0-rc.6"
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
28
|
"dist",
|
|
29
29
|
"package.json",
|
|
30
30
|
"README.md",
|
|
31
|
+
"CHANGELOG.md",
|
|
31
32
|
"LICENSE.txt",
|
|
32
33
|
"THIRD_PARTY.txt",
|
|
33
34
|
"!**/*.map"
|