terra-draw-route-snap-mode 0.0.1 → 0.1.2

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.
Files changed (77) hide show
  1. package/README.md +14 -5
  2. package/dist/routing.d.ts +17 -3
  3. package/dist/terra-draw-route-snap-mode.cjs +1 -1
  4. package/dist/terra-draw-route-snap-mode.cjs.map +1 -1
  5. package/dist/terra-draw-route-snap-mode.d.ts +2 -6
  6. package/dist/terra-draw-route-snap-mode.modern.js +1 -1
  7. package/dist/terra-draw-route-snap-mode.modern.js.map +1 -1
  8. package/dist/terra-draw-route-snap-mode.module.js +1 -1
  9. package/dist/terra-draw-route-snap-mode.module.js.map +1 -1
  10. package/dist/terra-draw-route-snap-mode.umd.js +1 -1
  11. package/dist/terra-draw-route-snap-mode.umd.js.map +1 -1
  12. package/package.json +28 -13
  13. package/src/routing.spec.ts +45 -0
  14. package/src/routing.ts +49 -9
  15. package/src/terra-draw-route-snap-mode.ts +13 -14
  16. package/src/terra-draw-route-snap.mode.spec.ts +2 -1
  17. package/.vscode/settings.json +0 -3
  18. package/CNAME +0 -1
  19. package/demo/assets/favicon.ico +0 -0
  20. package/demo/assets/icons/android-chrome-192x192.png +0 -0
  21. package/demo/assets/icons/android-chrome-512x512.png +0 -0
  22. package/demo/assets/icons/apple-touch-icon.png +0 -0
  23. package/demo/assets/icons/favicon-16x16.png +0 -0
  24. package/demo/assets/icons/favicon-32x32.png +0 -0
  25. package/demo/assets/icons/mstile-150x150.png +0 -0
  26. package/demo/assets/imgs/geolocation.png +0 -0
  27. package/demo/assets/imgs/github.png +0 -0
  28. package/demo/assets/imgs/logo.png +0 -0
  29. package/demo/components/app.tsx +0 -18
  30. package/demo/components/geojson-tab/GeoJSONTab.tsx +0 -42
  31. package/demo/components/geojson-tab/style.module.css +0 -30
  32. package/demo/components/geojson-tab/useDownloadJSON.ts +0 -34
  33. package/demo/components/header/Header.tsx +0 -25
  34. package/demo/components/header/style.module.css +0 -78
  35. package/demo/components/info-tab/InfoTab.tsx +0 -101
  36. package/demo/components/info-tab/style.module.css +0 -42
  37. package/demo/components/map-button/ClearButton.tsx +0 -24
  38. package/demo/components/map-button/MapButton.tsx +0 -41
  39. package/demo/components/map-button/style.module.css +0 -42
  40. package/demo/components/map-buttons/MapButtons.tsx +0 -28
  41. package/demo/components/map-buttons/style.module.css +0 -17
  42. package/demo/declaration.d.ts +0 -9
  43. package/demo/index.html +0 -23
  44. package/demo/index.tsx +0 -12
  45. package/demo/manifest.json +0 -21
  46. package/demo/package-lock.json +0 -18900
  47. package/demo/package.json +0 -50
  48. package/demo/public/network.json +0 -216459
  49. package/demo/routes/home/colors.ts +0 -31
  50. package/demo/routes/home/index.tsx +0 -101
  51. package/demo/routes/home/setup-draw.ts +0 -67
  52. package/demo/routes/home/setup-leaflet.ts +0 -41
  53. package/demo/routes/home/setup-routing.ts +0 -21
  54. package/demo/routes/home/style.module.css +0 -94
  55. package/demo/size-plugin.json +0 -1
  56. package/demo/style/index.css +0 -20
  57. package/demo/sw.js +0 -4
  58. package/demo/template.html +0 -30
  59. package/demo/tsconfig.json +0 -7
  60. package/demo/utils/casing.ts +0 -7
  61. package/demo/utils/dates.ts +0 -10
  62. package/demo/utils/geo.ts +0 -4
  63. package/demo/vite.config.js +0 -10
  64. package/docs/assets/favicon-r77Z2In5.ico +0 -0
  65. package/docs/assets/index-5ax2eNro.js +0 -4
  66. package/docs/assets/index-CEAM8jr3.css +0 -1
  67. package/docs/assets/index-Cfqr5nmq.js +0 -4
  68. package/docs/assets/index-CpmDVghy.css +0 -1
  69. package/docs/assets/index-D8NK55L4.js +0 -4
  70. package/docs/assets/index-DJYewHY6.js +0 -4
  71. package/docs/assets/index-DT3pkFX6.js +0 -4
  72. package/docs/assets/index-DZ8OkOfD.js +0 -4
  73. package/docs/assets/index-DjN8PkFw.js +0 -4
  74. package/docs/assets/index-iILsBcOs.js +0 -4
  75. package/docs/assets/logo-DQvm3LRv.png +0 -0
  76. package/docs/index.html +0 -24
  77. package/docs/network.json +0 -216459
package/README.md CHANGED
@@ -9,7 +9,11 @@ This repository is for the `TerraDrawRouteSnappingMode` module. `TerraDrawRouteS
9
9
  npm install terra-draw-route-snap-mode
10
10
  ```
11
11
 
12
- ## Usage
12
+ ## Docs
13
+
14
+ You can find the [API Docs here](https://jameslmilner.github.io/terra-draw-route-snap-mode/api/)
15
+
16
+ ## Basic Usage
13
17
 
14
18
  We can import `TerraDrawRouteSnapMode` in this way:
15
19
 
@@ -30,21 +34,26 @@ We can construct `TerraDrawRouteSnapMode` like so:
30
34
  }),
31
35
  ```
32
36
 
33
- Where routing is of type:
37
+ Where `routing` is a property of type:
34
38
 
35
39
  ```typescript
36
40
  export interface RoutingInterface {
37
- getRoute: (startCoord: Position, endCoord: Position) => Feature<LineString> | null;
41
+ getRoute: (
42
+ startCoord: Position,
43
+ endCoord: Position
44
+ ) => Feature<LineString> | null;
38
45
  getClosestNetworkCoordinate: (coordinate: Position) => Position | null;
46
+ setRouteFinder: (routeFinder: RouteFinder) => void;
47
+ setNetwork: (network: FeatureCollection<LineString>) => void
39
48
  }
40
49
  ```
41
50
 
42
51
  You could construct the `routing` like so:
43
52
 
44
53
  ```typescript
45
- import { Routing } from "../../../src/terra-draw-route-snap-mode";
54
+ import { Routing } from "terra-draw-route-snap-mode";
46
55
  import { FeatureCollection, LineString } from "geojson";
47
- import { TerraRoute, createCheapRuler } from 'terra-route';
56
+ import { TerraRoute } from 'terra-route';
48
57
 
49
58
  // Initialise the TerraRoute instance with the default distance
50
59
  const terraRoute = new TerraRoute()
package/dist/routing.d.ts CHANGED
@@ -1,8 +1,12 @@
1
1
  import { FeatureCollection, LineString, Position, Feature, Point } from "geojson";
2
- import { RoutingInterface } from "./terra-draw-route-snap-mode";
3
- type RouteFinder = {
2
+ export type RouteFinder = {
4
3
  getRoute: (positionA: Feature<Point>, positionB: Feature<Point>) => Feature<LineString> | null;
4
+ setNetwork: (network: FeatureCollection<LineString>) => void;
5
5
  };
6
+ export interface RoutingInterface {
7
+ getRoute: (startCoord: Position, endCoord: Position) => Feature<LineString> | null;
8
+ getClosestNetworkCoordinate: (coordinate: Position) => Position | null;
9
+ }
6
10
  /**
7
11
  * Routing class for finding routes on a network of LineStrings.
8
12
  * The LineString network must have coordinates that are shared between
@@ -20,12 +24,23 @@ export declare class Routing implements RoutingInterface {
20
24
  private routeFinder;
21
25
  private network;
22
26
  private routeCache;
27
+ private initialise;
23
28
  /**
24
29
  * Return the closest network coordinate to the input coordinate
25
30
  * @param inputCoordinate The coordinate to find the closest network coordinate to
26
31
  * @returns a coordinate on the network or null if no coordinate is found
27
32
  */
28
33
  getClosestNetworkCoordinate(inputCoordinate: Position): Position | null;
34
+ /**
35
+ * Set the route finder for the routing instance
36
+ * @param routeFinder The route finder to use
37
+ */
38
+ setRouteFinder(routeFinder: RouteFinder): void;
39
+ /**
40
+ * Set the network for the routing instance
41
+ * @param network The network to use
42
+ */
43
+ setNetwork(network: FeatureCollection<LineString>): void;
29
44
  /**
30
45
  * Get the route between two coordinates returned as a GeoJSON LineString
31
46
  * @param startCoord start coordinate
@@ -34,4 +49,3 @@ export declare class Routing implements RoutingInterface {
34
49
  */
35
50
  getRoute(startCoord: Position, endCoord: Position): Feature<LineString> | null;
36
51
  }
