@inlog/inlog-maps 6.0.0 → 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 (85) hide show
  1. package/lib/index.js +47 -0
  2. package/lib/index.js.map +1 -0
  3. package/lib/map.js +1137 -0
  4. package/lib/map.js.map +1 -0
  5. package/lib/models/apis/google/google-circles.js +134 -0
  6. package/lib/models/apis/google/google-circles.js.map +1 -0
  7. package/lib/models/apis/google/google-geojson.js +73 -0
  8. package/lib/models/apis/google/google-geojson.js.map +1 -0
  9. package/lib/models/apis/google/google-map.js +174 -0
  10. package/lib/models/apis/google/google-map.js.map +1 -0
  11. package/lib/models/apis/google/google-markers.js +325 -0
  12. package/lib/models/apis/google/google-markers.js.map +1 -0
  13. package/lib/models/apis/google/google-overlay.js +102 -0
  14. package/lib/models/apis/google/google-overlay.js.map +1 -0
  15. package/lib/models/apis/google/google-polygons.js +301 -0
  16. package/lib/models/apis/google/google-polygons.js.map +1 -0
  17. package/lib/models/apis/google/google-polylines.js +707 -0
  18. package/lib/models/apis/google/google-polylines.js.map +1 -0
  19. package/lib/models/apis/google/google-popup.js +59 -0
  20. package/lib/models/apis/google/google-popup.js.map +1 -0
  21. package/lib/models/apis/googleMaps.js +449 -0
  22. package/lib/models/apis/googleMaps.js.map +1 -0
  23. package/lib/models/apis/leaflet/leaflet-circle.js +163 -0
  24. package/lib/models/apis/leaflet/leaflet-circle.js.map +1 -0
  25. package/lib/models/apis/leaflet/leaflet-geojson.js +73 -0
  26. package/lib/models/apis/leaflet/leaflet-geojson.js.map +1 -0
  27. package/lib/models/apis/leaflet/leaflet-map.js +140 -0
  28. package/lib/models/apis/leaflet/leaflet-map.js.map +1 -0
  29. package/lib/models/apis/leaflet/leaflet-markers.js +294 -0
  30. package/lib/models/apis/leaflet/leaflet-markers.js.map +1 -0
  31. package/lib/models/apis/leaflet/leaflet-overlay.js +35 -0
  32. package/lib/models/apis/leaflet/leaflet-overlay.js.map +1 -0
  33. package/lib/models/apis/leaflet/leaflet-polygons.js +211 -0
  34. package/lib/models/apis/leaflet/leaflet-polygons.js.map +1 -0
  35. package/lib/models/apis/leaflet/leaflet-polylines.js +706 -0
  36. package/lib/models/apis/leaflet/leaflet-polylines.js.map +1 -0
  37. package/lib/models/apis/leaflet/leaflet-popup.js +74 -0
  38. package/lib/models/apis/leaflet/leaflet-popup.js.map +1 -0
  39. package/lib/models/apis/leaflet.js +464 -0
  40. package/lib/models/apis/leaflet.js.map +1 -0
  41. package/lib/models/apis/mapFunctions.js +2 -0
  42. package/lib/models/apis/mapFunctions.js.map +1 -0
  43. package/lib/models/dto/event-type.js +39 -0
  44. package/lib/models/dto/event-type.js.map +1 -0
  45. package/lib/models/dto/map-type.js +6 -0
  46. package/lib/models/dto/map-type.js.map +1 -0
  47. package/lib/models/dto/polyline-type.js +7 -0
  48. package/lib/models/dto/polyline-type.js.map +1 -0
  49. package/lib/models/features/circle/circle-alter-options.js +14 -0
  50. package/lib/models/features/circle/circle-alter-options.js.map +1 -0
  51. package/lib/models/features/circle/circle-options.js +19 -0
  52. package/lib/models/features/circle/circle-options.js.map +1 -0
  53. package/lib/models/features/events/event-return.js +8 -0
  54. package/lib/models/features/events/event-return.js.map +1 -0
  55. package/lib/models/features/geojson/geojson-options.js +9 -0
  56. package/lib/models/features/geojson/geojson-options.js.map +1 -0
  57. package/lib/models/features/marker/circle-marker-options.js +12 -0
  58. package/lib/models/features/marker/circle-marker-options.js.map +1 -0
  59. package/lib/models/features/marker/circle-marker-style.js +12 -0
  60. package/lib/models/features/marker/circle-marker-style.js.map +1 -0
  61. package/lib/models/features/marker/marker-alter-options.js +10 -0
  62. package/lib/models/features/marker/marker-alter-options.js.map +1 -0
  63. package/lib/models/features/marker/marker-icon.js +10 -0
  64. package/lib/models/features/marker/marker-icon.js.map +1 -0
  65. package/lib/models/features/marker/marker-options.js +18 -0
  66. package/lib/models/features/marker/marker-options.js.map +1 -0
  67. package/lib/models/features/marker-clusterer/marker-clusterer-config.js +10 -0
  68. package/lib/models/features/marker-clusterer/marker-clusterer-config.js.map +1 -0
  69. package/lib/models/features/overlay/overlay-options.js +15 -0
  70. package/lib/models/features/overlay/overlay-options.js.map +1 -0
  71. package/lib/models/features/polygons/polygon-alter-options.js +14 -0
  72. package/lib/models/features/polygons/polygon-alter-options.js.map +1 -0
  73. package/lib/models/features/polygons/polygon-options.js +19 -0
  74. package/lib/models/features/polygons/polygon-options.js.map +1 -0
  75. package/lib/models/features/polyline/navigations-options.js +16 -0
  76. package/lib/models/features/polyline/navigations-options.js.map +1 -0
  77. package/lib/models/features/polyline/polyline-options.js +20 -0
  78. package/lib/models/features/polyline/polyline-options.js.map +1 -0
  79. package/lib/models/features/popup/popup-options.js +13 -0
  80. package/lib/models/features/popup/popup-options.js.map +1 -0
  81. package/lib/utils/maps-api-loader.service.js +89 -0
  82. package/lib/utils/maps-api-loader.service.js.map +1 -0
  83. package/lib/utils/url-builder.js +44 -0
  84. package/lib/utils/url-builder.js.map +1 -0
  85. package/package.json +1 -1
@@ -0,0 +1,706 @@
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;
706
+ //# sourceMappingURL=leaflet-polylines.js.map