@raruto/leaflet-elevation 2.0.3 → 2.0.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 -3
- package/dist/leaflet-elevation.css +114 -138
- package/dist/leaflet-elevation.js +30 -46
- package/dist/leaflet-elevation.js.map +1 -1
- package/dist/leaflet-elevation.min.css +1 -1
- package/dist/leaflet-elevation.min.js +1 -1
- package/dist/leaflet-elevation.min.js.map +1 -1
- package/images/elevation-steelblue.svg +1 -1
- package/libs/fullpage.css +13 -0
- package/libs/leaflet-gpxgroup.js +1 -1
- package/libs/leaflet-gpxgroup.min.js +1 -1
- package/package.json +1 -1
- package/src/components/chart.js +17 -13
- package/src/components/d3.js +0 -1
- package/src/control.js +21 -37
- package/src/handlers/altitude.js +1 -1
- package/src/index.css +114 -138
- package/src/options.js +9 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 26 26"><defs/><path fill="#4682b4" fill-opacity=".8" d="M23.1 20.8l-4.2-8-3.9-.2-2.7 1.8-2.4-5.5-5.2 6.2v5.7" opacity=".9"/><path fill="none" stroke="#174a75" stroke-width="1.5" d="M4.7 14.8h1.1l4.3-6.2 2.5 5.6 2.5-2.3 3.7.2 4 8.3v.4"/><path fill="none" stroke="#737373" stroke-linecap="square" d="M3.4 5v19.8M24.7 22.4H.9"/></svg>
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="26" height="26" viewBox="0 0 26 26"><defs/><path fill="#4682b4" fill-opacity=".8" d="M23.1 20.8l-4.2-8-3.9-.2-2.7 1.8-2.4-5.5-5.2 6.2v5.7" opacity=".9"/><path fill="none" stroke="#174a75" stroke-width="1.5" d="M4.7 14.8h1.1l4.3-6.2 2.5 5.6 2.5-2.3 3.7.2 4 8.3v.4"/><path fill="none" stroke="#737373" stroke-linecap="square" d="M3.4 5v19.8M24.7 22.4H.9"/></svg>
|
package/libs/leaflet-gpxgroup.js
CHANGED
|
@@ -164,7 +164,7 @@ L.GpxGroup = L.Class.extend({
|
|
|
164
164
|
.then(text => this._elevation._parseFromString(text))
|
|
165
165
|
.then(geojson => {
|
|
166
166
|
if(geojson) {
|
|
167
|
-
geojson.name = geojson.name
|
|
167
|
+
geojson.name = geojson.name || (geojson[0] && geojson[0].properties.name) || track.split('/').pop().split('#')[0].split('?')[0];
|
|
168
168
|
this._loadRoute(geojson);
|
|
169
169
|
}
|
|
170
170
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
L.Mixin.Selectable={includes:L.Mixin.Events,setSelected:function(s){var selected=!!s;this._selected!==selected&&(this._selected=selected,this.fire("selected"))},isSelected:function(){return!!this._selected}},L.Mixin.Selection={includes:L.Mixin.Events,getSelection:function(){return this._selected},setSelection:function(item){this._selected===item?null!==item&&(item.setSelected(!item.isSelected()),item.isSelected()||(this._selected=null)):(this._selected&&this._selected.setSelected(!1),this._selected=item,this._selected&&this._selected.setSelected(!0)),this.fire("selection_changed")}},L.Control.LayersLegend=L.Control.Layers.extend({_onInputClick:function(){
|
|
1
|
+
L.Mixin.Selectable={includes:L.Mixin.Events,setSelected:function(s){var selected=!!s;this._selected!==selected&&(this._selected=selected,this.fire("selected"))},isSelected:function(){return!!this._selected}},L.Mixin.Selection={includes:L.Mixin.Events,getSelection:function(){return this._selected},setSelection:function(item){this._selected===item?null!==item&&(item.setSelected(!item.isSelected()),item.isSelected()||(this._selected=null)):(this._selected&&this._selected.setSelected(!1),this._selected=item,this._selected&&this._selected.setSelected(!0)),this.fire("selection_changed")}},L.Control.LayersLegend=L.Control.Layers.extend({_onInputClick:function(){this._handlingClick=!0,this._layerControlInputs.reduceRight((_,input)=>{if(input.checked)return this._map.fireEvent("legend_selected",{layer:this._getLayer(input.layerId).layer,input:input},!0),input},0),this._handlingClick=!1,this._refocusOnMap()}}),L.control.layersLegend=(baseLayers,overlays,options)=>new L.Control.LayersLegend(baseLayers,overlays,options),L.GeoJSON.include(L.Mixin.Selectable),L.GpxGroup=L.Class.extend({options:{highlight:{color:"#ff0",opacity:1},points:[],points_options:{icon:{iconUrl:"../images/elevation-poi.png",iconSize:[12,12]}},flyToBounds:!0,legend:!1,legend_options:{position:"topright",collapsed:!1},elevation:!0,elevation_options:{theme:"yellow-theme",detached:!0,elevationDiv:"#elevation-div"},distanceMarkers:!0,distanceMarkers_options:{lazy:!0}},initialize:function(tracks,options){L.Util.setOptions(this,options),this._count=0,this._loadedCount=0,this._tracks=tracks,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),this.options.points.forEach(poi=>L.marker(poi.latlng,{icon:L.icon(this.options.points_options.icon)}).bindTooltip(poi.name,{direction:"auto"}).addTo(this._markers))},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=>response.ok&&response.text()).then(text=>this._elevation._parseFromString(text)).then(geojson=>{geojson&&(geojson.name=geojson.name||geojson[0]&&geojson[0].properties.name||track.split("/").pop().split("#")[0].split("?")[0],this._loadRoute(geojson))})},_loadRoute:function(data){if(data){var line_style={color:this._uniqueColors(this._tracks.length)[this._count++],opacity:.75,weight:5,distanceMarkers:this.options.distanceMarkers_options},route=L.geoJson(data,{name:data.name||"",style:feature=>line_style,distanceMarkers:line_style.distanceMarkers,originalStyle:line_style,filter:feature=>"Point"!=feature.geometry.type});this._elevation.import(this._elevation.__LGEOMUTIL).then(()=>{route.addTo(this._layers),route.eachLayer(layer=>this._onEachRouteLayer(route,layer)),this._onEachRouteLoaded(route)})}},_onEachRouteLayer: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:!0})},_onEachRouteLoaded:function(route){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"><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}),++this._loadedCount===this._tracks.length&&(this.fire("loaded"),this.options.flyToBounds&&this._map.flyToBounds(this.getBounds(),{duration:.25,easeLinearity:.25,noMoveStart:!0}),this.options.legend&&this._legend.addTo(this._map))},highlight:function(route,polyline){polyline.setStyle(this.options.highlight),this.options.distanceMarkers&&polyline.addDistanceMarkers()},unhighlight:function(route,polyline){polyline.setStyle(route.options.originalStyle),this.options.distanceMarkers&&polyline.removeDistanceMarkers()},_onRouteMouseOver:function(route,polyline){route.isSelected()||(this.highlight(route,polyline),this.options.legend&&(this.setSelection(route),L.DomUtil.get("legend_"+route._leaflet_id).parentNode.previousSibling.click())),this.fire("route_mouseover",{route:route,polyline:polyline})},_onRouteMouseOut:function(route,polyline){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){route.isSelected()||this.unhighlight(route,polyline)},_onSelectionChanged:function(e){var elevation=this._elevation,eleDiv=elevation.getContainer(),route=this.getSelection();elevation.clear(),route&&route.isSelected()?(eleDiv||elevation.addTo(this._map),route.getLayers().forEach((function(layer){layer instanceof L.Polyline&&(elevation.addData(layer,!1),layer.bringToFront())}))):eleDiv&&elevation.remove()},_onLegendSelected:function(e){var parent=e.input.closest(".leaflet-control-layers-list"),route=e.layer;if(!route.isSelected()){for(var i in this.setSelection(route),route._layers)this.highlight(route,route._layers[i]);this._map.flyToBounds(e.layer.getBounds())}parent.scroll({top:e.input.offsetTop-parent.offsetTop||0,behavior:"smooth"}),this._layers.eachLayer(layer=>{var legend=L.DomUtil.get("legend_"+layer._leaflet_id);legend.querySelector("line").style.stroke=layer.isSelected()?this.options.highlight.color:"",legend.parentNode.style.fontWeight=layer.isSelected()?"700":""})},_uniqueColors:function(count){return 1===count?["#0000ff"]:new Array(count).fill(null).map((_,i)=>this._hsvToHex(i*(1/count),1,.7))},_hsvToHex:function(h,s,v){var i=Math.floor(6*h),f=6*h-i,p=v*(1-s),q=v*(1-f*s),t=v*(1-(1-f)*s),rgb;return{0:[v,t,p],1:[q,v,p],2:[p,v,t],3:[p,q,v],4:[t,p,v],5:[v,p,q]}[i%6].map(d=>255*d).reduce((hex,byte)=>hex+(byte>>4&15).toString(16)+(15&byte).toString(16),"#")},removeFrom:function(map){this._layers.removeFrom(map)}}),L.GpxGroup.include(L.Mixin.Events),L.GpxGroup.include(L.Mixin.Selection),L.gpxGroup=(tracks,options)=>new L.GpxGroup(tracks,options);
|
package/package.json
CHANGED
package/src/components/chart.js
CHANGED
|
@@ -351,7 +351,7 @@ export var Chart = L.Control.Elevation.Chart = L.Class.extend({
|
|
|
351
351
|
if (typeof props.preferCanvas === "undefined") props.preferCanvas = opts.preferCanvas;
|
|
352
352
|
|
|
353
353
|
// Save paths in memory for latter usage
|
|
354
|
-
this._paths[props.name] = D3.Path(props)
|
|
354
|
+
this._paths[props.name] = D3.Path(props);
|
|
355
355
|
this._props.areas[props.name] = props;
|
|
356
356
|
|
|
357
357
|
if (opts.legend) {
|
|
@@ -555,6 +555,8 @@ export var Chart = L.Control.Elevation.Chart = L.Class.extend({
|
|
|
555
555
|
|
|
556
556
|
// Reset legend items
|
|
557
557
|
this._legend.selectAll('g').remove();
|
|
558
|
+
|
|
559
|
+
// Render legend items
|
|
558
560
|
_.each(this._props.legendItems, (legend) => {
|
|
559
561
|
this._legend.append("g").call(
|
|
560
562
|
D3.LegendItem(L.extend({
|
|
@@ -565,18 +567,20 @@ export var Chart = L.Control.Elevation.Chart = L.Class.extend({
|
|
|
565
567
|
);
|
|
566
568
|
});
|
|
567
569
|
|
|
568
|
-
//
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
570
|
+
// Render legend item switcher
|
|
571
|
+
if (n > 1) {
|
|
572
|
+
this._legend.append("g").call(
|
|
573
|
+
D3.LegendSmall({
|
|
574
|
+
width : this._width(),
|
|
575
|
+
height : this._height(),
|
|
576
|
+
items : items,
|
|
577
|
+
onClick: (selected) => {
|
|
578
|
+
_.each(items, name => this._togglePath(name, selected == name, true));
|
|
579
|
+
this._updateArea();
|
|
580
|
+
}
|
|
581
|
+
})
|
|
582
|
+
);
|
|
583
|
+
}
|
|
580
584
|
|
|
581
585
|
_.each(items, (name, i) => {
|
|
582
586
|
// Adjust legend item positions
|
package/src/components/d3.js
CHANGED
|
@@ -205,7 +205,6 @@ export const LegendItem = ({
|
|
|
205
205
|
.text(L._(label || name))
|
|
206
206
|
.attr("x", (width / 2) + 5)
|
|
207
207
|
.attr("font-size", 10)
|
|
208
|
-
.style("text-decoration-thickness", "2px")
|
|
209
208
|
.style("font-weight", "700")
|
|
210
209
|
.attr('y', height + margins.bottom / 2)
|
|
211
210
|
.attr('dy', "0.75em");
|
package/src/control.js
CHANGED
|
@@ -7,8 +7,8 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
7
7
|
includes: L.Evented ? L.Evented.prototype : L.Mixin.Events,
|
|
8
8
|
|
|
9
9
|
options: Options,
|
|
10
|
-
__mileFactor:
|
|
11
|
-
__footFactor:
|
|
10
|
+
__mileFactor: 0.621371, // 1 km = (0.621371 mi)
|
|
11
|
+
__footFactor: 3.28084, // 1 m = (3.28084 ft)
|
|
12
12
|
__D3: 'https://unpkg.com/d3@6.5.0/dist/d3.min.js',
|
|
13
13
|
__TOGEOJSON: 'https://unpkg.com/@tmcw/togeojson@4.6.0/dist/togeojson.umd.js',
|
|
14
14
|
__LGEOMUTIL: 'https://unpkg.com/leaflet-geometryutil@0.9.3/src/leaflet.geometryutil.js',
|
|
@@ -37,9 +37,9 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
37
37
|
*/
|
|
38
38
|
addTo: function(map) {
|
|
39
39
|
if (this.options.detached) {
|
|
40
|
-
let
|
|
41
|
-
|
|
42
|
-
_.append(
|
|
40
|
+
let parent = _.select(this.options.elevationDiv);
|
|
41
|
+
let eleDiv = this.onAdd(map);
|
|
42
|
+
parent ? _.append(parent, eleDiv) : _.insert(map.getContainer(), eleDiv, 'afterend');
|
|
43
43
|
} else {
|
|
44
44
|
L.Control.prototype.addTo.call(this, map);
|
|
45
45
|
}
|
|
@@ -221,7 +221,9 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
221
221
|
onAdd: function(map) {
|
|
222
222
|
this._map = map;
|
|
223
223
|
|
|
224
|
-
let container = this._container = _.create("div", "elevation-control
|
|
224
|
+
let container = this._container = _.create("div", "elevation-control " + this.options.theme + " " + (this.options.detached ? 'elevation-detached' : 'leaflet-control'), this.options.detached ? { id: 'elevation-' + _.randomId() } : {});
|
|
225
|
+
|
|
226
|
+
if (!this.eleDiv) this.eleDiv = container;
|
|
225
227
|
|
|
226
228
|
let modules = [
|
|
227
229
|
"Distance",
|
|
@@ -413,21 +415,6 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
413
415
|
}
|
|
414
416
|
},
|
|
415
417
|
|
|
416
|
-
/**
|
|
417
|
-
* Adds the control to the given "detached" div.
|
|
418
|
-
*/
|
|
419
|
-
_initElevationDiv: function() {
|
|
420
|
-
let eleDiv = _.select(this.options.elevationDiv);
|
|
421
|
-
if (!eleDiv) {
|
|
422
|
-
this.options.elevationDiv = '#elevation-div_' + _.randomId();
|
|
423
|
-
eleDiv = _.create('div', 'leaflet-control elevation elevation-div', { id: this.options.elevationDiv.substr(1) });
|
|
424
|
-
}
|
|
425
|
-
if (this.options.detached) {
|
|
426
|
-
_.replaceClass(eleDiv, 'leaflet-control', 'elevation-detached');
|
|
427
|
-
}
|
|
428
|
-
return this.eleDiv = eleDiv;
|
|
429
|
-
},
|
|
430
|
-
|
|
431
418
|
/**
|
|
432
419
|
* Initialize "L.AlmostOver" and "L.DistanceMarkers"
|
|
433
420
|
*/
|
|
@@ -446,6 +433,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
446
433
|
} else if (control.options.polyline) {
|
|
447
434
|
layer.addTo(map);
|
|
448
435
|
}
|
|
436
|
+
map.invalidateSize();
|
|
449
437
|
} else {
|
|
450
438
|
console.warn("Undefined elevation map object");;
|
|
451
439
|
}
|
|
@@ -472,7 +460,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
472
460
|
let oldProto = L.Canvas.prototype._fillStroke;
|
|
473
461
|
let control = this;
|
|
474
462
|
|
|
475
|
-
let theme = this.options.theme.replace('-theme', '');
|
|
463
|
+
let theme = this.options.theme.split(' ')[0].replace('-theme', '');
|
|
476
464
|
let color = _.Colors[theme] || {};
|
|
477
465
|
|
|
478
466
|
L.Canvas.include({
|
|
@@ -657,23 +645,19 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
657
645
|
.disableScrollPropagation(container);
|
|
658
646
|
}
|
|
659
647
|
|
|
660
|
-
|
|
661
|
-
let link = this._button = _.create('a', "elevation-toggle elevation-toggle-icon" + (this.options.autohide ? "" : " close-button"), { href: '#', title: L._('Elevation') }, container);
|
|
648
|
+
this.options.collapsed ? this._collapse() : this._expand();
|
|
662
649
|
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
} else {
|
|
669
|
-
_.on(link, 'click', L.DomEvent.stop);
|
|
670
|
-
_.on(link, 'click', this._toggle, this);
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
_.on(link, 'focus', this._toggle, this);
|
|
650
|
+
if (this.options.autohide) {
|
|
651
|
+
_.on(container, 'mouseover', this._expand, this);
|
|
652
|
+
_.on(container, 'mouseout', this._collapse, this);
|
|
653
|
+
this._map.on('click', this._collapse, this);
|
|
654
|
+
}
|
|
674
655
|
|
|
675
|
-
|
|
676
|
-
}
|
|
656
|
+
if (this.options.closeBtn) {
|
|
657
|
+
let link = this._button = _.create('a', "elevation-toggle-icon", { href: '#', title: L._('Elevation'), }, container);
|
|
658
|
+
_.on(link, 'click', L.DomEvent.stop);
|
|
659
|
+
_.on(link, 'click', this._toggle, this);
|
|
660
|
+
_.on(link, 'focus', this._toggle, this);
|
|
677
661
|
}
|
|
678
662
|
},
|
|
679
663
|
|
package/src/handlers/altitude.js
CHANGED
|
@@ -5,7 +5,7 @@ export function Altitude() {
|
|
|
5
5
|
let opts = this.options;
|
|
6
6
|
let altitude = {};
|
|
7
7
|
|
|
8
|
-
let theme = opts.theme.replace('-theme', '');
|
|
8
|
+
let theme = opts.theme.split(' ')[0].replace('-theme', '');
|
|
9
9
|
let color = _.Colors[theme] || {};
|
|
10
10
|
|
|
11
11
|
opts.altitudeFactor = opts.imperial ? this.__footFactor : (opts.altitudeFactor || 1); // 1 m = (1 m)
|