37
- export {};
@@ -1,2 +1,2 @@
1
- var t=require("terra-draw");function e(){return e=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var r in i)({}).hasOwnProperty.call(i,r)&&(t[r]=i[r])}return t},e.apply(null,arguments)}function i(t,e){return i=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},i(t,e)}var r=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],o=/*#__PURE__*/function(){function t(t,e,i,o){if(void 0===e&&(e=64),void 0===i&&(i=Float64Array),this.data=void 0,this.ids=void 0,this.coords=void 0,this._pos=void 0,this._finished=void 0,this.numItems=void 0,this.nodeSize=void 0,this.ArrayType=void 0,this.IndexArrayType=void 0,isNaN(t)||t<0)throw new Error("Unexpected numItems value: "+t+".");this.numItems=t,this.nodeSize=Math.min(Math.max(e,2),65535),this.ArrayType=i,this.IndexArrayType=t<65536?Uint16Array:Uint32Array;var n=r.indexOf(this.ArrayType),s=2*t*this.ArrayType.BYTES_PER_ELEMENT,a=t*this.IndexArrayType.BYTES_PER_ELEMENT,h=(8-a%8)%8;if(n<0)throw new Error("Unexpected typed array class: "+i+".");o?(this.data=o,this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+a+h,2*t),this._pos=2*t,this._finished=!0):(this.data=new ArrayBuffer(8+s+a+h),this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+a+h,2*t),this._pos=0,this._finished=!1,new Uint8Array(this.data,0,2).set([219,16+n]),new Uint16Array(this.data,2,1)[0]=this.nodeSize,new Uint32Array(this.data,4,1)[0]=this.numItems)}var e=t.prototype;return e.add=function(t,e){var i=this._pos>>1;return this.ids[i]=i,this.coords[this._pos++]=t,this.coords[this._pos++]=e,i},e.finish=function(){var t=this._pos>>1;if(t!==this.numItems)throw new Error("Added "+t+" items when expected "+this.numItems+".");return n(this.ids,this.coords,this.nodeSize,0,this.numItems-1,0),this._finished=!0,this},t}();function n(t,e,i,r,o,a){if(!(o-r<=i)){var h=r+o>>1;s(t,e,h,r,o,a),n(t,e,i,r,h-1,1-a),n(t,e,i,h+1,o,1-a)}}function s(t,e,i,r,o,n){for(;o>r;){if(o-r>600){var h=o-r+1,d=i-r+1,u=Math.log(h),c=.5*Math.exp(2*u/3),p=.5*Math.sqrt(u*c*(h-c)/h)*(d-h/2<0?-1:1);s(t,e,i,Math.max(r,Math.floor(i-d*c/h+p)),Math.min(o,Math.floor(i+(h-d)*c/h+p)),n)}var l=e[2*i+n],y=r,f=o;for(a(t,e,r,i),e[2*o+n]>l&&a(t,e,r,o);y<f;){for(a(t,e,y,f),y++,f--;e[2*y+n]<l;)y++;for(;e[2*f+n]>l;)f--}e[2*r+n]===l?a(t,e,r,f):a(t,e,++f,o),f<=i&&(r=f+1),i<=f&&(o=f-1)}}function a(t,e,i,r){h(t,i,r),h(e,2*i,2*r),h(e,2*i+1,2*r+1)}function h(t,e,i){var r=t[e];t[e]=t[i],t[i]=r}var d=/*#__PURE__*/function(){function t(t,e){if(void 0===t&&(t=[]),void 0===e&&(e=function(t,e){return t<e?-1:t>e?1:0}),this.data=void 0,this.length=void 0,this.compare=void 0,this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(var i=(this.length>>1)-1;i>=0;i--)this._down(i)}var e=t.prototype;return e.push=function(t){this.data.push(t),this._up(this.length++)},e.pop=function(){if(0!==this.length){var t=this.data[0],e=this.data.pop();return this.length--,this.length>0&&(this.data[0]=e,this._down(0)),t}},e.peek=function(){return this.data[0]},e._up=function(t){for(var e=this.data,i=this.compare,r=e[t];t>0;){var o=t-1>>1,n=e[o];if(i(r,n)>=0)break;e[t]=n,t=o}e[t]=r},e._down=function(t){for(var e=this.data,i=this.compare,r=this.length>>1,o=e[t];t<r;){var n=1+(t<<1),s=n+1;if(s<this.length&&i(e[s],e[n])<0&&(n=s),i(e[n],o)>=0)break;e[t]=e[n],t=n}e[t]=o},t}(),u=Math.PI/180;function c(t,e,i,r){var o=r.minLng,n=r.maxLng,s=r.minLat,a=r.maxLat;if(t>=o&&t<=n)return e<s?l((e-s)*u):e>a?l((e-a)*u):0;var h=Math.min(l((t-o)*u),l((t-n)*u)),d=function(t,e){var i=1-2*e;return i<=0?t>0?90:-90:Math.atan(Math.tan(t*u)/i)/u}(e,h);return d>s&&d<a?y(h,i,e,d):Math.min(y(h,i,e,s),y(h,i,e,a))}function p(t,e){return t.dist-e.dist}function l(t){var e=Math.sin(t/2);return e*e}function y(t,e,i,r){return e*Math.cos(r*u)*t+l((i-r)*u)}function f(t,e,i,r,o){return y(l((t-i)*u),o,e,r)}var v=/*#__PURE__*/function(){function t(t){var e=this;this.useCache=!0,this.indexedNetworkPoints=void 0,this.points=[],this.routeFinder=void 0,this.network=void 0,this.routeCache={},this.useCache=t.useCache||!0,this.network=t.network,this.routeFinder=t.routeFinder,this.network.features.forEach(function(t){t.geometry.coordinates.forEach(function(t){e.points.push(t)})}),this.indexedNetworkPoints=new o(this.points.length),this.points.forEach(function(t){e.indexedNetworkPoints.add(t[0],t[1])}),this.indexedNetworkPoints.finish()}var e=t.prototype;return e.getClosestNetworkCoordinate=function(t){var e=function(t,e,i,r,o){void 0===r&&(r=Infinity),void 0===o&&(o=Infinity);var n=1,s=[];void 0===r&&(r=Infinity),void 0!==o&&(n=l(o/6371));for(var a=new d([],p),h={left:0,right:t.ids.length-1,axis:0,dist:0,minLng:-180,minLat:-90,maxLng:180,maxLat:90},y=Math.cos(i*u);h;){var v=h.right,m=h.left;if(v-m<=t.nodeSize)for(var g=m;g<=v;g++){var I=t.ids[g],x=f(e,i,t.coords[2*g],t.coords[2*g+1],y);a.push({id:I,dist:x})}else{var w=m+v>>1,C=t.coords[2*w],P=t.coords[2*w+1],L=t.ids[w],E=f(e,i,C,P,y);a.push({id:L,dist:E});var A=(h.axis+1)%2,k={left:m,right:w-1,axis:A,minLng:h.minLng,minLat:h.minLat,maxLng:0===h.axis?C:h.maxLng,maxLat:1===h.axis?P:h.maxLat,dist:0},S={left:w+1,right:v,axis:A,minLng:0===h.axis?C:h.minLng,minLat:1===h.axis?P:h.minLat,maxLng:h.maxLng,maxLat:h.maxLat,dist:0};k.dist=c(e,i,y,k),S.dist=c(e,i,y,S),a.push(k),a.push(S)}for(;a.length&&null!=a.peek().id;){var M=a.pop();if(M.dist>n)return s;if(s.push(M.id),s.length===r)return s}h=a.pop()}return s}(this.indexedNetworkPoints,t[0],t[1],1);return this.points[e[0]]||null},e.getRoute=function(t,e){if(this.useCache){var i=t+"-"+e;if(this.routeCache[i])return this.routeCache[i]}var r=this.routeFinder.getRoute({type:"Feature",geometry:{type:"Point",coordinates:t},properties:{}},{type:"Feature",geometry:{type:"Point",coordinates:e},properties:{}});return this.useCache?(this.routeCache[t+"-"+e]=r,r):r},t}(),m={cancel:"Escape",finish:"Enter"},g={draw:"crosshair",close:"pointer"},I=/*#__PURE__*/function(r){function o(t){var e;return(e=r.call(this,t,!0)||this).mode="routesnap",e.currentCoordinate=0,e.currentId=void 0,e.keyEvents=m,e.cursors=g,e.maxPoints=1,e.moveLineId=void 0,e.routing=void 0,e.currentPointIds=[],e.routeId=0,e.pixelDistance=function(t,e){var i=e.x-t.x,r=e.y-t.y;return Math.sqrt(r*r+i*i)},e.updateOptions(t),e}var n,s;s=r,(n=o).prototype=Object.create(s.prototype),n.prototype.constructor=n,i(n,s);var a=o.prototype;return a.updateOptions=function(t){r.prototype.updateOptions.call(this,t),null!=t&&t.routing&&t.routing!==this.routing&&(this.cleanUp(),this.routing=t.routing),void 0!==(null==t?void 0:t.maxPoints)&&t.maxPoints!==this.maxPoints&&t.maxPoints>0&&(this.maxPoints=t.maxPoints),null!=t&&t.cursors&&(this.cursors=e({},this.cursors,t.cursors)),null===(null==t?void 0:t.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=t&&t.keyEvents&&(this.keyEvents=e({},this.keyEvents,t.keyEvents))},a.measure=function(t,e){var i=this.project(e[0],e[1]);return this.pixelDistance({x:i.x,y:i.y},{x:t.containerX,y:t.containerY})},a.close=function(){this.currentId&&(this.currentCoordinate=0,this.currentId=void 0,this.currentPointIds=[],"drawing"===this.state&&this.setStarted())},a.registerBehaviors=function(t){},a.start=function(){this.setStarted(),this.setCursor(this.cursors.draw)},a.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},a.onMouseMove=function(t){if(this.setCursor(this.cursors.draw),this.currentId&&0!==this.currentCoordinate){if(this.currentId){var e=this.store.getGeometryCopy(this.currentId);if(this.measure(t,e.coordinates[e.coordinates.length-1])<this.pointerDistance)return this.setCursor(this.cursors.close),void(this.moveLineId&&(this.store.delete([this.moveLineId]),this.moveLineId=void 0))}var i=this.store.getGeometryCopy(this.currentId),r=this.routing.getClosestNetworkCoordinate([t.lng,t.lat]);if(r){var o=this.routing.getRoute(i.coordinates[i.coordinates.length-1],r);if(o)if(this.moveLineId)this.store.updateGeometry([{id:this.moveLineId,geometry:o.geometry}]);else{var n=this.store.create([{geometry:o.geometry,properties:{mode:this.mode,isDrawnRoute:!0,routeId:this.routeId}}]);this.moveLineId=n[0]}}}},a.onClick=function(t){if("right"!==t.button){var i=[t.lng,t.lat];if(this.currentId){var r=this.store.getGeometryCopy(this.currentId);if(this.measure(t,r.coordinates[r.coordinates.length-1])<this.pointerDistance)return 1===this.currentCoordinate&&this.store.delete(this.currentPointIds),void this.close()}else this.routeId++;var o=this.routing.getClosestNetworkCoordinate(i);if(0===this.currentCoordinate){if(o){var n=this.store.create([{geometry:{type:"LineString",coordinates:[o]},properties:{mode:this.mode,isDrawnRoute:!0,routeId:this.routeId}},{geometry:{type:"Point",coordinates:o},properties:{mode:this.mode,isDrawnRoute:!0,routeId:this.routeId}}]),s=n[1];this.currentId=n[0],this.currentPointIds.push(s),this.currentCoordinate++,"started"===this.state&&this.setDrawing()}}else if(1===this.currentCoordinate&&this.currentId&&o){var a=this.store.getGeometryCopy(this.currentId),h=this.routing.getRoute(a.coordinates[0],o);if(h){this.store.updateGeometry([{id:this.currentId,geometry:null==h?void 0:h.geometry}]);var d=this.store.create([{geometry:{type:"Point",coordinates:o},properties:{mode:this.mode,isDrawnRoute:!0,routeId:this.routeId}}])[0];this.currentCoordinate=2,this.currentPointIds.push(d)}if(1===this.maxPoints)return void this.close()}else if(this.currentCoordinate>1&&this.currentId&&o&&this.currentCoordinate<=this.maxPoints){var u=this.store.getGeometryCopy(this.currentId),c=this.routing.getRoute(u.coordinates[u.coordinates.length-1],o);if(c){var p=e({},u,{coordinates:[].concat(u.coordinates,c.geometry.coordinates)});this.store.updateGeometry([{id:this.currentId,geometry:p}]);var l=this.store.create([{geometry:{type:"Point",coordinates:o},properties:{mode:this.mode,isDrawnRoute:!0,routeId:this.routeId}}])[0];this.maxPoints===this.currentCoordinate?this.close():(this.currentCoordinate++,this.currentPointIds.push(l))}}}},a.onKeyDown=function(){},a.onKeyUp=function(t){t.key===this.keyEvents.cancel&&this.cleanUp(),t.key===this.keyEvents.finish&&this.close()},a.onDragStart=function(){},a.onDrag=function(){},a.onDragEnd=function(){},a.cleanUp=function(){try{this.currentId&&this.store.delete([this.currentId].concat(this.currentPointIds))}catch(t){}this.currentId=void 0,this.moveLineId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted()},a.styleFeature=function(e){var i=t.TerraDrawExtend.getDefaultStyling();return"Feature"===e.type&&"LineString"===e.geometry.type&&e.properties.mode===this.mode?(i.lineStringColor=this.getHexColorStylingValue(this.styles.lineStringColor,"#B90E0A",e),i.lineStringWidth=this.getNumericStylingValue(this.styles.lineStringWidth,4,e),i.zIndex=10,i):"Feature"===e.type&&"Point"===e.geometry.type&&e.properties.mode===this.mode?(i.pointColor=this.getHexColorStylingValue(this.styles.routePointColor,"#B90E0A",e),i.pointOutlineColor=this.getHexColorStylingValue(this.styles.routePointColor,"#B90E0A",e),i.pointOutlineWidth=this.getNumericStylingValue(this.styles.routePointOutlineWidth,1,e),i):i},a.validateFeature=function(t){return r.prototype.validateFeature.call(this,t)},a.afterFeatureAdded=function(t){},o}(t.TerraDrawExtend.TerraDrawBaseDrawMode);new I,exports.Routing=v,exports.TerraDrawRouteSnapMode=I;
1
+ var t=require("terra-draw");function i(){return i=Object.assign?Object.assign.bind():function(t){for(var i=1;i<arguments.length;i++){var e=arguments[i];for(var r in e)({}).hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t},i.apply(null,arguments)}function e(t,i){return e=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,i){return t.__proto__=i,t},e(t,i)}var r=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],o=/*#__PURE__*/function(){function t(t,i,e,o){if(void 0===i&&(i=64),void 0===e&&(e=Float64Array),this.data=void 0,this.ids=void 0,this.coords=void 0,this._pos=void 0,this._finished=void 0,this.numItems=void 0,this.nodeSize=void 0,this.ArrayType=void 0,this.IndexArrayType=void 0,isNaN(t)||t<0)throw new Error("Unexpected numItems value: "+t+".");this.numItems=t,this.nodeSize=Math.min(Math.max(i,2),65535),this.ArrayType=e,this.IndexArrayType=t<65536?Uint16Array:Uint32Array;var s=r.indexOf(this.ArrayType),n=2*t*this.ArrayType.BYTES_PER_ELEMENT,a=t*this.IndexArrayType.BYTES_PER_ELEMENT,h=(8-a%8)%8;if(s<0)throw new Error("Unexpected typed array class: "+e+".");o?(this.data=o,this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+a+h,2*t),this._pos=2*t,this._finished=!0):(this.data=new ArrayBuffer(8+n+a+h),this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+a+h,2*t),this._pos=0,this._finished=!1,new Uint8Array(this.data,0,2).set([219,16+s]),new Uint16Array(this.data,2,1)[0]=this.nodeSize,new Uint32Array(this.data,4,1)[0]=this.numItems)}var i=t.prototype;return i.add=function(t,i){var e=this._pos>>1;return this.ids[e]=e,this.coords[this._pos++]=t,this.coords[this._pos++]=i,e},i.finish=function(){var t=this._pos>>1;if(t!==this.numItems)throw new Error("Added "+t+" items when expected "+this.numItems+".");return s(this.ids,this.coords,this.nodeSize,0,this.numItems-1,0),this._finished=!0,this},t}();function s(t,i,e,r,o,a){if(!(o-r<=e)){var h=r+o>>1;n(t,i,h,r,o,a),s(t,i,e,r,h-1,1-a),s(t,i,e,h+1,o,1-a)}}function n(t,i,e,r,o,s){for(;o>r;){if(o-r>600){var h=o-r+1,d=e-r+1,u=Math.log(h),c=.5*Math.exp(2*u/3),p=.5*Math.sqrt(u*c*(h-c)/h)*(d-h/2<0?-1:1);n(t,i,e,Math.max(r,Math.floor(e-d*c/h+p)),Math.min(o,Math.floor(e+(h-d)*c/h+p)),s)}var l=i[2*e+s],f=r,y=o;for(a(t,i,r,e),i[2*o+s]>l&&a(t,i,r,o);f<y;){for(a(t,i,f,y),f++,y--;i[2*f+s]<l;)f++;for(;i[2*y+s]>l;)y--}i[2*r+s]===l?a(t,i,r,y):a(t,i,++y,o),y<=e&&(r=y+1),e<=y&&(o=y-1)}}function a(t,i,e,r){h(t,e,r),h(i,2*e,2*r),h(i,2*e+1,2*r+1)}function h(t,i,e){var r=t[i];t[i]=t[e],t[e]=r}var d=/*#__PURE__*/function(){function t(t,i){if(void 0===t&&(t=[]),void 0===i&&(i=function(t,i){return t<i?-1:t>i?1:0}),this.data=void 0,this.length=void 0,this.compare=void 0,this.data=t,this.length=this.data.length,this.compare=i,this.length>0)for(var e=(this.length>>1)-1;e>=0;e--)this._down(e)}var i=t.prototype;return i.push=function(t){this.data.push(t),this._up(this.length++)},i.pop=function(){if(0!==this.length){var t=this.data[0],i=this.data.pop();return this.length--,this.length>0&&(this.data[0]=i,this._down(0)),t}},i.peek=function(){return this.data[0]},i._up=function(t){for(var i=this.data,e=this.compare,r=i[t];t>0;){var o=t-1>>1,s=i[o];if(e(r,s)>=0)break;i[t]=s,t=o}i[t]=r},i._down=function(t){for(var i=this.data,e=this.compare,r=this.length>>1,o=i[t];t<r;){var s=1+(t<<1),n=s+1;if(n<this.length&&e(i[n],i[s])<0&&(s=n),e(i[s],o)>=0)break;i[t]=i[s],t=s}i[t]=o},t}(),u=Math.PI/180;function c(t,i,e,r){var o=r.minLng,s=r.maxLng,n=r.minLat,a=r.maxLat;if(t>=o&&t<=s)return i<n?l((i-n)*u):i>a?l((i-a)*u):0;var h=Math.min(l((t-o)*u),l((t-s)*u)),d=function(t,i){var e=1-2*i;return e<=0?t>0?90:-90:Math.atan(Math.tan(t*u)/e)/u}(i,h);return d>n&&d<a?f(h,e,i,d):Math.min(f(h,e,i,n),f(h,e,i,a))}function p(t,i){return t.dist-i.dist}function l(t){var i=Math.sin(t/2);return i*i}function f(t,i,e,r){return i*Math.cos(r*u)*t+l((e-r)*u)}function y(t,i,e,r,o){return f(l((t-e)*u),o,i,r)}var v=/*#__PURE__*/function(){function t(t){this.useCache=!0,this.indexedNetworkPoints=void 0,this.points=[],this.routeFinder=void 0,this.network=void 0,this.routeCache={},this.useCache=t.useCache||!0,this.network=t.network,this.routeFinder=t.routeFinder,this.initialise()}var i=t.prototype;return i.initialise=function(){var t=this;this.network.features.forEach(function(i){i.geometry.coordinates.forEach(function(i){t.points.push(i)})}),this.indexedNetworkPoints=new o(this.points.length),this.points.forEach(function(i){t.indexedNetworkPoints.add(i[0],i[1])}),this.indexedNetworkPoints.finish(),this.routeCache={}},i.getClosestNetworkCoordinate=function(t){var i=function(t,i,e,r,o){void 0===r&&(r=Infinity),void 0===o&&(o=Infinity);var s=1,n=[];void 0===r&&(r=Infinity),void 0!==o&&(s=l(o/6371));for(var a=new d([],p),h={left:0,right:t.ids.length-1,axis:0,dist:0,minLng:-180,minLat:-90,maxLng:180,maxLat:90},f=Math.cos(e*u);h;){var v=h.right,m=h.left;if(v-m<=t.nodeSize)for(var g=m;g<=v;g++){var I=t.ids[g],x=y(i,e,t.coords[2*g],t.coords[2*g+1],f);a.push({id:I,dist:x})}else{var w=m+v>>1,C=t.coords[2*w],L=t.coords[2*w+1],P=t.ids[w],E=y(i,e,C,L,f);a.push({id:P,dist:E});var A=(h.axis+1)%2,k={left:m,right:w-1,axis:A,minLng:h.minLng,minLat:h.minLat,maxLng:0===h.axis?C:h.maxLng,maxLat:1===h.axis?L:h.maxLat,dist:0},S={left:w+1,right:v,axis:A,minLng:0===h.axis?C:h.minLng,minLat:1===h.axis?L:h.minLat,maxLng:h.maxLng,maxLat:h.maxLat,dist:0};k.dist=c(i,e,f,k),S.dist=c(i,e,f,S),a.push(k),a.push(S)}for(;a.length&&null!=a.peek().id;){var M=a.pop();if(M.dist>s)return n;if(n.push(M.id),n.length===r)return n}h=a.pop()}return n}(this.indexedNetworkPoints,t[0],t[1],1);return this.points[i[0]]||null},i.setRouteFinder=function(t){this.routeFinder=t},i.setNetwork=function(t){this.network=t,this.routeFinder.setNetwork(t),this.initialise()},i.getRoute=function(t,i){if(this.useCache){var e=t+"-"+i;if(this.routeCache[e])return this.routeCache[e]}var r=this.routeFinder.getRoute({type:"Feature",geometry:{type:"Point",coordinates:t},properties:{}},{type:"Feature",geometry:{type:"Point",coordinates:i},properties:{}});return this.useCache?(this.routeCache[t+"-"+i]=r,r):r},t}(),m={cancel:"Escape",finish:"Enter"},g={draw:"crosshair",close:"pointer"},I=/*#__PURE__*/function(r){function o(t){var i;return(i=r.call(this,t,!0)||this).mode="routesnap",i.currentCoordinate=0,i.currentId=void 0,i.keyEvents=m,i.cursors=g,i.maxPoints=1,i.moveLineId=void 0,i.routing=void 0,i.currentPointIds=[],i.routeId=0,i.pixelDistance=function(t,i){var e=i.x-t.x,r=i.y-t.y;return Math.sqrt(r*r+e*e)},i.updateOptions(t),i}var s,n;n=r,(s=o).prototype=Object.create(n.prototype),s.prototype.constructor=s,e(s,n);var a=o.prototype;return a.updateOptions=function(t){r.prototype.updateOptions.call(this,t),null!=t&&t.routing&&t.routing!==this.routing&&(this.cleanUp(),this.routing=t.routing),void 0!==(null==t?void 0:t.maxPoints)&&t.maxPoints!==this.maxPoints&&t.maxPoints>0&&(this.maxPoints=t.maxPoints),null!=t&&t.cursors&&(this.cursors=i({},this.cursors,t.cursors)),null===(null==t?void 0:t.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=t&&t.keyEvents&&(this.keyEvents=i({},this.keyEvents,t.keyEvents))},a.measure=function(t,i){var e=this.project(i[0],i[1]);return this.pixelDistance({x:e.x,y:e.y},{x:t.containerX,y:t.containerY})},a.close=function(){this.currentId&&(this.currentCoordinate=0,this.currentId=void 0,this.currentPointIds=[],"drawing"===this.state&&this.setStarted())},a.registerBehaviors=function(t){},a.start=function(){this.setStarted(),this.setCursor(this.cursors.draw)},a.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},a.onMouseMove=function(t){if(this.setCursor(this.cursors.draw),this.moveLineId&&!this.store.has(this.moveLineId)&&(this.moveLineId=void 0),this.currentId&&0!==this.currentCoordinate){if(this.currentId){var i=this.store.getGeometryCopy(this.currentId);if(this.measure(t,i.coordinates[i.coordinates.length-1])<this.pointerDistance)return this.setCursor(this.cursors.close),void(this.moveLineId&&(this.store.delete([this.moveLineId]),this.moveLineId=void 0))}var e=this.store.getGeometryCopy(this.currentId),r=this.routing.getClosestNetworkCoordinate([t.lng,t.lat]);if(r){var o=this.routing.getRoute(e.coordinates[e.coordinates.length-1],r);if(o)if(this.moveLineId)this.store.updateGeometry([{id:this.moveLineId,geometry:o.geometry}]);else{var s=this.store.create([{geometry:o.geometry,properties:{mode:this.mode,isDrawnRoute:!0,routeId:this.routeId}}]);this.moveLineId=s[0]}}}},a.onClick=function(t){if("right"!==t.button){var e=[t.lng,t.lat];if(this.currentId&&!this.store.has(this.currentId)&&(this.currentId=void 0,this.currentCoordinate=0,this.currentPointIds=[]),this.currentId){var r=this.store.getGeometryCopy(this.currentId);if(this.measure(t,r.coordinates[r.coordinates.length-1])<this.pointerDistance)return 1===this.currentCoordinate&&this.store.delete(this.currentPointIds),void this.close()}else this.routeId++;var o=this.routing.getClosestNetworkCoordinate(e);if(0===this.currentCoordinate){if(o){var s=this.store.create([{geometry:{type:"LineString",coordinates:[o]},properties:{mode:this.mode,isDrawnRoute:!0,routeId:this.routeId}},{geometry:{type:"Point",coordinates:o},properties:{mode:this.mode,isDrawnRoute:!0,routeId:this.routeId}}]),n=s[1];this.currentId=s[0],this.currentPointIds.push(n),this.currentCoordinate++,"started"===this.state&&this.setDrawing()}}else if(1===this.currentCoordinate&&this.currentId&&o){var a=this.store.getGeometryCopy(this.currentId),h=this.routing.getRoute(a.coordinates[0],o);if(h){this.store.updateGeometry([{id:this.currentId,geometry:null==h?void 0:h.geometry}]);var d=this.store.create([{geometry:{type:"Point",coordinates:o},properties:{mode:this.mode,isDrawnRoute:!0,routeId:this.routeId}}])[0];this.currentCoordinate=2,this.currentPointIds.push(d)}if(1===this.maxPoints)return void this.close()}else if(this.currentCoordinate>1&&this.currentId&&o&&this.currentCoordinate<=this.maxPoints){var u=this.store.getGeometryCopy(this.currentId),c=this.routing.getRoute(u.coordinates[u.coordinates.length-1],o);if(c){var p=i({},u,{coordinates:[].concat(u.coordinates,c.geometry.coordinates)});this.store.updateGeometry([{id:this.currentId,geometry:p}]);var l=this.store.create([{geometry:{type:"Point",coordinates:o},properties:{mode:this.mode,isDrawnRoute:!0,routeId:this.routeId}}])[0];this.maxPoints===this.currentCoordinate?this.close():(this.currentCoordinate++,this.currentPointIds.push(l))}}}},a.onKeyDown=function(){},a.onKeyUp=function(t){t.key===this.keyEvents.cancel&&this.cleanUp(),t.key===this.keyEvents.finish&&this.close()},a.onDragStart=function(){},a.onDrag=function(){},a.onDragEnd=function(){},a.cleanUp=function(){try{this.currentId&&this.store.delete([this.currentId].concat(this.currentPointIds))}catch(t){}this.currentId=void 0,this.moveLineId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted()},a.styleFeature=function(i){var e=t.TerraDrawExtend.getDefaultStyling();return"Feature"===i.type&&"LineString"===i.geometry.type&&i.properties.mode===this.mode?(e.lineStringColor=this.getHexColorStylingValue(this.styles.lineStringColor,"#B90E0A",i),e.lineStringWidth=this.getNumericStylingValue(this.styles.lineStringWidth,4,i),e.zIndex=10,e):"Feature"===i.type&&"Point"===i.geometry.type&&i.properties.mode===this.mode?(e.pointColor=this.getHexColorStylingValue(this.styles.routePointColor,"#B90E0A",i),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.routePointColor,"#B90E0A",i),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.routePointOutlineWidth,1,i),e):e},a.validateFeature=function(t){return r.prototype.validateFeature.call(this,t)},a.afterFeatureAdded=function(t){},o}(t.TerraDrawExtend.TerraDrawBaseDrawMode);exports.Routing=v,exports.TerraDrawRouteSnapMode=I;
2
2
  //# sourceMappingURL=terra-draw-route-snap-mode.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"terra-draw-route-snap-mode.cjs","sources":["../src/kdbush/kdbush.ts","../src/kdbush/tinyqueue.ts","../src/kdbush/geokdbush.ts","../src/routing.ts","../src/terra-draw-route-snap-mode.ts"],"sourcesContent":["// Adapted from https://github.com/mourner/kdbush\n\n// ISC License\n\n// Copyright (c) 2018, Vladimir Agafonkin\n\n// Permission to use, copy, modify, and/or distribute this software for any purpose\n// with or without fee is hereby granted, provided that the above copyright notice\n// and this permission notice appear in all copies.\n\n// THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND\n// FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS\n// OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER\n// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\n// THIS SOFTWARE.\n\nconst ARRAY_TYPES = [\n Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array,\n Int32Array, Uint32Array, Float32Array, Float64Array\n];\n\nconst VERSION = 1;\nconst HEADER_SIZE = 8;\n\nexport class KDBush {\n private data: ArrayBuffer;\n public ids: Uint16Array | Uint32Array;\n public coords: InstanceType<TypedArrayConstructor>;\n private _pos: number;\n private _finished: boolean;\n private numItems: number;\n public nodeSize: number;\n private ArrayType: TypedArrayConstructor;\n private IndexArrayType: typeof Uint16Array | typeof Uint32Array;\n\n constructor(\n numItems: number,\n nodeSize: number = 64,\n ArrayType: TypedArrayConstructor = Float64Array,\n data?: ArrayBuffer\n ) {\n if (isNaN(numItems) || numItems < 0) {\n throw new Error(`Unexpected numItems value: ${numItems}.`);\n }\n\n this.numItems = numItems;\n this.nodeSize = Math.min(Math.max(nodeSize, 2), 65535);\n this.ArrayType = ArrayType;\n this.IndexArrayType = numItems < 65536 ? Uint16Array : Uint32Array;\n\n const arrayTypeIndex = ARRAY_TYPES.indexOf(this.ArrayType);\n const coordsByteSize = numItems * 2 * this.ArrayType.BYTES_PER_ELEMENT;\n const idsByteSize = numItems * this.IndexArrayType.BYTES_PER_ELEMENT;\n const padCoords = (8 - idsByteSize % 8) % 8;\n\n if (arrayTypeIndex < 0) {\n throw new Error(`Unexpected typed array class: ${ArrayType}.`);\n }\n\n if (data) {\n this.data = data;\n this.ids = new (this.IndexArrayType as any)(this.data, HEADER_SIZE, numItems);\n this.coords = new (this.ArrayType as any)(this.data, HEADER_SIZE + idsByteSize + padCoords, numItems * 2);\n this._pos = numItems * 2;\n this._finished = true;\n } else {\n this.data = new ArrayBuffer(HEADER_SIZE + coordsByteSize + idsByteSize + padCoords);\n this.ids = new (this.IndexArrayType as any)(this.data, HEADER_SIZE, numItems);\n this.coords = new (this.ArrayType as any)(this.data, HEADER_SIZE + idsByteSize + padCoords, numItems * 2);\n this._pos = 0;\n this._finished = false;\n\n new Uint8Array(this.data, 0, 2).set([0xdb, (VERSION << 4) + arrayTypeIndex]);\n new Uint16Array(this.data, 2, 1)[0] = this.nodeSize;\n new Uint32Array(this.data, 4, 1)[0] = this.numItems;\n }\n }\n\n add(x: number, y: number): number {\n const index = this._pos >> 1;\n this.ids[index] = index;\n this.coords[this._pos++] = x;\n this.coords[this._pos++] = y;\n return index;\n }\n\n finish(): this {\n const numAdded = this._pos >> 1;\n if (numAdded !== this.numItems) {\n throw new Error(`Added ${numAdded} items when expected ${this.numItems}.`);\n }\n sort(this.ids, this.coords, this.nodeSize, 0, this.numItems - 1, 0);\n this._finished = true;\n return this;\n }\n}\n\ntype TypedArrayConstructor =\n Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor |\n Int16ArrayConstructor | Uint16ArrayConstructor |\n Int32ArrayConstructor | Uint32ArrayConstructor |\n Float32ArrayConstructor | Float64ArrayConstructor;\n\nfunction sort(\n ids: Uint16Array | Uint32Array,\n coords: InstanceType<TypedArrayConstructor>,\n nodeSize: number,\n left: number,\n right: number,\n axis: number\n): void {\n if (right - left <= nodeSize) return;\n const m = (left + right) >> 1;\n select(ids, coords, m, left, right, axis);\n sort(ids, coords, nodeSize, left, m - 1, 1 - axis);\n sort(ids, coords, nodeSize, m + 1, right, 1 - axis);\n}\n\nfunction select(\n ids: Uint16Array | Uint32Array,\n coords: InstanceType<TypedArrayConstructor>,\n k: number,\n left: number,\n right: number,\n axis: number\n): void {\n while (right > left) {\n if (right - left > 600) {\n const n = right - left + 1;\n const m = k - left + 1;\n const z = Math.log(n);\n const s = 0.5 * Math.exp(2 * z / 3);\n const sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);\n const newLeft = Math.max(left, Math.floor(k - m * s / n + sd));\n const newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));\n select(ids, coords, k, newLeft, newRight, axis);\n }\n\n const t = coords[2 * k + axis];\n let i = left;\n let j = right;\n\n swapItem(ids, coords, left, k);\n if (coords[2 * right + axis] > t) {\n swapItem(ids, coords, left, right);\n }\n\n while (i < j) {\n swapItem(ids, coords, i, j);\n i++;\n j--;\n while (coords[2 * i + axis] < t) i++;\n while (coords[2 * j + axis] > t) j--;\n }\n\n if (coords[2 * left + axis] === t) {\n swapItem(ids, coords, left, j);\n } else {\n j++;\n swapItem(ids, coords, j, right);\n }\n\n if (j <= k) left = j + 1;\n if (k <= j) right = j - 1;\n }\n}\n\nfunction swapItem(\n ids: Uint16Array | Uint32Array,\n coords: InstanceType<TypedArrayConstructor>,\n i: number,\n j: number\n): void {\n swap(ids, i, j);\n swap(coords, 2 * i, 2 * j);\n swap(coords, 2 * i + 1, 2 * j + 1);\n}\n\nfunction swap<T extends Uint16Array | Uint32Array | Float32Array | Float64Array | Int8Array | Int16Array | Int32Array | Uint8Array | Uint8ClampedArray>(\n arr: T,\n i: number,\n j: number\n): void {\n const tmp = arr[i];\n arr[i] = arr[j];\n arr[j] = tmp;\n}\n","// Adapted from https://github.com/mourner/kdbush\n\n// ISC License\n\n// Copyright (c) 2017, Vladimir Agafonkin\n\n// Permission to use, copy, modify, and/or distribute this software for any purpose\n// with or without fee is hereby granted, provided that the above copyright notice\n// and this permission notice appear in all copies.\n\n// THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND\n// FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS\n// OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER\n// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\n// THIS SOFTWARE.\n\nexport default class TinyQueue<T> {\n\n private data: T[];\n public length: number;\n private compare: (a: T, b: T) => number;\n\n constructor(\n data: T[] = [],\n compare: (a: T, b: T) => number = (a, b) =>\n a < b ? -1 : a > b ? 1 : 0\n ) {\n this.data = data;\n this.length = this.data.length;\n this.compare = compare;\n\n if (this.length > 0) {\n for (let i = (this.length >> 1) - 1; i >= 0; i--) {\n this._down(i);\n }\n }\n }\n\n push(item: T): void {\n this.data.push(item);\n this._up(this.length++);\n }\n\n pop(): T | undefined {\n if (this.length === 0) {\n return undefined;\n }\n\n const top = this.data[0];\n const bottom = this.data.pop() as T;\n\n this.length--;\n\n if (this.length > 0) {\n this.data[0] = bottom;\n this._down(0);\n }\n\n return top;\n }\n\n peek(): T | undefined {\n return this.data[0];\n }\n\n private _up(pos: number): void {\n const { data, compare } = this;\n const item = data[pos];\n\n while (pos > 0) {\n const parent = (pos - 1) >> 1;\n const current = data[parent];\n if (compare(item, current) >= 0) {\n break;\n }\n data[pos] = current;\n pos = parent;\n }\n\n data[pos] = item;\n }\n\n private _down(pos: number): void {\n const { data, compare } = this;\n const halfLength = this.length >> 1;\n const item = data[pos];\n\n while (pos < halfLength) {\n let bestChild = (pos << 1) + 1;\n const right = bestChild + 1;\n\n if (right < this.length && compare(data[right], data[bestChild]) < 0) {\n bestChild = right;\n }\n\n if (compare(data[bestChild], item) >= 0) {\n break;\n }\n\n data[pos] = data[bestChild];\n pos = bestChild;\n }\n\n data[pos] = item;\n }\n}\n","// Adapted from https://github.com/mourner/geokdbush\n\n// ISC License\n\n// Copyright (c) 2017, Vladimir Agafonkin\n\n// Permission to use, copy, modify, and/or distribute this software for any purpose\n// with or without fee is hereby granted, provided that the above copyright notice\n// and this permission notice appear in all copies.\n\n// THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND\n// FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS\n// OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER\n// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\n// THIS SOFTWARE.\n\nimport { KDBush } from './kdbush';\nimport TinyQueue from './tinyqueue';\n\nconst earthRadius = 6371;\nconst rad = Math.PI / 180;\n\n\nexport function around(index: KDBush, lng: number, lat: number, maxResults = Infinity, maxDistance = Infinity) {\n let maxHaverSinDist = 1;\n const result = [];\n\n if (maxResults === undefined) maxResults = Infinity;\n if (maxDistance !== undefined) maxHaverSinDist = haverSin(maxDistance / earthRadius);\n\n // a distance-sorted priority queue that will contain both points and kd-tree nodes\n const q = new TinyQueue([], compareDist);\n\n // an object that represents the top kd-tree node (the whole Earth)\n let node = {\n left: 0, // left index in the kd-tree array\n right: index.ids.length - 1, // right index\n axis: 0, // 0 for longitude axis and 1 for latitude axis\n dist: 0, // will hold the lower bound of children's distances to the query point\n minLng: -180, // bounding box of the node\n minLat: -90,\n maxLng: 180,\n maxLat: 90\n };\n\n const cosLat = Math.cos(lat * rad);\n\n while (node) {\n const right = node.right;\n const left = node.left;\n\n if (right - left <= index.nodeSize) { // leaf node\n\n // add all points of the leaf node to the queue\n for (let i = left; i <= right; i++) {\n const id = index.ids[i];\n\n const dist = haverSinDist(lng, lat, index.coords[2 * i], index.coords[2 * i + 1], cosLat);\n q.push({ id, dist });\n }\n\n } else { // not a leaf node (has child nodes)\n\n const m = (left + right) >> 1; // middle index\n const midLng = index.coords[2 * m];\n const midLat = index.coords[2 * m + 1];\n\n // add middle point to the queue\n const id = index.ids[m];\n const dist = haverSinDist(lng, lat, midLng, midLat, cosLat);\n q.push({ id, dist });\n\n\n const nextAxis = (node.axis + 1) % 2;\n\n // first half of the node\n const leftNode = {\n left,\n right: m - 1,\n axis: nextAxis,\n minLng: node.minLng,\n minLat: node.minLat,\n maxLng: node.axis === 0 ? midLng : node.maxLng,\n maxLat: node.axis === 1 ? midLat : node.maxLat,\n dist: 0\n };\n // second half of the node\n const rightNode = {\n left: m + 1,\n right,\n axis: nextAxis,\n minLng: node.axis === 0 ? midLng : node.minLng,\n minLat: node.axis === 1 ? midLat : node.minLat,\n maxLng: node.maxLng,\n maxLat: node.maxLat,\n dist: 0\n };\n\n leftNode.dist = boxDist(lng, lat, cosLat, leftNode);\n rightNode.dist = boxDist(lng, lat, cosLat, rightNode);\n\n // add child nodes to the queue\n q.push(leftNode);\n q.push(rightNode);\n }\n\n // fetch closest points from the queue; they're guaranteed to be closer\n // than all remaining points (both individual and those in kd-tree nodes),\n // since each node's distance is a lower bound of distances to its children\n while (q.length && q.peek().id != null) {\n const candidate = q.pop()!;\n if (candidate.dist > maxHaverSinDist) return result;\n result.push(candidate.id);\n if (result.length === maxResults) return result;\n }\n\n // the next closest kd-tree node\n node = q.pop();\n }\n\n return result;\n}\n\n// lower bound for distance from a location to points inside a bounding box\nfunction boxDist(lng: number, lat: number, cosLat: number, node: any) {\n const minLng = node.minLng;\n const maxLng = node.maxLng;\n const minLat = node.minLat;\n const maxLat = node.maxLat;\n\n // query point is between minimum and maximum longitudes\n if (lng >= minLng && lng <= maxLng) {\n if (lat < minLat) return haverSin((lat - minLat) * rad);\n if (lat > maxLat) return haverSin((lat - maxLat) * rad);\n return 0;\n }\n\n // query point is west or east of the bounding box;\n // calculate the extremum for great circle distance from query point to the closest longitude;\n const haverSinDLng = Math.min(haverSin((lng - minLng) * rad), haverSin((lng - maxLng) * rad));\n const extremumLat = vertexLat(lat, haverSinDLng);\n\n // if extremum is inside the box, return the distance to it\n if (extremumLat > minLat && extremumLat < maxLat) {\n return haverSinDistPartial(haverSinDLng, cosLat, lat, extremumLat);\n }\n // otherwise return the distan e to one of the bbox corners (whichever is closest)\n return Math.min(\n haverSinDistPartial(haverSinDLng, cosLat, lat, minLat),\n haverSinDistPartial(haverSinDLng, cosLat, lat, maxLat)\n );\n}\n\nfunction compareDist(a: any, b: any) {\n return a.dist - b.dist;\n}\n\nfunction haverSin(theta: number) {\n const s = Math.sin(theta / 2);\n return s * s;\n}\n\nfunction haverSinDistPartial(haverSinDLng: number, cosLat1: number, lat1: number, lat2: number) {\n return cosLat1 * Math.cos(lat2 * rad) * haverSinDLng + haverSin((lat1 - lat2) * rad);\n}\n\nfunction haverSinDist(lng1: number, lat1: number, lng2: number, lat2: number, cosLat1: number) {\n const haverSinDLng = haverSin((lng1 - lng2) * rad);\n return haverSinDistPartial(haverSinDLng, cosLat1, lat1, lat2);\n}\n\nexport function distance(lng1: number, lat1: number, lng2: number, lat2: number) {\n const h = haverSinDist(lng1, lat1, lng2, lat2, Math.cos(lat1 * rad));\n return 2 * earthRadius * Math.asin(Math.sqrt(h));\n}\n\nfunction vertexLat(lat: number, haverSinDLng: number) {\n const cosDLng = 1 - 2 * haverSinDLng;\n if (cosDLng <= 0) return lat > 0 ? 90 : -90;\n return Math.atan(Math.tan(lat * rad) / cosDLng) / rad;\n}","import { KDBush } from \"./kdbush/kdbush\";\nimport { around } from \"./kdbush/geokdbush\";\nimport {\n FeatureCollection,\n LineString,\n Position,\n Feature,\n Point,\n} from \"geojson\";\nimport { RoutingInterface } from \"./terra-draw-route-snap-mode\";\n\ntype RouteFinder = {\n getRoute: (positionA: Feature<Point>, positionB: Feature<Point>) => Feature<LineString> | null\n}\n/**\n * Routing class for finding routes on a network of LineStrings.\n * The LineString network must have coordinates that are shared between\n * the LineStrings in order to find a route.\n */\nexport class Routing implements RoutingInterface {\n constructor(options: {\n network: FeatureCollection<LineString>, useCache?: boolean,\n routeFinder: RouteFinder\n }) {\n this.useCache = options.useCache || true;\n this.network = options.network;\n\n this.routeFinder = options.routeFinder;\n\n this.network.features.forEach((feature) => {\n feature.geometry.coordinates.forEach((coordinate) => {\n this.points.push(coordinate);\n });\n });\n\n this.indexedNetworkPoints = new KDBush(this.points.length);\n\n this.points.forEach(coordinate => {\n this.indexedNetworkPoints.add(coordinate[0], coordinate[1]);\n })\n\n this.indexedNetworkPoints.finish();\n }\n private useCache: boolean = true;\n private indexedNetworkPoints: KDBush;\n private points: Position[] = []\n private routeFinder: RouteFinder;\n private network: FeatureCollection<LineString>;\n private routeCache: Record<string, Feature<LineString> | null> = {};\n\n /**\n * Return the closest network coordinate to the input coordinate\n * @param inputCoordinate The coordinate to find the closest network coordinate to\n * @returns a coordinate on the network or null if no coordinate is found\n */\n public getClosestNetworkCoordinate(inputCoordinate: Position) {\n const aroundInput: number[] = around(\n this.indexedNetworkPoints,\n inputCoordinate[0],\n inputCoordinate[1],\n 1\n );\n\n const nearest = this.points[aroundInput[0]]\n return nearest ? nearest : null;\n }\n\n /**\n * Get the route between two coordinates returned as a GeoJSON LineString\n * @param startCoord start coordinate\n * @param endCoord end coordinate\n * @returns The route as a GeoJSON LineString\n */\n public getRoute(startCoord: Position, endCoord: Position): Feature<LineString> | null {\n\n // Check if caching is enabled, and if the coordinates are already in the cache \n if (this.useCache) {\n const routeKey = `${startCoord}-${endCoord}`;\n\n if (this.routeCache[routeKey]) {\n return this.routeCache[routeKey];\n }\n }\n\n const start = {\n type: \"Feature\",\n geometry: {\n type: \"Point\",\n coordinates: startCoord,\n },\n properties: {},\n } as Feature<Point>;\n\n const end = {\n type: \"Feature\",\n geometry: {\n type: \"Point\",\n coordinates: endCoord,\n },\n properties: {},\n } as Feature<Point>;\n\n const route = this.routeFinder.getRoute(start, end);\n\n // If caching is enabled, store the route in the cache\n if (this.useCache) {\n const routeKey = `${startCoord}-${endCoord}`\n this.routeCache[routeKey] = route;\n return route;\n }\n\n return route;\n\n }\n}\n","import {\n TerraDrawAdapterStyling,\n TerraDrawKeyboardEvent,\n TerraDrawMouseEvent,\n BehaviorConfig,\n GeoJSONStoreFeatures,\n TerraDrawExtend\n} from \"terra-draw\";\nimport { Feature, LineString, Position } from \"geojson\";\nimport { Validation } from \"terra-draw/dist/common\";\n\ntype TerraDrawLineStringModeKeyEvents = {\n cancel: KeyboardEvent[\"key\"] | null;\n finish: KeyboardEvent[\"key\"] | null;\n};\n\nconst defaultKeyEvents = { cancel: \"Escape\", finish: \"Enter\" };\n\ninterface Cursors {\n draw?: TerraDrawExtend.Cursor;\n close?: TerraDrawExtend.Cursor;\n}\n\nconst defaultCursors = {\n draw: \"crosshair\",\n close: \"pointer\"\n} as Required<Cursors>;\n\nexport interface RoutingInterface {\n getRoute: (\n startCoord: Position,\n endCoord: Position\n ) => Feature<LineString> | null;\n getClosestNetworkCoordinate: (coordinate: Position) => Position | null;\n}\n\ntype RouteStyling = {\n lineStringWidth: TerraDrawExtend.NumericStyling;\n lineStringColor: TerraDrawExtend.HexColorStyling\n routePointColor: TerraDrawExtend.HexColorStyling;\n routePointWidth: TerraDrawExtend.NumericStyling;\n routePointOutlineColor: TerraDrawExtend.HexColorStyling;\n routePointOutlineWidth: TerraDrawExtend.NumericStyling;\n};\n\ninterface TerraDrawPolygonModeOptions<T extends TerraDrawExtend.CustomStyling>\n extends TerraDrawExtend.BaseModeOptions<T> {\n routing: RoutingInterface;\n pointerDistance?: number;\n keyEvents?: TerraDrawLineStringModeKeyEvents | null;\n maxPoints?: number;\n cursors?: Partial<Cursors>;\n}\n\nconst { TerraDrawBaseDrawMode } = TerraDrawExtend;\n\nexport class TerraDrawRouteSnapMode extends TerraDrawBaseDrawMode<RouteStyling> {\n mode = \"routesnap\" as const;\n\n private currentCoordinate = 0;\n private currentId: string | undefined;\n private keyEvents: TerraDrawLineStringModeKeyEvents = defaultKeyEvents;\n private cursors: Required<Cursors> = defaultCursors;\n\n private maxPoints: number = 1\n private moveLineId: string | undefined;\n private routing!: RoutingInterface;\n private currentPointIds: string[] = [];\n private routeId = 0;\n\n constructor(options?: TerraDrawPolygonModeOptions<RouteStyling>) {\n super(options, true);\n this.updateOptions(options);\n }\n\n override updateOptions(options?: Partial<TerraDrawPolygonModeOptions<RouteStyling>>) {\n super.updateOptions(options);\n\n if (options?.routing && options.routing !== this.routing) {\n // We can't guarantee the rout created so far is valid with the new routing \n // So we need to clean up the current state\n this.cleanUp();\n this.routing = options.routing;\n }\n\n if (options?.maxPoints !== undefined && options.maxPoints !== this.maxPoints && options.maxPoints > 0) {\n this.maxPoints = options.maxPoints;\n }\n\n if (options?.cursors) {\n this.cursors = { ...this.cursors, ...options.cursors };\n }\n\n // null is the case where we want to explicitly turn key bindings off\n if (options?.keyEvents === null) {\n this.keyEvents = { cancel: null, finish: null };\n } else if (options?.keyEvents) {\n this.keyEvents = { ...this.keyEvents, ...options.keyEvents };\n }\n }\n\n private pixelDistance = (\n pointOne: { x: number; y: number },\n pointTwo: { x: number; y: number }\n ) => {\n const { x: x1, y: y1 } = pointOne;\n const { x: x2, y: y2 } = pointTwo;\n const y = x2 - x1;\n const x = y2 - y1;\n return Math.sqrt(x * x + y * y);\n };\n\n private measure(clickEvent: TerraDrawMouseEvent, secondCoordinate: Position) {\n const { x, y } = this.project(secondCoordinate[0], secondCoordinate[1]);\n\n const distance = this.pixelDistance(\n { x, y },\n { x: clickEvent.containerX, y: clickEvent.containerY }\n );\n\n return distance;\n }\n\n private close() {\n if (!this.currentId) {\n return;\n }\n\n // Reset the state back to starting state\n this.currentCoordinate = 0;\n this.currentId = undefined;\n this.currentPointIds = [];\n\n // Go back to started state\n if (this.state === \"drawing\") {\n this.setStarted();\n }\n }\n\n /** @internal */\n registerBehaviors(config: BehaviorConfig) { }\n\n /** @internal */\n start() {\n this.setStarted();\n this.setCursor(this.cursors.draw);\n }\n\n /** @internal */\n stop() {\n this.cleanUp();\n this.setStopped();\n this.setCursor(\"unset\");\n }\n\n /** @internal */\n onMouseMove(event: TerraDrawMouseEvent) {\n this.setCursor(this.cursors.draw);\n\n if (!this.currentId || this.currentCoordinate === 0) {\n return;\n }\n\n if (this.currentId) {\n const currentLineGeometry = this.store.getGeometryCopy<LineString>(\n this.currentId\n );\n\n // If the cursor is close the last line\n // delete the current moving line and set the cursor to pointer\n if (\n this.measure(\n event,\n currentLineGeometry.coordinates[\n currentLineGeometry.coordinates.length - 1\n ]\n ) < this.pointerDistance\n ) {\n this.setCursor(this.cursors.close);\n if (this.moveLineId) {\n this.store.delete([this.moveLineId]);\n this.moveLineId = undefined;\n }\n\n return;\n }\n }\n\n const currentLineGeometry = this.store.getGeometryCopy<LineString>(\n this.currentId\n );\n\n const eventCoord = [event.lng, event.lat];\n\n let closestPoint = this.routing.getClosestNetworkCoordinate(eventCoord);\n\n if (!closestPoint) {\n return;\n }\n\n const length = currentLineGeometry.coordinates.length - 1;\n\n const geojsonRoute = this.routing.getRoute(\n currentLineGeometry.coordinates[length],\n closestPoint\n );\n\n if (!geojsonRoute) {\n return;\n }\n\n if (!this.moveLineId) {\n const [createdId] = this.store.create([\n {\n geometry: geojsonRoute.geometry,\n properties: { mode: this.mode, isDrawnRoute: true, routeId: this.routeId },\n },\n ]);\n\n this.moveLineId = createdId as string;\n } else {\n this.store.updateGeometry([\n {\n id: this.moveLineId,\n geometry: geojsonRoute.geometry,\n },\n ]);\n }\n }\n\n /** @internal */\n onClick(event: TerraDrawMouseEvent) {\n if (event.button === \"right\") {\n return;\n }\n\n // this.setCursor(\"pointer\");\n\n const eventCoord = [event.lng, event.lat] as Position;\n\n if (this.currentId) {\n const currentLineGeometry = this.store.getGeometryCopy<LineString>(\n this.currentId\n );\n\n if (\n this.measure(\n event,\n currentLineGeometry.coordinates[\n currentLineGeometry.coordinates.length - 1\n ]\n ) < this.pointerDistance\n ) {\n if (this.currentCoordinate === 1) {\n this.store.delete(this.currentPointIds);\n }\n\n this.close();\n\n return;\n }\n } else {\n this.routeId++;\n }\n\n let closestPoint = this.routing.getClosestNetworkCoordinate(eventCoord);\n\n if (this.currentCoordinate === 0) {\n if (closestPoint) {\n const [createdId, pointId] = this.store.create([\n {\n geometry: {\n type: \"LineString\",\n coordinates: [closestPoint],\n },\n properties: { mode: this.mode, isDrawnRoute: true, routeId: this.routeId },\n },\n {\n geometry: {\n type: \"Point\",\n coordinates: closestPoint,\n },\n properties: { mode: this.mode, isDrawnRoute: true, routeId: this.routeId },\n },\n ]);\n\n this.currentId = createdId as string;\n this.currentPointIds.push(pointId as string);\n this.currentCoordinate++;\n\n if (this.state === \"started\") {\n this.setDrawing();\n }\n }\n } else if (this.currentCoordinate === 1 && this.currentId && closestPoint) {\n const currentLineGeometry = this.store.getGeometryCopy<LineString>(\n this.currentId\n );\n\n const geojsonRoute = this.routing.getRoute(\n currentLineGeometry.coordinates[0],\n closestPoint\n );\n if (geojsonRoute) {\n this.store.updateGeometry([\n {\n id: this.currentId,\n geometry: geojsonRoute?.geometry,\n },\n ]);\n\n const [pointId] = this.store.create([\n {\n geometry: {\n type: \"Point\",\n coordinates: closestPoint,\n },\n properties: { mode: this.mode, isDrawnRoute: true, routeId: this.routeId },\n },\n ]);\n\n this.currentCoordinate = 2;\n this.currentPointIds.push(pointId as string);\n }\n\n if (this.maxPoints === 1) {\n this.close();\n\n return;\n }\n } else if (\n this.currentCoordinate > 1 &&\n this.currentId &&\n closestPoint &&\n this.currentCoordinate <= this.maxPoints\n ) {\n const currentLineGeometry = this.store.getGeometryCopy<LineString>(\n this.currentId\n );\n\n const length = currentLineGeometry.coordinates.length - 1;\n\n const geojsonRoute = this.routing.getRoute(\n currentLineGeometry.coordinates[length],\n closestPoint\n );\n\n if (geojsonRoute) {\n const newGeometry = {\n ...currentLineGeometry,\n coordinates: [\n ...currentLineGeometry.coordinates,\n ...geojsonRoute.geometry.coordinates,\n ],\n };\n\n this.store.updateGeometry([\n {\n id: this.currentId,\n geometry: newGeometry,\n },\n ]);\n\n const [pointId] = this.store.create([\n {\n geometry: {\n type: \"Point\",\n coordinates: closestPoint,\n },\n properties: { mode: this.mode, isDrawnRoute: true, routeId: this.routeId },\n },\n ]);\n\n if (this.maxPoints === this.currentCoordinate) {\n this.close();\n } else {\n this.currentCoordinate++;\n this.currentPointIds.push(pointId as string);\n }\n }\n }\n }\n\n /** @internal */\n onKeyDown() { }\n\n /** @internal */\n onKeyUp(event: TerraDrawKeyboardEvent) {\n if (event.key === this.keyEvents.cancel) {\n this.cleanUp();\n }\n\n if (event.key === this.keyEvents.finish) {\n this.close();\n }\n }\n\n /** @internal */\n onDragStart() { }\n\n /** @internal */\n onDrag() { }\n\n /** @internal */\n onDragEnd() { }\n\n /** @internal */\n cleanUp() {\n try {\n if (this.currentId) {\n this.store.delete([this.currentId, ...this.currentPointIds]);\n }\n } catch (error) { }\n\n this.currentId = undefined;\n this.moveLineId = undefined;\n this.currentCoordinate = 0;\n if (this.state === \"drawing\") {\n this.setStarted();\n }\n }\n\n /** @internal */\n styleFeature(feature: GeoJSONStoreFeatures): TerraDrawAdapterStyling {\n const styles = TerraDrawExtend.getDefaultStyling();\n\n if (\n feature.type === \"Feature\" &&\n feature.geometry.type === \"LineString\" &&\n feature.properties.mode === this.mode\n ) {\n styles.lineStringColor = this.getHexColorStylingValue(this.styles.lineStringColor, \"#B90E0A\", feature);\n styles.lineStringWidth = this.getNumericStylingValue(this.styles.lineStringWidth, 4, feature);\n styles.zIndex = 10;\n\n return styles;\n } else if (\n feature.type === \"Feature\" &&\n feature.geometry.type === \"Point\" &&\n feature.properties.mode === this.mode\n ) {\n styles.pointColor = this.getHexColorStylingValue(this.styles.routePointColor, \"#B90E0A\", feature);\n styles.pointOutlineColor = this.getHexColorStylingValue(this.styles.routePointColor, \"#B90E0A\", feature);\n styles.pointOutlineWidth = this.getNumericStylingValue(this.styles.routePointOutlineWidth, 1, feature);\n\n return styles;\n }\n\n return styles;\n }\n\n validateFeature(feature: unknown): ReturnType<Validation> {\n return super.validateFeature(feature)\n }\n\n afterFeatureAdded(feature: GeoJSONStoreFeatures) { }\n\n}\n\nconst x = new TerraDrawRouteSnapMode();\n\nexport { Routing } from \"./routing\";"],"names":["ARRAY_TYPES","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","KDBush","numItems","nodeSize","ArrayType","data","ids","this","coords","_pos","_finished","IndexArrayType","isNaN","Error","Math","min","max","arrayTypeIndex","indexOf","coordsByteSize","BYTES_PER_ELEMENT","idsByteSize","padCoords","ArrayBuffer","set","_proto","prototype","add","x","y","index","finish","numAdded","sort","left","right","axis","m","select","k","n","z","log","s","exp","sd","sqrt","floor","t","i","j","swapItem","swap","arr","tmp","TinyQueue","compare","a","b","length","_down","push","item","_up","pop","top","bottom","peek","pos","parent","current","halfLength","bestChild","rad","PI","boxDist","lng","lat","cosLat","node","minLng","maxLng","minLat","maxLat","haverSin","haverSinDLng","extremumLat","cosDLng","atan","tan","vertexLat","haverSinDistPartial","compareDist","dist","theta","sin","cosLat1","lat1","lat2","cos","haverSinDist","lng1","lng2","Routing","options","_this","useCache","indexedNetworkPoints","points","routeFinder","network","routeCache","features","forEach","feature","geometry","coordinates","coordinate","getClosestNetworkCoordinate","inputCoordinate","aroundInput","maxResults","maxDistance","Infinity","maxHaverSinDist","result","undefined","q","id","midLng","midLat","nextAxis","leftNode","rightNode","candidate","around","getRoute","startCoord","endCoord","routeKey","route","type","properties","defaultKeyEvents","cancel","defaultCursors","draw","close","TerraDrawRouteSnapMode","_TerraDrawBaseDrawMod","call","mode","currentCoordinate","currentId","keyEvents","cursors","maxPoints","moveLineId","routing","currentPointIds","routeId","pixelDistance","pointOne","pointTwo","updateOptions","cleanUp","_extends","measure","clickEvent","secondCoordinate","_this$project","project","containerX","containerY","state","setStarted","registerBehaviors","config","start","setCursor","stop","setStopped","onMouseMove","event","currentLineGeometry","store","getGeometryCopy","pointerDistance","closestPoint","geojsonRoute","updateGeometry","_this$store$create","create","isDrawnRoute","onClick","button","eventCoord","_this$store$create2","pointId","setDrawing","newGeometry","concat","onKeyDown","onKeyUp","key","onDragStart","onDrag","onDragEnd","error","styleFeature","styles","TerraDrawExtend","getDefaultStyling","lineStringColor","getHexColorStylingValue","lineStringWidth","getNumericStylingValue","zIndex","pointColor","routePointColor","pointOutlineColor","pointOutlineWidth","routePointOutlineWidth","validateFeature","afterFeatureAdded","TerraDrawBaseDrawMode"],"mappings":"6WAkBA,IAAMA,EAAc,CAChBC,UAAWC,WAAYC,kBAAmBC,WAAYC,YACtDC,WAAYC,YAAaC,aAAcC,cAM9BC,eAWT,WAAA,SAAAA,EACIC,EACAC,EACAC,EACAC,GAEA,QAJAF,IAAAA,IAAAA,EAAmB,SACnBC,IAAAA,IAAAA,EAAmCJ,cAb/BK,KAAAA,iBACDC,SAAG,EAAAC,KACHC,YAAM,EAAAD,KACLE,UAAI,EAAAF,KACJG,eAAS,EAAAH,KACTL,cAAQ,EAAAK,KACTJ,cAAQ,EAAAI,KACPH,eAAS,EAAAG,KACTI,oBAAc,EAQdC,MAAMV,IAAaA,EAAW,EAC9B,MAAM,IAAIW,MAAoCX,8BAAAA,OAGlDK,KAAKL,SAAWA,E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G,EAAOW,kBAAoBtN,KAAKiN,uBAAuBjN,KAAK2M,OAAOY,uBAAwB,EAAG5G,GAEvFgG,GAGFA,CACT,EAACzL,EAEDsM,gBAAA,SAAgB7G,GACd,OAAAmC,EAAA3H,UAAaqM,gBAAezE,KAACpC,KAAAA,EAC/B,EAACzF,EAEDuM,kBAAA,SAAkB9G,GAAkC,EAAAkC,CAAA,CA/YlBC,CAFF8D,EAAeA,gBAAzCc,uBAqZE,IAAI7E"}
