@raruto/leaflet-elevation 1.9.6 → 2.0.2

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.
Binary file
@@ -143,102 +143,107 @@ L.DistanceMarkers = L.LayerGroup.extend({
143
143
  // Get line coords as an array
144
144
  let coords = typeof line.getLatLngs == 'function' ? line.getLatLngs() : line;
145
145
 
146
- // Get accumulated line lengths as well as overall length
147
- let accumulated = L.GeometryUtil.accumulatedLengths(line);
148
- let length = accumulated.length > 0 ? accumulated[accumulated.length - 1] : 0;
149
-
150
- // count = Number of distance markers to be added
151
- // j = Position in accumulated line length array
152
- for (let i = 1, count = Math.floor(length / options.offset), j = 0; i <= count; ++i) {
153
-
154
- let distance = options.offset * i;
155
-
156
- // Find the first accumulated distance that is greater than the distance of this marker
157
- while (j < accumulated.length - 1 && accumulated[j] < distance) ++j;
158
-
159
- // Grab two nearest points either side marker position
160
- let p1 = coords[j - 1];
161
- let p2 = coords[j];
162
- let m_line = L.polyline([p1, p2]);
163
-
164
- // and create a simple line to interpolate on
165
- let ratio = (distance - accumulated[j - 1]) / (accumulated[j] - accumulated[j - 1]);
166
- let position = L.GeometryUtil.interpolateOnLine(map, m_line, ratio);
167
- let delta = map.project(p2).subtract(map.project(p1));
168
- let angle = Math.atan2(delta.y, delta.x);
169
-
170
- // Generate distance marker label
171
- let text = options.textFunction.call(this, distance, i, options.offset);
172
-
173
- // Grouping layer of visible layers at zoom level (arrow + distance)
174
- let zoom = this._minimumZoomLevelForItem(i, showAll);
175
- let markers = this._zoomLayers[zoom] = this._zoomLayers[zoom] || L.layerGroup()
176
-
177
- // create arrow markers
178
- if (options.direction && ((options.distance && i % 2 == 1) || !options.distance)) {
179
- if (preferCanvas) {
180
- markers.addLayer(
181
- new L.DistanceMarker(p1, {
182
- radius: 0,
183
- icon: {
184
- url: options.arrowUrl, //image link
185
- size: options.arrowSize, //image size ( default [40, 40] )
186
- rotate: 0, //image base rotate ( default 0 )
187
- offset: { x: 0, y: 0 }, //image offset ( default { x: 0, y: 0 } )
188
- },
189
- rotation: angle,
190
- interactive: false,
191
- // label: '⮞', //'➜',
192
- // font: 'normal 20pt "Helvetica Neue", Arial, Helvetica, sans-serif',
193
- // fillStyle: 'white',//'#3366CC',
194
- // strokeStyle: 'black',
195
- })
196
- );
197
- } else {
198
- markers.addLayer(
199
- L.marker(position.latLng, {
200
- icon: L.icon({
201
- iconUrl: options.arrowUrl,
202
- iconSize: options.arrowSize,
203
- }),
204
- // NB the following option is added by "leaflet-rotate"
205
- rotation: angle * L.DomUtil.RAD_TO_DEG,
206
- interactive: false,
207
- })
208
- );
146
+ // Handle "MultiLineString" features
147
+ coords = L.LineUtil.isFlat(coords) ? [coords] : coords;
148
+
149
+ coords.forEach(latlngs => {
150
+ // Get accumulated line lengths as well as overall length
151
+ let accumulated = L.GeometryUtil.accumulatedLengths(latlngs);
152
+ let length = accumulated.length > 0 ? accumulated[accumulated.length - 1] : 0;
153
+
154
+ // count = Number of distance markers to be added
155
+ // j = Position in accumulated line length array
156
+ for (let i = 1, count = Math.floor(length / options.offset), j = 0; i <= count; ++i) {
157
+
158
+ let distance = options.offset * i;
159
+
160
+ // Find the first accumulated distance that is greater than the distance of this marker
161
+ while (j < accumulated.length - 1 && accumulated[j] < distance) ++j;
162
+
163
+ // Grab two nearest points either side marker position
164
+ let p1 = latlngs[j - 1];
165
+ let p2 = latlngs[j];
166
+ let m_line = L.polyline([p1, p2]);
167
+
168
+ // and create a simple line to interpolate on
169
+ let ratio = (distance - accumulated[j - 1]) / (accumulated[j] - accumulated[j - 1]);
170
+ let position = L.GeometryUtil.interpolateOnLine(map, m_line, ratio);
171
+ let delta = map.project(p2).subtract(map.project(p1));
172
+ let angle = Math.atan2(delta.y, delta.x);
173
+
174
+ // Generate distance marker label
175
+ let text = options.textFunction.call(this, distance, i, options.offset);
176
+
177
+ // Grouping layer of visible layers at zoom level (arrow + distance)
178
+ let zoom = this._minimumZoomLevelForItem(i, showAll);
179
+ let markers = this._zoomLayers[zoom] = this._zoomLayers[zoom] || L.layerGroup()
180
+
181
+ // create arrow markers
182
+ if (options.direction && ((options.distance && i % 2 == 1) || !options.distance)) {
183
+ if (preferCanvas) {
184
+ markers.addLayer(
185
+ new L.DistanceMarker(p1, {
186
+ radius: 0,
187
+ icon: {
188
+ url: options.arrowUrl, //image link
189
+ size: options.arrowSize, //image size ( default [40, 40] )
190
+ rotate: 0, //image base rotate ( default 0 )
191
+ offset: { x: 0, y: 0 }, //image offset ( default { x: 0, y: 0 } )
192
+ },
193
+ rotation: angle,
194
+ interactive: false,
195
+ // label: '⮞', //'➜',
196
+ // font: 'normal 20pt "Helvetica Neue", Arial, Helvetica, sans-serif',
197
+ // fillStyle: 'white',//'#3366CC',
198
+ // strokeStyle: 'black',
199
+ })
200
+ );
201
+ } else {
202
+ markers.addLayer(
203
+ L.marker(position.latLng, {
204
+ icon: L.icon({
205
+ iconUrl: options.arrowUrl,
206
+ iconSize: options.arrowSize,
207
+ }),
208
+ // NB the following option is added by "leaflet-rotate"
209
+ rotation: angle * L.DomUtil.RAD_TO_DEG,
210
+ interactive: false,
211
+ })
212
+ );
213
+ }
209
214
  }
210
- }
211
215
 
212
- // create distance markers
213
- if (options.distance && i % 2 == 0) {
214
- if (preferCanvas) {
215
- markers.addLayer(
216
- new L.DistanceMarker(position.latLng, {
217
- label: text, // TODO: handle text rotation (leaflet-rotate)
218
- radius: 7,
219
- fillColor: '#fff',
220
- fillOpacity: 1,
221
- fillStyle: 'black',
222
- color: '#777',
223
- weight: 1,
224
- interactive: false,
225
- })
226
- );
227
- } else {
228
- markers.addLayer(
229
- L.marker(position.latLng, {
230
- title: text,
231
- icon: L.divIcon({
232
- className: options.cssClass,
233
- html: text,
234
- iconSize: options.iconSize
235
- }),
236
- interactive: false,
237
- })
238
- );
216
+ // create distance markers
217
+ if (options.distance && i % 2 == 0) {
218
+ if (preferCanvas) {
219
+ markers.addLayer(
220
+ new L.DistanceMarker(position.latLng, {
221
+ label: text, // TODO: handle text rotation (leaflet-rotate)
222
+ radius: 7,
223
+ fillColor: '#fff',
224
+ fillOpacity: 1,
225
+ fillStyle: 'black',
226
+ color: '#777',
227
+ weight: 1,
228
+ interactive: false,
229
+ })
230
+ );
231
+ } else {
232
+ markers.addLayer(
233
+ L.marker(position.latLng, {
234
+ title: text,
235
+ icon: L.divIcon({
236
+ className: options.cssClass,
237
+ html: text,
238
+ iconSize: options.iconSize
239
+ }),
240
+ interactive: false,
241
+ })
242
+ );
243
+ }
239
244
  }
240
245
  }
241
- }
246
+ });
242
247
 
243
248
  const updateMarkerVisibility = () => {
244
249
  let oldZoom = this._lastZoomLevel || 0;
@@ -1 +1 @@
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({options:{cssClass:"dist-marker",iconSize:[12,12],arrowSize:[10,10],arrowUrl:"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='%23000' stroke='%23FFF' d='M280,40L522,525L280,420L38,525z'/%3E%3C/svg%3E",offset:1e3,showAll:12,textFunction:(distance,i,offset)=>i,distance:!0,direction:!0},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),zoom=this._minimumZoomLevelForItem(i,showAll),markers=this._zoomLayers[zoom]=this._zoomLayers[zoom]||L.layerGroup();options.direction&&(options.distance&&i%2==1||!options.distance)&&(preferCanvas?markers.addLayer(new L.DistanceMarker(p1,{radius:0,icon:{url:options.arrowUrl,size:options.arrowSize,rotate:0,offset:{x:0,y:0}},rotation:angle,interactive:!1})):markers.addLayer(L.marker(position.latLng,{icon:L.icon({iconUrl:options.arrowUrl,iconSize:options.arrowSize}),rotation:angle*L.DomUtil.RAD_TO_DEG,interactive:!1}))),options.distance&&i%2==0&&(preferCanvas?markers.addLayer(new L.DistanceMarker(position.latLng,{label:text,radius:7,fillColor:"#fff",fillOpacity:1,fillStyle:"black",color:"#777",weight:1,interactive:!1})):markers.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)}});
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({options:{cssClass:"dist-marker",iconSize:[12,12],arrowSize:[10,10],arrowUrl:"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='%23000' stroke='%23FFF' d='M280,40L522,525L280,420L38,525z'/%3E%3C/svg%3E",offset:1e3,showAll:12,textFunction:(distance,i,offset)=>i,distance:!0,direction:!0},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;coords=L.LineUtil.isFlat(coords)?[coords]:coords,coords.forEach(latlngs=>{let accumulated=L.GeometryUtil.accumulatedLengths(latlngs),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=latlngs[j-1],p2=latlngs[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),zoom=this._minimumZoomLevelForItem(i,showAll),markers=this._zoomLayers[zoom]=this._zoomLayers[zoom]||L.layerGroup();options.direction&&(options.distance&&i%2==1||!options.distance)&&(preferCanvas?markers.addLayer(new L.DistanceMarker(p1,{radius:0,icon:{url:options.arrowUrl,size:options.arrowSize,rotate:0,offset:{x:0,y:0}},rotation:angle,interactive:!1})):markers.addLayer(L.marker(position.latLng,{icon:L.icon({iconUrl:options.arrowUrl,iconSize:options.arrowSize}),rotation:angle*L.DomUtil.RAD_TO_DEG,interactive:!1}))),options.distance&&i%2==0&&(preferCanvas?markers.addLayer(new L.DistanceMarker(position.latLng,{label:text,radius:7,fillColor:"#fff",fillOpacity:1,fillStyle:"black",color:"#777",weight:1,interactive:!1})):markers.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)}});
@@ -189,7 +189,7 @@ L.GpxGroup = L.Class.extend({
189
189
  });
190
190
 
191
191
 
192
- this._elevation.lazyLoad(this._elevation.__LGEOMUTIL).then(() => {
192
+ this._elevation.import(this._elevation.__LGEOMUTIL).then(() => {
193
193
  route.addTo(this._layers);
194
194
 
195
195
  route.eachLayer((layer) => this._onEachRouteLayer(route, layer));
@@ -279,7 +279,7 @@ L.GpxGroup = L.Class.extend({
279
279
 
280
280
  if (route && route.isSelected()) {
281
281
  if (!eleDiv) {
282
- elevation.loadChart(this._map);
282
+ elevation.addTo(this._map);
283
283
  }
284
284
  route.getLayers().forEach(function(layer) {
285
285
  if (layer instanceof L.Polyline) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raruto/leaflet-elevation",
3
- "version": "1.9.6",
3
+ "version": "2.0.2",
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",
@@ -45,24 +45,22 @@
45
45
  },
46
46
  "homepage": "https://github.com/Raruto/leaflet-elevation#readme",
47
47
  "devDependencies": {
48
- "@babel/core": "^7.10.2",
49
- "@babel/preset-env": "^7.10.2",
50
- "@rollup/plugin-babel": "^5.0.3",
51
48
  "postcss-copy": "^7.1.0",
52
- "postcss-import": "^12.0.1",
53
- "rollup": "^2.2.0",
49
+ "postcss-import": "^14.0.2",
50
+ "rollup": "^2.70.0",
54
51
  "rollup-plugin-commonjs": "^10.1.0",
55
52
  "rollup-plugin-git-version": "^0.3.1",
56
53
  "rollup-plugin-node-resolve": "^5.2.0",
57
- "rollup-plugin-postcss": "^2.5.0",
54
+ "rollup-plugin-postcss": "^4.0.2",
58
55
  "rollup-plugin-terser": "^7.0.2"
59
56
  },
60
57
  "peerDependencies": {
61
- "leaflet": "^1.6.0",
62
- "leaflet-gpx": "^1.5.0",
63
- "d3": "5.15.0"
58
+ "leaflet": "^1.7.0",
59
+ "d3": "6.5.0",
60
+ "@tmcw/togeojson": "4.6.0"
64
61
  },
65
62
  "dependencies": {
66
- "leaflet-i18n": "^0.3.1"
63
+ "leaflet-i18n": "^0.3.1",
64
+ "postcss": "^8.4.8"
67
65
  }
68
66
  }