@raruto/leaflet-elevation 1.6.9 → 1.7.3
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 +65 -3
- package/dist/leaflet-elevation.css +1 -0
- package/dist/leaflet-elevation.js +76 -31
- package/dist/leaflet-elevation.js.map +1 -1
- package/dist/leaflet-elevation.min.css +1 -1
- package/dist/leaflet-elevation.min.js +1 -1
- package/dist/leaflet-elevation.min.js.map +1 -1
- package/libs/leaflet-gpxgroup.js +45 -35
- package/libs/leaflet-gpxgroup.min.js +14 -13
- package/package.json +1 -1
- package/src/chart.js +4 -0
- package/src/components.js +6 -0
- package/src/control.js +38 -6
- package/src/index.css +1 -0
- package/src/options.js +9 -16
- package/src/utils.js +10 -8
package/README.md
CHANGED
|
@@ -140,13 +140,16 @@ _For a working example see one of the following demos:_
|
|
|
140
140
|
// Display altitude info: true || "summary"
|
|
141
141
|
altitude: true,
|
|
142
142
|
|
|
143
|
-
// Summary track info style: "
|
|
143
|
+
// Summary track info style: "inline" || "multiline" || false
|
|
144
144
|
summary: 'multiline',
|
|
145
145
|
|
|
146
|
-
//
|
|
146
|
+
// Download link: "link" || false || "modal"
|
|
147
|
+
downloadLink: 'link',
|
|
148
|
+
|
|
149
|
+
// Toggle chart ruler filter
|
|
147
150
|
ruler: true,
|
|
148
151
|
|
|
149
|
-
// Toggle chart legend filter
|
|
152
|
+
// Toggle chart legend filter
|
|
150
153
|
legend: true,
|
|
151
154
|
|
|
152
155
|
// Toggle "leaflet-almostover" integration
|
|
@@ -155,6 +158,19 @@ _For a working example see one of the following demos:_
|
|
|
155
158
|
// Toggle "leaflet-distance-markers" integration
|
|
156
159
|
distanceMarkers: false,
|
|
157
160
|
|
|
161
|
+
// Display track waypoints
|
|
162
|
+
waypoints: true,
|
|
163
|
+
|
|
164
|
+
// Custom waypoint icons (associative array of <sym> tags)
|
|
165
|
+
wptIcons: {
|
|
166
|
+
'': L.divIcon({
|
|
167
|
+
className: 'elevation-waypoint-marker',
|
|
168
|
+
html: '<i class="elevation-waypoint-icon"></i>',
|
|
169
|
+
iconSize: [30, 30],
|
|
170
|
+
iconAnchor: [8, 30],
|
|
171
|
+
}),
|
|
172
|
+
},
|
|
173
|
+
|
|
158
174
|
// Render chart profiles as Canvas or SVG Paths
|
|
159
175
|
preferCanvas: true
|
|
160
176
|
|
|
@@ -171,6 +187,52 @@ _For a working example see one of the following demos:_
|
|
|
171
187
|
|
|
172
188
|
</script>
|
|
173
189
|
```
|
|
190
|
+
|
|
191
|
+
### FAQ
|
|
192
|
+
|
|
193
|
+
<details>
|
|
194
|
+
<summary>1. How can I change the color of the elevation plot?</summary><br>
|
|
195
|
+
|
|
196
|
+
There are multiple options to achieve this:
|
|
197
|
+
|
|
198
|
+
* You could either use some default presets (see: theme: "lightblue-theme" option in readme file and the following file `leaflet-elevation.css` for some other default "*-theme" names).
|
|
199
|
+
* check out [this example](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_custom-theme.html)
|
|
200
|
+
* Or add the following lines for custom colors.
|
|
201
|
+
```css
|
|
202
|
+
.elevation-control.elevation .area {
|
|
203
|
+
fill: red;
|
|
204
|
+
}
|
|
205
|
+
.elevation-control.elevation .background {
|
|
206
|
+
background-color: white;
|
|
207
|
+
```
|
|
208
|
+
</details>
|
|
209
|
+
|
|
210
|
+
<details>
|
|
211
|
+
<summary>2. How to enable/disable the leaflet user interface customizations?</summary><br>
|
|
212
|
+
|
|
213
|
+
These customizations are actually part of the [leaflet-ui](https://github.com/Raruto/leaflet-ui) and can be toggled on/off using e.g. the following options:
|
|
214
|
+
```js
|
|
215
|
+
var map = L.map('map', {
|
|
216
|
+
center: [41.4583, 12.7059], // needs value to initialize
|
|
217
|
+
zoom: 5, // needs value to initialize
|
|
218
|
+
mapTypeId: 'topo',
|
|
219
|
+
mapTypeIds: ['osm', 'terrain', 'satellite', 'topo'],
|
|
220
|
+
gestureHandling: false, // zoom with Cmd + Scroll
|
|
221
|
+
zoomControl: true, // plus minus buttons
|
|
222
|
+
pegmanControl: false,
|
|
223
|
+
locateControl: false,
|
|
224
|
+
fullscreenControl: true,
|
|
225
|
+
layersControl: true,
|
|
226
|
+
minimapControl: false,
|
|
227
|
+
editInOSMControl: false,
|
|
228
|
+
loadingControl: false,
|
|
229
|
+
searchControl: false,
|
|
230
|
+
disableDefaultUI: false,
|
|
231
|
+
printControl: false,
|
|
232
|
+
});
|
|
233
|
+
```
|
|
234
|
+
</details>
|
|
235
|
+
|
|
174
236
|
_Related: [Leaflet-UI presets](https://github.com/raruto/leaflet-ui), [QGIS Integration](https://github.com/faunalia/trackprofile2web)_
|
|
175
237
|
|
|
176
238
|
---
|
|
@@ -172,7 +172,7 @@
|
|
|
172
172
|
} : L.extend({
|
|
173
173
|
lazy: true
|
|
174
174
|
}, control.options.distanceMarkers);
|
|
175
|
-
var wptIcons = control.options.
|
|
175
|
+
var wptIcons = control.options.wptIcons;
|
|
176
176
|
var layer = L.geoJson(data, {
|
|
177
177
|
distanceMarkers: distanceMarkers,
|
|
178
178
|
style: function style(feature) {
|
|
@@ -185,17 +185,18 @@
|
|
|
185
185
|
return style;
|
|
186
186
|
},
|
|
187
187
|
pointToLayer: function pointToLayer(feature, latlng) {
|
|
188
|
+
if (!control.options.waypoints) return;
|
|
188
189
|
var prop = feature.properties;
|
|
189
190
|
var desc = prop.desc ? prop.desc : '';
|
|
190
191
|
var name = prop.name ? prop.name : '';
|
|
191
|
-
var sym = (prop.sym ? prop.sym : name).replace(' ', '-').replace('"', '').replace("'", '').toLowerCase(); // generate appropriate icon symbol
|
|
192
|
+
var sym = (prop.sym ? prop.sym : name).replace(' ', '-').replace('"', '').replace("'", '').toLowerCase(); // generate and cache appropriate icon symbol
|
|
193
|
+
|
|
194
|
+
if (!wptIcons.hasOwnProperty(sym)) {
|
|
195
|
+
wptIcons[sym] = L.divIcon(L.extend({}, wptIcons[""].options, {
|
|
196
|
+
html: '<i class="elevation-waypoint-icon ' + sym + '"></i>'
|
|
197
|
+
}));
|
|
198
|
+
}
|
|
192
199
|
|
|
193
|
-
wptIcons[sym] = wptIcons[sym] ? wptIcons[sym] : L.divIcon({
|
|
194
|
-
className: 'elevation-waypoint-marker',
|
|
195
|
-
html: '<i class="elevation-waypoint-icon ' + sym + '"></i>',
|
|
196
|
-
iconSize: [30, 30],
|
|
197
|
-
iconAnchor: [8, 30]
|
|
198
|
-
});
|
|
199
200
|
var marker = L.marker(latlng, {
|
|
200
201
|
icon: wptIcons[sym]
|
|
201
202
|
});
|
|
@@ -204,6 +205,8 @@
|
|
|
204
205
|
marker.bindPopup("<b>" + name + "</b>" + (desc.length > 0 ? '<br>' + desc : '')).openPopup();
|
|
205
206
|
}
|
|
206
207
|
|
|
208
|
+
control._addMarker(marker);
|
|
209
|
+
|
|
207
210
|
control._registerCheckPoint({
|
|
208
211
|
latlng: latlng,
|
|
209
212
|
label: name
|
|
@@ -968,7 +971,12 @@
|
|
|
968
971
|
var _height = height - margins.top - margins.bottom;
|
|
969
972
|
|
|
970
973
|
svg.attr("viewBox", "0 0 ".concat(width, " ").concat(height)).attr("width", width).attr("height", height);
|
|
971
|
-
g.attr("transform", "translate(" + margins.left + "," + margins.top + ")");
|
|
974
|
+
g.attr("transform", "translate(" + margins.left + "," + margins.top + ")"); // Partially fix: https://github.com/Raruto/leaflet-elevation/issues/123
|
|
975
|
+
|
|
976
|
+
if (/Mac|iPod|iPhone|iPad/.test(navigator.platform) && /AppleWebkit/i.test(navigator.userAgent)) {
|
|
977
|
+
canvas.style("transform", "translate(" + margins.left + "px," + margins.top + "px)");
|
|
978
|
+
}
|
|
979
|
+
|
|
972
980
|
clipRect.attr("x", 0).attr("y", 0).attr("width", _width).attr("height", _height);
|
|
973
981
|
foreignObject.attr('width', _width).attr('height', _height);
|
|
974
982
|
canvas.attr('width', _width).attr('height', _height);
|
|
@@ -1123,6 +1131,8 @@
|
|
|
1123
1131
|
clear: function clear() {
|
|
1124
1132
|
this._resetDrag();
|
|
1125
1133
|
|
|
1134
|
+
this._hideDiagramIndicator();
|
|
1135
|
+
|
|
1126
1136
|
this._area.selectAll('path').attr("d", "M0 0");
|
|
1127
1137
|
|
|
1128
1138
|
this._context.clearRect(0, 0, this._width(), this._height());
|
|
@@ -1193,6 +1203,7 @@
|
|
|
1193
1203
|
var _this2 = this;
|
|
1194
1204
|
|
|
1195
1205
|
var brush = function brush(e) {
|
|
1206
|
+
if (!_this2._data.length) return;
|
|
1196
1207
|
var extent = e.selection;
|
|
1197
1208
|
|
|
1198
1209
|
if (extent) {
|
|
@@ -1208,6 +1219,7 @@
|
|
|
1208
1219
|
};
|
|
1209
1220
|
|
|
1210
1221
|
var focus = function focus(e) {
|
|
1222
|
+
if (!_this2._data.length) return;
|
|
1211
1223
|
if (e.type == 'brush' && !e.sourceEvent) return;
|
|
1212
1224
|
|
|
1213
1225
|
var rect = _this2._chart.panes.brush.select('.overlay').node();
|
|
@@ -2012,22 +2024,6 @@
|
|
|
2012
2024
|
elevationDiv: "#elevation-div",
|
|
2013
2025
|
followMarker: true,
|
|
2014
2026
|
forceAxisBounds: false,
|
|
2015
|
-
gpxOptions: {
|
|
2016
|
-
async: true,
|
|
2017
|
-
marker_options: {
|
|
2018
|
-
startIconUrl: null,
|
|
2019
|
-
endIconUrl: null,
|
|
2020
|
-
shadowUrl: null,
|
|
2021
|
-
wptIcons: {
|
|
2022
|
-
'': L.divIcon({
|
|
2023
|
-
className: 'elevation-waypoint-marker',
|
|
2024
|
-
html: '<i class="elevation-waypoint-icon"></i>',
|
|
2025
|
-
iconSize: [30, 30],
|
|
2026
|
-
iconAnchor: [8, 30]
|
|
2027
|
-
})
|
|
2028
|
-
}
|
|
2029
|
-
}
|
|
2030
|
-
},
|
|
2031
2027
|
height: 200,
|
|
2032
2028
|
heightFactor: 1,
|
|
2033
2029
|
imperial: false,
|
|
@@ -2082,6 +2078,15 @@
|
|
|
2082
2078
|
sInterpolation: "curveStepAfter",
|
|
2083
2079
|
sRange: undefined,
|
|
2084
2080
|
width: 600,
|
|
2081
|
+
waypoints: true,
|
|
2082
|
+
wptIcons: {
|
|
2083
|
+
'': L.divIcon({
|
|
2084
|
+
className: 'elevation-waypoint-marker',
|
|
2085
|
+
html: '<i class="elevation-waypoint-icon"></i>',
|
|
2086
|
+
iconSize: [30, 30],
|
|
2087
|
+
iconAnchor: [8, 30]
|
|
2088
|
+
})
|
|
2089
|
+
},
|
|
2085
2090
|
xAttr: "dist",
|
|
2086
2091
|
xLabel: "km",
|
|
2087
2092
|
xTicks: undefined,
|
|
@@ -2103,7 +2108,7 @@
|
|
|
2103
2108
|
__TOGEOJSON: 'https://unpkg.com/@tmcw/togeojson@4.3.0/dist/togeojson.umd.js',
|
|
2104
2109
|
__LGEOMUTIL: 'https://unpkg.com/leaflet-geometryutil@0.9.3/src/leaflet.geometryutil.js',
|
|
2105
2110
|
__LALMOSTOVER: 'https://unpkg.com/leaflet-almostover@1.0.1/src/leaflet.almostover.js',
|
|
2106
|
-
__LDISTANCEM: 'https://unpkg.com/@raruto/leaflet-elevation@1.
|
|
2111
|
+
__LDISTANCEM: 'https://unpkg.com/@raruto/leaflet-elevation@1.7.3/libs/leaflet-distance-marker.min.js',
|
|
2107
2112
|
|
|
2108
2113
|
/*
|
|
2109
2114
|
* Add data to the diagram either from GPX or GeoJSON and update the axis domain and data
|
|
@@ -2111,7 +2116,7 @@
|
|
|
2111
2116
|
addData: function addData(d, layer) {
|
|
2112
2117
|
var _this = this;
|
|
2113
2118
|
|
|
2114
|
-
if (
|
|
2119
|
+
if (typeof layer === "undefined" && d.on) {
|
|
2115
2120
|
layer = d;
|
|
2116
2121
|
}
|
|
2117
2122
|
|
|
@@ -2150,12 +2155,46 @@
|
|
|
2150
2155
|
*/
|
|
2151
2156
|
clear: function clear() {
|
|
2152
2157
|
if (this._marker) this._marker.remove();
|
|
2153
|
-
if (this._chart) this.
|
|
2154
|
-
if (this._layers) this.
|
|
2158
|
+
if (this._chart) this._clearChart();
|
|
2159
|
+
if (this._layers) this._clearLayers();
|
|
2160
|
+
if (this._markers) this._clearMarkers();
|
|
2155
2161
|
this._data = [];
|
|
2156
2162
|
this.track_info = {};
|
|
2157
2163
|
|
|
2158
2164
|
this._fireEvt("eledata_clear");
|
|
2165
|
+
|
|
2166
|
+
this._updateChart();
|
|
2167
|
+
},
|
|
2168
|
+
_clearChart: function _clearChart() {
|
|
2169
|
+
if (this._events && this._events.elechart_updated) {
|
|
2170
|
+
this._events.elechart_updated.forEach(function (e) {
|
|
2171
|
+
return controlElevation.off('elechart_updated', e.fn, e.ctx);
|
|
2172
|
+
});
|
|
2173
|
+
}
|
|
2174
|
+
|
|
2175
|
+
if (this._chart && this._chart._container) {
|
|
2176
|
+
this._chart._container.selectAll('g.point .point').remove();
|
|
2177
|
+
|
|
2178
|
+
this._chart.clear();
|
|
2179
|
+
}
|
|
2180
|
+
},
|
|
2181
|
+
_clearLayers: function _clearLayers() {
|
|
2182
|
+
if (this._layers && this._layers.eachLayer) {
|
|
2183
|
+
this._layers.eachLayer(function (l) {
|
|
2184
|
+
return l.remove();
|
|
2185
|
+
});
|
|
2186
|
+
|
|
2187
|
+
this._layers.clearLayers();
|
|
2188
|
+
}
|
|
2189
|
+
},
|
|
2190
|
+
_clearMarkers: function _clearMarkers() {
|
|
2191
|
+
if (this._markers && this._markers.eachLayer) {
|
|
2192
|
+
this._markers.eachLayer(function (l) {
|
|
2193
|
+
return l.remove();
|
|
2194
|
+
});
|
|
2195
|
+
|
|
2196
|
+
this._markers.clearLayers();
|
|
2197
|
+
}
|
|
2159
2198
|
},
|
|
2160
2199
|
|
|
2161
2200
|
/**
|
|
@@ -2238,6 +2277,7 @@
|
|
|
2238
2277
|
initialize: function initialize(options) {
|
|
2239
2278
|
this._data = [];
|
|
2240
2279
|
this._layers = L.featureGroup();
|
|
2280
|
+
this._markers = L.featureGroup();
|
|
2241
2281
|
this._markedSegments = L.polyline([]);
|
|
2242
2282
|
this._chartEnabled = true, this.track_info = {};
|
|
2243
2283
|
this.options = deepMerge({}, this.options, options);
|
|
@@ -2539,7 +2579,7 @@
|
|
|
2539
2579
|
var _this8 = this;
|
|
2540
2580
|
|
|
2541
2581
|
each(coords, function (point) {
|
|
2542
|
-
_this8._addPoint(point.lat, point.lng, point.meta.ele);
|
|
2582
|
+
_this8._addPoint(point.lat, point.lng, typeof point.alt !== "undefined" ? point.alt : point.meta.ele);
|
|
2543
2583
|
|
|
2544
2584
|
_this8._fireEvt("elepoint_added", {
|
|
2545
2585
|
point: point,
|
|
@@ -2577,6 +2617,9 @@
|
|
|
2577
2617
|
_addLayer: function _addLayer(layer) {
|
|
2578
2618
|
if (layer) this._layers.addLayer(layer);
|
|
2579
2619
|
},
|
|
2620
|
+
_addMarker: function _addMarker(marker) {
|
|
2621
|
+
if (marker) this._markers.addLayer(marker);
|
|
2622
|
+
},
|
|
2580
2623
|
|
|
2581
2624
|
/**
|
|
2582
2625
|
* Adds the control to the given "detached" div.
|
|
@@ -3082,7 +3125,9 @@
|
|
|
3082
3125
|
* Calculates [x, y] domain and then update chart.
|
|
3083
3126
|
*/
|
|
3084
3127
|
_updateChart: function _updateChart() {
|
|
3085
|
-
if (
|
|
3128
|
+
if (
|
|
3129
|
+
/*!this._data.length ||*/
|
|
3130
|
+
!this._container) return;
|
|
3086
3131
|
|
|
3087
3132
|
this._fireEvt("elechart_axis");
|
|
3088
3133
|
|