@raruto/leaflet-elevation 2.2.8 → 2.3.1
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 +36 -5
- package/dist/leaflet-elevation.js +53 -33
- 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-edgescale.js +636 -0
- package/libs/leaflet-edgescale.min.js +1 -0
- package/package.json +72 -69
- package/src/control.js +20 -8
- package/src/options.js +4 -0
- package/src/utils.js +4 -0
- package/src/utils.spec.js +50 -0
package/README.md
CHANGED
|
@@ -35,8 +35,10 @@ _For a working example see one of the following demos:_
|
|
|
35
35
|
|
|
36
36
|
- [autohide map](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_hidden-map.html)
|
|
37
37
|
- [autohide chart](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_hidden-chart.html)
|
|
38
|
+
- [clear button](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_clear-button.html)
|
|
38
39
|
- [collapsible button](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_close-button.html)
|
|
39
40
|
- [custom summary](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_custom-summary.html)
|
|
41
|
+
- [edge scale control](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_edge-scale.html)
|
|
40
42
|
- [follow marker](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_follow-marker.html)
|
|
41
43
|
- [layer almostover](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_almost-over.html)
|
|
42
44
|
- [slope chart](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_slope-chart.html)
|
|
@@ -153,6 +155,9 @@ _For a working example see one of the following demos:_
|
|
|
153
155
|
|
|
154
156
|
// Toggle "leaflet-distance-markers" integration
|
|
155
157
|
distanceMarkers: false,
|
|
158
|
+
|
|
159
|
+
// Toggle "leaflet-edgescale" integration
|
|
160
|
+
edgeScale: false,
|
|
156
161
|
|
|
157
162
|
// Toggle "leaflet-hotline" integration
|
|
158
163
|
hotline: true,
|
|
@@ -195,19 +200,19 @@ _For a working example see one of the following demos:_
|
|
|
195
200
|
|
|
196
201
|
### Build Guide
|
|
197
202
|
|
|
198
|
-
|
|
203
|
+
Within your local development environment:
|
|
199
204
|
|
|
200
205
|
```shell
|
|
201
206
|
git clone git@github.com:Raruto/leaflet-elevation.git
|
|
202
207
|
cd ./leaflet-elevation
|
|
203
208
|
|
|
204
209
|
npm i # install dependencies
|
|
205
|
-
npm run
|
|
210
|
+
npm run dev # start dev server at: http://localhost:8080
|
|
206
211
|
npm run build # generate "dist" files (once)
|
|
207
|
-
npm run test # test "spec" files (once)
|
|
212
|
+
npm run test # test all "*.spec.js" files (once)
|
|
208
213
|
```
|
|
209
214
|
|
|
210
|
-
After that you can start developing inside the `src` and `test` folders (eg. open "http://localhost/
|
|
215
|
+
After that you can start developing inside the `src` and `test` folders (eg. open "http://localhost:8080/test" in your browser to preview changes). Check also [CONTRIBUTING.md](.github/CONTRIBUTING.md) file for some information about it.
|
|
211
216
|
|
|
212
217
|
### FAQ
|
|
213
218
|
|
|
@@ -254,8 +259,34 @@ var map = L.map('map', {
|
|
|
254
259
|
```
|
|
255
260
|
</details>
|
|
256
261
|
|
|
262
|
+
<details> <summary>3. How can I import this library as ES module?</summary>
|
|
263
|
+
|
|
264
|
+
Usually, when working with a js bundler like [Vite](https://vitest.dev/) or [Webpack](https://webpack.js.org/), you need to provide to this library the full path to some dynamically imported files from the [`srcFolder`](./src/):
|
|
265
|
+
|
|
266
|
+
```js
|
|
267
|
+
import './your-custom-style.css';
|
|
268
|
+
import 'leaflet/dist/leaflet.css';
|
|
269
|
+
import L from 'leaflet';
|
|
270
|
+
import '@raruto/leaflet-elevation/src/index.js';
|
|
271
|
+
import '@raruto/leaflet-elevation/src/index.css';
|
|
272
|
+
|
|
273
|
+
const map = L.map('map', {
|
|
274
|
+
center: [35.681, 139.767],
|
|
275
|
+
zoom: 11,
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
const controlElevation = L.control.elevation({
|
|
279
|
+
srcFolder: 'http://unpkg.com/@raruto/leaflet-elevation/src/' // CHANGE ME: with your own http server custom "src" folder
|
|
280
|
+
}).addTo(map);
|
|
281
|
+
|
|
282
|
+
// Load track from url (allowed data types: "*.geojson", "*.gpx", "*.tcx")
|
|
283
|
+
controlElevation.load("https://raruto.github.io/leaflet-elevation/examples/via-emilia.gpx");
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
</details>
|
|
287
|
+
|
|
257
288
|
<details>
|
|
258
|
-
<summary>
|
|
289
|
+
<summary>4. Some real world projects based on this plugin?</summary><br>
|
|
259
290
|
|
|
260
291
|
- https://parcours.scasb.org/
|
|
261
292
|
- https://velocat.ru/velo/phpBB3/map.php
|
|
@@ -21,6 +21,9 @@
|
|
|
21
21
|
const HOUR = MIN * 60;
|
|
22
22
|
const DAY = HOUR * 24;
|
|
23
23
|
|
|
24
|
+
function resolveURL(src, baseUrl) {
|
|
25
|
+
return (new URL(src, (src.startsWith('../') || src.startsWith('./')) ? baseUrl : undefined)).toString()
|
|
26
|
+
}
|
|
24
27
|
/**
|
|
25
28
|
* Convert a time (millis) to a human readable duration string (%Dd %H:%M'%S")
|
|
26
29
|
*/
|
|
@@ -166,39 +169,40 @@
|
|
|
166
169
|
var _ = /*#__PURE__*/Object.freeze({
|
|
167
170
|
__proto__: null,
|
|
168
171
|
Colors: Colors,
|
|
169
|
-
formatTime: formatTime,
|
|
170
|
-
formatDate: formatDate,
|
|
171
|
-
saveFile: saveFile,
|
|
172
|
-
drawCanvas: drawCanvas,
|
|
173
|
-
coordPropsToMeta: coordPropsToMeta,
|
|
174
|
-
parseNumeric: parseNumeric,
|
|
175
|
-
parseDate: parseDate,
|
|
176
172
|
addClass: addClass,
|
|
177
|
-
removeClass: removeClass,
|
|
178
|
-
toggleClass: toggleClass,
|
|
179
|
-
replaceClass: replaceClass,
|
|
180
|
-
style: style,
|
|
181
|
-
toggleStyle: toggleStyle,
|
|
182
|
-
setAttributes: setAttributes,
|
|
183
|
-
toggleEvent: toggleEvent,
|
|
184
|
-
create: create,
|
|
185
173
|
append: append,
|
|
186
|
-
|
|
187
|
-
|
|
174
|
+
clamp: clamp,
|
|
175
|
+
coordPropsToMeta: coordPropsToMeta,
|
|
176
|
+
create: create,
|
|
177
|
+
drawCanvas: drawCanvas,
|
|
188
178
|
each: each,
|
|
189
|
-
|
|
179
|
+
formatDate: formatDate,
|
|
180
|
+
formatTime: formatTime,
|
|
181
|
+
hasClass: hasClass,
|
|
182
|
+
iAvg: iAvg,
|
|
190
183
|
iMax: iMax,
|
|
191
184
|
iMin: iMin,
|
|
192
|
-
iAvg: iAvg,
|
|
193
185
|
iSum: iSum,
|
|
194
|
-
|
|
186
|
+
insert: insert,
|
|
195
187
|
off: off,
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
188
|
+
on: on,
|
|
189
|
+
parseDate: parseDate,
|
|
190
|
+
parseNumeric: parseNumeric,
|
|
191
|
+
randomId: randomId,
|
|
192
|
+
removeClass: removeClass,
|
|
193
|
+
replaceClass: replaceClass,
|
|
194
|
+
resolveURL: resolveURL,
|
|
199
195
|
round: round,
|
|
200
|
-
|
|
201
|
-
|
|
196
|
+
saveFile: saveFile,
|
|
197
|
+
select: select,
|
|
198
|
+
setAttributes: setAttributes,
|
|
199
|
+
style: style,
|
|
200
|
+
throttle: throttle,
|
|
201
|
+
toggleClass: toggleClass,
|
|
202
|
+
toggleEvent: toggleEvent,
|
|
203
|
+
toggleStyle: toggleStyle,
|
|
204
|
+
wrapDelta: wrapDelta,
|
|
205
|
+
wrapNum: wrapNum
|
|
202
206
|
});
|
|
203
207
|
|
|
204
208
|
var Options = {
|
|
@@ -215,6 +219,7 @@
|
|
|
215
219
|
dragging: !L.Browser.mobile,
|
|
216
220
|
downloadLink: 'link',
|
|
217
221
|
elevationDiv: "#elevation-div",
|
|
222
|
+
edgeScale: { bar: true, icon: false, coords: false },
|
|
218
223
|
followMarker: true,
|
|
219
224
|
imperial: false,
|
|
220
225
|
legend: true,
|
|
@@ -282,6 +287,9 @@
|
|
|
282
287
|
interpolation: "curveLinear",
|
|
283
288
|
yAxisMax: undefined,
|
|
284
289
|
yAxisMin: undefined,
|
|
290
|
+
|
|
291
|
+
// Prevent CORS issues for relative locations (dynamic import)
|
|
292
|
+
srcFolder: ((document.currentScript && document.currentScript.src) || (({ url: (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('leaflet-elevation.js', document.baseURI).href)) }) && (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('leaflet-elevation.js', document.baseURI).href)))).split("/").slice(0,-1).join("/") + '/',
|
|
285
293
|
};
|
|
286
294
|
|
|
287
295
|
// "leaflet-i18n" fallback
|
|
@@ -289,9 +297,6 @@
|
|
|
289
297
|
L._ = L.i18n = (string, data) => string;
|
|
290
298
|
}
|
|
291
299
|
|
|
292
|
-
// Prevent CORS issues for relative locations (dynamic import)
|
|
293
|
-
const baseURL = ((document.currentScript && document.currentScript.src) || (({ url: (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('leaflet-elevation.js', document.baseURI).href)) }) && (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('leaflet-elevation.js', document.baseURI).href)))).split("/").slice(0,-1).join("/") + '/';
|
|
294
|
-
|
|
295
300
|
const Elevation = L.Control.Elevation = L.Control.extend({
|
|
296
301
|
|
|
297
302
|
includes: L.Evented ? L.Evented.prototype : L.Mixin.Events,
|
|
@@ -305,11 +310,12 @@
|
|
|
305
310
|
__LALMOSTOVER: 'https://unpkg.com/leaflet-almostover@1.0.1/src/leaflet.almostover.js',
|
|
306
311
|
__LHOTLINE: '../libs/leaflet-hotline.min.js',
|
|
307
312
|
__LDISTANCEM: '../libs/leaflet-distance-marker.min.js',
|
|
313
|
+
__LEDGESCALE: '../libs/leaflet-edgescale.min.js',
|
|
308
314
|
__LCHART: '../src/components/chart.js',
|
|
309
315
|
__LMARKER: '../src/components/marker.js',
|
|
310
316
|
__LSUMMARY: '../src/components/summary.js',
|
|
311
317
|
__modulesFolder: '../src/handlers/',
|
|
312
|
-
__btnIcon:
|
|
318
|
+
__btnIcon: '../images/elevation.svg',
|
|
313
319
|
|
|
314
320
|
/*
|
|
315
321
|
* Add data to the diagram either from GPX or GeoJSON and update the axis domain and data
|
|
@@ -456,7 +462,10 @@
|
|
|
456
462
|
*/
|
|
457
463
|
initialize: function(opts) {
|
|
458
464
|
|
|
459
|
-
opts = L.setOptions(this, opts);
|
|
465
|
+
// opts = L.setOptions(this, opts);
|
|
466
|
+
|
|
467
|
+
// Fixes: https://github.com/Raruto/leaflet-elevation/pull/240
|
|
468
|
+
opts = L.setOptions(this, L.extend({}, structuredClone(Options), opts)); // "deep copy" nested objects (multiple charts)
|
|
460
469
|
|
|
461
470
|
this._data = [];
|
|
462
471
|
this._layers = L.featureGroup();
|
|
@@ -501,10 +510,10 @@
|
|
|
501
510
|
case this.__LGEOMUTIL: condition = typeof L.GeometryUtil !== 'object'; break;
|
|
502
511
|
case this.__LALMOSTOVER: condition = typeof L.Handler.AlmostOver !== 'function'; break;
|
|
503
512
|
case this.__LDISTANCEM: condition = typeof L.DistanceMarkers !== 'function'; break;
|
|
513
|
+
case this.__LEDGESCALE: condition = typeof L.Control.EdgeScale !== 'function'; break;
|
|
504
514
|
case this.__LHOTLINE: condition = typeof L.Hotline !== 'function'; break;
|
|
505
515
|
}
|
|
506
|
-
|
|
507
|
-
return condition !== false ? import(src) : Promise.resolve();
|
|
516
|
+
return condition !== false ? import(resolveURL(src, this.options.srcFolder)) : Promise.resolve();
|
|
508
517
|
},
|
|
509
518
|
|
|
510
519
|
/**
|
|
@@ -703,6 +712,16 @@
|
|
|
703
712
|
return this.options.distanceMarkers ? Promise.all([this.import(this.__LGEOMUTIL), this.import(this.__LDISTANCEM)]) : Promise.resolve();
|
|
704
713
|
},
|
|
705
714
|
|
|
715
|
+
/**
|
|
716
|
+
* Initialize "L.Control.EdgeScale" integration
|
|
717
|
+
*/
|
|
718
|
+
_initEdgeScale: function(map) {
|
|
719
|
+
return this.options.edgeScale ? Promise.all([this.import(this.__LEDGESCALE)])
|
|
720
|
+
.then(() => {
|
|
721
|
+
map.edgeScaleControl = map.edgeScaleControl || L.control.edgeScale('boolean' !== typeof this.options.edgeScale ? this.options.edgeScale : {}).addTo(map);
|
|
722
|
+
}) : Promise.resolve();
|
|
723
|
+
},
|
|
724
|
+
|
|
706
725
|
_initHotLine: function(layer) {
|
|
707
726
|
let prop = typeof this.options.hotline == 'string' ? this.options.hotline : 'elevation';
|
|
708
727
|
return this.options.hotline ? this.import(this.__LHOTLINE)
|
|
@@ -748,6 +767,7 @@
|
|
|
748
767
|
this._initHotLine(layer),
|
|
749
768
|
this._initAlmostOverHandler(map, layer),
|
|
750
769
|
this._initDistanceMarkers(),
|
|
770
|
+
this._initEdgeScale(map),
|
|
751
771
|
]).then(() => {
|
|
752
772
|
if (this.options.polyline) {
|
|
753
773
|
layer.addTo(map);
|
|
@@ -983,7 +1003,7 @@
|
|
|
983
1003
|
on(link, 'click', L.DomEvent.stop);
|
|
984
1004
|
on(link, 'click', this._toggle, this);
|
|
985
1005
|
on(link, 'focus', this._toggle, this);
|
|
986
|
-
fetch(this.__btnIcon).then(r => r.ok && r.text().then(img => link.innerHTML = img));
|
|
1006
|
+
fetch(resolveURL(this.__btnIcon, this.options.srcFolder)).then(r => r.ok && r.text().then(img => link.innerHTML = img));
|
|
987
1007
|
}
|
|
988
1008
|
},
|
|
989
1009
|
|