@raruto/leaflet-elevation 1.7.3 → 1.7.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 +5 -2
- package/dist/leaflet-elevation.js +115 -96
- 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 +5 -2
- package/libs/leaflet-gpxgroup.min.js +10 -10
- package/package.json +1 -1
- package/src/control.js +3 -1
- package/src/options.js +1 -0
- package/src/utils.js +33 -19
package/libs/leaflet-gpxgroup.js
CHANGED
|
@@ -194,15 +194,17 @@ L.GpxGroup = L.Class.extend({
|
|
|
194
194
|
type = xml.documentElement.tagName == "TrainingCenterDatabase" ? 'tcx' : 'gpx';
|
|
195
195
|
}
|
|
196
196
|
geojson = toGeoJSON[type](xml);
|
|
197
|
-
geojson.name = name.length > 0 ? name
|
|
197
|
+
geojson.name = name.length > 0 ? Array.from(name).find(tag => tag.parentElement.tagName == "trk").textContent : '';
|
|
198
198
|
} catch (e) {
|
|
199
199
|
try {
|
|
200
200
|
geojson = JSON.parse(doc.toString());
|
|
201
|
-
geojson.name = geojson.name || '';
|
|
202
201
|
} catch (e) {
|
|
203
202
|
console.warn("Error parsing track: " + track);
|
|
204
203
|
}
|
|
205
204
|
}
|
|
205
|
+
if (!geojson.name) {
|
|
206
|
+
geojson.name = track.split('/').pop().split('#')[0].split('?')[0];
|
|
207
|
+
}
|
|
206
208
|
this._loadRoute(geojson);
|
|
207
209
|
});
|
|
208
210
|
}
|
|
@@ -227,6 +229,7 @@ L.GpxGroup = L.Class.extend({
|
|
|
227
229
|
style: (feature) => line_style,
|
|
228
230
|
distanceMarkers: line_style.distanceMarkers,
|
|
229
231
|
originalStyle: line_style,
|
|
232
|
+
filter: feature => feature.geometry.type != "Point",
|
|
230
233
|
});
|
|
231
234
|
|
|
232
235
|
route.addTo(this._layers);
|
|
@@ -5,13 +5,13 @@ L.control.layersLegend=function(baseLayers,overlays,options){return new L.Contro
|
|
|
5
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
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
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?name
|
|
9
|
-
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});route.addTo(this._layers);this._routes[route._leaflet_id]=route;route.eachLayer((layer)=>
|
|
10
|
-
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(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
|
-
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
|
-
'" 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
|
-
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
|
-
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
|
-
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
|
-
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)};
|
|
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/control.js
CHANGED
|
@@ -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
|
},
|
package/src/options.js
CHANGED
package/src/utils.js
CHANGED
|
@@ -79,7 +79,8 @@ export function GeoJSONLoader(data, control) {
|
|
|
79
79
|
: L.extend({ lazy: true }, control.options.distanceMarkers)
|
|
80
80
|
);
|
|
81
81
|
|
|
82
|
-
let wptIcons
|
|
82
|
+
let wptIcons = control.options.wptIcons;
|
|
83
|
+
let wptLabels = control.options.wptLabels;
|
|
83
84
|
|
|
84
85
|
let layer = L.geoJson(data, {
|
|
85
86
|
distanceMarkers: distanceMarkers,
|
|
@@ -94,24 +95,37 @@ export function GeoJSONLoader(data, control) {
|
|
|
94
95
|
if (!control.options.waypoints) return;
|
|
95
96
|
|
|
96
97
|
let prop = feature.properties;
|
|
97
|
-
let desc = prop.desc
|
|
98
|
-
let name = prop.name
|
|
99
|
-
let sym = (prop.sym
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
98
|
+
let desc = prop.desc ?? '';
|
|
99
|
+
let name = prop.name ?? '';
|
|
100
|
+
let sym = (prop.sym ?? name).replace(' ', '-').replace('"', '').replace("'", '').toLowerCase();
|
|
101
|
+
|
|
102
|
+
// Handle waypoint lables (markers and dots)
|
|
103
|
+
if (!wptLabels) {
|
|
104
|
+
name = '';
|
|
105
|
+
desc = '';
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Handle chart waypoints (dots)
|
|
109
|
+
if ([true, "dots"].includes(control.options.waypoints)) {
|
|
110
|
+
control._registerCheckPoint({latlng: latlng, label: name}, true);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Handle map waypoints (markers)
|
|
114
|
+
if ([true, "markers"].includes(control.options.waypoints) && wptIcons != false) {
|
|
115
|
+
// generate and cache appropriate icon symbol
|
|
116
|
+
if (!wptIcons.hasOwnProperty(sym)) {
|
|
117
|
+
wptIcons[sym] = L.divIcon(
|
|
118
|
+
L.extend({}, wptIcons[""].options, { html: '<i class="elevation-waypoint-icon ' + sym + '"></i>' } )
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
let marker = L.marker(latlng, { icon: wptIcons[sym] });
|
|
122
|
+
if (name || desc) {
|
|
123
|
+
marker.bindPopup("<b>" + name + "</b>" + (desc.length > 0 ? '<br>' + desc : '')).openPopup();
|
|
124
|
+
}
|
|
125
|
+
control._addMarker(marker);
|
|
126
|
+
control.fire('waypoint_added', { point: marker, element: latlng, properties: prop });
|
|
127
|
+
return marker;
|
|
128
|
+
}
|
|
115
129
|
},
|
|
116
130
|
onEachFeature: (feature, layer) => {
|
|
117
131
|
if (feature.geometry && feature.geometry.type == 'Point') return;
|