@inlog/inlog-maps 5.0.6 → 6.1.0

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 (243) hide show
  1. package/DOCUMENTATION.md +19 -2
  2. package/_bundles/inlog-maps.js +2 -7239
  3. package/_bundles/inlog-maps.js.LICENSE.txt +20 -0
  4. package/_bundles/inlog-maps.js.map +1 -1
  5. package/_bundles/inlog-maps.min.js +2 -1
  6. package/_bundles/inlog-maps.min.js.LICENSE.txt +20 -0
  7. package/_bundles/inlog-maps.min.js.map +1 -1
  8. package/lib/index.js +46 -46
  9. package/lib/index.js.map +1 -1
  10. package/lib/map.js +1136 -1010
  11. package/lib/map.js.map +1 -1
  12. package/lib/models/apis/google/google-circles.js +133 -130
  13. package/lib/models/apis/google/google-circles.js.map +1 -1
  14. package/lib/models/apis/google/google-geojson.js +72 -71
  15. package/lib/models/apis/google/google-geojson.js.map +1 -1
  16. package/lib/models/apis/google/google-map.js +173 -90
  17. package/lib/models/apis/google/google-map.js.map +1 -1
  18. package/lib/models/apis/google/google-markers.js +324 -290
  19. package/lib/models/apis/google/google-markers.js.map +1 -1
  20. package/lib/models/apis/google/google-overlay.js +101 -96
  21. package/lib/models/apis/google/google-overlay.js.map +1 -1
  22. package/lib/models/apis/google/google-polygons.js +300 -227
  23. package/lib/models/apis/google/google-polygons.js.map +1 -1
  24. package/lib/models/apis/google/google-polylines.js +706 -596
  25. package/lib/models/apis/google/google-polylines.js.map +1 -1
  26. package/lib/models/apis/google/google-popup.js +58 -60
  27. package/lib/models/apis/google/google-popup.js.map +1 -1
  28. package/lib/models/apis/googleMaps.js +448 -354
  29. package/lib/models/apis/googleMaps.js.map +1 -1
  30. package/lib/models/apis/leaflet/leaflet-circle.js +162 -134
  31. package/lib/models/apis/leaflet/leaflet-circle.js.map +1 -1
  32. package/lib/models/apis/leaflet/leaflet-geojson.js +72 -68
  33. package/lib/models/apis/leaflet/leaflet-geojson.js.map +1 -1
  34. package/lib/models/apis/leaflet/leaflet-map.js +139 -85
  35. package/lib/models/apis/leaflet/leaflet-map.js.map +1 -1
  36. package/lib/models/apis/leaflet/leaflet-markers.js +293 -259
  37. package/lib/models/apis/leaflet/leaflet-markers.js.map +1 -1
  38. package/lib/models/apis/leaflet/leaflet-overlay.js +34 -36
  39. package/lib/models/apis/leaflet/leaflet-overlay.js.map +1 -1
  40. package/lib/models/apis/leaflet/leaflet-polygons.js +210 -212
  41. package/lib/models/apis/leaflet/leaflet-polygons.js.map +1 -1
  42. package/lib/models/apis/leaflet/leaflet-polylines.js +705 -590
  43. package/lib/models/apis/leaflet/leaflet-polylines.js.map +1 -1
  44. package/lib/models/apis/leaflet/leaflet-popup.js +73 -75
  45. package/lib/models/apis/leaflet/leaflet-popup.js.map +1 -1
  46. package/lib/models/apis/leaflet.js +463 -360
  47. package/lib/models/apis/leaflet.js.map +1 -1
  48. package/lib/models/apis/mapFunctions.js +1 -2
  49. package/lib/models/dto/event-type.js +38 -40
  50. package/lib/models/dto/event-type.js.map +1 -1
  51. package/lib/models/dto/map-type.js +5 -7
  52. package/lib/models/dto/map-type.js.map +1 -1
  53. package/lib/models/dto/polyline-type.js +6 -8
  54. package/lib/models/dto/polyline-type.js.map +1 -1
  55. package/lib/models/features/circle/circle-alter-options.js +13 -15
  56. package/lib/models/features/circle/circle-alter-options.js.map +1 -1
  57. package/lib/models/features/circle/circle-options.js +18 -20
  58. package/lib/models/features/circle/circle-options.js.map +1 -1
  59. package/lib/models/features/events/event-return.js +7 -9
  60. package/lib/models/features/events/event-return.js.map +1 -1
  61. package/lib/models/features/geojson/geojson-options.js +8 -10
  62. package/lib/models/features/geojson/geojson-options.js.map +1 -1
  63. package/lib/models/features/marker/circle-marker-options.js +11 -13
  64. package/lib/models/features/marker/circle-marker-options.js.map +1 -1
  65. package/lib/models/features/marker/circle-marker-style.js +11 -13
  66. package/lib/models/features/marker/circle-marker-style.js.map +1 -1
  67. package/lib/models/features/marker/marker-alter-options.js +9 -11
  68. package/lib/models/features/marker/marker-alter-options.js.map +1 -1
  69. package/lib/models/features/marker/marker-icon.js +9 -11
  70. package/lib/models/features/marker/marker-icon.js.map +1 -1
  71. package/lib/models/features/marker/marker-options.js +17 -19
  72. package/lib/models/features/marker/marker-options.js.map +1 -1
  73. package/lib/models/features/marker-clusterer/marker-clusterer-config.js +9 -11
  74. package/lib/models/features/marker-clusterer/marker-clusterer-config.js.map +1 -1
  75. package/lib/models/features/overlay/overlay-options.js +14 -16
  76. package/lib/models/features/overlay/overlay-options.js.map +1 -1
  77. package/lib/models/features/polygons/polygon-alter-options.js +13 -14
  78. package/lib/models/features/polygons/polygon-alter-options.js.map +1 -1
  79. package/lib/models/features/polygons/polygon-options.js +18 -19
  80. package/lib/models/features/polygons/polygon-options.js.map +1 -1
  81. package/lib/models/features/polyline/navigations-options.js +15 -15
  82. package/lib/models/features/polyline/navigations-options.js.map +1 -1
  83. package/lib/models/features/polyline/polyline-options.js +19 -21
  84. package/lib/models/features/polyline/polyline-options.js.map +1 -1
  85. package/lib/models/features/popup/popup-options.js +12 -14
  86. package/lib/models/features/popup/popup-options.js.map +1 -1
  87. package/lib/utils/maps-api-loader.service.js +88 -77
  88. package/lib/utils/maps-api-loader.service.js.map +1 -1
  89. package/lib/utils/url-builder.js +43 -45
  90. package/lib/utils/url-builder.js.map +1 -1
  91. package/lib-esm/index.js +46 -45
  92. package/lib-esm/index.js.map +1 -1
  93. package/lib-esm/map.js +1136 -1008
  94. package/lib-esm/map.js.map +1 -1
  95. package/lib-esm/models/apis/google/google-circles.js +133 -128
  96. package/lib-esm/models/apis/google/google-circles.js.map +1 -1
  97. package/lib-esm/models/apis/google/google-geojson.js +72 -69
  98. package/lib-esm/models/apis/google/google-geojson.js.map +1 -1
  99. package/lib-esm/models/apis/google/google-map.js +173 -88
  100. package/lib-esm/models/apis/google/google-map.js.map +1 -1
  101. package/lib-esm/models/apis/google/google-markers.js +324 -288
  102. package/lib-esm/models/apis/google/google-markers.js.map +1 -1
  103. package/lib-esm/models/apis/google/google-overlay.js +101 -94
  104. package/lib-esm/models/apis/google/google-overlay.js.map +1 -1
  105. package/lib-esm/models/apis/google/google-polygons.js +300 -225
  106. package/lib-esm/models/apis/google/google-polygons.js.map +1 -1
  107. package/lib-esm/models/apis/google/google-polylines.js +706 -594
  108. package/lib-esm/models/apis/google/google-polylines.js.map +1 -1
  109. package/lib-esm/models/apis/google/google-popup.js +58 -58
  110. package/lib-esm/models/apis/google/google-popup.js.map +1 -1
  111. package/lib-esm/models/apis/googleMaps.js +448 -352
  112. package/lib-esm/models/apis/googleMaps.js.map +1 -1
  113. package/lib-esm/models/apis/leaflet/leaflet-circle.js +162 -132
  114. package/lib-esm/models/apis/leaflet/leaflet-circle.js.map +1 -1
  115. package/lib-esm/models/apis/leaflet/leaflet-geojson.js +72 -66
  116. package/lib-esm/models/apis/leaflet/leaflet-geojson.js.map +1 -1
  117. package/lib-esm/models/apis/leaflet/leaflet-map.js +139 -83
  118. package/lib-esm/models/apis/leaflet/leaflet-map.js.map +1 -1
  119. package/lib-esm/models/apis/leaflet/leaflet-markers.js +293 -257
  120. package/lib-esm/models/apis/leaflet/leaflet-markers.js.map +1 -1
  121. package/lib-esm/models/apis/leaflet/leaflet-overlay.js +34 -34
  122. package/lib-esm/models/apis/leaflet/leaflet-overlay.js.map +1 -1
  123. package/lib-esm/models/apis/leaflet/leaflet-polygons.js +210 -210
  124. package/lib-esm/models/apis/leaflet/leaflet-polygons.js.map +1 -1
  125. package/lib-esm/models/apis/leaflet/leaflet-polylines.js +705 -588
  126. package/lib-esm/models/apis/leaflet/leaflet-polylines.js.map +1 -1
  127. package/lib-esm/models/apis/leaflet/leaflet-popup.js +73 -73
  128. package/lib-esm/models/apis/leaflet/leaflet-popup.js.map +1 -1
  129. package/lib-esm/models/apis/leaflet.js +463 -358
  130. package/lib-esm/models/apis/leaflet.js.map +1 -1
  131. package/lib-esm/models/apis/mapFunctions.js +1 -0
  132. package/lib-esm/models/dto/event-type.js +38 -38
  133. package/lib-esm/models/dto/map-type.js +5 -5
  134. package/lib-esm/models/dto/polyline-type.js +6 -6
  135. package/lib-esm/models/features/circle/circle-alter-options.js +13 -13
  136. package/lib-esm/models/features/circle/circle-options.js +18 -18
  137. package/lib-esm/models/features/events/event-return.js +7 -7
  138. package/lib-esm/models/features/geojson/geojson-options.js +8 -8
  139. package/lib-esm/models/features/marker/circle-marker-options.js +11 -11
  140. package/lib-esm/models/features/marker/circle-marker-style.js +11 -11
  141. package/lib-esm/models/features/marker/marker-alter-options.js +9 -9
  142. package/lib-esm/models/features/marker/marker-icon.js +9 -9
  143. package/lib-esm/models/features/marker/marker-options.js +17 -17
  144. package/lib-esm/models/features/marker-clusterer/marker-clusterer-config.js +9 -9
  145. package/lib-esm/models/features/overlay/overlay-options.js +14 -14
  146. package/lib-esm/models/features/polygons/polygon-alter-options.js +13 -12
  147. package/lib-esm/models/features/polygons/polygon-alter-options.js.map +1 -1
  148. package/lib-esm/models/features/polygons/polygon-options.js +18 -17
  149. package/lib-esm/models/features/polygons/polygon-options.js.map +1 -1
  150. package/lib-esm/models/features/polyline/navigations-options.js +15 -13
  151. package/lib-esm/models/features/polyline/navigations-options.js.map +1 -1
  152. package/lib-esm/models/features/polyline/polyline-options.js +19 -19
  153. package/lib-esm/models/features/polyline/polyline-options.js.map +1 -1
  154. package/lib-esm/models/features/popup/popup-options.js +12 -12
  155. package/lib-esm/utils/maps-api-loader.service.js +88 -75
  156. package/lib-esm/utils/maps-api-loader.service.js.map +1 -1
  157. package/lib-esm/utils/url-builder.js +43 -43
  158. package/lib-esm/utils/url-builder.js.map +1 -1
  159. package/package.json +67 -63
  160. package/lib/index.d.ts +0 -46
  161. package/lib/map.d.ts +0 -513
  162. package/lib/models/apis/google/google-circles.d.ts +0 -18
  163. package/lib/models/apis/google/google-geojson.d.ts +0 -9
  164. package/lib/models/apis/google/google-map.d.ts +0 -15
  165. package/lib/models/apis/google/google-markers.d.ts +0 -29
  166. package/lib/models/apis/google/google-overlay.d.ts +0 -11
  167. package/lib/models/apis/google/google-polygons.d.ts +0 -29
  168. package/lib/models/apis/google/google-polylines.d.ts +0 -55
  169. package/lib/models/apis/google/google-popup.d.ts +0 -10
  170. package/lib/models/apis/googleMaps.d.ts +0 -95
  171. package/lib/models/apis/leaflet/leaflet-circle.d.ts +0 -18
  172. package/lib/models/apis/leaflet/leaflet-geojson.d.ts +0 -9
  173. package/lib/models/apis/leaflet/leaflet-map.d.ts +0 -15
  174. package/lib/models/apis/leaflet/leaflet-markers.d.ts +0 -29
  175. package/lib/models/apis/leaflet/leaflet-overlay.d.ts +0 -10
  176. package/lib/models/apis/leaflet/leaflet-polygons.d.ts +0 -23
  177. package/lib/models/apis/leaflet/leaflet-polylines.d.ts +0 -54
  178. package/lib/models/apis/leaflet/leaflet-popup.d.ts +0 -11
  179. package/lib/models/apis/leaflet.d.ts +0 -97
  180. package/lib/models/apis/mapFunctions.d.ts +0 -84
  181. package/lib/models/dto/event-type.d.ts +0 -33
  182. package/lib/models/dto/map-type.d.ts +0 -4
  183. package/lib/models/dto/polyline-type.d.ts +0 -5
  184. package/lib/models/features/circle/circle-alter-options.d.ts +0 -12
  185. package/lib/models/features/circle/circle-options.d.ts +0 -15
  186. package/lib/models/features/events/event-return.d.ts +0 -4
  187. package/lib/models/features/geojson/geojson-options.d.ts +0 -5
  188. package/lib/models/features/marker/circle-marker-options.d.ts +0 -9
  189. package/lib/models/features/marker/circle-marker-style.d.ts +0 -8
  190. package/lib/models/features/marker/marker-alter-options.d.ts +0 -8
  191. package/lib/models/features/marker/marker-icon.d.ts +0 -6
  192. package/lib/models/features/marker/marker-options.d.ts +0 -11
  193. package/lib/models/features/marker-clusterer/marker-clusterer-config.d.ts +0 -6
  194. package/lib/models/features/overlay/overlay-options.d.ts +0 -11
  195. package/lib/models/features/polygons/polygon-alter-options.d.ts +0 -13
  196. package/lib/models/features/polygons/polygon-options.d.ts +0 -15
  197. package/lib/models/features/polyline/navigations-options.d.ts +0 -11
  198. package/lib/models/features/polyline/polyline-options.d.ts +0 -18
  199. package/lib/models/features/popup/popup-options.d.ts +0 -9
  200. package/lib/utils/maps-api-loader.service.d.ts +0 -9
  201. package/lib/utils/url-builder.d.ts +0 -11
  202. package/lib-esm/index.d.ts +0 -46
  203. package/lib-esm/map.d.ts +0 -513
  204. package/lib-esm/models/apis/google/google-circles.d.ts +0 -18
  205. package/lib-esm/models/apis/google/google-geojson.d.ts +0 -9
  206. package/lib-esm/models/apis/google/google-map.d.ts +0 -15
  207. package/lib-esm/models/apis/google/google-markers.d.ts +0 -29
  208. package/lib-esm/models/apis/google/google-overlay.d.ts +0 -11
  209. package/lib-esm/models/apis/google/google-polygons.d.ts +0 -29
  210. package/lib-esm/models/apis/google/google-polylines.d.ts +0 -55
  211. package/lib-esm/models/apis/google/google-popup.d.ts +0 -10
  212. package/lib-esm/models/apis/googleMaps.d.ts +0 -95
  213. package/lib-esm/models/apis/leaflet/leaflet-circle.d.ts +0 -18
  214. package/lib-esm/models/apis/leaflet/leaflet-geojson.d.ts +0 -9
  215. package/lib-esm/models/apis/leaflet/leaflet-map.d.ts +0 -15
  216. package/lib-esm/models/apis/leaflet/leaflet-markers.d.ts +0 -29
  217. package/lib-esm/models/apis/leaflet/leaflet-overlay.d.ts +0 -10
  218. package/lib-esm/models/apis/leaflet/leaflet-polygons.d.ts +0 -23
  219. package/lib-esm/models/apis/leaflet/leaflet-polylines.d.ts +0 -54
  220. package/lib-esm/models/apis/leaflet/leaflet-popup.d.ts +0 -11
  221. package/lib-esm/models/apis/leaflet.d.ts +0 -97
  222. package/lib-esm/models/apis/mapFunctions.d.ts +0 -84
  223. package/lib-esm/models/dto/event-type.d.ts +0 -33
  224. package/lib-esm/models/dto/map-type.d.ts +0 -4
  225. package/lib-esm/models/dto/polyline-type.d.ts +0 -5
  226. package/lib-esm/models/features/circle/circle-alter-options.d.ts +0 -12
  227. package/lib-esm/models/features/circle/circle-options.d.ts +0 -15
  228. package/lib-esm/models/features/events/event-return.d.ts +0 -4
  229. package/lib-esm/models/features/geojson/geojson-options.d.ts +0 -5
  230. package/lib-esm/models/features/marker/circle-marker-options.d.ts +0 -9
  231. package/lib-esm/models/features/marker/circle-marker-style.d.ts +0 -8
  232. package/lib-esm/models/features/marker/marker-alter-options.d.ts +0 -8
  233. package/lib-esm/models/features/marker/marker-icon.d.ts +0 -6
  234. package/lib-esm/models/features/marker/marker-options.d.ts +0 -11
  235. package/lib-esm/models/features/marker-clusterer/marker-clusterer-config.d.ts +0 -6
  236. package/lib-esm/models/features/overlay/overlay-options.d.ts +0 -11
  237. package/lib-esm/models/features/polygons/polygon-alter-options.d.ts +0 -13
  238. package/lib-esm/models/features/polygons/polygon-options.d.ts +0 -15
  239. package/lib-esm/models/features/polyline/navigations-options.d.ts +0 -11
  240. package/lib-esm/models/features/polyline/polyline-options.d.ts +0 -18
  241. package/lib-esm/models/features/popup/popup-options.d.ts +0 -9
  242. package/lib-esm/utils/maps-api-loader.service.d.ts +0 -9
  243. package/lib-esm/utils/url-builder.d.ts +0 -11
