@raruto/leaflet-elevation 1.9.3 → 1.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/leaflet-elevation.js +7 -5
- package/dist/leaflet-elevation.js.map +1 -1
- package/dist/leaflet-elevation.min.js +1 -1
- package/dist/leaflet-elevation.min.js.map +1 -1
- package/libs/leaflet-distance-marker.js +240 -80
- package/libs/leaflet-distance-marker.min.js +1 -1
- package/package.json +1 -1
- package/src/control.js +2 -2
- package/src/options.js +5 -1
|
@@ -1,109 +1,269 @@
|
|
|
1
1
|
/*
|
|
2
|
-
*
|
|
2
|
+
* Copyright (c) 2022, GPL-3.0+ Project, Raruto
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* This file is free software: you may copy, redistribute and/or modify it
|
|
5
|
+
* under the terms of the GNU General Public License as published by the
|
|
6
|
+
* Free Software Foundation, either version 2 of the License, or (at your
|
|
7
|
+
* option) any later version.
|
|
5
8
|
*
|
|
6
|
-
*
|
|
9
|
+
* This file is distributed in the hope that it will be useful, but
|
|
10
|
+
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12
|
+
* General Public License for more details.
|
|
7
13
|
*
|
|
8
|
-
*
|
|
9
|
-
* this
|
|
10
|
-
* the Software without restriction, including without limitation the rights to
|
|
11
|
-
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
12
|
-
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
13
|
-
* subject to the following conditions:
|
|
14
|
+
* You should have received a copy of the GNU General Public License
|
|
15
|
+
* along with this program. If not, see .
|
|
14
16
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
+
* This file incorporates work covered by the following copyright and
|
|
18
|
+
* permission notice:
|
|
19
|
+
*
|
|
20
|
+
* Copyright (c) 2014- Doroszlai Attila, 2016- Phil Whitehurst
|
|
17
21
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
22
|
+
* Permission to use, copy, modify, and/or distribute this software
|
|
23
|
+
* for any purpose with or without fee is hereby granted, provided
|
|
24
|
+
* that the above copyright notice and this permission notice appear
|
|
25
|
+
* in all copies.
|
|
26
|
+
*
|
|
27
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
|
28
|
+
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
|
29
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
|
30
|
+
* AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
|
|
31
|
+
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
32
|
+
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
|
33
|
+
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
34
|
+
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
24
35
|
*/
|
|
25
36
|
|
|
37
|
+
// TODO: the "L.DistanceMarker" (canvas marker) class could be alternatively provided by "leaflet-rotate"?
|
|
38
|
+
|
|
39
|
+
L.DistanceMarker = L.CircleMarker.extend({
|
|
40
|
+
_updatePath: function () {
|
|
41
|
+
let ctx = this._renderer._ctx;
|
|
42
|
+
let p = this._point;
|
|
43
|
+
|
|
44
|
+
// Calculate image direction (rotation)
|
|
45
|
+
this.options.rotation = this.options.rotation || 0;
|
|
46
|
+
|
|
47
|
+
// Draw circle marker (canvas point)
|
|
48
|
+
if (this.options.radius && this._renderer._updateCircle) {
|
|
49
|
+
this._renderer._updateCircle(this);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Draw image over circle (distance marker)
|
|
53
|
+
if (this.options.icon && this.options.icon.url) {
|
|
54
|
+
if (!this.options.icon.element) {
|
|
55
|
+
const icon = document.createElement('img');
|
|
56
|
+
this.options.icon = L.extend({ rotate: 0, size: [40, 40], offset: { x: 0, y: 0 } }, this.options.icon);
|
|
57
|
+
this.options.icon.rotate += this.options.rotation;
|
|
58
|
+
this.options.icon.element = icon;
|
|
59
|
+
icon.src = this.options.icon.url;
|
|
60
|
+
icon.onload = () => this.redraw();
|
|
61
|
+
icon.onerror = () => this.options.icon = null;
|
|
62
|
+
} else {
|
|
63
|
+
const icon = this.options.icon;
|
|
64
|
+
let cx = p.x + icon.offset.x;
|
|
65
|
+
let cy = p.y + icon.offset.y;
|
|
66
|
+
ctx.save();
|
|
67
|
+
if (icon.rotate) {
|
|
68
|
+
ctx.translate(p.x, p.y);
|
|
69
|
+
ctx.rotate(icon.rotate);
|
|
70
|
+
cx = 0;
|
|
71
|
+
cy = 0;
|
|
72
|
+
}
|
|
73
|
+
ctx.drawImage(icon.element, cx - icon.size[0] / 2, cy - icon.size[1] / 2, icon.size[0], icon.size[1]);
|
|
74
|
+
ctx.restore();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Add a label inside the circle (distance marker)
|
|
79
|
+
if (this.options.label) {
|
|
80
|
+
let cx = p.x, cy = p.y;
|
|
81
|
+
ctx.save();
|
|
82
|
+
|
|
83
|
+
ctx.font = this.options.font || 'normal 7pt "Helvetica Neue", Arial, Helvetica, sans-serif';
|
|
84
|
+
ctx.textAlign = "center";
|
|
85
|
+
ctx.textBaseline = "middle";
|
|
86
|
+
ctx.fillStyle = this.options.fillStyle || 'black';
|
|
87
|
+
|
|
88
|
+
// TODO rescale circle to fit text
|
|
89
|
+
// let fontSize = Number(/[0-9\.]+/.exec(ctx.font)[0]);
|
|
90
|
+
// let fontWidth = ctx.measureText(this.options.html).width;
|
|
91
|
+
|
|
92
|
+
if (this.options.rotation) {
|
|
93
|
+
ctx.translate(p.x, p.y);
|
|
94
|
+
ctx.rotate(this.options.rotation);
|
|
95
|
+
cx = 0;
|
|
96
|
+
cy = 0;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Temporary fix to prevent stroke blurs at higher zoom levels
|
|
100
|
+
if (this._map.getZoom() > 17) {
|
|
101
|
+
ctx.fillStyle = this.options.strokeStyle || 'black';
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
ctx.fillText(this.options.label, cx, cy);
|
|
105
|
+
|
|
106
|
+
if (this.options.strokeStyle && this._map.getZoom() <= 17) {
|
|
107
|
+
ctx.strokeStyle = this.options.strokeStyle;
|
|
108
|
+
ctx.strokeText(this.options.label, cx, cy);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
ctx.restore();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
26
116
|
L.DistanceMarkers = L.LayerGroup.extend({
|
|
117
|
+
__arrowIcon: "data:image/svg+xml,%3Csvg transform='rotate(90)' xmlns='http://www.w3.org/2000/svg' width='560px' height='560px' viewBox='0 0 560 560'%3E%3Cpath stroke-width='35' fill='%23FFF' stroke='%23000' d='M280,40L522,525L280,420L38,525z'/%3E%3C/svg%3E",
|
|
118
|
+
options: {
|
|
119
|
+
cssClass: 'dist-marker',
|
|
120
|
+
iconSize: [12, 12],
|
|
121
|
+
offset: 1000,
|
|
122
|
+
showAll: 12,
|
|
123
|
+
textFunction: (distance, i, offset) => i,
|
|
124
|
+
},
|
|
27
125
|
initialize: function (line, map, options) {
|
|
28
|
-
options = options || {};
|
|
29
|
-
var offset = options.offset || 1000;
|
|
30
|
-
var showAll = Math.min(map.getMaxZoom(), options.showAll || 12);
|
|
31
|
-
var cssClass = options.cssClass || 'dist-marker';
|
|
32
|
-
var iconSize = options.iconSize !== undefined ? options.iconSize : [12, 12];
|
|
33
|
-
var textFunction = options.textFunction || function(distance, i, offset) {
|
|
34
|
-
return i;
|
|
35
|
-
};
|
|
36
126
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
127
|
+
this._layers = {};
|
|
128
|
+
this._zoomLayers = {};
|
|
129
|
+
|
|
130
|
+
options = L.setOptions(this, options);
|
|
131
|
+
|
|
132
|
+
let preferCanvas = map.options.preferCanvas;
|
|
133
|
+
let showAll = Math.min(map.getMaxZoom(), options.showAll);
|
|
134
|
+
|
|
135
|
+
// You should use "leaflet-rotate" to show rotated arrow markers (preferCanvas: false)
|
|
136
|
+
if (!preferCanvas && !map.options.rotate) {
|
|
137
|
+
console.warn('Missing dependency: "leaflet-rotate"');
|
|
42
138
|
}
|
|
139
|
+
|
|
140
|
+
// Get line coords as an array
|
|
141
|
+
let coords = typeof line.getLatLngs == 'function' ? line.getLatLngs() : line;
|
|
142
|
+
|
|
43
143
|
// Get accumulated line lengths as well as overall length
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
//
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
// Find the first accumulated distance that is greater
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
144
|
+
let accumulated = L.GeometryUtil.accumulatedLengths(line);
|
|
145
|
+
let length = accumulated.length > 0 ? accumulated[accumulated.length - 1] : 0;
|
|
146
|
+
|
|
147
|
+
// count = Number of distance markers to be added
|
|
148
|
+
// j = Position in accumulated line length array
|
|
149
|
+
for (let i = 1, count = Math.floor(length / options.offset), j = 0; i <= count; ++i) {
|
|
150
|
+
|
|
151
|
+
let distance = options.offset * i;
|
|
152
|
+
|
|
153
|
+
// Find the first accumulated distance that is greater than the distance of this marker
|
|
154
|
+
while (j < accumulated.length - 1 && accumulated[j] < distance) ++j;
|
|
155
|
+
|
|
156
|
+
// Grab two nearest points either side marker position
|
|
157
|
+
let p1 = coords[j - 1];
|
|
158
|
+
let p2 = coords[j];
|
|
159
|
+
let m_line = L.polyline([p1, p2]);
|
|
160
|
+
|
|
161
|
+
// and create a simple line to interpolate on
|
|
162
|
+
let ratio = (distance - accumulated[j - 1]) / (accumulated[j] - accumulated[j - 1]);
|
|
163
|
+
let position = L.GeometryUtil.interpolateOnLine(map, m_line, ratio);
|
|
164
|
+
let delta = map.project(p2).subtract(map.project(p1));
|
|
165
|
+
let angle = Math.atan2(delta.y, delta.x);
|
|
166
|
+
|
|
167
|
+
// Generate distance marker label
|
|
168
|
+
let text = options.textFunction.call(this, distance, i, options.offset);
|
|
169
|
+
|
|
170
|
+
// Grouping layer of generated markers (arrow + distance)
|
|
171
|
+
let marker = L.layerGroup();
|
|
172
|
+
|
|
173
|
+
// Grouping layer of visible layers (at zoom level)
|
|
174
|
+
let zoom = this._minimumZoomLevelForItem(i, showAll);
|
|
175
|
+
this._zoomLayers[zoom] = this._zoomLayers[zoom] || L.layerGroup()
|
|
176
|
+
this._zoomLayers[zoom].addLayer(marker);
|
|
177
|
+
|
|
178
|
+
// create arrow markers
|
|
179
|
+
if (options.arrows && ((options.distance && i % 2 == 1) || !options.distance)) {
|
|
180
|
+
if (preferCanvas) {
|
|
181
|
+
marker.addLayer(
|
|
182
|
+
new L.DistanceMarker(p1, {
|
|
183
|
+
radius: 0,
|
|
184
|
+
icon: {
|
|
185
|
+
url: this.__arrowIcon, //image link
|
|
186
|
+
size: [20, 20], //image size ( default [40, 40] )
|
|
187
|
+
rotate: 0, //image base rotate ( default 0 )
|
|
188
|
+
offset: { x: 0, y: 0 },//image offset ( default { x: 0, y: 0 } )
|
|
189
|
+
},
|
|
190
|
+
rotation: angle,
|
|
191
|
+
interactive: false,
|
|
192
|
+
// label: '⮞', //'➜',
|
|
193
|
+
// font: 'normal 20pt "Helvetica Neue", Arial, Helvetica, sans-serif',
|
|
194
|
+
// fillStyle: 'white',//'#3366CC',
|
|
195
|
+
// strokeStyle: 'black',
|
|
196
|
+
})
|
|
197
|
+
);
|
|
198
|
+
} else {
|
|
199
|
+
marker.addLayer(
|
|
200
|
+
L.marker(position.latLng, {
|
|
201
|
+
icon: L.icon({
|
|
202
|
+
iconUrl: __arrowIcon,
|
|
203
|
+
iconSize: [20, 20],
|
|
204
|
+
}),
|
|
205
|
+
// NB the following option is added by "leaflet-rotate"
|
|
206
|
+
rotation: angle * L.DomUtil.RAD_TO_DEG,
|
|
207
|
+
interactive: false,
|
|
208
|
+
})
|
|
209
|
+
);
|
|
210
|
+
}
|
|
57
211
|
}
|
|
58
|
-
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
212
|
+
|
|
213
|
+
// create distance markers
|
|
214
|
+
if (options.distance && i % 2 == 0) {
|
|
215
|
+
if (preferCanvas) {
|
|
216
|
+
marker.addLayer(
|
|
217
|
+
new L.DistanceMarker(position.latLng, {
|
|
218
|
+
label: text, // TODO: handle text rotation (leaflet-rotate)
|
|
219
|
+
radius: 7,
|
|
220
|
+
fillColor: '#fff',
|
|
221
|
+
fillOpacity: 1,
|
|
222
|
+
fillStyle: 'black',
|
|
223
|
+
color: '#777',
|
|
224
|
+
weight: 1,
|
|
225
|
+
interactive: false,
|
|
226
|
+
})
|
|
227
|
+
);
|
|
228
|
+
} else {
|
|
229
|
+
marker.addLayer(
|
|
230
|
+
L.marker(position.latLng, {
|
|
231
|
+
title: text,
|
|
232
|
+
icon: L.divIcon({
|
|
233
|
+
className: options.cssClass,
|
|
234
|
+
html: text,
|
|
235
|
+
iconSize: options.iconSize
|
|
236
|
+
}),
|
|
237
|
+
interactive: false,
|
|
238
|
+
})
|
|
239
|
+
);
|
|
240
|
+
}
|
|
74
241
|
}
|
|
75
|
-
zoomLayers[zoom].addLayer(marker);
|
|
76
242
|
}
|
|
77
243
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
var oldZoom = currentZoomLevel;
|
|
82
|
-
var newZoom = currentZoomLevel = map.getZoom();
|
|
83
|
-
|
|
244
|
+
const updateMarkerVisibility = () => {
|
|
245
|
+
let oldZoom = this._lastZoomLevel || 0;
|
|
246
|
+
let newZoom = map.getZoom();
|
|
84
247
|
if (newZoom > oldZoom) {
|
|
85
|
-
for (
|
|
86
|
-
if (
|
|
87
|
-
|
|
248
|
+
for (let i = oldZoom + 1; i <= newZoom; ++i) {
|
|
249
|
+
if (this._zoomLayers[i] !== undefined) {
|
|
250
|
+
this.addLayer(this._zoomLayers[i]);
|
|
88
251
|
}
|
|
89
252
|
}
|
|
90
253
|
} else if (newZoom < oldZoom) {
|
|
91
|
-
for (
|
|
92
|
-
if (
|
|
93
|
-
|
|
254
|
+
for (let i = oldZoom; i > newZoom; --i) {
|
|
255
|
+
if (this._zoomLayers[i] !== undefined) {
|
|
256
|
+
this.removeLayer(this._zoomLayers[i]);
|
|
94
257
|
}
|
|
95
258
|
}
|
|
96
259
|
}
|
|
260
|
+
this._lastZoomLevel = newZoom;
|
|
97
261
|
};
|
|
98
262
|
map.on('zoomend', updateMarkerVisibility);
|
|
99
|
-
|
|
100
|
-
this._layers = {}; // need to initialize before adding markers to this LayerGroup
|
|
101
263
|
updateMarkerVisibility();
|
|
102
264
|
},
|
|
103
265
|
|
|
104
|
-
_minimumZoomLevelForItem: function (
|
|
105
|
-
var zoom = showAllLevel;
|
|
106
|
-
var i = item;
|
|
266
|
+
_minimumZoomLevelForItem: function (i, zoom) {
|
|
107
267
|
while (i > 0 && i % 2 === 0) {
|
|
108
268
|
--zoom;
|
|
109
269
|
i = Math.floor(i / 2);
|
|
@@ -133,9 +293,9 @@ L.Polyline.include({
|
|
|
133
293
|
onAdd: function (map) {
|
|
134
294
|
this._originalOnAdd(map);
|
|
135
295
|
|
|
136
|
-
|
|
137
|
-
if (this.
|
|
138
|
-
this._distanceMarkers = new L.DistanceMarkers(this, map, opts);
|
|
296
|
+
let opts = this.options.distanceMarkers || {};
|
|
297
|
+
if (this.options.distanceMarkers) {
|
|
298
|
+
this._distanceMarkers = this._distanceMarkers || new L.DistanceMarkers(this, map, opts);
|
|
139
299
|
}
|
|
140
300
|
if (opts.lazy === undefined || opts.lazy === false) {
|
|
141
301
|
this.addDistanceMarkers();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
L.
|
|
1
|
+
L.DistanceMarker=L.CircleMarker.extend({_updatePath:function(){let ctx=this._renderer._ctx,p=this._point;if(this.options.rotation=this.options.rotation||0,this.options.radius&&this._renderer._updateCircle&&this._renderer._updateCircle(this),this.options.icon&&this.options.icon.url)if(this.options.icon.element){const icon=this.options.icon;let cx=p.x+icon.offset.x,cy=p.y+icon.offset.y;ctx.save(),icon.rotate&&(ctx.translate(p.x,p.y),ctx.rotate(icon.rotate),cx=0,cy=0),ctx.drawImage(icon.element,cx-icon.size[0]/2,cy-icon.size[1]/2,icon.size[0],icon.size[1]),ctx.restore()}else{const icon=document.createElement("img");this.options.icon=L.extend({rotate:0,size:[40,40],offset:{x:0,y:0}},this.options.icon),this.options.icon.rotate+=this.options.rotation,this.options.icon.element=icon,icon.src=this.options.icon.url,icon.onload=()=>this.redraw(),icon.onerror=()=>this.options.icon=null}if(this.options.label){let cx=p.x,cy=p.y;ctx.save(),ctx.font=this.options.font||'normal 7pt "Helvetica Neue", Arial, Helvetica, sans-serif',ctx.textAlign="center",ctx.textBaseline="middle",ctx.fillStyle=this.options.fillStyle||"black",this.options.rotation&&(ctx.translate(p.x,p.y),ctx.rotate(this.options.rotation),cx=0,cy=0),this._map.getZoom()>17&&(ctx.fillStyle=this.options.strokeStyle||"black"),ctx.fillText(this.options.label,cx,cy),this.options.strokeStyle&&this._map.getZoom()<=17&&(ctx.strokeStyle=this.options.strokeStyle,ctx.strokeText(this.options.label,cx,cy)),ctx.restore()}}}),L.DistanceMarkers=L.LayerGroup.extend({__arrowIcon:"data:image/svg+xml,%3Csvg transform='rotate(90)' xmlns='http://www.w3.org/2000/svg' width='560px' height='560px' viewBox='0 0 560 560'%3E%3Cpath stroke-width='35' fill='%23FFF' stroke='%23000' d='M280,40L522,525L280,420L38,525z'/%3E%3C/svg%3E",options:{cssClass:"dist-marker",iconSize:[12,12],offset:1e3,showAll:12,textFunction:(distance,i,offset)=>i},initialize:function(line,map,options){this._layers={},this._zoomLayers={},options=L.setOptions(this,options);let preferCanvas=map.options.preferCanvas,showAll=Math.min(map.getMaxZoom(),options.showAll);preferCanvas||map.options.rotate||console.warn('Missing dependency: "leaflet-rotate"');let coords="function"==typeof line.getLatLngs?line.getLatLngs():line,accumulated=L.GeometryUtil.accumulatedLengths(line),length=accumulated.length>0?accumulated[accumulated.length-1]:0;for(let i=1,count=Math.floor(length/options.offset),j=0;i<=count;++i){let distance=options.offset*i;for(;j<accumulated.length-1&&accumulated[j]<distance;)++j;let p1=coords[j-1],p2=coords[j],m_line=L.polyline([p1,p2]),ratio=(distance-accumulated[j-1])/(accumulated[j]-accumulated[j-1]),position=L.GeometryUtil.interpolateOnLine(map,m_line,ratio),delta=map.project(p2).subtract(map.project(p1)),angle=Math.atan2(delta.y,delta.x),text=options.textFunction.call(this,distance,i,options.offset),marker=L.layerGroup(),zoom=this._minimumZoomLevelForItem(i,showAll);this._zoomLayers[zoom]=this._zoomLayers[zoom]||L.layerGroup(),this._zoomLayers[zoom].addLayer(marker),options.arrows&&(options.distance&&i%2==1||!options.distance)&&(preferCanvas?marker.addLayer(new L.DistanceMarker(p1,{radius:0,icon:{url:this.__arrowIcon,size:[20,20],rotate:0,offset:{x:0,y:0}},rotation:angle,interactive:!1})):marker.addLayer(L.marker(position.latLng,{icon:L.icon({iconUrl:__arrowIcon,iconSize:[20,20]}),rotation:angle*L.DomUtil.RAD_TO_DEG,interactive:!1}))),options.distance&&i%2==0&&(preferCanvas?marker.addLayer(new L.DistanceMarker(position.latLng,{label:text,radius:7,fillColor:"#fff",fillOpacity:1,fillStyle:"black",color:"#777",weight:1,interactive:!1})):marker.addLayer(L.marker(position.latLng,{title:text,icon:L.divIcon({className:options.cssClass,html:text,iconSize:options.iconSize}),interactive:!1})))}const updateMarkerVisibility=()=>{let oldZoom=this._lastZoomLevel||0,newZoom=map.getZoom();if(newZoom>oldZoom)for(let i=oldZoom+1;i<=newZoom;++i)void 0!==this._zoomLayers[i]&&this.addLayer(this._zoomLayers[i]);else if(newZoom<oldZoom)for(let i=oldZoom;i>newZoom;--i)void 0!==this._zoomLayers[i]&&this.removeLayer(this._zoomLayers[i]);this._lastZoomLevel=newZoom};map.on("zoomend",updateMarkerVisibility),updateMarkerVisibility()},_minimumZoomLevelForItem:function(i,zoom){for(;i>0&&i%2==0;)--zoom,i=Math.floor(i/2);return zoom}}),L.Polyline.include({_originalOnAdd:L.Polyline.prototype.onAdd,_originalOnRemove:L.Polyline.prototype.onRemove,addDistanceMarkers:function(){this._map&&this._distanceMarkers&&this._map.addLayer(this._distanceMarkers)},removeDistanceMarkers:function(){this._map&&this._distanceMarkers&&this._map.removeLayer(this._distanceMarkers)},onAdd:function(map){this._originalOnAdd(map);let opts=this.options.distanceMarkers||{};this.options.distanceMarkers&&(this._distanceMarkers=this._distanceMarkers||new L.DistanceMarkers(this,map,opts)),void 0!==opts.lazy&&!1!==opts.lazy||this.addDistanceMarkers()},onRemove:function(map){this.removeDistanceMarkers(),this._originalOnRemove(map)}});
|
package/package.json
CHANGED
package/src/control.js
CHANGED
|
@@ -17,7 +17,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
17
17
|
__TOGEOJSON: 'https://unpkg.com/@tmcw/togeojson@4.5.0/dist/togeojson.umd.js',
|
|
18
18
|
__LGEOMUTIL: 'https://unpkg.com/leaflet-geometryutil@0.9.3/src/leaflet.geometryutil.js',
|
|
19
19
|
__LALMOSTOVER: 'https://unpkg.com/leaflet-almostover@1.0.1/src/leaflet.almostover.js',
|
|
20
|
-
__LDISTANCEM: 'https://unpkg.com/@raruto/leaflet-elevation@1.9.
|
|
20
|
+
__LDISTANCEM: 'https://unpkg.com/@raruto/leaflet-elevation@1.9.4/libs/leaflet-distance-marker.min.js',
|
|
21
21
|
|
|
22
22
|
/*
|
|
23
23
|
* Add data to the diagram either from GPX or GeoJSON and update the axis domain and data
|
|
@@ -163,7 +163,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
163
163
|
if (this.options.legend) this.options.margins.bottom += 30;
|
|
164
164
|
if (this.options.theme) this.options.polylineSegments.className += ' ' + this.options.theme;
|
|
165
165
|
if (this.options.wptIcons === true) this.options.wptIcons = Options.wptIcons;
|
|
166
|
-
if (this.options.distanceMarkers === true) this.options.distanceMarkers =
|
|
166
|
+
if (this.options.distanceMarkers === true) this.options.distanceMarkers = Options.distanceMarkers;
|
|
167
167
|
|
|
168
168
|
this._markedSegments.setStyle(this.options.polylineSegments);
|
|
169
169
|
|
package/src/options.js
CHANGED