@raruto/leaflet-elevation 1.8.2 → 1.8.3

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.
@@ -1,6 +1 @@
1
- 'use strict';L.DistanceMarkers=L.LayerGroup.extend({initialize:function(line,map,options){options=options||{};var offset=options.offset||1E3;var showAll=Math.min(map.getMaxZoom(),options.showAll||12);var cssClass=options.cssClass||"dist-marker";var iconSize=options.iconSize!==undefined?options.iconSize:[12,12];var textFunction=options.textFunction||function(distance,i,offset){return i};var zoomLayers={};var coords=line;if(typeof line.getLatLngs=="function")coords=line.getLatLngs();var accumulated=
2
- L.GeometryUtil.accumulatedLengths(line);var length=accumulated.length>0?accumulated[accumulated.length-1]:0;var j=0;var count=Math.floor(length/offset);for(var i=1;i<=count;++i){var distance=offset*i;while(j<accumulated.length-1&&accumulated[j]<distance)++j;var p1=coords[j-1];var p2=coords[j];var m_line=L.polyline([p1,p2]);var ratio=(distance-accumulated[j-1])/(accumulated[j]-accumulated[j-1]);var position=L.GeometryUtil.interpolateOnLine(map,m_line,ratio);var text=textFunction.call(this,distance,
3
- i,offset);var icon=L.divIcon({className:cssClass,html:text,iconSize:iconSize});var marker=L.marker(position.latLng,{title:text,icon:icon});var zoom=this._minimumZoomLevelForItem(i,showAll);if(zoomLayers[zoom]===undefined)zoomLayers[zoom]=L.layerGroup();zoomLayers[zoom].addLayer(marker)}var currentZoomLevel=0;var markerLayer=this;var updateMarkerVisibility=function(){var oldZoom=currentZoomLevel;var newZoom=currentZoomLevel=map.getZoom();if(newZoom>oldZoom)for(var i=oldZoom+1;i<=newZoom;++i){if(zoomLayers[i]!==
4
- undefined)markerLayer.addLayer(zoomLayers[i])}else if(newZoom<oldZoom)for(var i=oldZoom;i>newZoom;--i)if(zoomLayers[i]!==undefined)markerLayer.removeLayer(zoomLayers[i])};map.on("zoomend",updateMarkerVisibility);this._layers={};updateMarkerVisibility()},_minimumZoomLevelForItem:function(item,showAllLevel){var zoom=showAllLevel;var i=item;while(i>0&&i%2===0){--zoom;i=Math.floor(i/2)}return zoom}});
5
- L.Polyline.include({_originalOnAdd:L.Polyline.prototype.onAdd,_originalOnRemove:L.Polyline.prototype.onRemove,addDistanceMarkers:function(){if(this._map&&this._distanceMarkers)this._map.addLayer(this._distanceMarkers)},removeDistanceMarkers:function(){if(this._map&&this._distanceMarkers)this._map.removeLayer(this._distanceMarkers)},onAdd:function(map){this._originalOnAdd(map);var opts=this.options.distanceMarkers||{};if(this._distanceMarkers===undefined&&this.options.distanceMarkers)this._distanceMarkers=
6
- new L.DistanceMarkers(this,map,opts);if(opts.lazy===undefined||opts.lazy===false)this.addDistanceMarkers()},onRemove:function(map){this.removeDistanceMarkers();this._originalOnRemove(map)}});
1
+ L.DistanceMarkers=L.LayerGroup.extend({initialize:function(line,map,options){var offset=(options=options||{}).offset||1e3,showAll=Math.min(map.getMaxZoom(),options.showAll||12),cssClass=options.cssClass||"dist-marker",iconSize=void 0!==options.iconSize?options.iconSize:[12,12],textFunction=options.textFunction||function(distance,i,offset){return i},zoomLayers={},coords=line;"function"==typeof line.getLatLngs&&(coords=line.getLatLngs());for(var accumulated=L.GeometryUtil.accumulatedLengths(line),length=accumulated.length>0?accumulated[accumulated.length-1]:0,j=0,count=Math.floor(length/offset),i=1;i<=count;++i){for(var distance=offset*i;j<accumulated.length-1&&accumulated[j]<distance;)++j;var 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),text=textFunction.call(this,distance,i,offset),icon=L.divIcon({className:cssClass,html:text,iconSize:iconSize}),marker=L.marker(position.latLng,{title:text,icon:icon}),zoom=this._minimumZoomLevelForItem(i,showAll);void 0===zoomLayers[zoom]&&(zoomLayers[zoom]=L.layerGroup()),zoomLayers[zoom].addLayer(marker)}var currentZoomLevel=0,markerLayer=this,updateMarkerVisibility=function(){var oldZoom=currentZoomLevel,newZoom=currentZoomLevel=map.getZoom();if(newZoom>oldZoom)for(var i=oldZoom+1;i<=newZoom;++i)void 0!==zoomLayers[i]&&markerLayer.addLayer(zoomLayers[i]);else if(newZoom<oldZoom)for(var i=oldZoom;i>newZoom;--i)void 0!==zoomLayers[i]&&markerLayer.removeLayer(zoomLayers[i])};map.on("zoomend",updateMarkerVisibility),this._layers={},updateMarkerVisibility()},_minimumZoomLevelForItem:function(item,showAllLevel){for(var zoom=showAllLevel,i=item;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);var opts=this.options.distanceMarkers||{};void 0===this._distanceMarkers&&this.options.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raruto/leaflet-elevation",
3
- "version": "1.8.2",
3
+ "version": "1.8.3",
4
4
  "description": "A Leaflet plugin that allows to add elevation profiles using d3js",
5
5
  "main": "dist/leaflet-elevation.min.js",
6
6
  "module": "src/index.js",
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.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.8.2/libs/leaflet-distance-marker.min.js',
20
+ __LDISTANCEM: 'https://unpkg.com/@raruto/leaflet-elevation@1.8.3/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
package/src/utils.js CHANGED
@@ -58,6 +58,23 @@ export function GeoJSONLoader(data, control) {
58
58
 
59
59
  let { wptIcons, wptLabels } = control.options;
60
60
 
61
+ // Partially fix MultiLineStrings (trk > trkseg + trkseg) splitting them into seperate LineStrings (trk > trkseg, trk > trkseg)
62
+ data.features.forEach(d => {
63
+ if(d.type == 'Feature' && d.geometry.type == "MultiLineString") {
64
+ d.geometry.coordinates.forEach(coords => {
65
+ data.features.push({
66
+ type: 'Feature',
67
+ geometry: {
68
+ type: 'LineString',
69
+ coordinates: coords,
70
+ },
71
+ properties: d.properties
72
+ });
73
+ });
74
+ }
75
+ });
76
+ data.features = data.features.filter(d=> d.type && d.geometry.type != "MultiLineString");
77
+
61
78
  let layer = L.geoJson(data, {
62
79
  distanceMarkers: distanceMarkers,
63
80
  style: (feature) => {