@@ -1,589 +1,706 @@
1
- import { PolylineEventType } from '../../dto/event-type';
2
- import { PolylineType } from '../../dto/polyline-type';
3
- import EventReturn from '../../features/events/event-return';
4
- var LeafletPolylines = /** @class */ (function () {
5
- function LeafletPolylines(map, leaflet, leafletPopup) {
6
- this.map = null;
7
- this.leaflet = null;
8
- this.selectedPolyline = null;
9
- this.selectedPath = null;
10
- this.navigateInfoWindow = null;
11
- this.directionForward = false;
12
- this.multiSelectionForward = false;
13
- this.multiSelection = false;
14
- this.map = map;
15
- this.leaflet = leaflet;
16
- this.leafletPopup = leafletPopup;
17
- }
18
- LeafletPolylines.prototype.drawPolyline = function (options, eventClick) {
19
- var self = this;
20
- var newOptions = {
21
- color: options.color || '#000000',
22
- dashArray: null,
23
- draggable: options.draggable,
24
- editable: options.editable,
25
- infowindows: options.infowindows,
26
- opacity: options.opacity || 1,
27
- weight: options.weight || 3,
28
- zIndex: options.zIndex
29
- };
30
- if (options.style !== null) {
31
- switch (options.style) {
32
- case PolylineType.Dotted:
33
- console.warn('PolylineType.Dotted is deprecated, instead use PolylineType.Dashed.');
34
- case PolylineType.Dashed:
35
- newOptions.opacity = .7;
36
- newOptions.dashArray = '20,15';
37
- break;
38
- default:
39
- break;
40
- }
41
- }
42
- var polyline = new this.leaflet.Polyline(options.path || [], newOptions);
43
- polyline.on('editable:vertex:rawclick', function (e) { return e.cancel(); });
44
- if (eventClick) {
45
- polyline.on('click', function (event) {
46
- self.leaflet.DomEvent.stopPropagation(event);
47
- var param = new EventReturn([event.latlng.lat, event.latlng.lng]);
48
- eventClick(param, event.target.object);
49
- });
50
- polyline.on('editable:vertex:rawclick', function (event) {
51
- event.cancel();
52
- var param = new EventReturn([event.latlng.lat, event.latlng.lng]);
53
- eventClick(param, event.target.object);
54
- });
55
- }
56
- if (options.style && options.style === PolylineType.Arrow) {
57
- var pathOptions = { fillOpacity: 1, weight: 0, color: polyline.options.color };
58
- polyline.decorator = self.leaflet.polylineDecorator(polyline, {
59
- patterns: [{
60
- offset: '20%',
61
- repeat: '90px',
62
- symbol: self.leaflet.Symbol.arrowHead({ pixelSize: 20, pathOptions: pathOptions })
63
- },
64
- { offset: '0%', symbol: self.leaflet.Symbol.arrowHead({ pathOptions: pathOptions, pixelSize: 20 }) },
65
- { offset: '100%', symbol: self.leaflet.Symbol.arrowHead({ pixelSize: 20, pathOptions: pathOptions }) }]
66
- });
67
- }
68
- if (options.addToMap) {
69
- polyline.addTo(self.map);
70
- if (polyline.decorator) {
71
- polyline.decorator.addTo(self.map);
72
- }
73
- if (options.editable) {
74
- polyline.enableEdit();
75
- }
76
- }
77
- if (options.object) {
78
- polyline.object = options.object;
79
- }
80
- if (options.fitBounds) {
81
- self.map.fitBounds(polyline.getBounds());
82
- }
83
- return polyline;
84
- };
85
- LeafletPolylines.prototype.drawPolylineWithNavigation = function (options, eventClick) {
86
- var polyline = this.drawPolyline(options, null);
87
- polyline.navigationHandlerClick = eventClick;
88
- this.navigationOptions = options.navigateOptions;
89
- this.navigateByPoint = this.navigationOptions ? this.navigationOptions.navigateByPoint : true;
90
- this.addNavigation(polyline);
91
- return polyline;
92
- };
93
- LeafletPolylines.prototype.togglePolylines = function (polylines, show) {
94
- var self = this;
95
- polylines.forEach(function (polyline) {
96
- if (show) {
97
- self.map.addLayer(polyline);
98
- if (polyline.options.editable) {
99
- polyline.enableEdit();
100
- }
101
- if (polyline.decorator) {
102
- self.map.addLayer(polyline.decorator);
103
- }
104
- }
105
- else {
106
- self.map.removeLayer(polyline);
107
- if (polyline.options.editable) {
108
- polyline.disableEdit();
109
- }
110
- if (polyline.decorator) {
111
- self.map.removeLayer(polyline.decorator);
112
- }
113
- }
114
- });
115
- };
116
- LeafletPolylines.prototype.alterPolylineOptions = function (polylines, options) {
117
- var self = this;
118
- polylines.forEach(function (polyline) {
119
- var style = {
120
- color: options.color ? options.color : polyline.options.color,
121
- draggable: options.draggable ? options.draggable : polyline.options.draggable,
122
- opacity: options.opacity ? options.opacity : polyline.options.opacity,
123
- weight: options.weight ? options.weight : polyline.options.weight,
124
- zIndex: options.zIndex ? options.zIndex : polyline.options.zIndex
125
- };
126
- if (options.path) {
127
- polyline.setLatLngs(options.path);
128
- }
129
- switch (options.style) {
130
- case PolylineType.Dotted:
131
- console.warn('PolylineType.Dotted is deprecated, instead use PolylineType.Dashed.');
132
- case PolylineType.Dashed:
133
- style.dashArray = '20,15';
134
- break;
135
- case PolylineType.Arrow:
136
- var pathOptions = { fillOpacity: 1, weight: 0, color: style.color };
137
- if (polyline.decorator) {
138
- self.map.removeLayer(polyline.decorator);
139
- }
140
- polyline.decorator = self.leaflet.polylineDecorator(polyline, {
141
- patterns: [{
142
- offset: '20%',
143
- repeat: '90px',
144
- symbol: self.leaflet.Symbol.arrowHead({ pixelSize: 20, pathOptions: pathOptions })
145
- },
146
- { offset: '0%', symbol: self.leaflet.Symbol.arrowHead({ pixelSize: 20, pathOptions: pathOptions }) },
147
- { offset: '100%', symbol: self.leaflet.Symbol.arrowHead({ pixelSize: 20, pathOptions: pathOptions }) }]
148
- });
149
- if (self.map.hasLayer(polyline)) {
150
- polyline.decorator.addTo(self.map);
151
- }
152
- break;
153
- default:
154
- if (polyline.decorator) {
155
- self.map.removeLayer(polyline.decorator);
156
- polyline.decorator = null;
157
- }
158
- break;
159
- }
160
- polyline.setStyle(style);
161
- if (options.object) {
162
- polyline.object = options.object;
163
- }
164
- if (options.editable) {
165
- polyline.disableEdit();
166
- polyline.enableEdit();
167
- }
168
- });
169
- };
170
- LeafletPolylines.prototype.fitBoundsPolylines = function (polylines) {
171
- var self = this;
172
- self.map.fitBounds(self.getBoundsPolylines(polylines));
173
- };
174
- LeafletPolylines.prototype.isPolylineOnMap = function (polyline) {
175
- return this.map.hasLayer(polyline);
176
- };
177
- LeafletPolylines.prototype.addPolylinePath = function (polylines, position) {
178
- var _this = this;
179
- polylines.forEach(function (polyline) {
180
- var path = polyline.getLatLngs();
181
- path.push(new _this.leaflet.LatLng(position[0], position[1]));
182
- polyline.setLatLngs(path);
183
- if (polyline.editEnabled && polyline.editEnabled()) {
184
- polyline.disableEdit();
185
- polyline.enableEdit();
186
- }
187
- });
188
- };
189
- LeafletPolylines.prototype.getPolylinePath = function (polyline) {
190
- return polyline.getLatLngs().map(function (x) { return [x.lat, x.lng]; });
191
- };
192
- LeafletPolylines.prototype.removePolylineHighlight = function () {
193
- var self = this;
194
- if (self.selectedPath) {
195
- if (this.selectedPath.decorator) {
196
- this.map.removeLayer(this.selectedPath.decorator);
197
- }
198
- this.map.removeLayer(self.selectedPath);
199
- self.selectedPath = null;
200
- }
201
- if (self.navigateInfoWindow) {
202
- self.navigateInfoWindow.remove();
203
- }
204
- document.onkeyup = null;
205
- document.onkeydown = null;
206
- };
207
- LeafletPolylines.prototype.addPolylineEvent = function (polylines, eventType, eventFunction) {
208
- var _this = this;
209
- polylines.forEach(function (polyline) {
210
- switch (eventType) {
211
- case PolylineEventType.SetAt:
212
- _this.addPolylineEventMove(polyline, eventFunction);
213
- break;
214
- case PolylineEventType.RightClick:
215
- _this.addPolylineEventRightClick(polyline, eventFunction);
216
- break;
217
- case PolylineEventType.InsertAt:
218
- _this.addPolylineEventInsertAt(polyline, eventFunction);
219
- break;
220
- case PolylineEventType.RemoveAt:
221
- _this.addPolylineEventRemoveAt(polyline, eventFunction);
222
- break;
223
- case PolylineEventType.MouseOver:
224
- _this.addPolylineEventMouseOver(polyline, eventFunction);
225
- break;
226
- case PolylineEventType.MouseOut:
227
- _this.addPolylineEventMouseOut(polyline, eventFunction);
228
- break;
229
- case PolylineEventType.DragPolyline:
230
- _this.addPolylineEventDragPolyline(polyline, eventFunction);
231
- break;
232
- default:
233
- break;
234
- }
235
- });
236
- };
237
- LeafletPolylines.prototype.removePolylineEvent = function (polylines, event) {
238
- polylines.forEach(function (polyline) {
239
- switch (event) {
240
- case PolylineEventType.SetAt:
241
- polyline.off('editable:vertex:dragstart');
242
- break;
243
- case PolylineEventType.RightClick:
244
- polyline.off('contextmenu');
245
- polyline.off('editable:vertex:contextmenu');
246
- break;
247
- case PolylineEventType.InsertAt:
248
- polyline.off('editable:vertex:new');
249
- break;
250
- case PolylineEventType.RemoveAt:
251
- polyline.off('editable:vertex:deleted');
252
- break;
253
- case PolylineEventType.DragPolyline:
254
- polyline.off('dragend');
255
- break;
256
- case PolylineEventType.MouseOver:
257
- polyline.off('mouseover');
258
- break;
259
- case PolylineEventType.MouseOut:
260
- polyline.off('mouseout');
261
- break;
262
- default:
263
- break;
264
- }
265
- });
266
- };
267
- LeafletPolylines.prototype.setIndexPolylineHighlight = function (polyline, index) {
268
- this.directionForward = false;
269
- polyline.initialIdx = index;
270
- polyline.finalIdx = index + 1;
271
- this.moveSelectedPath(polyline, this.navigationOptions);
272
- this.selectedPolyline = polyline;
273
- if (this.navigationOptions.navegateOnKeyPress) {
274
- document.onkeydown = this.onKeyUp.bind(this);
275
- }
276
- else {
277
- document.onkeyup = this.onKeyUp.bind(this);
278
- }
279
- };
280
- LeafletPolylines.prototype.getObjectPolyline = function (polyline) {
281
- return polyline.object;
282
- };
283
- LeafletPolylines.prototype.getObjectPolylineHighlight = function () {
284
- if (this.selectedPath) {
285
- return this.selectedPath.object;
286
- }
287
- return null;
288
- };
289
- LeafletPolylines.prototype.addPolylineHighlightEvent = function (eventType, eventFunction) {
290
- if (this.selectedPolyline) {
291
- this.addPolylineEvent([this.selectedPath], eventType, eventFunction);
292
- }
293
- };
294
- LeafletPolylines.prototype.getPolylineHighlightIndex = function () {
295
- if (this.selectedPath) {
296
- return [this.selectedPath.initialIdx, this.selectedPath.finalIdx];
297
- }
298
- return null;
299
- };
300
- /* Private methods */
301
- LeafletPolylines.prototype.addNavigation = function (polyline) {
302
- polyline.clearAllEventListeners();
303
- polyline.on('click', this.onClickPolyline.bind(this, polyline));
304
- };
305
- LeafletPolylines.prototype.onClickPolyline = function (polyline, event) {
306
- var index = this.checkIdx(polyline, event.latlng);
307
- polyline.initialIdx = index;
308
- polyline.finalIdx = index + 1;
309
- this.moveSelectedPath(polyline, this.navigationOptions);
310
- this.selectedPolyline = polyline;
311
- if (this.navigationOptions.navegateOnKeyPress) {
312
- document.onkeydown = this.onKeyUp.bind(this);
313
- }
314
- else {
315
- document.onkeyup = this.onKeyUp.bind(this);
316
- }
317
- if (polyline.navigationHandlerClick) {
318
- var param = new EventReturn([event.latlng.lat, event.latlng.lng]);
319
- polyline.navigationHandlerClick(param, event.target.object);
320
- }
321
- };
322
- LeafletPolylines.prototype.onKeyUp = function (event) {
323
- var self = this;
324
- if (self.selectedPath) {
325
- if (event.ctrlKey) {
326
- console.warn('Deprecated: CTRL is not needed in navigation anymore');
327
- }
328
- switch (event.which ? event.which : event.keyCode) {
329
- case 38:
330
- case 39:
331
- // up arrow or right arrow
332
- self.moveFowards(event.shiftKey);
333
- break;
334
- case 37:
335
- case 40:
336
- // left arrow or down arrow
337
- self.moveBackwards(event.shiftKey);
338
- break;
339
- }
340
- }
341
- };
342
- LeafletPolylines.prototype.moveFowards = function (multiselection) {
343
- var polyline = this.selectedPolyline;
344
- if ((!this.navigateByPoint || this.directionForward) && polyline.finalIdx < polyline.getLatLngs().length - 1) {
345
- this.navigateFoward(multiselection, polyline);
346
- }
347
- this.directionForward = true;
348
- this.moveSelectedPath(polyline, null);
349
- };
350
- LeafletPolylines.prototype.navigateFoward = function (multiSelection, polyline) {
351
- if (!multiSelection) {
352
- polyline.finalIdx++;
353
- polyline.initialIdx = this.multiSelection ? polyline.finalIdx - 1 : polyline.initialIdx + 1;
354
- this.multiSelection = false;
355
- }
356
- else {
357
- this.multiSelection = true;
358
- if (this.multiSelectionForward) {
359
- polyline.finalIdx++;
360
- }
361
- this.multiSelectionForward = true;
362
- }
363
- };
364
- LeafletPolylines.prototype.moveBackwards = function (multiSelection) {
365
- var polyline = this.selectedPolyline;
366
- if ((!this.navigateByPoint || !this.directionForward) && polyline.initialIdx > 0) {
367
- this.navigateBackward(multiSelection, polyline);
368
- }
369
- this.directionForward = false;
370
- this.moveSelectedPath(polyline, null);
371
- };
372
- LeafletPolylines.prototype.navigateBackward = function (multiSelection, polyline) {
373
- var self = this;
374
- if (!multiSelection) {
375
- polyline.initialIdx--;
376
- polyline.finalIdx = !self.multiSelection ? polyline.finalIdx - 1 : polyline.initialIdx + 1;
377
- self.multiSelection = false;
378
- }
379
- else {
380
- self.multiSelection = true;
381
- if (!self.multiSelectionForward) {
382
- polyline.initialIdx--;
383
- }
384
- self.multiSelectionForward = false;
385
- }
386
- };
387
- LeafletPolylines.prototype.moveSelectedPath = function (polyline, options) {
388
- var self = this;
389
- var pathSelected = polyline.getLatLngs().map(function (x) { return [x.lat, x.lng]; })
390
- .slice(polyline.initialIdx, polyline.finalIdx + 1);
391
- if (self.selectedPath) {
392
- self.selectedPath.setLatLngs(pathSelected);
393
- this.selectedPath.object = polyline.object;
394
- }
395
- else {
396
- this.addNewSelectedPath(pathSelected, options, polyline.object);
397
- this.selectedPath.addTo(this.map);
398
- }
399
- if (this.selectedPath.decorator) {
400
- this.map.removeLayer(this.selectedPath.decorator);
401
- this.setArrowSelectedPath();
402
- }
403
- if ((options && options.editable) ||
404
- (this.selectedPath.editEnabled && this.selectedPath.editEnabled())) {
405
- this.selectedPath.disableEdit();
406
- this.selectedPath.enableEdit();
407
- }
408
- this.selectedPath.initialIdx = polyline.initialIdx;
409
- this.selectedPath.finalIdx = polyline.finalIdx;
410
- var idx = self.directionForward ? polyline.finalIdx : polyline.initialIdx;
411
- if (!this.navigateByPoint) {
412
- idx = polyline.finalIdx > polyline.initialIdx ? polyline.finalIdx : polyline.initialIdx;
413
- }
414
- var infowindow = polyline.options.infowindows ? polyline.options.infowindows[idx] : null;
415
- if (infowindow) {
416
- var point = polyline.getLatLngs()[idx];
417
- if (self.navigateInfoWindow) {
418
- self.leafletPopup.alterPopup(self.navigateInfoWindow, {
419
- content: infowindow,
420
- latlng: [point.lat, point.lng]
421
- });
422
- }
423
- else {
424
- self.navigateInfoWindow = self.leafletPopup.drawPopup({
425
- content: infowindow,
426
- latlng: [point.lat, point.lng]
427
- });
428
- }
429
- }
430
- };
431
- LeafletPolylines.prototype.setArrowSelectedPath = function () {
432
- var pathOptions = { fillOpacity: 1, weight: 0, color: this.selectedPath.options.color };
433
- this.selectedPath.decorator = this.leaflet.polylineDecorator(this.selectedPath, {
434
- patterns: [{ offset: '100%', symbol: this.leaflet.Symbol.arrowHead({ pixelSize: 20, pathOptions: pathOptions }) }]
435
- });
436
- this.selectedPath.decorator.addTo(this.map);
437
- };
438
- LeafletPolylines.prototype.addNewSelectedPath = function (pathSelected, options, object) {
439
- var newOptions = {
440
- color: options && options.color || '#FF0000',
441
- draggable: false,
442
- editable: options.editable,
443
- opacity: options && options.opacity || 1,
444
- weight: options && options.weight || 10,
445
- zIndex: 9999
446
- };
447
- if (options.style !== null) {
448
- switch (options.style) {
449
- case PolylineType.Dotted:
450
- console.warn('PolylineType.Dotted is deprecated, instead use PolylineType.Dashed.');
451
- case PolylineType.Dashed:
452
- newOptions.opacity = .7;
453
- newOptions.dashArray = '20,15';
454
- break;
455
- default:
456
- break;
457
- }
458
- }
459
- this.selectedPath = new this.leaflet.Polyline(pathSelected, newOptions);
460
- this.selectedPath.on('editable:vertex:rawclick', function (e) { return e.cancel(); });
461
- if (options.style && options.style === PolylineType.Arrow) {
462
- this.setArrowSelectedPath();
463
- }
464
- this.selectedPath.object = object;
465
- this.selectedPath.highlight = true;
466
- };
467
- LeafletPolylines.prototype.checkIdx = function (polyline, point) {
468
- var self = this;
469
- var path = polyline.getLatLngs();
470
- var distance = 0;
471
- var minDistance = Number.MAX_VALUE;
472
- var returnValue = -1;
473
- for (var i = 0; i < path.length - 1; i++) {
474
- distance = self.distanceToLine(path[i], path[i + 1], point);
475
- if (distance < minDistance) {
476
- minDistance = distance;
477
- returnValue = i;
478
- }
479
- }
480
- return returnValue;
481
- };
482
- LeafletPolylines.prototype.distanceToLine = function (pt1, pt2, pt) {
483
- var self = this;
484
- var deltaX = pt2.lng - pt1.lng;
485
- var deltaY = pt2.lat - pt1.lat;
486
- var incIntersect = (pt.lng - pt1.lng) * deltaX;
487
- var deltaSum = (deltaX * deltaX) + (deltaY * deltaY);
488
- incIntersect += (pt.lat - pt1.lat) * deltaY;
489
- if (deltaSum > 0) {
490
- incIntersect /= deltaSum;
491
- }
492
- else {
493
- incIntersect = -1;
494
- }
495
- // The intersection occurs outside the line segment, 'before' pt1.
496
- if (incIntersect < 0) {
497
- return self.kmTo(pt, pt1);
498
- }
499
- else if (incIntersect > 1) {
500
- return self.kmTo(pt, pt2);
501
- }
502
- // Intersection point calculation.
503
- var intersect = new this.leaflet.LatLng(pt1.lat + incIntersect * deltaY, pt1.lng + incIntersect * deltaX);
504
- return self.kmTo(pt, intersect);
505
- };
506
- LeafletPolylines.prototype.kmTo = function (pt1, pt2) {
507
- var e = Math;
508
- var ra = e.PI / 180;
509
- var b = pt1.lat * ra;
510
- var c = pt2.lat * ra;
511
- var d = b - c;
512
- var g = pt1.lng * ra - pt2.lng * ra;
513
- var f = 2 * e.asin(e.sqrt(e.pow(e.sin(d / 2), 2) + e.cos(b) * e.cos(c) * e.pow(e.sin(g / 2), 2)));
514
- return f * 6378.137 * 1000;
515
- };
516
- LeafletPolylines.prototype.getBoundsPolylines = function (polylines) {
517
- var group = new this.leaflet.FeatureGroup(polylines);
518
- return group.getBounds();
519
- };
520
- LeafletPolylines.prototype.addPolylineEventMove = function (polyline, eventFunction) {
521
- var self = this;
522
- polyline.on('editable:vertex:dragstart', function (eventStart) {
523
- var lastPosition = new EventReturn([eventStart.vertex.latlng.lat, eventStart.vertex.latlng.lng]);
524
- polyline.on('editable:vertex:dragend', function (eventEnd) {
525
- if (polyline.highlight && polyline.decorator) {
526
- self.map.removeLayer(polyline.decorator);
527
- self.setArrowSelectedPath();
528
- }
529
- var newPosition = new EventReturn([eventEnd.vertex.latlng.lat, eventEnd.vertex.latlng.lng]);
530
- eventFunction(newPosition, lastPosition, eventEnd.target.object, eventEnd.vertex.getIndex(), polyline.getLatLngs().map(function (x) { return new EventReturn([x.lat, x.lng]); }));
531
- polyline.off('editable:vertex:dragend');
532
- });
533
- });
534
- };
535
- LeafletPolylines.prototype.addPolylineEventInsertAt = function (polyline, eventFunction) {
536
- var self = this;
537
- polyline.on('editable:vertex:new', function (eventNew) {
538
- var latlngs = eventNew.vertex.latlngs;
539
- var previous = latlngs[latlngs.findIndex(function (x) { return x === eventNew.vertex.latlng; }) - 1];
540
- var previousPoint = new EventReturn([previous.lat, previous.lng]);
541
- polyline.on('editable:vertex:dragend', function (event) {
542
- if (polyline.highlight && polyline.decorator) {
543
- self.map.removeLayer(polyline.decorator);
544
- self.setArrowSelectedPath();
545
- }
546
- var newPoint = new EventReturn([event.vertex.latlng.lat, event.vertex.latlng.lng]);
547
- eventFunction(newPoint, previousPoint, event.target.object, event.vertex.getIndex(), polyline.getLatLngs().map(function (x) { return new EventReturn([x.lat, x.lng]); }));
548
- polyline.off('editable:vertex:dragend');
549
- });
550
- });
551
- };
552
- LeafletPolylines.prototype.addPolylineEventRemoveAt = function (polyline, eventFunction) {
553
- polyline.on('editable:vertex:deleted', function (event) {
554
- var param = new EventReturn([event.vertex.latlng.lat, event.vertex.latlng.lng]);
555
- eventFunction(param, event.target.object, polyline.getLatLngs().map(function (x) { return new EventReturn([x.lat, x.lng]); }));
556
- });
557
- };
558
- LeafletPolylines.prototype.addPolylineEventRightClick = function (polyline, eventFunction) {
559
- polyline.on('contextmenu', function (event) {
560
- var param = new EventReturn([event.latlng.lat, event.latlng.lng]);
561
- eventFunction(param, polyline.object);
562
- });
563
- polyline.on('editable:vertex:contextmenu', function (event) {
564
- var param = new EventReturn([event.latlng.lat, event.latlng.lng]);
565
- eventFunction(param, polyline.object);
566
- });
567
- };
568
- LeafletPolylines.prototype.addPolylineEventMouseOver = function (polyline, eventFunction) {
569
- polyline.on('mouseover', function (event) {
570
- var param = new EventReturn([event.latlng.lat, event.latlng.lng]);
571
- eventFunction(param, event.target.object);
572
- });
573
- };
574
- LeafletPolylines.prototype.addPolylineEventMouseOut = function (polyline, eventFunction) {
575
- polyline.on('mouseout', function (event) {
576
- var param = new EventReturn([event.latlng.lat, event.latlng.lng]);
577
- eventFunction(param, event.target.object);
578
- });
579
- };
580
- LeafletPolylines.prototype.addPolylineEventDragPolyline = function (polyline, eventFunction) {
581
- polyline.on('dragend', function (event) {
582
- var param = event.target.getLatLngs().map(function (x) { return new EventReturn([x.lat, x.lng]); });
583
- eventFunction(param, event.target.object);
584
- });
585
- };
586
- return LeafletPolylines;
587
- }());
588
- export default LeafletPolylines;
1
+ // import { Polyline } from "leaflet";
2
+ import { PolylineEventType } from "../../dto/event-type";
3
+ import { PolylineType } from "../../dto/polyline-type";
4
+ import EventReturn from "../../features/events/event-return";
5
+ var LeafletPolylines = /** @class */ (function () {
6
+ function LeafletPolylines(map, leaflet, leafletPopup) {
7
+ this.map = {};
8
+ this.leaflet = {};
9
+ this.selectedPolyline = null;
10
+ this.selectedPath = null;
11
+ this.navigateInfoWindow = null;
12
+ this.directionForward = false;
13
+ this.multiSelectionForward = false;
14
+ this.multiSelection = false;
15
+ this.navigateByPoint = false;
16
+ this.navigationOptions = {};
17
+ this.map = map;
18
+ this.leaflet = leaflet;
19
+ this.leafletPopup = leafletPopup;
20
+ }
21
+ LeafletPolylines.prototype.drawPolyline = function (options, eventClick) {
22
+ var self = this;
23
+ var newOptions = {
24
+ color: options.color || "#000000",
25
+ dashArray: null,
26
+ draggable: options.draggable,
27
+ editable: options.editable,
28
+ infowindows: options.infowindows,
29
+ opacity: options.opacity || 1,
30
+ weight: options.weight || 3,
31
+ zIndex: options.zIndex,
32
+ };
33
+ if (options.style !== null) {
34
+ switch (options.style) {
35
+ case PolylineType.Dotted:
36
+ console.warn("PolylineType.Dotted is deprecated, instead use PolylineType.Dashed.");
37
+ break;
38
+ case PolylineType.Dashed:
39
+ newOptions.opacity = 0.7;
40
+ newOptions.dashArray = "20,15";
41
+ break;
42
+ default:
43
+ break;
44
+ }
45
+ }
46
+ var polyline = new this.leaflet.Polyline(options.path || [], newOptions);
47
+ polyline.on("editable:vertex:rawclick", function (e) {
48
+ return e.cancel();
49
+ });
50
+ if (eventClick) {
51
+ polyline.on("click", function (event) {
52
+ self.leaflet.DomEvent.stopPropagation(event);
53
+ var param = new EventReturn([
54
+ event.latlng.lat,
55
+ event.latlng.lng,
56
+ ]);
57
+ eventClick(param, event.target.object);
58
+ });
59
+ polyline.on("editable:vertex:rawclick", function (event) {
60
+ event.cancel();
61
+ var param = new EventReturn([
62
+ event.latlng.lat,
63
+ event.latlng.lng,
64
+ ]);
65
+ eventClick(param, event.target.object);
66
+ });
67
+ }
68
+ if (options.style && options.style === PolylineType.Arrow) {
69
+ var pathOptions = {
70
+ fillOpacity: 1,
71
+ weight: 0,
72
+ color: polyline.options.color,
73
+ };
74
+ polyline.decorator = self.leaflet.polylineDecorator(polyline, {
75
+ patterns: [
76
+ {
77
+ offset: "20%",
78
+ repeat: "90px",
79
+ symbol: self.leaflet.Symbol.arrowHead({
80
+ pixelSize: 20,
81
+ pathOptions: pathOptions,
82
+ }),
83
+ },
84
+ {
85
+ offset: "0%",
86
+ symbol: self.leaflet.Symbol.arrowHead({
87
+ pathOptions: pathOptions,
88
+ pixelSize: 20,
89
+ }),
90
+ },
91
+ {
92
+ offset: "100%",
93
+ symbol: self.leaflet.Symbol.arrowHead({
94
+ pixelSize: 20,
95
+ pathOptions: pathOptions,
96
+ }),
97
+ },
98
+ ],
99
+ });
100
+ }
101
+ if (options.addToMap) {
102
+ polyline.addTo(self.map);
103
+ if (polyline.decorator) {
104
+ polyline.decorator.addTo(self.map);
105
+ }
106
+ if (options.editable) {
107
+ polyline.enableEdit();
108
+ }
109
+ }
110
+ if (options.object) {
111
+ polyline.object = options.object;
112
+ }
113
+ if (options.fitBounds) {
114
+ self.map.fitBounds(polyline.getBounds());
115
+ }
116
+ return polyline;
117
+ };
118
+ LeafletPolylines.prototype.drawPolylineWithNavigation = function (options, eventClick) {
119
+ var polyline = this.drawPolyline(options, null);
120
+ polyline.navigationHandlerClick = eventClick;
121
+ this.navigationOptions = options.navigateOptions;
122
+ this.navigateByPoint = this.navigationOptions
123
+ ? this.navigationOptions.navigateByPoint
124
+ : true;
125
+ this.addNavigation(polyline);
126
+ return polyline;
127
+ };
128
+ LeafletPolylines.prototype.togglePolylines = function (polylines, show) {
129
+ var self = this;
130
+ polylines.forEach(function (polyline) {
131
+ if (show) {
132
+ self.map.addLayer(polyline);
133
+ if (polyline.options.editable) {
134
+ polyline.enableEdit();
135
+ }
136
+ if (polyline.decorator) {
137
+ self.map.addLayer(polyline.decorator);
138
+ }
139
+ }
140
+ else {
141
+ self.map.removeLayer(polyline);
142
+ if (polyline.options.editable) {
143
+ polyline.disableEdit();
144
+ }
145
+ if (polyline.decorator) {
146
+ self.map.removeLayer(polyline.decorator);
147
+ }
148
+ }
149
+ });
150
+ };
151
+ LeafletPolylines.prototype.alterPolylineOptions = function (polylines, options) {
152
+ var self = this;
153
+ polylines.forEach(function (polyline) {
154
+ var style = {
155
+ color: options.color ? options.color : polyline.options.color,
156
+ draggable: options.draggable
157
+ ? options.draggable
158
+ : polyline.options.draggable,
159
+ opacity: options.opacity
160
+ ? options.opacity
161
+ : polyline.options.opacity,
162
+ weight: options.weight
163
+ ? options.weight
164
+ : polyline.options.weight,
165
+ zIndex: options.zIndex
166
+ ? options.zIndex
167
+ : polyline.options.zIndex,
168
+ };
169
+ if (options.path) {
170
+ polyline.setLatLngs(options.path);
171
+ }
172
+ switch (options.style) {
173
+ case PolylineType.Dotted:
174
+ console.warn("PolylineType.Dotted is deprecated, instead use PolylineType.Dashed.");
175
+ break;
176
+ case PolylineType.Dashed:
177
+ style.dashArray = "20,15";
178
+ break;
179
+ case PolylineType.Arrow:
180
+ var pathOptions = {
181
+ fillOpacity: 1,
182
+ weight: 0,
183
+ color: style.color,
184
+ };
185
+ if (polyline.decorator) {
186
+ self.map.removeLayer(polyline.decorator);
187
+ }
188
+ polyline.decorator = self.leaflet.polylineDecorator(polyline, {
189
+ patterns: [
190
+ {
191
+ offset: "20%",
192
+ repeat: "90px",
193
+ symbol: self.leaflet.Symbol.arrowHead({
194
+ pixelSize: 20,
195
+ pathOptions: pathOptions,
196
+ }),
197
+ },
198
+ {
199
+ offset: "0%",
200
+ symbol: self.leaflet.Symbol.arrowHead({
201
+ pixelSize: 20,
202
+ pathOptions: pathOptions,
203
+ }),
204
+ },
205
+ {
206
+ offset: "100%",
207
+ symbol: self.leaflet.Symbol.arrowHead({
208
+ pixelSize: 20,
209
+ pathOptions: pathOptions,
210
+ }),
211
+ },
212
+ ],
213
+ });
214
+ if (self.map.hasLayer(polyline)) {
215
+ polyline.decorator.addTo(self.map);
216
+ }
217
+ break;
218
+ default:
219
+ if (polyline.decorator) {
220
+ self.map.removeLayer(polyline.decorator);
221
+ polyline.decorator = null;
222
+ }
223
+ break;
224
+ }
225
+ polyline.setStyle(style);
226
+ if (options.object) {
227
+ polyline.object = options.object;
228
+ }
229
+ if (options.editable) {
230
+ polyline.disableEdit();
231
+ polyline.enableEdit();
232
+ }
233
+ });
234
+ };
235
+ LeafletPolylines.prototype.fitBoundsPolylines = function (polylines) {
236
+ var self = this;
237
+ self.map.fitBounds(self.getBoundsPolylines(polylines));
238
+ };
239
+ LeafletPolylines.prototype.isPolylineOnMap = function (polyline) {
240
+ return this.map.hasLayer(polyline);
241
+ };
242
+ LeafletPolylines.prototype.addPolylinePath = function (polylines, position) {
243
+ var _this = this;
244
+ polylines.forEach(function (polyline) {
245
+ var path = polyline.getLatLngs();
246
+ path.push(new _this.leaflet.LatLng(position[0], position[1]));
247
+ polyline.setLatLngs(path);
248
+ if (polyline.editEnabled && polyline.editEnabled()) {
249
+ polyline.disableEdit();
250
+ polyline.enableEdit();
251
+ }
252
+ });
253
+ };
254
+ LeafletPolylines.prototype.getPolylinePath = function (polyline) {
255
+ return polyline.getLatLngs().map(function (x) { return [x.lat, x.lng]; });
256
+ };
257
+ LeafletPolylines.prototype.removePolylineHighlight = function () {
258
+ var self = this;
259
+ if (self.selectedPath) {
260
+ if (this.selectedPath.decorator) {
261
+ this.map.removeLayer(this.selectedPath.decorator);
262
+ }
263
+ this.map.removeLayer(self.selectedPath);
264
+ self.selectedPath = null;
265
+ }
266
+ if (self.navigateInfoWindow) {
267
+ self.navigateInfoWindow.remove();
268
+ }
269
+ document.onkeyup = null;
270
+ document.onkeydown = null;
271
+ };
272
+ LeafletPolylines.prototype.addPolylineEvent = function (polylines, eventType, eventFunction) {
273
+ var _this = this;
274
+ polylines.forEach(function (polyline) {
275
+ switch (eventType) {
276
+ case PolylineEventType.SetAt:
277
+ _this.addPolylineEventMove(polyline, eventFunction);
278
+ break;
279
+ case PolylineEventType.RightClick:
280
+ _this.addPolylineEventRightClick(polyline, eventFunction);
281
+ break;
282
+ case PolylineEventType.InsertAt:
283
+ _this.addPolylineEventInsertAt(polyline, eventFunction);
284
+ break;
285
+ case PolylineEventType.RemoveAt:
286
+ _this.addPolylineEventRemoveAt(polyline, eventFunction);
287
+ break;
288
+ case PolylineEventType.MouseOver:
289
+ _this.addPolylineEventMouseOver(polyline, eventFunction);
290
+ break;
291
+ case PolylineEventType.MouseOut:
292
+ _this.addPolylineEventMouseOut(polyline, eventFunction);
293
+ break;
294
+ case PolylineEventType.DragPolyline:
295
+ _this.addPolylineEventDragPolyline(polyline, eventFunction);
296
+ break;
297
+ default:
298
+ break;
299
+ }
300
+ });
301
+ };
302
+ LeafletPolylines.prototype.removePolylineEvent = function (polylines, event) {
303
+ polylines.forEach(function (polyline) {
304
+ switch (event) {
305
+ case PolylineEventType.SetAt:
306
+ polyline.off("editable:vertex:dragstart");
307
+ break;
308
+ case PolylineEventType.RightClick:
309
+ polyline.off("contextmenu");
310
+ polyline.off("editable:vertex:contextmenu");
311
+ break;
312
+ case PolylineEventType.InsertAt:
313
+ polyline.off("editable:vertex:new");
314
+ break;
315
+ case PolylineEventType.RemoveAt:
316
+ polyline.off("editable:vertex:deleted");
317
+ break;
318
+ case PolylineEventType.DragPolyline:
319
+ polyline.off("dragend");
320
+ break;
321
+ case PolylineEventType.MouseOver:
322
+ polyline.off("mouseover");
323
+ break;
324
+ case PolylineEventType.MouseOut:
325
+ polyline.off("mouseout");
326
+ break;
327
+ default:
328
+ break;
329
+ }
330
+ });
331
+ };
332
+ LeafletPolylines.prototype.setIndexPolylineHighlight = function (polyline, index) {
333
+ this.directionForward = false;
334
+ polyline.initialIdx = index;
335
+ polyline.finalIdx = index + 1;
336
+ this.moveSelectedPath(polyline, this.navigationOptions);
337
+ this.selectedPolyline = polyline;
338
+ if (this.navigationOptions.navegateOnKeyPress) {
339
+ document.onkeydown = this.onKeyUp.bind(this);
340
+ }
341
+ else {
342
+ document.onkeyup = this.onKeyUp.bind(this);
343
+ }
344
+ };
345
+ LeafletPolylines.prototype.getObjectPolyline = function (polyline) {
346
+ return polyline.object;
347
+ };
348
+ LeafletPolylines.prototype.getObjectPolylineHighlight = function () {
349
+ if (this.selectedPath) {
350
+ return this.selectedPath.object;
351
+ }
352
+ return null;
353
+ };
354
+ LeafletPolylines.prototype.addPolylineHighlightEvent = function (eventType, eventFunction) {
355
+ if (this.selectedPolyline) {
356
+ this.addPolylineEvent([this.selectedPath], eventType, eventFunction);
357
+ }
358
+ };
359
+ LeafletPolylines.prototype.getPolylineHighlightIndex = function () {
360
+ if (this.selectedPath) {
361
+ return [this.selectedPath.initialIdx, this.selectedPath.finalIdx];
362
+ }
363
+ return null;
364
+ };
365
+ /* Private methods */
366
+ LeafletPolylines.prototype.addNavigation = function (polyline) {
367
+ polyline.clearAllEventListeners();
368
+ polyline.on("click", this.onClickPolyline.bind(this, polyline));
369
+ };
370
+ LeafletPolylines.prototype.onClickPolyline = function (polyline, event) {
371
+ var index = this.checkIdx(polyline, event.latlng);
372
+ polyline.initialIdx = index;
373
+ polyline.finalIdx = index + 1;
374
+ this.moveSelectedPath(polyline, this.navigationOptions);
375
+ this.selectedPolyline = polyline;
376
+ if (this.navigationOptions.navegateOnKeyPress) {
377
+ document.onkeydown = this.onKeyUp.bind(this);
378
+ }
379
+ else {
380
+ document.onkeyup = this.onKeyUp.bind(this);
381
+ }
382
+ if (polyline.navigationHandlerClick) {
383
+ var param = new EventReturn([event.latlng.lat, event.latlng.lng]);
384
+ polyline.navigationHandlerClick(param, event.target.object);
385
+ }
386
+ };
387
+ LeafletPolylines.prototype.onKeyUp = function (event) {
388
+ var self = this;
389
+ if (self.selectedPath) {
390
+ if (event.ctrlKey) {
391
+ console.warn("Deprecated: CTRL is not needed in navigation anymore");
392
+ }
393
+ switch (event.which ? event.which : event.keyCode) {
394
+ case 38:
395
+ case 39:
396
+ // up arrow or right arrow
397
+ self.moveFowards(event.shiftKey);
398
+ break;
399
+ case 37:
400
+ case 40:
401
+ // left arrow or down arrow
402
+ self.moveBackwards(event.shiftKey);
403
+ break;
404
+ }
405
+ }
406
+ };
407
+ LeafletPolylines.prototype.moveFowards = function (multiselection) {
408
+ var polyline = this.selectedPolyline;
409
+ if ((!this.navigateByPoint || this.directionForward) &&
410
+ polyline.finalIdx < polyline.getLatLngs().length - 1) {
411
+ this.navigateFoward(multiselection, polyline);
412
+ }
413
+ this.directionForward = true;
414
+ this.moveSelectedPath(polyline, null);
415
+ };
416
+ LeafletPolylines.prototype.navigateFoward = function (multiSelection, polyline) {
417
+ if (!multiSelection) {
418
+ polyline.finalIdx++;
419
+ polyline.initialIdx = this.multiSelection
420
+ ? polyline.finalIdx - 1
421
+ : polyline.initialIdx + 1;
422
+ this.multiSelection = false;
423
+ }
424
+ else {
425
+ this.multiSelection = true;
426
+ if (this.multiSelectionForward) {
427
+ polyline.finalIdx++;
428
+ }
429
+ this.multiSelectionForward = true;
430
+ }
431
+ };
432
+ LeafletPolylines.prototype.moveBackwards = function (multiSelection) {
433
+ var polyline = this.selectedPolyline;
434
+ if ((!this.navigateByPoint || !this.directionForward) &&
435
+ polyline.initialIdx > 0) {
436
+ this.navigateBackward(multiSelection, polyline);
437
+ }
438
+ this.directionForward = false;
439
+ this.moveSelectedPath(polyline, null);
440
+ };
441
+ LeafletPolylines.prototype.navigateBackward = function (multiSelection, polyline) {
442
+ var self = this;
443
+ if (!multiSelection) {
444
+ polyline.initialIdx--;
445
+ polyline.finalIdx = !self.multiSelection
446
+ ? polyline.finalIdx - 1
447
+ : polyline.initialIdx + 1;
448
+ self.multiSelection = false;
449
+ }
450
+ else {
451
+ self.multiSelection = true;
452
+ if (!self.multiSelectionForward) {
453
+ polyline.initialIdx--;
454
+ }
455
+ self.multiSelectionForward = false;
456
+ }
457
+ };
458
+ LeafletPolylines.prototype.moveSelectedPath = function (polyline, options) {
459
+ var self = this;
460
+ var pathSelected = polyline
461
+ .getLatLngs()
462
+ .map(function (x) { return [x.lat, x.lng]; })
463
+ .slice(polyline.initialIdx, polyline.finalIdx + 1);
464
+ if (self.selectedPath) {
465
+ self.selectedPath.setLatLngs(pathSelected);
466
+ this.selectedPath.object = polyline.object;
467
+ }
468
+ else {
469
+ this.addNewSelectedPath(pathSelected, options, polyline.object);
470
+ this.selectedPath.addTo(this.map);
471
+ }
472
+ if (this.selectedPath.decorator) {
473
+ this.map.removeLayer(this.selectedPath.decorator);
474
+ this.setArrowSelectedPath();
475
+ }
476
+ if ((options && options.editable) ||
477
+ (this.selectedPath.editEnabled && this.selectedPath.editEnabled())) {
478
+ this.selectedPath.disableEdit();
479
+ this.selectedPath.enableEdit();
480
+ }
481
+ this.selectedPath.initialIdx = polyline.initialIdx;
482
+ this.selectedPath.finalIdx = polyline.finalIdx;
483
+ var idx = self.directionForward
484
+ ? polyline.finalIdx
485
+ : polyline.initialIdx;
486
+ if (!this.navigateByPoint) {
487
+ idx =
488
+ polyline.finalIdx > polyline.initialIdx
489
+ ? polyline.finalIdx
490
+ : polyline.initialIdx;
491
+ }
492
+ var infowindow = polyline.options.infowindows
493
+ ? polyline.options.infowindows[idx]
494
+ : null;
495
+ if (infowindow) {
496
+ var point = polyline.getLatLngs()[idx];
497
+ if (self.navigateInfoWindow) {
498
+ self.leafletPopup.alterPopup(self.navigateInfoWindow, {
499
+ content: infowindow,
500
+ latlng: [point.lat, point.lng],
501
+ });
502
+ }
503
+ else {
504
+ self.navigateInfoWindow = self.leafletPopup.drawPopup({
505
+ content: infowindow,
506
+ latlng: [point.lat, point.lng],
507
+ });
508
+ }
509
+ }
510
+ };
511
+ LeafletPolylines.prototype.setArrowSelectedPath = function () {
512
+ var pathOptions = {
513
+ fillOpacity: 1,
514
+ weight: 0,
515
+ color: this.selectedPath.options.color,
516
+ };
517
+ this.selectedPath.decorator = this.leaflet.polylineDecorator(this.selectedPath, {
518
+ patterns: [
519
+ {
520
+ offset: "100%",
521
+ symbol: this.leaflet.Symbol.arrowHead({
522
+ pixelSize: 20,
523
+ pathOptions: pathOptions,
524
+ }),
525
+ },
526
+ ],
527
+ });
528
+ this.selectedPath.decorator.addTo(this.map);
529
+ };
530
+ LeafletPolylines.prototype.addNewSelectedPath = function (pathSelected, options, object) {
531
+ var newOptions = {
532
+ color: (options && options.color) || "#FF0000",
533
+ draggable: false,
534
+ editable: options === null || options === void 0 ? void 0 : options.editable,
535
+ opacity: (options && options.opacity) || 1,
536
+ weight: (options && options.weight) || 10,
537
+ zIndex: 9999,
538
+ };
539
+ if ((options === null || options === void 0 ? void 0 : options.style) !== null) {
540
+ switch (options === null || options === void 0 ? void 0 : options.style) {
541
+ case PolylineType.Dotted:
542
+ console.warn("PolylineType.Dotted is deprecated, instead use PolylineType.Dashed.");
543
+ break;
544
+ case PolylineType.Dashed:
545
+ newOptions.opacity = 0.7;
546
+ newOptions.dashArray = "20,15";
547
+ break;
548
+ default:
549
+ break;
550
+ }
551
+ }
552
+ this.selectedPath = new this.leaflet.Polyline(pathSelected, newOptions);
553
+ this.selectedPath.on("editable:vertex:rawclick", function (e) {
554
+ return e.cancel();
555
+ });
556
+ if ((options === null || options === void 0 ? void 0 : options.style) && options.style === PolylineType.Arrow) {
557
+ this.setArrowSelectedPath();
558
+ }
559
+ this.selectedPath.object = object;
560
+ this.selectedPath.highlight = true;
561
+ };
562
+ LeafletPolylines.prototype.checkIdx = function (polyline, point) {
563
+ var self = this;
564
+ var path = polyline.getLatLngs();
565
+ var distance = 0;
566
+ var minDistance = Number.MAX_VALUE;
567
+ var returnValue = -1;
568
+ for (var i = 0; i < path.length - 1; i++) {
569
+ distance = self.distanceToLine(path[i], path[i + 1], point);
570
+ if (distance < minDistance) {
571
+ minDistance = distance;
572
+ returnValue = i;
573
+ }
574
+ }
575
+ return returnValue;
576
+ };
577
+ LeafletPolylines.prototype.distanceToLine = function (pt1, pt2, pt) {
578
+ var self = this;
579
+ var deltaX = pt2.lng - pt1.lng;
580
+ var deltaY = pt2.lat - pt1.lat;
581
+ var incIntersect = (pt.lng - pt1.lng) * deltaX;
582
+ var deltaSum = deltaX * deltaX + deltaY * deltaY;
583
+ incIntersect += (pt.lat - pt1.lat) * deltaY;
584
+ if (deltaSum > 0) {
585
+ incIntersect /= deltaSum;
586
+ }
587
+ else {
588
+ incIntersect = -1;
589
+ }
590
+ // The intersection occurs outside the line segment, 'before' pt1.
591
+ if (incIntersect < 0) {
592
+ return self.kmTo(pt, pt1);
593
+ }
594
+ else if (incIntersect > 1) {
595
+ return self.kmTo(pt, pt2);
596
+ }
597
+ // Intersection point calculation.
598
+ var intersect = new this.leaflet.LatLng(pt1.lat + incIntersect * deltaY, pt1.lng + incIntersect * deltaX);
599
+ return self.kmTo(pt, intersect);
600
+ };
601
+ LeafletPolylines.prototype.kmTo = function (pt1, pt2) {
602
+ var e = Math;
603
+ var ra = e.PI / 180;
604
+ var b = pt1.lat * ra;
605
+ var c = pt2.lat * ra;
606
+ var d = b - c;
607
+ var g = pt1.lng * ra - pt2.lng * ra;
608
+ var f = 2 *
609
+ e.asin(e.sqrt(e.pow(e.sin(d / 2), 2) +
610
+ e.cos(b) * e.cos(c) * e.pow(e.sin(g / 2), 2)));
611
+ return f * 6378.137 * 1000;
612
+ };
613
+ LeafletPolylines.prototype.getBoundsPolylines = function (polylines) {
614
+ var group = new this.leaflet.FeatureGroup(polylines);
615
+ return group.getBounds();
616
+ };
617
+ LeafletPolylines.prototype.addPolylineEventMove = function (polyline, eventFunction) {
618
+ var self = this;
619
+ polyline.on("editable:vertex:dragstart", function (eventStart) {
620
+ var lastPosition = new EventReturn([
621
+ eventStart.vertex.latlng.lat,
622
+ eventStart.vertex.latlng.lng,
623
+ ]);
624
+ polyline.on("editable:vertex:dragend", function (eventEnd) {
625
+ if (polyline.highlight && polyline.decorator) {
626
+ self.map.removeLayer(polyline.decorator);
627
+ self.setArrowSelectedPath();
628
+ }
629
+ var newPosition = new EventReturn([
630
+ eventEnd.vertex.latlng.lat,
631
+ eventEnd.vertex.latlng.lng,
632
+ ]);
633
+ eventFunction(newPosition, lastPosition, eventEnd.target.object, eventEnd.vertex.getIndex(), polyline
634
+ .getLatLngs()
635
+ .map(function (x) { return new EventReturn([x.lat, x.lng]); }));
636
+ polyline.off("editable:vertex:dragend");
637
+ });
638
+ });
639
+ };
640
+ LeafletPolylines.prototype.addPolylineEventInsertAt = function (polyline, eventFunction) {
641
+ var self = this;
642
+ polyline.on("editable:vertex:new", function (eventNew) {
643
+ var latlngs = eventNew.vertex.latlngs;
644
+ var previous = latlngs[latlngs.findIndex(function (x) { return x === eventNew.vertex.latlng; }) - 1];
645
+ var previousPoint = new EventReturn([previous.lat, previous.lng]);
646
+ polyline.on("editable:vertex:dragend", function (event) {
647
+ if (polyline.highlight && polyline.decorator) {
648
+ self.map.removeLayer(polyline.decorator);
649
+ self.setArrowSelectedPath();
650
+ }
651
+ var newPoint = new EventReturn([
652
+ event.vertex.latlng.lat,
653
+ event.vertex.latlng.lng,
654
+ ]);
655
+ eventFunction(newPoint, previousPoint, event.target.object, event.vertex.getIndex(), polyline
656
+ .getLatLngs()
657
+ .map(function (x) { return new EventReturn([x.lat, x.lng]); }));
658
+ polyline.off("editable:vertex:dragend");
659
+ });
660
+ });
661
+ };
662
+ LeafletPolylines.prototype.addPolylineEventRemoveAt = function (polyline, eventFunction) {
663
+ polyline.on("editable:vertex:deleted", function (event) {
664
+ var param = new EventReturn([
665
+ event.vertex.latlng.lat,
666
+ event.vertex.latlng.lng,
667
+ ]);
668
+ eventFunction(param, event.target.object, polyline
669
+ .getLatLngs()
670
+ .map(function (x) { return new EventReturn([x.lat, x.lng]); }));
671
+ });
672
+ };
673
+ LeafletPolylines.prototype.addPolylineEventRightClick = function (polyline, eventFunction) {
674
+ polyline.on("contextmenu", function (event) {
675
+ var param = new EventReturn([event.latlng.lat, event.latlng.lng]);
676
+ eventFunction(param, polyline.object);
677
+ });
678
+ polyline.on("editable:vertex:contextmenu", function (event) {
679
+ var param = new EventReturn([event.latlng.lat, event.latlng.lng]);
680
+ eventFunction(param, polyline.object);
681
+ });
682
+ };
683
+ LeafletPolylines.prototype.addPolylineEventMouseOver = function (polyline, eventFunction) {
684
+ polyline.on("mouseover", function (event) {
685
+ var param = new EventReturn([event.latlng.lat, event.latlng.lng]);
686
+ eventFunction(param, event.target.object);
687
+ });
688
+ };
689
+ LeafletPolylines.prototype.addPolylineEventMouseOut = function (polyline, eventFunction) {
690
+ polyline.on("mouseout", function (event) {
691
+ var param = new EventReturn([event.latlng.lat, event.latlng.lng]);
692
+ eventFunction(param, event.target.object);
693
+ });
694
+ };
695
+ LeafletPolylines.prototype.addPolylineEventDragPolyline = function (polyline, eventFunction) {
696
+ polyline.on("dragend", function (event) {
697
+ var param = event.target
698
+ .getLatLngs()
699
+ .map(function (x) { return new EventReturn([x.lat, x.lng]); });
700
+ eventFunction(param, event.target.object);
701
+ });
702
+ };
703
+ return LeafletPolylines;
704
+ }());
705
+ export default LeafletPolylines;
589
706
  //# sourceMappingURL=leaflet-polylines.js.map