@raruto/leaflet-elevation 2.3.0 → 2.3.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 +30 -3
- package/dist/leaflet-elevation.js +13 -10
- 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/package.json +6 -6
- package/src/control.js +6 -10
- package/src/options.js +3 -0
- package/src/utils.js +4 -0
package/README.md
CHANGED
|
@@ -65,7 +65,7 @@ _For a working example see one of the following demos:_
|
|
|
65
65
|
|
|
66
66
|
<!-- leaflet-ui -->
|
|
67
67
|
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
|
|
68
|
-
<script src="https://unpkg.com/leaflet-ui@0.
|
|
68
|
+
<script src="https://unpkg.com/leaflet-ui@0.6.0/dist/leaflet-ui.js"></script>
|
|
69
69
|
|
|
70
70
|
<!-- leaflet-elevation -->
|
|
71
71
|
<link rel="stylesheet" href="https://unpkg.com/@raruto/leaflet-elevation/dist/leaflet-elevation.css" />
|
|
@@ -209,7 +209,7 @@ cd ./leaflet-elevation
|
|
|
209
209
|
npm i # install dependencies
|
|
210
210
|
npm run dev # start dev server at: http://localhost:8080
|
|
211
211
|
npm run build # generate "dist" files (once)
|
|
212
|
-
npm run test # test all "
|
|
212
|
+
npm run test # test all "*.spec.js" files (once)
|
|
213
213
|
```
|
|
214
214
|
|
|
215
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.
|
|
@@ -259,8 +259,35 @@ var map = L.map('map', {
|
|
|
259
259
|
```
|
|
260
260
|
</details>
|
|
261
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: [41.4583, 12.7059]
|
|
275
|
+
zoom: 5,
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
const controlElevation = L.control.elevation({
|
|
279
|
+
// CHANGE ME: with your own http server folder (eg. "http://custom-server/public/path/to/leaflet-elevation/src/")
|
|
280
|
+
srcFolder: 'http://unpkg.com/@raruto/leaflet-elevation/src/'
|
|
281
|
+
}).addTo(map);
|
|
282
|
+
|
|
283
|
+
// Load track from url (allowed data types: "*.geojson", "*.gpx", "*.tcx")
|
|
284
|
+
controlElevation.load("https://raruto.github.io/leaflet-elevation/examples/via-emilia.gpx");
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
</details>
|
|
288
|
+
|
|
262
289
|
<details>
|
|
263
|
-
<summary>
|
|
290
|
+
<summary>4. Some real world projects based on this plugin?</summary><br>
|
|
264
291
|
|
|
265
292
|
- https://parcours.scasb.org/
|
|
266
293
|
- 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
|
*/
|
|
@@ -188,6 +191,7 @@
|
|
|
188
191
|
randomId: randomId,
|
|
189
192
|
removeClass: removeClass,
|
|
190
193
|
replaceClass: replaceClass,
|
|
194
|
+
resolveURL: resolveURL,
|
|
191
195
|
round: round,
|
|
192
196
|
saveFile: saveFile,
|
|
193
197
|
select: select,
|
|
@@ -283,6 +287,9 @@
|
|
|
283
287
|
interpolation: "curveLinear",
|
|
284
288
|
yAxisMax: undefined,
|
|
285
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("/") + '/',
|
|
286
293
|
};
|
|
287
294
|
|
|
288
295
|
// "leaflet-i18n" fallback
|
|
@@ -290,9 +297,6 @@
|
|
|
290
297
|
L._ = L.i18n = (string, data) => string;
|
|
291
298
|
}
|
|
292
299
|
|
|
293
|
-
// Prevent CORS issues for relative locations (dynamic import)
|
|
294
|
-
const baseURL = ((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("/") + '/';
|
|
295
|
-
|
|
296
300
|
const Elevation = L.Control.Elevation = L.Control.extend({
|
|
297
301
|
|
|
298
302
|
includes: L.Evented ? L.Evented.prototype : L.Mixin.Events,
|
|
@@ -300,9 +304,9 @@
|
|
|
300
304
|
options: Options,
|
|
301
305
|
__mileFactor: 0.621371, // 1 km = (0.621371 mi)
|
|
302
306
|
__footFactor: 3.28084, // 1 m = (3.28084 ft)
|
|
303
|
-
__D3: 'https://unpkg.com/d3@
|
|
304
|
-
__TOGEOJSON: 'https://unpkg.com/@tmcw/togeojson@
|
|
305
|
-
__LGEOMUTIL: 'https://unpkg.com/leaflet-geometryutil@0.
|
|
307
|
+
__D3: 'https://unpkg.com/d3@7.8.4/dist/d3.min.js',
|
|
308
|
+
__TOGEOJSON: 'https://unpkg.com/@tmcw/togeojson@5.6.0/dist/togeojson.umd.js',
|
|
309
|
+
__LGEOMUTIL: 'https://unpkg.com/leaflet-geometryutil@0.10.1/src/leaflet.geometryutil.js',
|
|
306
310
|
__LALMOSTOVER: 'https://unpkg.com/leaflet-almostover@1.0.1/src/leaflet.almostover.js',
|
|
307
311
|
__LHOTLINE: '../libs/leaflet-hotline.min.js',
|
|
308
312
|
__LDISTANCEM: '../libs/leaflet-distance-marker.min.js',
|
|
@@ -311,7 +315,7 @@
|
|
|
311
315
|
__LMARKER: '../src/components/marker.js',
|
|
312
316
|
__LSUMMARY: '../src/components/summary.js',
|
|
313
317
|
__modulesFolder: '../src/handlers/',
|
|
314
|
-
__btnIcon:
|
|
318
|
+
__btnIcon: '../images/elevation.svg',
|
|
315
319
|
|
|
316
320
|
/*
|
|
317
321
|
* Add data to the diagram either from GPX or GeoJSON and update the axis domain and data
|
|
@@ -509,8 +513,7 @@
|
|
|
509
513
|
case this.__LEDGESCALE: condition = typeof L.Control.EdgeScale !== 'function'; break;
|
|
510
514
|
case this.__LHOTLINE: condition = typeof L.Hotline !== 'function'; break;
|
|
511
515
|
}
|
|
512
|
-
|
|
513
|
-
return condition !== false ? import(src) : Promise.resolve();
|
|
516
|
+
return condition !== false ? import(resolveURL(src, this.options.srcFolder)) : Promise.resolve();
|
|
514
517
|
},
|
|
515
518
|
|
|
516
519
|
/**
|
|
@@ -1000,7 +1003,7 @@
|
|
|
1000
1003
|
on(link, 'click', L.DomEvent.stop);
|
|
1001
1004
|
on(link, 'click', this._toggle, this);
|
|
1002
1005
|
on(link, 'focus', this._toggle, this);
|
|
1003
|
-
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));
|
|
1004
1007
|
}
|
|
1005
1008
|
},
|
|
1006
1009
|
|