@raruto/leaflet-elevation 1.8.4 → 1.8.5
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/dist/leaflet-elevation.css +16 -1
- package/dist/leaflet-elevation.js +489 -546
- package/dist/leaflet-elevation.js.map +1 -1
- package/dist/leaflet-elevation.min.css +1 -1
- package/dist/leaflet-elevation.min.js +2 -2
- package/dist/leaflet-elevation.min.js.map +1 -1
- package/libs/leaflet-gpxgroup.js +69 -186
- package/libs/leaflet-gpxgroup.min.js +1 -17
- package/package.json +1 -1
- package/src/control.js +352 -219
- package/src/index.css +16 -1
- package/src/index.js +12 -0
- package/src/utils.js +0 -218
- package/images/remove.svg +0 -1
package/src/index.css
CHANGED
|
@@ -211,7 +211,7 @@
|
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
.elevation-control.elevation.elevation-expanded .elevation-toggle-icon.close-button {
|
|
214
|
-
background: transparent
|
|
214
|
+
background: transparent;
|
|
215
215
|
position: absolute;
|
|
216
216
|
right: 5px;
|
|
217
217
|
top: 5px;
|
|
@@ -219,6 +219,21 @@
|
|
|
219
219
|
width: 20px;
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
+
.elevation-control.elevation.elevation-expanded .elevation-toggle-icon.close-button:before {
|
|
223
|
+
content: '\2716';
|
|
224
|
+
display: inline-block;
|
|
225
|
+
color: #000;
|
|
226
|
+
position: absolute;
|
|
227
|
+
left: 0;
|
|
228
|
+
right: 0;
|
|
229
|
+
top: 0;
|
|
230
|
+
bottom: 0;
|
|
231
|
+
line-height: 20px;
|
|
232
|
+
text-align: center;
|
|
233
|
+
font-weight: bold;
|
|
234
|
+
font-size: 15px;
|
|
235
|
+
}
|
|
236
|
+
|
|
222
237
|
.elevation-control.elevation g.area > foreignObject {
|
|
223
238
|
pointer-events: none;
|
|
224
239
|
}
|
package/src/index.js
CHANGED
|
@@ -61,4 +61,16 @@ Elevation.Chart = Chart;
|
|
|
61
61
|
};
|
|
62
62
|
})();
|
|
63
63
|
|
|
64
|
+
// Alias deprecated functions
|
|
65
|
+
Elevation.addInitHook(function() {
|
|
66
|
+
this.enableDragging = this.enableBrush;
|
|
67
|
+
this.disableDragging = this.disableBrush;
|
|
68
|
+
this.loadChart = this.addTo;
|
|
69
|
+
this.loadData = this.load;
|
|
70
|
+
this.loadGPX = this.load;
|
|
71
|
+
this.loadGeoJSON = this.load;
|
|
72
|
+
this.loadXML = this.load;
|
|
73
|
+
this.loadFile = this.load;
|
|
74
|
+
});
|
|
75
|
+
|
|
64
76
|
L.control.elevation = (options) => new Elevation(options);
|
package/src/utils.js
CHANGED
|
@@ -1,27 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Recursive deep merge objects.
|
|
3
|
-
* Alternative to L.Util.setOptions(this, options).
|
|
4
|
-
*/
|
|
5
|
-
export function deepMerge(target, ...sources) {
|
|
6
|
-
if (!sources.length) return target;
|
|
7
|
-
const source = sources.shift();
|
|
8
|
-
if (isObject(target) && isObject(source)) {
|
|
9
|
-
for (const key in source) {
|
|
10
|
-
if (isObject(source[key])) {
|
|
11
|
-
if (!target[key]) Object.assign(target, {
|
|
12
|
-
[key]: {}
|
|
13
|
-
});
|
|
14
|
-
deepMerge(target[key], source[key]);
|
|
15
|
-
} else {
|
|
16
|
-
Object.assign(target, {
|
|
17
|
-
[key]: source[key]
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return deepMerge(target, ...sources);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
1
|
const SEC = 1000;
|
|
26
2
|
const MIN = SEC * 60;
|
|
27
3
|
const HOUR = MIN * 60;
|
|
@@ -41,169 +17,6 @@ export function formatTime(t) {
|
|
|
41
17
|
return (d ? d + "d " : '') + h.toString().padStart(2, 0) + ':' + m.toString().padStart(2, 0) + "'" + s.toString().padStart(2, 0) + '"';
|
|
42
18
|
}
|
|
43
19
|
|
|
44
|
-
/**
|
|
45
|
-
* Simple GeoJSON data loader.
|
|
46
|
-
*/
|
|
47
|
-
export function GeoJSONLoader(data, control) {
|
|
48
|
-
if (typeof data === "string") {
|
|
49
|
-
data = JSON.parse(data);
|
|
50
|
-
}
|
|
51
|
-
control = control || this;
|
|
52
|
-
|
|
53
|
-
let distanceMarkers = (
|
|
54
|
-
control.options.distanceMarkers === true
|
|
55
|
-
? { lazy: true }
|
|
56
|
-
: L.extend({ lazy: true }, control.options.distanceMarkers)
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
let { wptIcons, wptLabels } = control.options;
|
|
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
|
-
|
|
78
|
-
let layer = L.geoJson(data, {
|
|
79
|
-
distanceMarkers: distanceMarkers,
|
|
80
|
-
style: (feature) => {
|
|
81
|
-
let style = L.extend({}, control.options.polyline);
|
|
82
|
-
if (control.options.theme) {
|
|
83
|
-
style.className += ' ' + control.options.theme;
|
|
84
|
-
}
|
|
85
|
-
return style;
|
|
86
|
-
},
|
|
87
|
-
pointToLayer: (feature, latlng) => {
|
|
88
|
-
if (!control.options.waypoints) return;
|
|
89
|
-
|
|
90
|
-
let prop = feature.properties;
|
|
91
|
-
let desc = prop.desc ?? '';
|
|
92
|
-
let name = prop.name ?? '';
|
|
93
|
-
let sym = (prop.sym ?? name).replace(' ', '-').replace('"', '').replace("'", '').toLowerCase();
|
|
94
|
-
|
|
95
|
-
// Handle chart waypoints (dots)
|
|
96
|
-
if ([true, 'dots'].includes(control.options.waypoints)) {
|
|
97
|
-
control._registerCheckPoint({
|
|
98
|
-
latlng: latlng,
|
|
99
|
-
label: ([true, 'dots'].includes(wptLabels) ? name : '')
|
|
100
|
-
},
|
|
101
|
-
true
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Handle map waypoints (markers)
|
|
106
|
-
if ([true, 'markers'].includes(control.options.waypoints) && wptIcons != false) {
|
|
107
|
-
// generate and cache appropriate icon symbol
|
|
108
|
-
if (!wptIcons.hasOwnProperty(sym)) {
|
|
109
|
-
wptIcons[sym] = L.divIcon(
|
|
110
|
-
L.extend({}, wptIcons[""].options, { html: '<i class="elevation-waypoint-icon ' + sym + '"></i>' } )
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
let marker = L.marker(latlng, { icon: wptIcons[sym] });
|
|
114
|
-
if ([true, 'markers'].includes(wptLabels) && (name || desc)) {
|
|
115
|
-
marker.bindPopup("<b>" + name + "</b>" + (desc.length > 0 ? '<br>' + desc : '')).openPopup();
|
|
116
|
-
}
|
|
117
|
-
control._addMarker(marker);
|
|
118
|
-
control.fire('waypoint_added', { point: marker, element: latlng, properties: prop });
|
|
119
|
-
return marker;
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
onEachFeature: (feature, layer) => {
|
|
123
|
-
if (feature.geometry && feature.geometry.type == 'Point') return;
|
|
124
|
-
|
|
125
|
-
// Standard GeoJSON
|
|
126
|
-
// control.addData(feature, layer); // NB uses "_addGeoJSONData"
|
|
127
|
-
|
|
128
|
-
// Extended GeoJSON
|
|
129
|
-
layer._latlngs.forEach((point, i, data) => {
|
|
130
|
-
// same properties as L.GPX layer
|
|
131
|
-
point.meta = { time: null, ele: null, hr: null, cad: null, atemp: null };
|
|
132
|
-
if("alt" in point) point.meta.ele = point.alt;
|
|
133
|
-
if(feature.properties) {
|
|
134
|
-
let prop = feature.properties;
|
|
135
|
-
if("coordTimes" in prop) point.meta.time = new Date(Date.parse(prop.coordTimes[i]));
|
|
136
|
-
else if("times" in prop) point.meta.time = new Date(Date.parse(prop.times[i]));
|
|
137
|
-
else if("time" in prop) point.meta.time = new Date(Date.parse((typeof prop.time === 'object' ? prop.time[i] : prop.time)));
|
|
138
|
-
if("heartRates" in prop) point.meta.hr = parseInt(prop.heartRates[i]);
|
|
139
|
-
else if("heartRate" in prop) point.meta.hr = parseInt((typeof prop.heartRate === 'object' ? prop.heartRate[i] : prop.heartRate));
|
|
140
|
-
// TODO: cadence, temperature
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
control.addData(layer); // NB uses "_addGPXData"
|
|
144
|
-
|
|
145
|
-
// Postpone adding the distance markers (lazy: true)
|
|
146
|
-
if(control.options.distanceMarkers && distanceMarkers.lazy) {
|
|
147
|
-
layer.on('add remove', (e) => {
|
|
148
|
-
let path = e.target;
|
|
149
|
-
if (L.DistanceMarkers && path instanceof L.Polyline) {
|
|
150
|
-
path[e.type + 'DistanceMarkers']();
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
control.track_info = L.extend({}, control.track_info, { type: "geojson", name: data.name });
|
|
156
|
-
},
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
L.Control.Elevation._d3LazyLoader.then(() => {
|
|
160
|
-
control._fireEvt("eledata_loaded", { data: data, layer: layer, name: control.track_info.name, track_info: control.track_info })
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
return layer;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Check object type.
|
|
168
|
-
*/
|
|
169
|
-
export function isObject(item) {
|
|
170
|
-
return (item && typeof item === 'object' && !Array.isArray(item));
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Check JSON object type.
|
|
175
|
-
*/
|
|
176
|
-
export function isJSONDoc(doc, lazy) {
|
|
177
|
-
lazy = typeof lazy === "undefined" ? true : lazy;
|
|
178
|
-
if (typeof doc === "string" && lazy) {
|
|
179
|
-
doc = doc.trim();
|
|
180
|
-
return doc.indexOf("{") == 0 || doc.indexOf("[") == 0;
|
|
181
|
-
} else {
|
|
182
|
-
try {
|
|
183
|
-
JSON.parse(doc.toString());
|
|
184
|
-
} catch (e) {
|
|
185
|
-
if (typeof doc === "object" && lazy) return true;
|
|
186
|
-
console.warn(e);
|
|
187
|
-
return false;
|
|
188
|
-
}
|
|
189
|
-
return true;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Check XML object type.
|
|
195
|
-
*/
|
|
196
|
-
export function isXMLDoc(doc, lazy) {
|
|
197
|
-
lazy = typeof lazy === "undefined" ? true : lazy;
|
|
198
|
-
if (typeof doc === "string" && lazy) {
|
|
199
|
-
doc = doc.trim();
|
|
200
|
-
return doc.indexOf("<") == 0;
|
|
201
|
-
} else {
|
|
202
|
-
let documentElement = (doc ? doc.ownerDocument || doc : 0).documentElement;
|
|
203
|
-
return documentElement ? documentElement.nodeName !== "HTML" : false;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
20
|
/**
|
|
208
21
|
* Generate download data event.
|
|
209
22
|
*/
|
|
@@ -233,37 +46,6 @@ export function lazyLoader(url, skip, loader) {
|
|
|
233
46
|
});
|
|
234
47
|
}
|
|
235
48
|
|
|
236
|
-
export function lazyLoad(src, control) {
|
|
237
|
-
if (!control.options.lazyLoadJS) return Promise.resolve();
|
|
238
|
-
|
|
239
|
-
const Elevation = L.Control.Elevation;
|
|
240
|
-
let loader = '';
|
|
241
|
-
let condition = false;
|
|
242
|
-
|
|
243
|
-
switch(src) {
|
|
244
|
-
case control.__D3:
|
|
245
|
-
loader = '_d3LazyLoader';
|
|
246
|
-
condition = typeof d3 !== 'object';
|
|
247
|
-
break;
|
|
248
|
-
case control.__TOGEOJSON:
|
|
249
|
-
loader = '_togeojsonLazyLoader';
|
|
250
|
-
condition = typeof toGeoJSON !== 'object';
|
|
251
|
-
break;
|
|
252
|
-
case control.__LGEOMUTIL:
|
|
253
|
-
loader = '_geomutilLazyLoader';
|
|
254
|
-
condition = typeof L.GeometryUtil !== 'object';
|
|
255
|
-
case control.__LALMOSTOVER:
|
|
256
|
-
loader = '_almostoverLazyLoader';
|
|
257
|
-
condition = typeof L.Handler.AlmostOver !== 'function ';
|
|
258
|
-
break;
|
|
259
|
-
case control.__LDISTANCEM:
|
|
260
|
-
loader = '_distanceMarkersLazyLoader';
|
|
261
|
-
condition = typeof L.DistanceMarkers !== 'function';
|
|
262
|
-
break;
|
|
263
|
-
}
|
|
264
|
-
return Elevation[loader] = lazyLoader(src, condition, Elevation[loader]);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
49
|
/**
|
|
268
50
|
* Convert SVG Path into Path2D and then update canvas
|
|
269
51
|
*/
|
package/images/remove.svg
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 1792 1792"><defs/><path d="M1490 1322q0 40-28 68l-136 136q-28 28-68 28t-68-28l-294-294-294 294q-28 28-68 28t-68-28l-136-136q-28-28-28-68t28-68l294-294-294-294q-28-28-28-68t28-68l136-136q28-28 68-28t68 28l294 294 294-294q28-28 68-28t68 28l136 136q28 28 28 68t-28 68l-294 294 294 294q28 28 28 68z"/></svg>
|