@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.
- package/README.md +7 -5
- package/dist/leaflet-elevation.css +52 -161
- package/dist/leaflet-elevation.js +1550 -3884
- package/dist/leaflet-elevation.js.map +1 -1
- package/dist/leaflet-elevation.min.css +1 -1
- package/dist/leaflet-elevation.min.js +1 -3
- package/dist/leaflet-elevation.min.js.map +1 -1
- package/images/checkered.png +0 -0
- package/libs/leaflet-distance-marker.js +97 -92
- package/libs/leaflet-distance-marker.min.js +1 -1
- package/libs/leaflet-gpxgroup.js +2 -2
- package/package.json +9 -11
- package/src/{chart.js → components/chart.js} +147 -144
- package/src/{components.js → components/d3.js} +43 -71
- package/src/{marker.js → components/marker.js} +11 -14
- package/src/{summary.js → components/summary.js} +4 -5
- package/src/control.js +492 -434
- package/src/handlers/acceleration.js +64 -0
- package/src/handlers/altitude.js +79 -0
- package/src/handlers/cadence.js +54 -0
- package/src/handlers/distance.js +45 -0
- package/src/handlers/heart.js +53 -0
- package/src/handlers/slope.js +79 -0
- package/src/handlers/speed.js +66 -0
- package/src/{time.js → handlers/time.js} +31 -54
- package/src/index.css +52 -161
- package/src/index.js +0 -24
- package/src/options.js +20 -28
- package/src/utils.js +74 -102
- package/src/acceleration.js +0 -113
- package/src/altitude.js +0 -119
- package/src/distance.js +0 -69
- package/src/slope.js +0 -129
- package/src/speed.js +0 -118
|
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
|
-
//
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
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(
|
|
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)}});
|
package/libs/leaflet-gpxgroup.js
CHANGED
|
@@ -189,7 +189,7 @@ L.GpxGroup = L.Class.extend({
|
|
|
189
189
|
});
|
|
190
190
|
|
|
191
191
|
|
|
192
|
-
this._elevation.
|
|
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.
|
|
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": "
|
|
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": "^
|
|
53
|
-
"rollup": "^2.
|
|
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": "^
|
|
54
|
+
"rollup-plugin-postcss": "^4.0.2",
|
|
58
55
|
"rollup-plugin-terser": "^7.0.2"
|
|
59
56
|
},
|
|
60
57
|
"peerDependencies": {
|
|
61
|
-
"leaflet": "^1.
|
|
62
|
-
"
|
|
63
|
-
"
|
|
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
|
}
|