@raruto/leaflet-elevation 1.7.1 → 1.7.5
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 +5 -2
- package/dist/leaflet-elevation.js +119 -100
- 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-gpxgroup.js +48 -35
- package/libs/leaflet-gpxgroup.min.js +14 -13
- package/package.json +1 -1
- package/src/components.js +7 -1
- package/src/control.js +6 -4
- package/src/options.js +1 -0
- package/src/utils.js +37 -25
package/libs/leaflet-gpxgroup.js
CHANGED
|
@@ -100,11 +100,10 @@ L.control.layersLegend = function(baseLayers, overlays, options) {
|
|
|
100
100
|
return new L.Control.LayersLegend(baseLayers, overlays, options);
|
|
101
101
|
};
|
|
102
102
|
|
|
103
|
-
L.
|
|
103
|
+
L.GeoJSON.include(L.Mixin.Selectable);
|
|
104
104
|
|
|
105
105
|
L.GpxGroup = L.Class.extend({
|
|
106
106
|
options: {
|
|
107
|
-
async: true,
|
|
108
107
|
highlight: {
|
|
109
108
|
color: '#ff0',
|
|
110
109
|
opacity: 1,
|
|
@@ -125,7 +124,6 @@ L.GpxGroup = L.Class.extend({
|
|
|
125
124
|
elevation: true,
|
|
126
125
|
elevation_options: {
|
|
127
126
|
theme: 'yellow-theme',
|
|
128
|
-
// width: 500,
|
|
129
127
|
detachedView: true,
|
|
130
128
|
elevationDiv: '#elevation-div',
|
|
131
129
|
},
|
|
@@ -133,11 +131,6 @@ L.GpxGroup = L.Class.extend({
|
|
|
133
131
|
distanceMarkers_options: {
|
|
134
132
|
lazy: true
|
|
135
133
|
},
|
|
136
|
-
marker_options: {
|
|
137
|
-
startIconUrl: null,
|
|
138
|
-
endIconUrl: null,
|
|
139
|
-
shadowUrl: null,
|
|
140
|
-
}
|
|
141
134
|
},
|
|
142
135
|
|
|
143
136
|
initialize: function(tracks, options) {
|
|
@@ -187,10 +180,40 @@ L.GpxGroup = L.Class.extend({
|
|
|
187
180
|
},
|
|
188
181
|
|
|
189
182
|
addTrack: function(track) {
|
|
190
|
-
|
|
183
|
+
fetch(track).then(response => {
|
|
184
|
+
if (response.ok) {
|
|
185
|
+
response.text().then(doc => {
|
|
186
|
+
let geojson;
|
|
187
|
+
doc = doc.trim();
|
|
188
|
+
|
|
189
|
+
try {
|
|
190
|
+
let xml = (new DOMParser()).parseFromString(doc, "text/xml");
|
|
191
|
+
let type = xml.documentElement.tagName.toLowerCase(); // "kml" or "gpx"
|
|
192
|
+
let name = xml.getElementsByTagName('name');
|
|
193
|
+
if (!(type in toGeoJSON)) {
|
|
194
|
+
type = xml.documentElement.tagName == "TrainingCenterDatabase" ? 'tcx' : 'gpx';
|
|
195
|
+
}
|
|
196
|
+
geojson = toGeoJSON[type](xml);
|
|
197
|
+
geojson.name = name.length > 0 ? Array.from(name).find(tag => tag.parentElement.tagName == "trk").textContent : '';
|
|
198
|
+
} catch (e) {
|
|
199
|
+
try {
|
|
200
|
+
geojson = JSON.parse(doc.toString());
|
|
201
|
+
} catch (e) {
|
|
202
|
+
console.warn("Error parsing track: " + track);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (!geojson.name) {
|
|
206
|
+
geojson.name = track.split('/').pop().split('#')[0].split('?')[0];
|
|
207
|
+
}
|
|
208
|
+
this._loadRoute(geojson);
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
});
|
|
191
212
|
},
|
|
192
213
|
|
|
193
214
|
_loadRoute: function(data) {
|
|
215
|
+
if (!data) return;
|
|
216
|
+
|
|
194
217
|
var colors = this._uniqueColors(this._tracks.length);
|
|
195
218
|
var color = colors[this._count++];
|
|
196
219
|
|
|
@@ -201,23 +224,24 @@ L.GpxGroup = L.Class.extend({
|
|
|
201
224
|
distanceMarkers: this.options.distanceMarkers_options,
|
|
202
225
|
};
|
|
203
226
|
|
|
204
|
-
var route =
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
227
|
+
var route = L.geoJson(data, {
|
|
228
|
+
name: data.name || '',
|
|
229
|
+
style: (feature) => line_style,
|
|
230
|
+
distanceMarkers: line_style.distanceMarkers,
|
|
231
|
+
originalStyle: line_style,
|
|
232
|
+
filter: feature => feature.geometry.type != "Point",
|
|
208
233
|
});
|
|
209
234
|
|
|
210
|
-
route.originalStyle = line_style;
|
|
211
|
-
|
|
212
|
-
route.on('addline', L.bind(this._onRouteAddLine, this, route));
|
|
213
|
-
route.on('loaded', L.bind(this._onRouteLoaded, this, route));
|
|
214
|
-
|
|
215
235
|
route.addTo(this._layers);
|
|
216
236
|
this._routes[route._leaflet_id] = route;
|
|
237
|
+
|
|
238
|
+
route.eachLayer((layer) => this._onRouteLayer(route, layer));
|
|
239
|
+
this._onRouteLoaded(route);
|
|
240
|
+
|
|
217
241
|
},
|
|
218
242
|
|
|
219
|
-
|
|
220
|
-
var polyline =
|
|
243
|
+
_onRouteLayer: function(route, layer) {
|
|
244
|
+
var polyline = layer;
|
|
221
245
|
|
|
222
246
|
route.on('selected', L.bind(this._onRouteSelected, this, route, polyline));
|
|
223
247
|
|
|
@@ -225,7 +249,7 @@ L.GpxGroup = L.Class.extend({
|
|
|
225
249
|
polyline.on('mouseout', L.bind(this._onRouteMouseOut, this, route, polyline));
|
|
226
250
|
polyline.on('click', L.bind(this._onRouteClick, this, route, polyline));
|
|
227
251
|
|
|
228
|
-
polyline.bindTooltip(route.
|
|
252
|
+
polyline.bindTooltip(route.options.name, {
|
|
229
253
|
direction: 'auto',
|
|
230
254
|
sticky: true,
|
|
231
255
|
});
|
|
@@ -239,7 +263,7 @@ L.GpxGroup = L.Class.extend({
|
|
|
239
263
|
},
|
|
240
264
|
|
|
241
265
|
unhighlight: function(route, polyline) {
|
|
242
|
-
polyline.setStyle(route.originalStyle);
|
|
266
|
+
polyline.setStyle(route.options.originalStyle);
|
|
243
267
|
if (this.options.distanceMarkers) {
|
|
244
268
|
polyline.removeDistanceMarkers();
|
|
245
269
|
}
|
|
@@ -281,7 +305,7 @@ L.GpxGroup = L.Class.extend({
|
|
|
281
305
|
|
|
282
306
|
_onRouteLoaded: function(route) {
|
|
283
307
|
if (this.options.legend) {
|
|
284
|
-
this._legend.addBaseLayer(route, '<svg id="legend_' + route._leaflet_id + '" width="25" height="10" version="1.1" xmlns="http://www.w3.org/2000/svg">' + '<line x1="0" x2="50" y1="5" y2="5" stroke="' + route.options.
|
|
308
|
+
this._legend.addBaseLayer(route, '<svg id="legend_' + route._leaflet_id + '" width="25" height="10" version="1.1" xmlns="http://www.w3.org/2000/svg">' + '<line x1="0" x2="50" y1="5" y2="5" stroke="' + route.options.originalStyle.color + '" fill="transparent" stroke-width="5" /></svg>' + ' ' + route.options.name);
|
|
285
309
|
}
|
|
286
310
|
this.fire('route_loaded', {
|
|
287
311
|
route: route,
|
|
@@ -314,7 +338,7 @@ L.GpxGroup = L.Class.extend({
|
|
|
314
338
|
}
|
|
315
339
|
route.getLayers().forEach(function(layer) {
|
|
316
340
|
if (layer instanceof L.Polyline) {
|
|
317
|
-
elevation.addData(layer);
|
|
341
|
+
elevation.addData(layer, false);
|
|
318
342
|
layer.bringToFront();
|
|
319
343
|
}
|
|
320
344
|
});
|
|
@@ -353,17 +377,6 @@ L.GpxGroup = L.Class.extend({
|
|
|
353
377
|
}
|
|
354
378
|
},
|
|
355
379
|
|
|
356
|
-
_get: function(url, callback) {
|
|
357
|
-
var xhr = new XMLHttpRequest();
|
|
358
|
-
xhr.open("GET", url);
|
|
359
|
-
xhr.onreadystatechange = function() {
|
|
360
|
-
if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
|
|
361
|
-
callback(xhr.response);
|
|
362
|
-
}
|
|
363
|
-
};
|
|
364
|
-
xhr.send();
|
|
365
|
-
},
|
|
366
|
-
|
|
367
380
|
_uniqueColors: function(count) {
|
|
368
381
|
if (count === 0) return [];
|
|
369
382
|
if (count === 1) return ['#0000ff'];
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
'use strict';L.Mixin.Selectable={includes:L.Mixin.Events,setSelected:function(s){var selected=!!s;if(this._selected!==selected){this._selected=selected;this.fire("selected")}},isSelected:function(){return!!this._selected}};
|
|
2
2
|
L.Mixin.Selection={includes:L.Mixin.Events,getSelection:function(){return this._selected},setSelection:function(item){if(this._selected===item){if(item!==null){item.setSelected(!item.isSelected());if(!item.isSelected())this._selected=null}}else{if(this._selected)this._selected.setSelected(false);this._selected=item;if(this._selected)this._selected.setSelected(true)}this.fire("selection_changed")}};
|
|
3
3
|
L.Control.LayersLegend=L.Control.Layers.extend({_onInputClick:function(){var inputs=this._layerControlInputs,input,layer;var addedLayers=[],removedLayers=[];this._handlingClick=true;for(var i=inputs.length-1;i>=0;i--){input=inputs[i];layer=this._getLayer(input.layerId).layer;if(input.checked)this._map.fireEvent("legend_selected",{layer:layer,input:input},true)}this._handlingClick=false;this._refocusOnMap()}});
|
|
4
|
-
L.control.layersLegend=function(baseLayers,overlays,options){return new L.Control.LayersLegend(baseLayers,overlays,options)};L.
|
|
5
|
-
L.GpxGroup=L.Class.extend({options:{
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
polyline);this.
|
|
12
|
-
|
|
13
|
-
route.
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
p;g=v;b=t;break;case 3:r=p;g=q;b=v;break;case 4:r=t;g=p;b=v;break;case 5:r=v;g=p;b=q;
|
|
4
|
+
L.control.layersLegend=function(baseLayers,overlays,options){return new L.Control.LayersLegend(baseLayers,overlays,options)};L.GeoJSON.include(L.Mixin.Selectable);
|
|
5
|
+
L.GpxGroup=L.Class.extend({options:{highlight:{color:"#ff0",opacity:1},points:[],points_options:{icon:{iconUrl:"../images/elevation-poi.png",iconSize:[12,12]}},flyToBounds:true,legend:false,legend_options:{position:"topright",collapsed:false},elevation:true,elevation_options:{theme:"yellow-theme",detachedView:true,elevationDiv:"#elevation-div"},distanceMarkers:true,distanceMarkers_options:{lazy:true}},initialize:function(tracks,options){L.Util.setOptions(this,options);this._count=0;this._loadedCount=
|
|
6
|
+
0;this._tracks=tracks;this._routes={};this._layers=L.featureGroup();this._markers=L.featureGroup();this._elevation=L.control.elevation(this.options.elevation_options);this._legend=L.control.layersLegend(null,null,this.options.legend_options);var icon=L.icon(this.options.points_options.icon);this.options.points.forEach(function(poi){var marker=L.marker(poi.latlng,{icon:icon});marker.bindTooltip(poi.name,{direction:"auto"});marker.addTo(this._markers)},this);if(typeof L.DistanceMarkers==="undefined")this.options.distanceMarkers=
|
|
7
|
+
false},getBounds:function(){return this._layers.getBounds()},addTo:function(map){this._layers.addTo(map);this._markers.addTo(map);this._map=map;this.on("selection_changed",this._onSelectionChanged,this);this._map.on("legend_selected",this._onLegendSelected,this);this._tracks.forEach(this.addTrack,this)},addTrack:function(track){fetch(track).then((response)=>{if(response.ok)response.text().then((doc)=>{let geojson;doc=doc.trim();try{let xml=(new DOMParser).parseFromString(doc,"text/xml");let type=
|
|
8
|
+
xml.documentElement.tagName.toLowerCase();let name=xml.getElementsByTagName("name");if(!(type in toGeoJSON))type=xml.documentElement.tagName=="TrainingCenterDatabase"?"tcx":"gpx";geojson=toGeoJSON[type](xml);geojson.name=name.length>0?Array.from(name).find((tag)=>tag.parentElement.tagName=="trk").textContent:""}catch(e){try{geojson=JSON.parse(doc.toString())}catch(e){console.warn("Error parsing track: "+track)}}if(!geojson.name)geojson.name=track.split("/").pop().split("#")[0].split("?")[0];this._loadRoute(geojson)})})},
|
|
9
|
+
_loadRoute:function(data){if(!data)return;var colors=this._uniqueColors(this._tracks.length);var color=colors[this._count++];var line_style={color:color,opacity:.75,weight:5,distanceMarkers:this.options.distanceMarkers_options};var route=L.geoJson(data,{name:data.name||"",style:(feature)=>line_style,distanceMarkers:line_style.distanceMarkers,originalStyle:line_style,filter:(feature)=>feature.geometry.type!="Point"});route.addTo(this._layers);this._routes[route._leaflet_id]=route;route.eachLayer((layer)=>
|
|
10
|
+
this._onRouteLayer(route,layer));this._onRouteLoaded(route)},_onRouteLayer:function(route,layer){var polyline=layer;route.on("selected",L.bind(this._onRouteSelected,this,route,polyline));polyline.on("mouseover",L.bind(this._onRouteMouseOver,this,route,polyline));polyline.on("mouseout",L.bind(this._onRouteMouseOut,this,route,polyline));polyline.on("click",L.bind(this._onRouteClick,this,route,polyline));polyline.bindTooltip(route.options.name,{direction:"auto",sticky:true})},highlight:function(route,
|
|
11
|
+
polyline){polyline.setStyle(this.options.highlight);if(this.options.distanceMarkers)polyline.addDistanceMarkers()},unhighlight:function(route,polyline){polyline.setStyle(route.options.originalStyle);if(this.options.distanceMarkers)polyline.removeDistanceMarkers()},_onRouteMouseOver:function(route,polyline){if(!route.isSelected()){this.highlight(route,polyline);if(this.options.legend){this.setSelection(route);L.DomUtil.get("legend_"+route._leaflet_id).parentNode.previousSibling.click()}}this.fire("route_mouseover",
|
|
12
|
+
{route:route,polyline:polyline})},_onRouteMouseOut:function(route,polyline){if(!route.isSelected())this.unhighlight(route,polyline);this.fire("route_mouseout",{route:route,polyline:polyline})},_onRouteClick:function(route,polyline){this.setSelection(route)},_onRouteSelected:function(route,polyline){if(!route.isSelected())this.unhighlight(route,polyline)},_onRouteLoaded:function(route){if(this.options.legend)this._legend.addBaseLayer(route,'<svg id="legend_'+route._leaflet_id+'" width="25" height="10" version="1.1" xmlns="http://www.w3.org/2000/svg">'+
|
|
13
|
+
'<line x1="0" x2="50" y1="5" y2="5" stroke="'+route.options.originalStyle.color+'" fill="transparent" stroke-width="5" /></svg>'+" "+route.options.name);this.fire("route_loaded",{route:route});if(++this._loadedCount===this._tracks.length){this.fire("loaded");if(this.options.flyToBounds)this._map.flyToBounds(this.getBounds(),{duration:.25,easeLinearity:.25,noMoveStart:true});if(this.options.legend)this._legend.addTo(this._map)}},_onSelectionChanged:function(e){var elevation=this._elevation;var eleDiv=
|
|
14
|
+
elevation.getContainer();var route=this.getSelection();elevation.clear();if(route&&route.isSelected()){if(!eleDiv)elevation.loadChart(this._map);route.getLayers().forEach(function(layer){if(layer instanceof L.Polyline){elevation.addData(layer,false);layer.bringToFront()}})}else if(eleDiv)elevation.remove()},_onLegendSelected:function(e){var layers=this._layers._layers;var route=e.layer;if(!route.isSelected()){this.setSelection(route);for(var i in route._layers)this.highlight(route,route._layers[i]);
|
|
15
|
+
this._map.flyToBounds(e.layer.getBounds())}var parent=e.input.closest(".leaflet-control-layers-list");var offset=e.input.offsetTop-parent.offsetTop;parent.scroll({top:offset||0,behavior:"smooth"});for(var j in layers){var selected=layers[j].isSelected();var legend=L.DomUtil.get("legend_"+layers[j]._leaflet_id);legend.querySelector("line").style.stroke=selected?this.options.highlight.color:"";legend.parentNode.style.fontWeight=selected?"700":""}},_uniqueColors:function(count){if(count===0)return[];
|
|
16
|
+
if(count===1)return["#0000ff"];var increment=1/count;var colors=[];for(var i=0;i<count;++i){var hue=i*increment;var rgb=this._hsvToRgb(hue,1,.7);var hex="#"+this._rgbToHex(rgb[0],rgb[1],rgb[2]);colors.push(hex)}return colors},_hsvToRgb:function(h,s,v){var r,g,b;var i=Math.floor(h*6);var f=h*6-i;var p=v*(1-s);var q=v*(1-f*s);var t=v*(1-(1-f)*s);switch(i%6){case 0:r=v;g=t;b=p;break;case 1:r=q;g=v;b=p;break;case 2:r=p;g=v;b=t;break;case 3:r=p;g=q;b=v;break;case 4:r=t;g=p;b=v;break;case 5:r=v;g=p;b=q;
|
|
17
|
+
break}return[r*255,g*255,b*255]},_rgbToHex:function(r,g,b){return this._byteToHex(r)+this._byteToHex(g)+this._byteToHex(b)},_byteToHex:function(n){return(n>>4&15).toString(16)+(n&15).toString(16)},removeFrom:function(map){this._layers.removeFrom(map)}});L.GpxGroup.include(L.Mixin.Events);L.GpxGroup.include(L.Mixin.Selection);L.gpxGroup=function(tracks,options){return new L.GpxGroup(tracks,options)};
|
package/package.json
CHANGED
package/src/components.js
CHANGED
|
@@ -161,7 +161,7 @@ export const HeightFocusMarker = ({
|
|
|
161
161
|
|
|
162
162
|
export const LegendItem = ({
|
|
163
163
|
name,
|
|
164
|
-
|
|
164
|
+
label,
|
|
165
165
|
width,
|
|
166
166
|
height,
|
|
167
167
|
margins = {},
|
|
@@ -506,6 +506,12 @@ export const Chart = ({
|
|
|
506
506
|
|
|
507
507
|
g.attr("transform", "translate(" + margins.left + "," + margins.top + ")");
|
|
508
508
|
|
|
509
|
+
// Partially fix: https://github.com/Raruto/leaflet-elevation/issues/123
|
|
510
|
+
if(/Mac|iPod|iPhone|iPad/.test(navigator.platform) && /AppleWebkit/i.test(navigator.userAgent)) {
|
|
511
|
+
canvas
|
|
512
|
+
.style("transform", "translate(" + margins.left + "px," + margins.top + "px)");
|
|
513
|
+
}
|
|
514
|
+
|
|
509
515
|
clipRect
|
|
510
516
|
.attr("x", 0)
|
|
511
517
|
.attr("y", 0)
|
package/src/control.js
CHANGED
|
@@ -17,13 +17,13 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
17
17
|
__TOGEOJSON: 'https://unpkg.com/@tmcw/togeojson@4.3.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.7.
|
|
20
|
+
__LDISTANCEM: 'https://unpkg.com/@raruto/leaflet-elevation@1.7.5/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
|
|
24
24
|
*/
|
|
25
25
|
addData: function(d, layer) {
|
|
26
|
-
if (
|
|
26
|
+
if (typeof layer === "undefined" && d.on) {
|
|
27
27
|
layer = d;
|
|
28
28
|
}
|
|
29
29
|
Elevation._d3LazyLoader = _.lazyLoader(
|
|
@@ -70,7 +70,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
70
70
|
|
|
71
71
|
_clearChart: function() {
|
|
72
72
|
if (this._events && this._events.elechart_updated) {
|
|
73
|
-
this._events.elechart_updated.forEach(e =>
|
|
73
|
+
this._events.elechart_updated.forEach(e => this.off('elechart_updated', e.fn, e.ctx));
|
|
74
74
|
}
|
|
75
75
|
if (this._chart && this._chart._container) {
|
|
76
76
|
this._chart._container.selectAll('g.point .point').remove();
|
|
@@ -196,6 +196,8 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
196
196
|
// this._updateSummary = _.debounce(this._updateSummary, 300, this);
|
|
197
197
|
// }
|
|
198
198
|
|
|
199
|
+
if (this.options.wptIcons === true) this.options.wptIcons = Options.wptIcons;
|
|
200
|
+
|
|
199
201
|
// Leaflet canvas renderer colors
|
|
200
202
|
L.extend(D3.Colors, this.options.colors || {});
|
|
201
203
|
},
|
|
@@ -448,7 +450,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
448
450
|
*/
|
|
449
451
|
_addGPXData: function(coords) {
|
|
450
452
|
_.each(coords, point => {
|
|
451
|
-
this._addPoint(point.lat, point.lng, point.meta.ele);
|
|
453
|
+
this._addPoint(point.lat, point.lng, typeof point.alt !== "undefined" ? point.alt : point.meta.ele);
|
|
452
454
|
this._fireEvt("elepoint_added", { point: point, index: this._data.length - 1 });
|
|
453
455
|
});
|
|
454
456
|
this._fireEvt("eletrack_added", { coords: coords, index: this._data.length - 1 });
|
package/src/options.js
CHANGED
package/src/utils.js
CHANGED
|
@@ -73,13 +73,13 @@ export function GeoJSONLoader(data, control) {
|
|
|
73
73
|
}
|
|
74
74
|
control = control || this;
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
let distanceMarkers = (
|
|
77
77
|
control.options.distanceMarkers === true
|
|
78
78
|
? { lazy: true }
|
|
79
79
|
: L.extend({ lazy: true }, control.options.distanceMarkers)
|
|
80
80
|
);
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
let { wptIcons, wptLabels } = control.options;
|
|
83
83
|
|
|
84
84
|
let layer = L.geoJson(data, {
|
|
85
85
|
distanceMarkers: distanceMarkers,
|
|
@@ -94,24 +94,36 @@ export function GeoJSONLoader(data, control) {
|
|
|
94
94
|
if (!control.options.waypoints) return;
|
|
95
95
|
|
|
96
96
|
let prop = feature.properties;
|
|
97
|
-
let desc = prop.desc
|
|
98
|
-
let name = prop.name
|
|
99
|
-
let sym = (prop.sym
|
|
100
|
-
|
|
101
|
-
//
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
|
|
97
|
+
let desc = prop.desc ?? '';
|
|
98
|
+
let name = prop.name ?? '';
|
|
99
|
+
let sym = (prop.sym ?? name).replace(' ', '-').replace('"', '').replace("'", '').toLowerCase();
|
|
100
|
+
|
|
101
|
+
// Handle chart waypoints (dots)
|
|
102
|
+
if ([true, 'dots'].includes(control.options.waypoints)) {
|
|
103
|
+
control._registerCheckPoint({
|
|
104
|
+
latlng: latlng,
|
|
105
|
+
label: ([true, 'dots'].includes(wptLabels) ? name : '')
|
|
106
|
+
},
|
|
107
|
+
true
|
|
105
108
|
);
|
|
106
109
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
|
|
111
|
+
// Handle map waypoints (markers)
|
|
112
|
+
if ([true, 'markers'].includes(control.options.waypoints) && wptIcons != false) {
|
|
113
|
+
// generate and cache appropriate icon symbol
|
|
114
|
+
if (!wptIcons.hasOwnProperty(sym)) {
|
|
115
|
+
wptIcons[sym] = L.divIcon(
|
|
116
|
+
L.extend({}, wptIcons[""].options, { html: '<i class="elevation-waypoint-icon ' + sym + '"></i>' } )
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
let marker = L.marker(latlng, { icon: wptIcons[sym] });
|
|
120
|
+
if ([true, 'markers'].includes(wptLabels) && (name || desc)) {
|
|
121
|
+
marker.bindPopup("<b>" + name + "</b>" + (desc.length > 0 ? '<br>' + desc : '')).openPopup();
|
|
122
|
+
}
|
|
123
|
+
control._addMarker(marker);
|
|
124
|
+
control.fire('waypoint_added', { point: marker, element: latlng, properties: prop });
|
|
125
|
+
return marker;
|
|
110
126
|
}
|
|
111
|
-
control._addMarker(marker);
|
|
112
|
-
control._registerCheckPoint({latlng: latlng, label: name}, true);
|
|
113
|
-
control.fire('waypoint_added', { point: marker, element: latlng, properties: prop });
|
|
114
|
-
return marker;
|
|
115
127
|
},
|
|
116
128
|
onEachFeature: (feature, layer) => {
|
|
117
129
|
if (feature.geometry && feature.geometry.type == 'Point') return;
|
|
@@ -138,12 +150,12 @@ export function GeoJSONLoader(data, control) {
|
|
|
138
150
|
|
|
139
151
|
// Postpone adding the distance markers (lazy: true)
|
|
140
152
|
if(control.options.distanceMarkers && distanceMarkers.lazy) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
153
|
+
layer.on('add remove', (e) => {
|
|
154
|
+
let path = e.target;
|
|
155
|
+
if (L.DistanceMarkers && path instanceof L.Polyline) {
|
|
144
156
|
path[e.type + 'DistanceMarkers']();
|
|
145
|
-
|
|
146
|
-
|
|
157
|
+
}
|
|
158
|
+
});
|
|
147
159
|
}
|
|
148
160
|
|
|
149
161
|
control.track_info = L.extend({}, control.track_info, { type: "geojson", name: data.name });
|
|
@@ -318,8 +330,8 @@ export function toggleClass(targetNode, className, conditional) {
|
|
|
318
330
|
}
|
|
319
331
|
|
|
320
332
|
export function replaceClass(targetNode, removeClassName, addClassName) {
|
|
321
|
-
|
|
322
|
-
|
|
333
|
+
if (removeClassName) removeClass(targetNode, removeClassName);
|
|
334
|
+
if (addClassName) addClass(targetNode, addClassName);
|
|
323
335
|
}
|
|
324
336
|
|
|
325
337
|
export function style(targetNode, name, value) {
|
|
@@ -328,7 +340,7 @@ export function style(targetNode, name, value) {
|
|
|
328
340
|
}
|
|
329
341
|
|
|
330
342
|
export function toggleStyle(targetNode, name, value, conditional) {
|
|
331
|
-
|
|
343
|
+
return style(targetNode, name, conditional ? value : '');
|
|
332
344
|
}
|
|
333
345
|
|
|
334
346
|
export function toggleEvent(leafletElement, eventName, handler, conditional) {
|