@raruto/leaflet-elevation 1.8.2 → 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/src/index.css CHANGED
@@ -36,10 +36,6 @@
36
36
  user-select: none;
37
37
  }
38
38
 
39
- .elevation-control.elevation .background.zoomed .axis.time {
40
- display: none;
41
- }
42
-
43
39
  .elevation-control.elevation .axis line,
44
40
  .elevation-control.elevation .axis path {
45
41
  stroke: #2D1130;
@@ -215,7 +211,7 @@
215
211
  }
216
212
 
217
213
  .elevation-control.elevation.elevation-expanded .elevation-toggle-icon.close-button {
218
- background: transparent url(../images/remove.svg) no-repeat center center;
214
+ background: transparent;
219
215
  position: absolute;
220
216
  right: 5px;
221
217
  top: 5px;
@@ -223,6 +219,21 @@
223
219
  width: 20px;
224
220
  }
225
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
+
226
237
  .elevation-control.elevation g.area > foreignObject {
227
238
  pointer-events: none;
228
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,152 +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
- let layer = L.geoJson(data, {
62
- distanceMarkers: distanceMarkers,
63
- style: (feature) => {
64
- let style = L.extend({}, control.options.polyline);
65
- if (control.options.theme) {
66
- style.className += ' ' + control.options.theme;
67
- }
68
- return style;
69
- },
70
- pointToLayer: (feature, latlng) => {
71
- if (!control.options.waypoints) return;
72
-
73
- let prop = feature.properties;
74
- let desc = prop.desc ?? '';
75
- let name = prop.name ?? '';
76
- let sym = (prop.sym ?? name).replace(' ', '-').replace('"', '').replace("'", '').toLowerCase();
77
-
78
- // Handle chart waypoints (dots)
79
- if ([true, 'dots'].includes(control.options.waypoints)) {
80
- control._registerCheckPoint({
81
- latlng: latlng,
82
- label: ([true, 'dots'].includes(wptLabels) ? name : '')
83
- },
84
- true
85
- );
86
- }
87
-
88
- // Handle map waypoints (markers)
89
- if ([true, 'markers'].includes(control.options.waypoints) && wptIcons != false) {
90
- // generate and cache appropriate icon symbol
91
- if (!wptIcons.hasOwnProperty(sym)) {
92
- wptIcons[sym] = L.divIcon(
93
- L.extend({}, wptIcons[""].options, { html: '<i class="elevation-waypoint-icon ' + sym + '"></i>' } )
94
- );
95
- }
96
- let marker = L.marker(latlng, { icon: wptIcons[sym] });
97
- if ([true, 'markers'].includes(wptLabels) && (name || desc)) {
98
- marker.bindPopup("<b>" + name + "</b>" + (desc.length > 0 ? '<br>' + desc : '')).openPopup();
99
- }
100
- control._addMarker(marker);
101
- control.fire('waypoint_added', { point: marker, element: latlng, properties: prop });
102
- return marker;
103
- }
104
- },
105
- onEachFeature: (feature, layer) => {
106
- if (feature.geometry && feature.geometry.type == 'Point') return;
107
-
108
- // Standard GeoJSON
109
- // control.addData(feature, layer); // NB uses "_addGeoJSONData"
110
-
111
- // Extended GeoJSON
112
- layer._latlngs.forEach((point, i, data) => {
113
- // same properties as L.GPX layer
114
- point.meta = { time: null, ele: null, hr: null, cad: null, atemp: null };
115
- if("alt" in point) point.meta.ele = point.alt;
116
- if(feature.properties) {
117
- let prop = feature.properties;
118
- if("coordTimes" in prop) point.meta.time = new Date(Date.parse(prop.coordTimes[i]));
119
- else if("times" in prop) point.meta.time = new Date(Date.parse(prop.times[i]));
120
- else if("time" in prop) point.meta.time = new Date(Date.parse((typeof prop.time === 'object' ? prop.time[i] : prop.time)));
121
- if("heartRates" in prop) point.meta.hr = parseInt(prop.heartRates[i]);
122
- else if("heartRate" in prop) point.meta.hr = parseInt((typeof prop.heartRate === 'object' ? prop.heartRate[i] : prop.heartRate));
123
- // TODO: cadence, temperature
124
- }
125
- });
126
- control.addData(layer); // NB uses "_addGPXData"
127
-
128
- // Postpone adding the distance markers (lazy: true)
129
- if(control.options.distanceMarkers && distanceMarkers.lazy) {
130
- layer.on('add remove', (e) => {
131
- let path = e.target;
132
- if (L.DistanceMarkers && path instanceof L.Polyline) {
133
- path[e.type + 'DistanceMarkers']();
134
- }
135
- });
136
- }
137
-
138
- control.track_info = L.extend({}, control.track_info, { type: "geojson", name: data.name });
139
- },
140
- });
141
-
142
- L.Control.Elevation._d3LazyLoader.then(() => {
143
- control._fireEvt("eledata_loaded", { data: data, layer: layer, name: control.track_info.name, track_info: control.track_info })
144
- });
145
-
146
- return layer;
147
- }
148
-
149
- /**
150
- * Check object type.
151
- */
152
- export function isObject(item) {
153
- return (item && typeof item === 'object' && !Array.isArray(item));
154
- }
155
-
156
- /**
157
- * Check JSON object type.
158
- */
159
- export function isJSONDoc(doc, lazy) {
160
- lazy = typeof lazy === "undefined" ? true : lazy;
161
- if (typeof doc === "string" && lazy) {
162
- doc = doc.trim();
163
- return doc.indexOf("{") == 0 || doc.indexOf("[") == 0;
164
- } else {
165
- try {
166
- JSON.parse(doc.toString());
167
- } catch (e) {
168
- if (typeof doc === "object" && lazy) return true;
169
- console.warn(e);
170
- return false;
171
- }
172
- return true;
173
- }
174
- }
175
-
176
- /**
177
- * Check XML object type.
178
- */
179
- export function isXMLDoc(doc, lazy) {
180
- lazy = typeof lazy === "undefined" ? true : lazy;
181
- if (typeof doc === "string" && lazy) {
182
- doc = doc.trim();
183
- return doc.indexOf("<") == 0;
184
- } else {
185
- let documentElement = (doc ? doc.ownerDocument || doc : 0).documentElement;
186
- return documentElement ? documentElement.nodeName !== "HTML" : false;
187
- }
188
- }
189
-
190
20
  /**
191
21
  * Generate download data event.
192
22
  */