1
+ {"version":3,"file":"terra-draw-route-snap-mode.cjs","sources":["../src/kdbush/kdbush.ts","../src/kdbush/tinyqueue.ts","../src/kdbush/geokdbush.ts","../src/routing.ts","../src/terra-draw-route-snap-mode.ts"],"sourcesContent":["// Adapted from https://github.com/mourner/kdbush\n\n// ISC License\n\n// Copyright (c) 2018, Vladimir Agafonkin\n\n// Permission to use, copy, modify, and/or distribute this software for any purpose\n// with or without fee is hereby granted, provided that the above copyright notice\n// and this permission notice appear in all copies.\n\n// THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND\n// FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS\n// OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER\n// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\n// THIS SOFTWARE.\n\nconst ARRAY_TYPES = [\n Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array,\n Int32Array, Uint32Array, Float32Array, Float64Array\n];\n\nconst VERSION = 1;\nconst HEADER_SIZE = 8;\n\nexport class KDBush {\n private data: ArrayBuffer;\n public ids: Uint16Array | Uint32Array;\n public coords: InstanceType<TypedArrayConstructor>;\n private _pos: number;\n private _finished: boolean;\n private numItems: number;\n public nodeSize: number;\n private ArrayType: TypedArrayConstructor;\n private IndexArrayType: typeof Uint16Array | typeof Uint32Array;\n\n constructor(\n numItems: number,\n nodeSize: number = 64,\n ArrayType: TypedArrayConstructor = Float64Array,\n data?: ArrayBuffer\n ) {\n if (isNaN(numItems) || numItems < 0) {\n throw new Error(`Unexpected numItems value: ${numItems}.`);\n }\n\n this.numItems = numItems;\n this.nodeSize = Math.min(Math.max(nodeSize, 2), 65535);\n this.ArrayType = ArrayType;\n this.IndexArrayType = numItems < 65536 ? Uint16Array : Uint32Array;\n\n const arrayTypeIndex = ARRAY_TYPES.indexOf(this.ArrayType);\n const coordsByteSize = numItems * 2 * this.ArrayType.BYTES_PER_ELEMENT;\n const idsByteSize = numItems * this.IndexArrayType.BYTES_PER_ELEMENT;\n const padCoords = (8 - idsByteSize % 8) % 8;\n\n if (arrayTypeIndex < 0) {\n throw new Error(`Unexpected typed array class: ${ArrayType}.`);\n }\n\n if (data) {\n this.data = data;\n this.ids = new (this.IndexArrayType as any)(this.data, HEADER_SIZE, numItems);\n this.coords = new (this.ArrayType as any)(this.data, HEADER_SIZE + idsByteSize + padCoords, numItems * 2);\n this._pos = numItems * 2;\n this._finished = true;\n } else {\n this.data = new ArrayBuffer(HEADER_SIZE + coordsByteSize + idsByteSize + padCoords);\n this.ids = new (this.IndexArrayType as any)(this.data, HEADER_SIZE, numItems);\n this.coords = new (this.ArrayType as any)(this.data, HEADER_SIZE + idsByteSize + padCoords, numItems * 2);\n this._pos = 0;\n this._finished = false;\n\n new Uint8Array(this.data, 0, 2).set([0xdb, (VERSION << 4) + arrayTypeIndex]);\n new Uint16Array(this.data, 2, 1)[0] = this.nodeSize;\n new Uint32Array(this.data, 4, 1)[0] = this.numItems;\n }\n }\n\n add(x: number, y: number): number {\n const index = this._pos >> 1;\n this.ids[index] = index;\n this.coords[this._pos++] = x;\n this.coords[this._pos++] = y;\n return index;\n }\n\n finish(): this {\n const numAdded = this._pos >> 1;\n if (numAdded !== this.numItems) {\n throw new Error(`Added ${numAdded} items when expected ${this.numItems}.`);\n }\n sort(this.ids, this.coords, this.nodeSize, 0, this.numItems - 1, 0);\n this._finished = true;\n return this;\n }\n}\n\ntype TypedArrayConstructor =\n Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor |\n Int16ArrayConstructor | Uint16ArrayConstructor |\n Int32ArrayConstructor | Uint32ArrayConstructor |\n Float32ArrayConstructor | Float64ArrayConstructor;\n\nfunction sort(\n ids: Uint16Array | Uint32Array,\n coords: InstanceType<TypedArrayConstructor>,\n nodeSize: number,\n left: number,\n right: number,\n axis: number\n): void {\n if (right - left <= nodeSize) return;\n const m = (left + right) >> 1;\n select(ids, coords, m, left, right, axis);\n sort(ids, coords, nodeSize, left, m - 1, 1 - axis);\n sort(ids, coords, nodeSize, m + 1, right, 1 - axis);\n}\n\nfunction select(\n ids: Uint16Array | Uint32Array,\n coords: InstanceType<TypedArrayConstructor>,\n k: number,\n left: number,\n right: number,\n axis: number\n): void {\n while (right > left) {\n if (right - left > 600) {\n const n = right - left + 1;\n const m = k - left + 1;\n const z = Math.log(n);\n const s = 0.5 * Math.exp(2 * z / 3);\n const sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);\n const newLeft = Math.max(left, Math.floor(k - m * s / n + sd));\n const newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));\n select(ids, coords, k, newLeft, newRight, axis);\n }\n\n const t = coords[2 * k + axis];\n let i = left;\n let j = right;\n\n swapItem(ids, coords, left, k);\n if (coords[2 * right + axis] > t) {\n swapItem(ids, coords, left, right);\n }\n\n while (i < j) {\n swapItem(ids, coords, i, j);\n i++;\n j--;\n while (coords[2 * i + axis] < t) i++;\n while (coords[2 * j + axis] > t) j--;\n }\n\n if (coords[2 * left + axis] === t) {\n swapItem(ids, coords, left, j);\n } else {\n j++;\n swapItem(ids, coords, j, right);\n }\n\n if (j <= k) left = j + 1;\n if (k <= j) right = j - 1;\n }\n}\n\nfunction swapItem(\n ids: Uint16Array | Uint32Array,\n coords: InstanceType<TypedArrayConstructor>,\n i: number,\n j: number\n): void {\n swap(ids, i, j);\n swap(coords, 2 * i, 2 * j);\n swap(coords, 2 * i + 1, 2 * j + 1);\n}\n\nfunction swap<T extends Uint16Array | Uint32Array | Float32Array | Float64Array | Int8Array | Int16Array | Int32Array | Uint8Array | Uint8ClampedArray>(\n arr: T,\n i: number,\n j: number\n): void {\n const tmp = arr[i];\n arr[i] = arr[j];\n arr[j] = tmp;\n}\n","// Adapted from https://github.com/mourner/kdbush\n\n// ISC License\n\n// Copyright (c) 2017, Vladimir Agafonkin\n\n// Permission to use, copy, modify, and/or distribute this software for any purpose\n// with or without fee is hereby granted, provided that the above copyright notice\n// and this permission notice appear in all copies.\n\n// THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND\n// FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS\n// OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER\n// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\n// THIS SOFTWARE.\n\nexport default class TinyQueue<T> {\n\n private data: T[];\n public length: number;\n private compare: (a: T, b: T) => number;\n\n constructor(\n data: T[] = [],\n compare: (a: T, b: T) => number = (a, b) =>\n a < b ? -1 : a > b ? 1 : 0\n ) {\n this.data = data;\n this.length = this.data.length;\n this.compare = compare;\n\n if (this.length > 0) {\n for (let i = (this.length >> 1) - 1; i >= 0; i--) {\n this._down(i);\n }\n }\n }\n\n push(item: T): void {\n this.data.push(item);\n this._up(this.length++);\n }\n\n pop(): T | undefined {\n if (this.length === 0) {\n return undefined;\n }\n\n const top = this.data[0];\n const bottom = this.data.pop() as T;\n\n this.length--;\n\n if (this.length > 0) {\n this.data[0] = bottom;\n this._down(0);\n }\n\n return top;\n }\n\n peek(): T | undefined {\n return this.data[0];\n }\n\n private _up(pos: number): void {\n const { data, compare } = this;\n const item = data[pos];\n\n while (pos > 0) {\n const parent = (pos - 1) >> 1;\n const current = data[parent];\n if (compare(item, current) >= 0) {\n break;\n }\n data[pos] = current;\n pos = parent;\n }\n\n data[pos] = item;\n }\n\n private _down(pos: number): void {\n const { data, compare } = this;\n const halfLength = this.length >> 1;\n const item = data[pos];\n\n while (pos < halfLength) {\n let bestChild = (pos << 1) + 1;\n const right = bestChild + 1;\n\n if (right < this.length && compare(data[right], data[bestChild]) < 0) {\n bestChild = right;\n }\n\n if (compare(data[bestChild], item) >= 0) {\n break;\n }\n\n data[pos] = data[bestChild];\n pos = bestChild;\n }\n\n data[pos] = item;\n }\n}\n","// Adapted from https://github.com/mourner/geokdbush\n\n// ISC License\n\n// Copyright (c) 2017, Vladimir Agafonkin\n\n// Permission to use, copy, modify, and/or distribute this software for any purpose\n// with or without fee is hereby granted, provided that the above copyright notice\n// and this permission notice appear in all copies.\n\n// THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND\n// FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS\n// OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER\n// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\n// THIS SOFTWARE.\n\nimport { KDBush } from './kdbush';\nimport TinyQueue from './tinyqueue';\n\nconst earthRadius = 6371;\nconst rad = Math.PI / 180;\n\n\nexport function around(index: KDBush, lng: number, lat: number, maxResults = Infinity, maxDistance = Infinity) {\n let maxHaverSinDist = 1;\n const result = [];\n\n if (maxResults === undefined) maxResults = Infinity;\n if (maxDistance !== undefined) maxHaverSinDist = haverSin(maxDistance / earthRadius);\n\n // a distance-sorted priority queue that will contain both points and kd-tree nodes\n const q = new TinyQueue([], compareDist);\n\n // an object that represents the top kd-tree node (the whole Earth)\n let node = {\n left: 0, // left index in the kd-tree array\n right: index.ids.length - 1, // right index\n axis: 0, // 0 for longitude axis and 1 for latitude axis\n dist: 0, // will hold the lower bound of children's distances to the query point\n minLng: -180, // bounding box of the node\n minLat: -90,\n maxLng: 180,\n maxLat: 90\n };\n\n const cosLat = Math.cos(lat * rad);\n\n while (node) {\n const right = node.right;\n const left = node.left;\n\n if (right - left <= index.nodeSize) { // leaf node\n\n // add all points of the leaf node to the queue\n for (let i = left; i <= right; i++) {\n const id = index.ids[i];\n\n const dist = haverSinDist(lng, lat, index.coords[2 * i], index.coords[2 * i + 1], cosLat);\n q.push({ id, dist });\n }\n\n } else { // not a leaf node (has child nodes)\n\n const m = (left + right) >> 1; // middle index\n const midLng = index.coords[2 * m];\n const midLat = index.coords[2 * m + 1];\n\n // add middle point to the queue\n const id = index.ids[m];\n const dist = haverSinDist(lng, lat, midLng, midLat, cosLat);\n q.push({ id, dist });\n\n\n const nextAxis = (node.axis + 1) % 2;\n\n // first half of the node\n const leftNode = {\n left,\n right: m - 1,\n axis: nextAxis,\n minLng: node.minLng,\n minLat: node.minLat,\n maxLng: node.axis === 0 ? midLng : node.maxLng,\n maxLat: node.axis === 1 ? midLat : node.maxLat,\n dist: 0\n };\n // second half of the node\n const rightNode = {\n left: m + 1,\n right,\n axis: nextAxis,\n minLng: node.axis === 0 ? midLng : node.minLng,\n minLat: node.axis === 1 ? midLat : node.minLat,\n maxLng: node.maxLng,\n maxLat: node.maxLat,\n dist: 0\n };\n\n leftNode.dist = boxDist(lng, lat, cosLat, leftNode);\n rightNode.dist = boxDist(lng, lat, cosLat, rightNode);\n\n // add child nodes to the queue\n q.push(leftNode);\n q.push(rightNode);\n }\n\n // fetch closest points from the queue; they're guaranteed to be closer\n // than all remaining points (both individual and those in kd-tree nodes),\n // since each node's distance is a lower bound of distances to its children\n while (q.length && q.peek().id != null) {\n const candidate = q.pop()!;\n if (candidate.dist > maxHaverSinDist) return result;\n result.push(candidate.id);\n if (result.length === maxResults) return result;\n }\n\n // the next closest kd-tree node\n node = q.pop();\n }\n\n return result;\n}\n\n// lower bound for distance from a location to points inside a bounding box\nfunction boxDist(lng: number, lat: number, cosLat: number, node: any) {\n const minLng = node.minLng;\n const maxLng = node.maxLng;\n const minLat = node.minLat;\n const maxLat = node.maxLat;\n\n // query point is between minimum and maximum longitudes\n if (lng >= minLng && lng <= maxLng) {\n if (lat < minLat) return haverSin((lat - minLat) * rad);\n if (lat > maxLat) return haverSin((lat - maxLat) * rad);\n return 0;\n }\n\n // query point is west or east of the bounding box;\n // calculate the extremum for great circle distance from query point to the closest longitude;\n const haverSinDLng = Math.min(haverSin((lng - minLng) * rad), haverSin((lng - maxLng) * rad));\n const extremumLat = vertexLat(lat, haverSinDLng);\n\n // if extremum is inside the box, return the distance to it\n if (extremumLat > minLat && extremumLat < maxLat) {\n return haverSinDistPartial(haverSinDLng, cosLat, lat, extremumLat);\n }\n // otherwise return the distan e to one of the bbox corners (whichever is closest)\n return Math.min(\n haverSinDistPartial(haverSinDLng, cosLat, lat, minLat),\n haverSinDistPartial(haverSinDLng, cosLat, lat, maxLat)\n );\n}\n\nfunction compareDist(a: any, b: any) {\n return a.dist - b.dist;\n}\n\nfunction haverSin(theta: number) {\n const s = Math.sin(theta / 2);\n return s * s;\n}\n\nfunction haverSinDistPartial(haverSinDLng: number, cosLat1: number, lat1: number, lat2: number) {\n return cosLat1 * Math.cos(lat2 * rad) * haverSinDLng + haverSin((lat1 - lat2) * rad);\n}\n\nfunction haverSinDist(lng1: number, lat1: number, lng2: number, lat2: number, cosLat1: number) {\n const haverSinDLng = haverSin((lng1 - lng2) * rad);\n return haverSinDistPartial(haverSinDLng, cosLat1, lat1, lat2);\n}\n\nexport function distance(lng1: number, lat1: number, lng2: number, lat2: number) {\n const h = haverSinDist(lng1, lat1, lng2, lat2, Math.cos(lat1 * rad));\n return 2 * earthRadius * Math.asin(Math.sqrt(h));\n}\n\nfunction vertexLat(lat: number, haverSinDLng: number) {\n const cosDLng = 1 - 2 * haverSinDLng;\n if (cosDLng <= 0) return lat > 0 ? 90 : -90;\n return Math.atan(Math.tan(lat * rad) / cosDLng) / rad;\n}","import { KDBush } from \"./kdbush/kdbush\";\nimport { around } from \"./kdbush/geokdbush\";\nimport {\n FeatureCollection,\n LineString,\n Position,\n Feature,\n Point,\n} from \"geojson\";\n\nexport type RouteFinder = {\n getRoute: (positionA: Feature<Point>, positionB: Feature<Point>) => Feature<LineString> | null\n setNetwork: (network: FeatureCollection<LineString>) => void\n}\n\nexport interface RoutingInterface {\n getRoute: (\n startCoord: Position,\n endCoord: Position\n ) => Feature<LineString> | null;\n getClosestNetworkCoordinate: (coordinate: Position) => Position | null;\n}\n\n/**\n * Routing class for finding routes on a network of LineStrings.\n * The LineString network must have coordinates that are shared between\n * the LineStrings in order to find a route.\n */\nexport class Routing implements RoutingInterface {\n constructor(options: {\n network: FeatureCollection<LineString>, useCache?: boolean,\n routeFinder: RouteFinder\n }) {\n this.useCache = options.useCache || true;\n this.network = options.network;\n this.routeFinder = options.routeFinder;\n\n this.initialise();\n }\n\n private useCache: boolean = true;\n private indexedNetworkPoints!: KDBush;\n private points: Position[] = []\n private routeFinder: RouteFinder;\n private network: FeatureCollection<LineString>;\n private routeCache: Record<string, Feature<LineString> | null> = {};\n\n // Initialise the routing instance setting internal data structures\n private initialise() {\n this.network.features.forEach((feature) => {\n feature.geometry.coordinates.forEach((coordinate) => {\n this.points.push(coordinate);\n });\n });\n\n this.indexedNetworkPoints = new KDBush(this.points.length);\n\n this.points.forEach(coordinate => {\n this.indexedNetworkPoints.add(coordinate[0], coordinate[1]);\n })\n\n this.indexedNetworkPoints.finish();\n\n this.routeCache = {};\n }\n\n /**\n * Return the closest network coordinate to the input coordinate\n * @param inputCoordinate The coordinate to find the closest network coordinate to\n * @returns a coordinate on the network or null if no coordinate is found\n */\n public getClosestNetworkCoordinate(inputCoordinate: Position) {\n const aroundInput: number[] = around(\n this.indexedNetworkPoints,\n inputCoordinate[0],\n inputCoordinate[1],\n 1\n );\n\n const nearest = this.points[aroundInput[0]]\n return nearest ? nearest : null;\n }\n\n /**\n * Set the route finder for the routing instance\n * @param routeFinder The route finder to use\n */\n public setRouteFinder(routeFinder: RouteFinder) {\n this.routeFinder = routeFinder;\n }\n\n /**\n * Set the network for the routing instance\n * @param network The network to use\n */\n public setNetwork(network: FeatureCollection<LineString>) {\n this.network = network;\n\n // Ensure the network is updated correctly for the router finder\n this.routeFinder.setNetwork(network);\n\n // Re-initialize all internal data structures for this class\n this.initialise();\n }\n\n /**\n * Get the route between two coordinates returned as a GeoJSON LineString\n * @param startCoord start coordinate\n * @param endCoord end coordinate\n * @returns The route as a GeoJSON LineString\n */\n public getRoute(startCoord: Position, endCoord: Position): Feature<LineString> | null {\n\n // Check if caching is enabled, and if the coordinates are already in the cache \n if (this.useCache) {\n const routeKey = `${startCoord}-${endCoord}`;\n\n if (this.routeCache[routeKey]) {\n return this.routeCache[routeKey];\n }\n }\n\n const start = {\n type: \"Feature\",\n geometry: {\n type: \"Point\",\n coordinates: startCoord,\n },\n properties: {},\n } as Feature<Point>;\n\n const end = {\n type: \"Feature\",\n geometry: {\n type: \"Point\",\n coordinates: endCoord,\n },\n properties: {},\n } as Feature<Point>;\n\n const route = this.routeFinder.getRoute(start, end);\n\n // If caching is enabled, store the route in the cache\n if (this.useCache) {\n const routeKey = `${startCoord}-${endCoord}`\n this.routeCache[routeKey] = route;\n return route;\n }\n\n return route;\n\n }\n}\n","import {\n TerraDrawAdapterStyling,\n TerraDrawKeyboardEvent,\n TerraDrawMouseEvent,\n BehaviorConfig,\n GeoJSONStoreFeatures,\n TerraDrawExtend\n} from \"terra-draw\";\nimport { LineString, Position } from \"geojson\";\nimport { Validation } from \"terra-draw/dist/common\";\nimport { RoutingInterface } from \"./routing\";\n\ntype TerraDrawLineStringModeKeyEvents = {\n cancel: KeyboardEvent[\"key\"] | null;\n finish: KeyboardEvent[\"key\"] | null;\n};\n\nconst defaultKeyEvents = { cancel: \"Escape\", finish: \"Enter\" };\n\ninterface Cursors {\n draw?: TerraDrawExtend.Cursor;\n close?: TerraDrawExtend.Cursor;\n}\n\nconst defaultCursors = {\n draw: \"crosshair\",\n close: \"pointer\"\n} as Required<Cursors>;\n\ntype RouteStyling = {\n lineStringWidth: TerraDrawExtend.NumericStyling;\n lineStringColor: TerraDrawExtend.HexColorStyling\n routePointColor: TerraDrawExtend.HexColorStyling;\n routePointWidth: TerraDrawExtend.NumericStyling;\n routePointOutlineColor: TerraDrawExtend.HexColorStyling;\n routePointOutlineWidth: TerraDrawExtend.NumericStyling;\n};\n\ninterface TerraDrawPolygonModeOptions<T extends TerraDrawExtend.CustomStyling>\n extends TerraDrawExtend.BaseModeOptions<T> {\n routing: RoutingInterface;\n pointerDistance?: number;\n keyEvents?: TerraDrawLineStringModeKeyEvents | null;\n maxPoints?: number;\n cursors?: Partial<Cursors>;\n}\n\nconst { TerraDrawBaseDrawMode } = TerraDrawExtend;\n\nexport class TerraDrawRouteSnapMode extends TerraDrawBaseDrawMode<RouteStyling> {\n mode = \"routesnap\" as const;\n\n private currentCoordinate = 0;\n private currentId: string | undefined;\n private keyEvents: TerraDrawLineStringModeKeyEvents = defaultKeyEvents;\n private cursors: Required<Cursors> = defaultCursors;\n\n private maxPoints: number = 1\n private moveLineId: string | undefined;\n private routing!: RoutingInterface;\n private currentPointIds: string[] = [];\n private routeId = 0;\n\n constructor(options?: TerraDrawPolygonModeOptions<RouteStyling>) {\n super(options, true);\n this.updateOptions(options);\n }\n\n override updateOptions(options?: Partial<TerraDrawPolygonModeOptions<RouteStyling>>) {\n super.updateOptions(options);\n\n if (options?.routing && options.routing !== this.routing) {\n // We can't guarantee the rout created so far is valid with the new routing \n // So we need to clean up the current state\n this.cleanUp();\n this.routing = options.routing;\n }\n\n if (options?.maxPoints !== undefined && options.maxPoints !== this.maxPoints && options.maxPoints > 0) {\n this.maxPoints = options.maxPoints;\n }\n\n if (options?.cursors) {\n this.cursors = { ...this.cursors, ...options.cursors };\n }\n\n // null is the case where we want to explicitly turn key bindings off\n if (options?.keyEvents === null) {\n this.keyEvents = { cancel: null, finish: null };\n } else if (options?.keyEvents) {\n this.keyEvents = { ...this.keyEvents, ...options.keyEvents };\n }\n }\n\n private pixelDistance = (\n pointOne: { x: number; y: number },\n pointTwo: { x: number; y: number }\n ) => {\n const { x: x1, y: y1 } = pointOne;\n const { x: x2, y: y2 } = pointTwo;\n const y = x2 - x1;\n const x = y2 - y1;\n return Math.sqrt(x * x + y * y);\n };\n\n private measure(clickEvent: TerraDrawMouseEvent, secondCoordinate: Position) {\n const { x, y } = this.project(secondCoordinate[0], secondCoordinate[1]);\n\n const distance = this.pixelDistance(\n { x, y },\n { x: clickEvent.containerX, y: clickEvent.containerY }\n );\n\n return distance;\n }\n\n private close() {\n if (!this.currentId) {\n return;\n }\n\n // Reset the state back to starting state\n this.currentCoordinate = 0;\n this.currentId = undefined;\n this.currentPointIds = [];\n\n // Go back to started state\n if (this.state === \"drawing\") {\n this.setStarted();\n }\n }\n\n /** @internal */\n registerBehaviors(config: BehaviorConfig) { }\n\n /** @internal */\n start() {\n this.setStarted();\n this.setCursor(this.cursors.draw);\n }\n\n /** @internal */\n stop() {\n this.cleanUp();\n this.setStopped();\n this.setCursor(\"unset\");\n }\n\n /** @internal */\n onMouseMove(event: TerraDrawMouseEvent) {\n this.setCursor(this.cursors.draw);\n\n if (this.moveLineId && !this.store.has(this.moveLineId)) {\n this.moveLineId = undefined;\n }\n\n if (!this.currentId || this.currentCoordinate === 0) {\n return;\n }\n\n if (this.currentId) {\n const currentLineGeometry = this.store.getGeometryCopy<LineString>(\n this.currentId\n );\n\n // If the cursor is close the last line\n // delete the current moving line and set the cursor to pointer\n if (\n this.measure(\n event,\n currentLineGeometry.coordinates[\n currentLineGeometry.coordinates.length - 1\n ]\n ) < this.pointerDistance\n ) {\n this.setCursor(this.cursors.close);\n if (this.moveLineId) {\n this.store.delete([this.moveLineId]);\n this.moveLineId = undefined;\n }\n\n return;\n }\n }\n\n const currentLineGeometry = this.store.getGeometryCopy<LineString>(\n this.currentId\n );\n\n const eventCoord = [event.lng, event.lat];\n\n let closestPoint = this.routing.getClosestNetworkCoordinate(eventCoord);\n\n if (!closestPoint) {\n return;\n }\n\n const length = currentLineGeometry.coordinates.length - 1;\n\n const geojsonRoute = this.routing.getRoute(\n currentLineGeometry.coordinates[length],\n closestPoint\n );\n\n if (!geojsonRoute) {\n return;\n }\n\n if (!this.moveLineId) {\n const [createdId] = this.store.create([\n {\n geometry: geojsonRoute.geometry,\n properties: { mode: this.mode, isDrawnRoute: true, routeId: this.routeId },\n },\n ]);\n\n this.moveLineId = createdId as string;\n } else {\n this.store.updateGeometry([\n {\n id: this.moveLineId,\n geometry: geojsonRoute.geometry,\n },\n ]);\n }\n }\n\n /** @internal */\n onClick(event: TerraDrawMouseEvent) {\n if (event.button === \"right\") {\n return;\n }\n\n const eventCoord = [event.lng, event.lat] as Position;\n\n if (this.currentId && !this.store.has(this.currentId)) {\n this.currentId = undefined;\n this.currentCoordinate = 0;\n this.currentPointIds = [];\n }\n\n if (this.currentId) {\n const currentLineGeometry = this.store.getGeometryCopy<LineString>(\n this.currentId\n );\n\n if (\n this.measure(\n event,\n currentLineGeometry.coordinates[\n currentLineGeometry.coordinates.length - 1\n ]\n ) < this.pointerDistance\n ) {\n if (this.currentCoordinate === 1) {\n this.store.delete(this.currentPointIds);\n }\n\n this.close();\n\n return;\n }\n } else {\n this.routeId++;\n }\n\n let closestPoint = this.routing.getClosestNetworkCoordinate(eventCoord);\n\n if (this.currentCoordinate === 0) {\n if (closestPoint) {\n const [createdId, pointId] = this.store.create([\n {\n geometry: {\n type: \"LineString\",\n coordinates: [closestPoint],\n },\n properties: { mode: this.mode, isDrawnRoute: true, routeId: this.routeId },\n },\n {\n geometry: {\n type: \"Point\",\n coordinates: closestPoint,\n },\n properties: { mode: this.mode, isDrawnRoute: true, routeId: this.routeId },\n },\n ]);\n\n this.currentId = createdId as string;\n this.currentPointIds.push(pointId as string);\n this.currentCoordinate++;\n\n if (this.state === \"started\") {\n this.setDrawing();\n }\n }\n } else if (this.currentCoordinate === 1 && this.currentId && closestPoint) {\n const currentLineGeometry = this.store.getGeometryCopy<LineString>(\n this.currentId\n );\n\n const geojsonRoute = this.routing.getRoute(\n currentLineGeometry.coordinates[0],\n closestPoint\n );\n if (geojsonRoute) {\n this.store.updateGeometry([\n {\n id: this.currentId,\n geometry: geojsonRoute?.geometry,\n },\n ]);\n\n const [pointId] = this.store.create([\n {\n geometry: {\n type: \"Point\",\n coordinates: closestPoint,\n },\n properties: { mode: this.mode, isDrawnRoute: true, routeId: this.routeId },\n },\n ]);\n\n this.currentCoordinate = 2;\n this.currentPointIds.push(pointId as string);\n }\n\n if (this.maxPoints === 1) {\n this.close();\n\n return;\n }\n } else if (\n this.currentCoordinate > 1 &&\n this.currentId &&\n closestPoint &&\n this.currentCoordinate <= this.maxPoints\n ) {\n const currentLineGeometry = this.store.getGeometryCopy<LineString>(\n this.currentId\n );\n\n const length = currentLineGeometry.coordinates.length - 1;\n\n const geojsonRoute = this.routing.getRoute(\n currentLineGeometry.coordinates[length],\n closestPoint\n );\n\n if (geojsonRoute) {\n const newGeometry = {\n ...currentLineGeometry,\n coordinates: [\n ...currentLineGeometry.coordinates,\n ...geojsonRoute.geometry.coordinates,\n ],\n };\n\n this.store.updateGeometry([\n {\n id: this.currentId,\n geometry: newGeometry,\n },\n ]);\n\n const [pointId] = this.store.create([\n {\n geometry: {\n type: \"Point\",\n coordinates: closestPoint,\n },\n properties: { mode: this.mode, isDrawnRoute: true, routeId: this.routeId },\n },\n ]);\n\n if (this.maxPoints === this.currentCoordinate) {\n this.close();\n } else {\n this.currentCoordinate++;\n this.currentPointIds.push(pointId as string);\n }\n }\n }\n }\n\n /** @internal */\n onKeyDown() { }\n\n /** @internal */\n onKeyUp(event: TerraDrawKeyboardEvent) {\n if (event.key === this.keyEvents.cancel) {\n this.cleanUp();\n }\n\n if (event.key === this.keyEvents.finish) {\n this.close();\n }\n }\n\n /** @internal */\n onDragStart() { }\n\n /** @internal */\n onDrag() { }\n\n /** @internal */\n onDragEnd() { }\n\n /** @internal */\n cleanUp() {\n try {\n if (this.currentId) {\n this.store.delete([this.currentId, ...this.currentPointIds]);\n }\n } catch (error) { }\n\n this.currentId = undefined;\n this.moveLineId = undefined;\n this.currentCoordinate = 0;\n if (this.state === \"drawing\") {\n this.setStarted();\n }\n }\n\n /** @internal */\n styleFeature(feature: GeoJSONStoreFeatures): TerraDrawAdapterStyling {\n const styles = TerraDrawExtend.getDefaultStyling();\n\n if (\n feature.type === \"Feature\" &&\n feature.geometry.type === \"LineString\" &&\n feature.properties.mode === this.mode\n ) {\n styles.lineStringColor = this.getHexColorStylingValue(this.styles.lineStringColor, \"#B90E0A\", feature);\n styles.lineStringWidth = this.getNumericStylingValue(this.styles.lineStringWidth, 4, feature);\n styles.zIndex = 10;\n\n return styles;\n } else if (\n feature.type === \"Feature\" &&\n feature.geometry.type === \"Point\" &&\n feature.properties.mode === this.mode\n ) {\n styles.pointColor = this.getHexColorStylingValue(this.styles.routePointColor, \"#B90E0A\", feature);\n styles.pointOutlineColor = this.getHexColorStylingValue(this.styles.routePointColor, \"#B90E0A\", feature);\n styles.pointOutlineWidth = this.getNumericStylingValue(this.styles.routePointOutlineWidth, 1, feature);\n\n return styles;\n }\n\n return styles;\n }\n\n validateFeature(feature: unknown): ReturnType<Validation> {\n return super.validateFeature(feature)\n }\n\n afterFeatureAdded(feature: GeoJSONStoreFeatures) { }\n\n}\n\nexport { Routing, RouteFinder, RoutingInterface } from \"./routing\";"],"names":["ARRAY_TYPES","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","KDBush","numItems","nodeSize","ArrayType","data","ids","this","coords","_pos","_finished","IndexArrayType","isNaN","Error","Math","min","max","arrayTypeIndex","indexOf","coordsByteSize","BYTES_PER_ELEMENT","idsByteSize","padCoords","ArrayBuffer","set","_proto","prototype","add","x","y","index","finish","numAdded","sort","left","right","axis","m","select","k","n","z","log","s","exp","sd","sqrt","floor","t","i","j","swapItem","swap","arr","tmp","TinyQueue","compare","a","b","length","_down","push","item","_up","pop","top","bottom","peek","pos","parent","current","halfLength","bestChild","rad","PI","boxDist","lng","lat","cosLat","node","minLng","maxLng","minLat","maxLat","haverSin","haverSinDLng","extremumLat","cosDLng","atan","tan","vertexLat","haverSinDistPartial","compareDist","dist","theta","sin","cosLat1","lat1","lat2","cos","haverSinDist","lng1","lng2","Routing","options","useCache","indexedNetworkPoints","points","routeFinder","network","routeCache","initialise","_this","features","forEach","feature","geometry","coordinates","coordinate","getClosestNetworkCoordinate","inputCoordinate","aroundInput","maxResults","maxDistance","Infinity","maxHaverSinDist","result","undefined","q","id","midLng","midLat","nextAxis","leftNode","rightNode","candidate","around","setRouteFinder","setNetwork","getRoute","startCoord","endCoord","routeKey","route","type","properties","defaultKeyEvents","cancel","defaultCursors","draw","close","TerraDrawRouteSnapMode","_TerraDrawBaseDrawMod","call","mode","currentCoordinate","currentId","keyEvents","cursors","maxPoints","moveLineId","routing","currentPointIds","routeId","pixelDistance","pointOne","pointTwo","updateOptions","cleanUp","_extends","measure","clickEvent","secondCoordinate","_this$project","project","containerX","containerY","state","setStarted","registerBehaviors","config","start","setCursor","stop","setStopped","onMouseMove","event","store","has","currentLineGeometry","getGeometryCopy","pointerDistance","closestPoint","geojsonRoute","updateGeometry","_this$store$create","create","isDrawnRoute","onClick","button","eventCoord","_this$store$create2","pointId","setDrawing","newGeometry","concat","onKeyDown","onKeyUp","key","onDragStart","onDrag","onDragEnd","error","styleFeature","styles","TerraDrawExtend","getDefaultStyling","lineStringColor","getHexColorStylingValue","lineStringWidth","getNumericStylingValue","zIndex","pointColor","routePointColor","pointOutlineColor","pointOutlineWidth","routePointOutlineWidth","validateFeature","afterFeatureAdded","TerraDrawBaseDrawMode"],"mappings":"6WAkBA,IAAMA,EAAc,CAChBC,UAAWC,WAAYC,kBAAmBC,WAAYC,YACtDC,WAAYC,YAAaC,aAAcC,cAM9BC,eAWT,WAAA,SAAAA,EACIC,EACAC,EACAC,EACAC,GAEA,QAJAF,IAAAA,IAAAA,EAAmB,SACnBC,IAAAA,IAAAA,EAAmCJ,cAb/BK,KAAAA,iBACDC,SAAG,EAAAC,KACHC,YAAM,EAAAD,KACLE,UAAI,EAAAF,KACJG,eAAS,EAAAH,KACTL,cAAQ,EAAAK,KACTJ,cAAQ,EAAAI,KACPH,eAAS,EAAAG,KACTI,oBAAc,EAQdC,MAAMV,IAAaA,EAAW,EAC9B,MAAM,IAAIW,MAAoCX,8BAAAA,OAGlDK,KAAKL,SAAWA,EAChBK,KAAKJ,SAAWW,KAAKC,IAAID,KAAKE,IAAIb,EAAU,GAAI,OAChDI,KAAKH,UAAYA,EACjBG,KAAKI,eAAiBT,EAAW,MAAQN,YAAcE,YAEvD,IAAMmB,EAAiB1B,EAAY2B,QAAQX,KAAKH,WAC1Ce,EAA4B,EAAXjB,EAAeK,KAAKH,UAAUgB,kBAC/CC,EAAcnB,EAAWK,KAAKI,eAAeS,kBAC7CE,GAAa,EAAID,EAAc,GAAK,EAE1C,GAAIJ,EAAiB,EACjB,MAAM,IAAIJ,MAAuCT,iCAAAA,EAAY,KAG7DC,GACAE,KAAKF,KAAOA,EACZE,KAAKD,IAAM,IAAKC,KAAKI,eAAuBJ,KAAKF,KAvCzC,EAuC4DH,GACpEK,KAAKC,OAAS,IAASD,KAACH,UAA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AOW,kBAAoB1N,KAAKqN,uBAAuBrN,KAAK+M,OAAOY,uBAAwB,EAAG/G,GAEvFmG,GAGFA,CACT,EAAC7L,EAED0M,gBAAA,SAAgBhH,GACd,OAAAqC,EAAA9H,UAAayM,gBAAe1E,KAACtC,KAAAA,EAC/B,EAAC1F,EAED2M,kBAAA,SAAkBjH,GAAkC,EAAAoC,CAAA,EAzZpBgE,kBAA1Bc"}
@@ -1,6 +1,6 @@
1
1
  import { TerraDrawAdapterStyling, TerraDrawKeyboardEvent, TerraDrawMouseEvent, BehaviorConfig, GeoJSONStoreFeatures, TerraDrawExtend } from "terra-draw";
2
- import { Feature, LineString, Position } from "geojson";
3
2
  import { Validation } from "terra-draw/dist/common";
3
+ import { RoutingInterface } from "./routing";
4
4
  type TerraDrawLineStringModeKeyEvents = {
5
5
  cancel: KeyboardEvent["key"] | null;
6
6
  finish: KeyboardEvent["key"] | null;
@@ -9,10 +9,6 @@ interface Cursors {
9
9
  draw?: TerraDrawExtend.Cursor;
10
10
  close?: TerraDrawExtend.Cursor;
11
11
  }
12
- export interface RoutingInterface {
13
- getRoute: (startCoord: Position, endCoord: Position) => Feature<LineString> | null;
14
- getClosestNetworkCoordinate: (coordinate: Position) => Position | null;
15
- }
16
12
  type RouteStyling = {
17
13
  lineStringWidth: TerraDrawExtend.NumericStyling;
18
14
  lineStringColor: TerraDrawExtend.HexColorStyling;
@@ -72,4 +68,4 @@ export declare class TerraDrawRouteSnapMode extends TerraDrawBaseDrawMode<RouteS
72
68
  validateFeature(feature: unknown): ReturnType<Validation>;
73
69
  afterFeatureAdded(feature: GeoJSONStoreFeatures): void;
74
70
  }
75
- export { Routing } from "./routing";
71
+ export { Routing, RouteFinder, RoutingInterface } from "./routing";
@@ -1,2 +1,2 @@
1
- import{TerraDrawExtend as t}from"terra-draw";function e(){return e=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var s in i)({}).hasOwnProperty.call(i,s)&&(t[s]=i[s])}return t},e.apply(null,arguments)}const i=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class s{constructor(t,e=64,s=Float64Array,r){if(this.data=void 0,this.ids=void 0,this.coords=void 0,this._pos=void 0,this._finished=void 0,this.numItems=void 0,this.nodeSize=void 0,this.ArrayType=void 0,this.IndexArrayType=void 0,isNaN(t)||t<0)throw new Error(`Unexpected numItems value: ${t}.`);this.numItems=t,this.nodeSize=Math.min(Math.max(e,2),65535),this.ArrayType=s,this.IndexArrayType=t<65536?Uint16Array:Uint32Array;const o=i.indexOf(this.ArrayType),n=2*t*this.ArrayType.BYTES_PER_ELEMENT,h=t*this.IndexArrayType.BYTES_PER_ELEMENT,a=(8-h%8)%8;if(o<0)throw new Error(`Unexpected typed array class: ${s}.`);r?(this.data=r,this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+h+a,2*t),this._pos=2*t,this._finished=!0):(this.data=new ArrayBuffer(8+n+h+a),this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+h+a,2*t),this._pos=0,this._finished=!1,new Uint8Array(this.data,0,2).set([219,16+o]),new Uint16Array(this.data,2,1)[0]=this.nodeSize,new Uint32Array(this.data,4,1)[0]=this.numItems)}add(t,e){const i=this._pos>>1;return this.ids[i]=i,this.coords[this._pos++]=t,this.coords[this._pos++]=e,i}finish(){const t=this._pos>>1;if(t!==this.numItems)throw new Error(`Added ${t} items when expected ${this.numItems}.`);return r(this.ids,this.coords,this.nodeSize,0,this.numItems-1,0),this._finished=!0,this}}function r(t,e,i,s,n,h){if(n-s<=i)return;const a=s+n>>1;o(t,e,a,s,n,h),r(t,e,i,s,a-1,1-h),r(t,e,i,a+1,n,1-h)}function o(t,e,i,s,r,h){for(;r>s;){if(r-s>600){const n=r-s+1,a=i-s+1,d=Math.log(n),u=.5*Math.exp(2*d/3),c=.5*Math.sqrt(d*u*(n-u)/n)*(a-n/2<0?-1:1);o(t,e,i,Math.max(s,Math.floor(i-a*u/n+c)),Math.min(r,Math.floor(i+(n-a)*u/n+c)),h)}const a=e[2*i+h];let d=s,u=r;for(n(t,e,s,i),e[2*r+h]>a&&n(t,e,s,r);d<u;){for(n(t,e,d,u),d++,u--;e[2*d+h]<a;)d++;for(;e[2*u+h]>a;)u--}e[2*s+h]===a?n(t,e,s,u):(u++,n(t,e,u,r)),u<=i&&(s=u+1),i<=u&&(r=u-1)}}function n(t,e,i,s){h(t,i,s),h(e,2*i,2*s),h(e,2*i+1,2*s+1)}function h(t,e,i){const s=t[e];t[e]=t[i],t[i]=s}class a{constructor(t=[],e=(t,e)=>t<e?-1:t>e?1:0){if(this.data=void 0,this.length=void 0,this.compare=void 0,this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let t=(this.length>>1)-1;t>=0;t--)this._down(t)}push(t){this.data.push(t),this._up(this.length++)}pop(){if(0===this.length)return;const t=this.data[0],e=this.data.pop();return this.length--,this.length>0&&(this.data[0]=e,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:e,compare:i}=this,s=e[t];for(;t>0;){const r=t-1>>1,o=e[r];if(i(s,o)>=0)break;e[t]=o,t=r}e[t]=s}_down(t){const{data:e,compare:i}=this,s=this.length>>1,r=e[t];for(;t<s;){let s=1+(t<<1);const o=s+1;if(o<this.length&&i(e[o],e[s])<0&&(s=o),i(e[s],r)>=0)break;e[t]=e[s],t=s}e[t]=r}}const d=Math.PI/180;function u(t,e,i,s){const r=s.minLng,o=s.maxLng,n=s.minLat,h=s.maxLat;if(t>=r&&t<=o)return e<n?l((e-n)*d):e>h?l((e-h)*d):0;const a=Math.min(l((t-r)*d),l((t-o)*d)),u=function(t,e){const i=1-2*e;return i<=0?t>0?90:-90:Math.atan(Math.tan(t*d)/i)/d}(e,a);return u>n&&u<h?p(a,i,e,u):Math.min(p(a,i,e,n),p(a,i,e,h))}function c(t,e){return t.dist-e.dist}function l(t){const e=Math.sin(t/2);return e*e}function p(t,e,i,s){return e*Math.cos(s*d)*t+l((i-s)*d)}function y(t,e,i,s,r){return p(l((t-i)*d),r,e,s)}class m{constructor(t){this.useCache=!0,this.indexedNetworkPoints=void 0,this.points=[],this.routeFinder=void 0,this.network=void 0,this.routeCache={},this.useCache=t.useCache||!0,this.network=t.network,this.routeFinder=t.routeFinder,this.network.features.forEach(t=>{t.geometry.coordinates.forEach(t=>{this.points.push(t)})}),this.indexedNetworkPoints=new s(this.points.length),this.points.forEach(t=>{this.indexedNetworkPoints.add(t[0],t[1])}),this.indexedNetworkPoints.finish()}getClosestNetworkCoordinate(t){const e=function(t,e,i,s=Infinity,r=Infinity){let o=1;const n=[];void 0===s&&(s=Infinity),void 0!==r&&(o=l(r/6371));const h=new a([],c);let p={left:0,right:t.ids.length-1,axis:0,dist:0,minLng:-180,minLat:-90,maxLng:180,maxLat:90};const m=Math.cos(i*d);for(;p;){const r=p.right,a=p.left;if(r-a<=t.nodeSize)for(let s=a;s<=r;s++){const r=t.ids[s],o=y(e,i,t.coords[2*s],t.coords[2*s+1],m);h.push({id:r,dist:o})}else{const s=a+r>>1,o=t.coords[2*s],n=t.coords[2*s+1],d=t.ids[s],c=y(e,i,o,n,m);h.push({id:d,dist:c});const l=(p.axis+1)%2,g={left:a,right:s-1,axis:l,minLng:p.minLng,minLat:p.minLat,maxLng:0===p.axis?o:p.maxLng,maxLat:1===p.axis?n:p.maxLat,dist:0},f={left:s+1,right:r,axis:l,minLng:0===p.axis?o:p.minLng,minLat:1===p.axis?n:p.minLat,maxLng:p.maxLng,maxLat:p.maxLat,dist:0};g.dist=u(e,i,m,g),f.dist=u(e,i,m,f),h.push(g),h.push(f)}for(;h.length&&null!=h.peek().id;){const t=h.pop();if(t.dist>o)return n;if(n.push(t.id),n.length===s)return n}p=h.pop()}return n}(this.indexedNetworkPoints,t[0],t[1],1);return this.points[e[0]]||null}getRoute(t,e){if(this.useCache){const i=`${t}-${e}`;if(this.routeCache[i])return this.routeCache[i]}const i=this.routeFinder.getRoute({type:"Feature",geometry:{type:"Point",coordinates:t},properties:{}},{type:"Feature",geometry:{type:"Point",coordinates:e},properties:{}});return this.useCache?(this.routeCache[`${t}-${e}`]=i,i):i}}const g={cancel:"Escape",finish:"Enter"},f={draw:"crosshair",close:"pointer"},{TerraDrawBaseDrawMode:I}=t;class x extends I{constructor(t){super(t,!0),this.mode="routesnap",this.currentCoordinate=0,this.currentId=void 0,this.keyEvents=g,this.cursors=f,this.maxPoints=1,this.moveLineId=void 0,this.routing=void 0,this.currentPointIds=[],this.routeId=0,this.pixelDistance=(t,e)=>{const{x:i,y:s}=t,{x:r,y:o}=e,n=r-i,h=o-s;return Math.sqrt(h*h+n*n)},this.updateOptions(t)}updateOptions(t){super.updateOptions(t),null!=t&&t.routing&&t.routing!==this.routing&&(this.cleanUp(),this.routing=t.routing),void 0!==(null==t?void 0:t.maxPoints)&&t.maxPoints!==this.maxPoints&&t.maxPoints>0&&(this.maxPoints=t.maxPoints),null!=t&&t.cursors&&(this.cursors=e({},this.cursors,t.cursors)),null===(null==t?void 0:t.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=t&&t.keyEvents&&(this.keyEvents=e({},this.keyEvents,t.keyEvents))}measure(t,e){const{x:i,y:s}=this.project(e[0],e[1]);return this.pixelDistance({x:i,y:s},{x:t.containerX,y:t.containerY})}close(){this.currentId&&(this.currentCoordinate=0,this.currentId=void 0,this.currentPointIds=[],"drawing"===this.state&&this.setStarted())}registerBehaviors(t){}start(){this.setStarted(),this.setCursor(this.cursors.draw)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onMouseMove(t){if(this.setCursor(this.cursors.draw),!this.currentId||0===this.currentCoordinate)return;if(this.currentId){const e=this.store.getGeometryCopy(this.currentId);if(this.measure(t,e.coordinates[e.coordinates.length-1])<this.pointerDistance)return this.setCursor(this.cursors.close),void(this.moveLineId&&(this.store.delete([this.moveLineId]),this.moveLineId=void 0))}const e=this.store.getGeometryCopy(this.currentId);let i=this.routing.getClosestNetworkCoordinate([t.lng,t.lat]);if(!i)return;const s=this.routing.getRoute(e.coordinates[e.coordinates.length-1],i);if(s)if(this.moveLineId)this.store.updateGeometry([{id:this.moveLineId,geometry:s.geometry}]);else{const[t]=this.store.create([{geometry:s.geometry,properties:{mode:this.mode,isDrawnRoute:!0,routeId:this.routeId}}]);this.moveLineId=t}}onClick(t){if("right"===t.button)return;const i=[t.lng,t.lat];if(this.currentId){const e=this.store.getGeometryCopy(this.currentId);if(this.measure(t,e.coordinates[e.coordinates.length-1])<this.pointerDistance)return 1===this.currentCoordinate&&this.store.delete(this.currentPointIds),void this.close()}else this.routeId++;let s=this.routing.getClosestNetworkCoordinate(i);if(0===this.currentCoordinate){if(s){const[t,e]=this.store.create([{geometry:{type:"LineString",coordinates:[s]},properties:{mode:this.mode,isDrawnRoute:!0,routeId:this.routeId}},{geometry:{type:"Point",coordinates:s},properties:{mode:this.mode,isDrawnRoute:!0,routeId:this.routeId}}]);this.currentId=t,this.currentPointIds.push(e),this.currentCoordinate++,"started"===this.state&&this.setDrawing()}}else if(1===this.currentCoordinate&&this.currentId&&s){const t=this.store.getGeometryCopy(this.currentId),e=this.routing.getRoute(t.coordinates[0],s);if(e){this.store.updateGeometry([{id:this.currentId,geometry:null==e?void 0:e.geometry}]);const[t]=this.store.create([{geometry:{type:"Point",coordinates:s},properties:{mode:this.mode,isDrawnRoute:!0,routeId:this.routeId}}]);this.currentCoordinate=2,this.currentPointIds.push(t)}if(1===this.maxPoints)return void this.close()}else if(this.currentCoordinate>1&&this.currentId&&s&&this.currentCoordinate<=this.maxPoints){const t=this.store.getGeometryCopy(this.currentId),i=this.routing.getRoute(t.coordinates[t.coordinates.length-1],s);if(i){const r=e({},t,{coordinates:[...t.coordinates,...i.geometry.coordinates]});this.store.updateGeometry([{id:this.currentId,geometry:r}]);const[o]=this.store.create([{geometry:{type:"Point",coordinates:s},properties:{mode:this.mode,isDrawnRoute:!0,routeId:this.routeId}}]);this.maxPoints===this.currentCoordinate?this.close():(this.currentCoordinate++,this.currentPointIds.push(o))}}}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel&&this.cleanUp(),t.key===this.keyEvents.finish&&this.close()}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){try{this.currentId&&this.store.delete([this.currentId,...this.currentPointIds])}catch(t){}this.currentId=void 0,this.moveLineId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted()}styleFeature(e){const i=t.getDefaultStyling();return"Feature"===e.type&&"LineString"===e.geometry.type&&e.properties.mode===this.mode?(i.lineStringColor=this.getHexColorStylingValue(this.styles.lineStringColor,"#B90E0A",e),i.lineStringWidth=this.getNumericStylingValue(this.styles.lineStringWidth,4,e),i.zIndex=10,i):"Feature"===e.type&&"Point"===e.geometry.type&&e.properties.mode===this.mode?(i.pointColor=this.getHexColorStylingValue(this.styles.routePointColor,"#B90E0A",e),i.pointOutlineColor=this.getHexColorStylingValue(this.styles.routePointColor,"#B90E0A",e),i.pointOutlineWidth=this.getNumericStylingValue(this.styles.routePointOutlineWidth,1,e),i):i}validateFeature(t){return super.validateFeature(t)}afterFeatureAdded(t){}}new x;export{m as Routing,x as TerraDrawRouteSnapMode};
1
+ import{TerraDrawExtend as t}from"terra-draw";function e(){return e=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var s in i)({}).hasOwnProperty.call(i,s)&&(t[s]=i[s])}return t},e.apply(null,arguments)}const i=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class s{constructor(t,e=64,s=Float64Array,r){if(this.data=void 0,this.ids=void 0,this.coords=void 0,this._pos=void 0,this._finished=void 0,this.numItems=void 0,this.nodeSize=void 0,this.ArrayType=void 0,this.IndexArrayType=void 0,isNaN(t)||t<0)throw new Error(`Unexpected numItems value: ${t}.`);this.numItems=t,this.nodeSize=Math.min(Math.max(e,2),65535),this.ArrayType=s,this.IndexArrayType=t<65536?Uint16Array:Uint32Array;const o=i.indexOf(this.ArrayType),n=2*t*this.ArrayType.BYTES_PER_ELEMENT,h=t*this.IndexArrayType.BYTES_PER_ELEMENT,a=(8-h%8)%8;if(o<0)throw new Error(`Unexpected typed array class: ${s}.`);r?(this.data=r,this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+h+a,2*t),this._pos=2*t,this._finished=!0):(this.data=new ArrayBuffer(8+n+h+a),this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+h+a,2*t),this._pos=0,this._finished=!1,new Uint8Array(this.data,0,2).set([219,16+o]),new Uint16Array(this.data,2,1)[0]=this.nodeSize,new Uint32Array(this.data,4,1)[0]=this.numItems)}add(t,e){const i=this._pos>>1;return this.ids[i]=i,this.coords[this._pos++]=t,this.coords[this._pos++]=e,i}finish(){const t=this._pos>>1;if(t!==this.numItems)throw new Error(`Added ${t} items when expected ${this.numItems}.`);return r(this.ids,this.coords,this.nodeSize,0,this.numItems-1,0),this._finished=!0,this}}function r(t,e,i,s,n,h){if(n-s<=i)return;const a=s+n>>1;o(t,e,a,s,n,h),r(t,e,i,s,a-1,1-h),r(t,e,i,a+1,n,1-h)}function o(t,e,i,s,r,h){for(;r>s;){if(r-s>600){const n=r-s+1,a=i-s+1,d=Math.log(n),u=.5*Math.exp(2*d/3),c=.5*Math.sqrt(d*u*(n-u)/n)*(a-n/2<0?-1:1);o(t,e,i,Math.max(s,Math.floor(i-a*u/n+c)),Math.min(r,Math.floor(i+(n-a)*u/n+c)),h)}const a=e[2*i+h];let d=s,u=r;for(n(t,e,s,i),e[2*r+h]>a&&n(t,e,s,r);d<u;){for(n(t,e,d,u),d++,u--;e[2*d+h]<a;)d++;for(;e[2*u+h]>a;)u--}e[2*s+h]===a?n(t,e,s,u):(u++,n(t,e,u,r)),u<=i&&(s=u+1),i<=u&&(r=u-1)}}function n(t,e,i,s){h(t,i,s),h(e,2*i,2*s),h(e,2*i+1,2*s+1)}function h(t,e,i){const s=t[e];t[e]=t[i],t[i]=s}class a{constructor(t=[],e=(t,e)=>t<e?-1:t>e?1:0){if(this.data=void 0,this.length=void 0,this.compare=void 0,this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let t=(this.length>>1)-1;t>=0;t--)this._down(t)}push(t){this.data.push(t),this._up(this.length++)}pop(){if(0===this.length)return;const t=this.data[0],e=this.data.pop();return this.length--,this.length>0&&(this.data[0]=e,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:e,compare:i}=this,s=e[t];for(;t>0;){const r=t-1>>1,o=e[r];if(i(s,o)>=0)break;e[t]=o,t=r}e[t]=s}_down(t){const{data:e,compare:i}=this,s=this.length>>1,r=e[t];for(;t<s;){let s=1+(t<<1);const o=s+1;if(o<this.length&&i(e[o],e[s])<0&&(s=o),i(e[s],r)>=0)break;e[t]=e[s],t=s}e[t]=r}}const d=Math.PI/180;function u(t,e,i,s){const r=s.minLng,o=s.maxLng,n=s.minLat,h=s.maxLat;if(t>=r&&t<=o)return e<n?l((e-n)*d):e>h?l((e-h)*d):0;const a=Math.min(l((t-r)*d),l((t-o)*d)),u=function(t,e){const i=1-2*e;return i<=0?t>0?90:-90:Math.atan(Math.tan(t*d)/i)/d}(e,a);return u>n&&u<h?p(a,i,e,u):Math.min(p(a,i,e,n),p(a,i,e,h))}function c(t,e){return t.dist-e.dist}function l(t){const e=Math.sin(t/2);return e*e}function p(t,e,i,s){return e*Math.cos(s*d)*t+l((i-s)*d)}function m(t,e,i,s,r){return p(l((t-i)*d),r,e,s)}class y{constructor(t){this.useCache=!0,this.indexedNetworkPoints=void 0,this.points=[],this.routeFinder=void 0,this.network=void 0,this.routeCache={},this.useCache=t.useCache||!0,this.network=t.network,this.routeFinder=t.routeFinder,this.initialise()}initialise(){this.network.features.forEach(t=>{t.geometry.coordinates.forEach(t=>{this.points.push(t)})}),this.indexedNetworkPoints=new s(this.points.length),this.points.forEach(t=>{this.indexedNetworkPoints.add(t[0],t[1])}),this.indexedNetworkPoints.finish(),this.routeCache={}}getClosestNetworkCoordinate(t){const e=function(t,e,i,s=Infinity,r=Infinity){let o=1;const n=[];void 0===s&&(s=Infinity),void 0!==r&&(o=l(r/6371));const h=new a([],c);let p={left:0,right:t.ids.length-1,axis:0,dist:0,minLng:-180,minLat:-90,maxLng:180,maxLat:90};const y=Math.cos(i*d);for(;p;){const r=p.right,a=p.left;if(r-a<=t.nodeSize)for(let s=a;s<=r;s++){const r=t.ids[s],o=m(e,i,t.coords[2*s],t.coords[2*s+1],y);h.push({id:r,dist:o})}else{const s=a+r>>1,o=t.coords[2*s],n=t.coords[2*s+1],d=t.ids[s],c=m(e,i,o,n,y);h.push({id:d,dist:c});const l=(p.axis+1)%2,g={left:a,right:s-1,axis:l,minLng:p.minLng,minLat:p.minLat,maxLng:0===p.axis?o:p.maxLng,maxLat:1===p.axis?n:p.maxLat,dist:0},f={left:s+1,right:r,axis:l,minLng:0===p.axis?o:p.minLng,minLat:1===p.axis?n:p.minLat,maxLng:p.maxLng,maxLat:p.maxLat,dist:0};g.dist=u(e,i,y,g),f.dist=u(e,i,y,f),h.push(g),h.push(f)}for(;h.length&&null!=h.peek().id;){const t=h.pop();if(t.dist>o)return n;if(n.push(t.id),n.length===s)return n}p=h.pop()}return n}(this.indexedNetworkPoints,t[0],t[1],1);return this.points[e[0]]||null}setRouteFinder(t){this.routeFinder=t}setNetwork(t){this.network=t,this.routeFinder.setNetwork(t),this.initialise()}getRoute(t,e){if(this.useCache){const i=`${t}-${e}`;if(this.routeCache[i])return this.routeCache[i]}const i=this.routeFinder.getRoute({type:"Feature",geometry:{type:"Point",coordinates:t},properties:{}},{type:"Feature",geometry:{type:"Point",coordinates:e},properties:{}});return this.useCache?(this.routeCache[`${t}-${e}`]=i,i):i}}const g={cancel:"Escape",finish:"Enter"},f={draw:"crosshair",close:"pointer"},{TerraDrawBaseDrawMode:I}=t;class v extends I{constructor(t){super(t,!0),this.mode="routesnap",this.currentCoordinate=0,this.currentId=void 0,this.keyEvents=g,this.cursors=f,this.maxPoints=1,this.moveLineId=void 0,this.routing=void 0,this.currentPointIds=[],this.routeId=0,this.pixelDistance=(t,e)=>{const{x:i,y:s}=t,{x:r,y:o}=e,n=r-i,h=o-s;return Math.sqrt(h*h+n*n)},this.updateOptions(t)}updateOptions(t){super.updateOptions(t),null!=t&&t.routing&&t.routing!==this.routing&&(this.cleanUp(),this.routing=t.routing),void 0!==(null==t?void 0:t.maxPoints)&&t.maxPoints!==this.maxPoints&&t.maxPoints>0&&(this.maxPoints=t.maxPoints),null!=t&&t.cursors&&(this.cursors=e({},this.cursors,t.cursors)),null===(null==t?void 0:t.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=t&&t.keyEvents&&(this.keyEvents=e({},this.keyEvents,t.keyEvents))}measure(t,e){const{x:i,y:s}=this.project(e[0],e[1]);return this.pixelDistance({x:i,y:s},{x:t.containerX,y:t.containerY})}close(){this.currentId&&(this.currentCoordinate=0,this.currentId=void 0,this.currentPointIds=[],"drawing"===this.state&&this.setStarted())}registerBehaviors(t){}start(){this.setStarted(),this.setCursor(this.cursors.draw)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onMouseMove(t){if(this.setCursor(this.cursors.draw),this.moveLineId&&!this.store.has(this.moveLineId)&&(this.moveLineId=void 0),!this.currentId||0===this.currentCoordinate)return;if(this.currentId){const e=this.store.getGeometryCopy(this.currentId);if(this.measure(t,e.coordinates[e.coordinates.length-1])<this.pointerDistance)return this.setCursor(this.cursors.close),void(this.moveLineId&&(this.store.delete([this.moveLineId]),this.moveLineId=void 0))}const e=this.store.getGeometryCopy(this.currentId);let i=this.routing.getClosestNetworkCoordinate([t.lng,t.lat]);if(!i)return;const s=this.routing.getRoute(e.coordinates[e.coordinates.length-1],i);if(s)if(this.moveLineId)this.store.updateGeometry([{id:this.moveLineId,geometry:s.geometry}]);else{const[t]=this.store.create([{geometry:s.geometry,properties:{mode:this.mode,isDrawnRoute:!0,routeId:this.routeId}}]);this.moveLineId=t}}onClick(t){if("right"===t.button)return;const i=[t.lng,t.lat];if(this.currentId&&!this.store.has(this.currentId)&&(this.currentId=void 0,this.currentCoordinate=0,this.currentPointIds=[]),this.currentId){const e=this.store.getGeometryCopy(this.currentId);if(this.measure(t,e.coordinates[e.coordinates.length-1])<this.pointerDistance)return 1===this.currentCoordinate&&this.store.delete(this.currentPointIds),void this.close()}else this.routeId++;let s=this.routing.getClosestNetworkCoordinate(i);if(0===this.currentCoordinate){if(s){const[t,e]=this.store.create([{geometry:{type:"LineString",coordinates:[s]},properties:{mode:this.mode,isDrawnRoute:!0,routeId:this.routeId}},{geometry:{type:"Point",coordinates:s},properties:{mode:this.mode,isDrawnRoute:!0,routeId:this.routeId}}]);this.currentId=t,this.currentPointIds.push(e),this.currentCoordinate++,"started"===this.state&&this.setDrawing()}}else if(1===this.currentCoordinate&&this.currentId&&s){const t=this.store.getGeometryCopy(this.currentId),e=this.routing.getRoute(t.coordinates[0],s);if(e){this.store.updateGeometry([{id:this.currentId,geometry:null==e?void 0:e.geometry}]);const[t]=this.store.create([{geometry:{type:"Point",coordinates:s},properties:{mode:this.mode,isDrawnRoute:!0,routeId:this.routeId}}]);this.currentCoordinate=2,this.currentPointIds.push(t)}if(1===this.maxPoints)return void this.close()}else if(this.currentCoordinate>1&&this.currentId&&s&&this.currentCoordinate<=this.maxPoints){const t=this.store.getGeometryCopy(this.currentId),i=this.routing.getRoute(t.coordinates[t.coordinates.length-1],s);if(i){const r=e({},t,{coordinates:[...t.coordinates,...i.geometry.coordinates]});this.store.updateGeometry([{id:this.currentId,geometry:r}]);const[o]=this.store.create([{geometry:{type:"Point",coordinates:s},properties:{mode:this.mode,isDrawnRoute:!0,routeId:this.routeId}}]);this.maxPoints===this.currentCoordinate?this.close():(this.currentCoordinate++,this.currentPointIds.push(o))}}}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel&&this.cleanUp(),t.key===this.keyEvents.finish&&this.close()}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){try{this.currentId&&this.store.delete([this.currentId,...this.currentPointIds])}catch(t){}this.currentId=void 0,this.moveLineId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted()}styleFeature(e){const i=t.getDefaultStyling();return"Feature"===e.type&&"LineString"===e.geometry.type&&e.properties.mode===this.mode?(i.lineStringColor=this.getHexColorStylingValue(this.styles.lineStringColor,"#B90E0A",e),i.lineStringWidth=this.getNumericStylingValue(this.styles.lineStringWidth,4,e),i.zIndex=10,i):"Feature"===e.type&&"Point"===e.geometry.type&&e.properties.mode===this.mode?(i.pointColor=this.getHexColorStylingValue(this.styles.routePointColor,"#B90E0A",e),i.pointOutlineColor=this.getHexColorStylingValue(this.styles.routePointColor,"#B90E0A",e),i.pointOutlineWidth=this.getNumericStylingValue(this.styles.routePointOutlineWidth,1,e),i):i}validateFeature(t){return super.validateFeature(t)}afterFeatureAdded(t){}}export{y as Routing,v as TerraDrawRouteSnapMode};
2
2
  //# sourceMappingURL=terra-draw-route-snap-mode.modern.js.map