@@ -216,37 +46,6 @@ export function lazyLoader(url, skip, loader) {
216
46
  });
217
47
  }
218
48
 
219
- export function lazyLoad(src, control) {
220
- if (!control.options.lazyLoadJS) return Promise.resolve();
221
-
222
- const Elevation = L.Control.Elevation;
223
- let loader = '';
224
- let condition = false;
225
-
226
- switch(src) {
227
- case control.__D3:
228
- loader = '_d3LazyLoader';
229
- condition = typeof d3 !== 'object';
230
- break;
231
- case control.__TOGEOJSON:
232
- loader = '_togeojsonLazyLoader';
233
- condition = typeof toGeoJSON !== 'object';
234
- break;
235
- case control.__LGEOMUTIL:
236
- loader = '_geomutilLazyLoader';
237
- condition = typeof L.GeometryUtil !== 'object';
238
- case control.__LALMOSTOVER:
239
- loader = '_almostoverLazyLoader';
240
- condition = typeof L.Handler.AlmostOver !== 'function ';
241
- break;
242
- case control.__LDISTANCEM:
243
- loader = '_distanceMarkersLazyLoader';
244
- condition = typeof L.DistanceMarkers !== 'function';
245
- break;
246
- }
247
- return Elevation[loader] = lazyLoader(src, condition, Elevation[loader]);
248
- }
249
-
250
49
  /**
251
50
  * Convert SVG Path into Path2D and then update canvas
252
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>