@raruto/leaflet-elevation 1.8.0 → 1.8.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.
@@ -36,7 +36,6 @@
36
36
  user-select: none;
37
37
  }
38
38
 
39
- .elevation-control.elevation .background.zoomed .point,
40
39
  .elevation-control.elevation .background.zoomed .axis.time {
41
40
  display: none;
42
41
  }
@@ -149,7 +149,25 @@
149
149
  }, control.options.distanceMarkers);
150
150
  var _control$options = control.options,
151
151
  wptIcons = _control$options.wptIcons,
152
- wptLabels = _control$options.wptLabels;
152
+ wptLabels = _control$options.wptLabels; // Partially fix MultiLineStrings (trk > trkseg + trkseg) splitting them into seperate LineStrings (trk > trkseg, trk > trkseg)
153
+
154
+ data.features.forEach(function (d) {
155
+ if (d.type == 'Feature' && d.geometry.type == "MultiLineString") {
156
+ d.geometry.coordinates.forEach(function (coords) {
157
+ data.features.push({
158
+ type: 'Feature',
159
+ geometry: {
160
+ type: 'LineString',
161
+ coordinates: coords
162
+ },
163
+ properties: d.properties
164
+ });
165
+ });
166
+ }
167
+ });
168
+ data.features = data.features.filter(function (d) {
169
+ return d.type && d.geometry.type != "MultiLineString";
170
+ });
153
171
  var layer = L.geoJson(data, {
154
172
  distanceMarkers: distanceMarkers,
155
173
  style: function style(feature) {
@@ -949,10 +967,11 @@
949
967
  legend: g.append('g').attr("class", "legend")
950
968
  }; // SVG Paths
951
969
 
952
- var clipPath = panes.area.append("svg:clipPath").attr("id", 'elevation-clipper');
953
- var clipRect = clipPath.append("svg:rect"); // Canvas Paths
970
+ var mask = panes.area.append("svg:mask").attr("id", 'elevation-clipper').attr('fill-opacity', 1);
971
+ var maskRect = mask.append("svg:rect").attr('class', 'zoom').attr('fill', 'white'); // white = transparent
972
+ // Canvas Paths
954
973
 
955
- var foreignObject = panes.area.append('svg:foreignObject');
974
+ var foreignObject = panes.area.append('svg:foreignObject').attr('mask', 'url(#' + mask.attr('id') + ')');
956
975
  var canvas = foreignObject.append('xhtml:canvas').attr('class', 'canvas-plot');
957
976
  var context = canvas.node().getContext('2d'); // Add tooltip
958
977
 
@@ -976,7 +995,7 @@
976
995
  };
977
996
 
978
997
  var utils = {
979
- clipPath: clipPath,
998
+ mask: mask,
980
999
  canvas: canvas,
981
1000
  context: context,
982
1001
  brush: brush
@@ -1007,7 +1026,7 @@
1007
1026
  canvas.style("transform", "translate(" + margins.left + "px," + margins.top + "px)");
1008
1027
  }
1009
1028
 
1010
- clipRect.attr("x", 0).attr("y", 0).attr("width", _width).attr("height", _height);
1029
+ maskRect.attr("x", 0).attr("y", 0).attr("width", _width).attr("height", _height);
1011
1030
  foreignObject.attr('width', _width).attr('height', _height);
1012
1031
  canvas.attr('width', _width).attr('height', _height);
1013
1032
 
@@ -1073,6 +1092,8 @@
1073
1092
  var Chart$1 = L.Class.extend({
1074
1093
  includes: L.Evented ? L.Evented.prototype : L.Mixin.Events,
1075
1094
  initialize: function initialize(opts, control) {
1095
+ var _this = this;
1096
+
1076
1097
  this.options = opts;
1077
1098
  this.control = control;
1078
1099
  this._data = []; // cache registered components
@@ -1107,14 +1128,24 @@
1107
1128
  this._initScale(); // Helpers
1108
1129
 
1109
1130
 
1110
- this._clipPath = chart.get('clipPath');
1131
+ this._mask = chart.get('mask');
1111
1132
  this._context = chart.get('context');
1112
1133
  this._brush = chart.get('brush');
1113
1134
  this._zoom = d3.zoom();
1114
1135
  this._drag = d3.drag(); // Interactions
1115
1136
 
1116
1137
  this._initInteractions(); // svg.on('resize', (e)=>console.log(e.detail));
1138
+ // Handle multi-track segments (BETA)
1139
+
1140
+
1141
+ this._maskGaps = [];
1142
+ control.on('eletrack_added', function (e) {
1143
+ _this._maskGaps.push(e.index);
1117
1144
 
1145
+ control.once('eledata_updated', function (e) {
1146
+ return _this._maskGaps.push(e.index);
1147
+ });
1148
+ });
1118
1149
  },
1119
1150
  update: function update(props) {
1120
1151
  if (props) {
@@ -1135,11 +1166,11 @@
1135
1166
  return this;
1136
1167
  },
1137
1168
  render: function render() {
1138
- var _this = this;
1169
+ var _this2 = this;
1139
1170
 
1140
1171
  return function (container) {
1141
1172
  return container.append(function () {
1142
- return _this._container.node();
1173
+ return _this2._container.node();
1143
1174
  });
1144
1175
  };
1145
1176
  },
@@ -1155,6 +1186,10 @@
1155
1186
  // this._y.domain([0, 1]);
1156
1187
  // }
1157
1188
 
1189
+
1190
+ this._maskGaps = [];
1191
+
1192
+ this._mask.selectAll(".gap").remove();
1158
1193
  },
1159
1194
  _drawPath: function _drawPath(name) {
1160
1195
  var path = this._paths[name];
@@ -1191,43 +1226,43 @@
1191
1226
  * Initialize "d3-brush".
1192
1227
  */
1193
1228
  _initBrush: function _initBrush(e) {
1194
- var _this2 = this;
1229
+ var _this3 = this;
1195
1230
 
1196
1231
  var brush = function brush(e) {
1197
- if (!_this2._data.length) return;
1232
+ if (!_this3._data.length) return;
1198
1233
  var extent = e.selection;
1199
1234
 
1200
1235
  if (extent) {
1201
- var start = _this2._findIndexForXCoord(extent[0]);
1236
+ var start = _this3._findIndexForXCoord(extent[0]);
1202
1237
 
1203
- var end = _this2._findIndexForXCoord(extent[1]);
1238
+ var end = _this3._findIndexForXCoord(extent[1]);
1204
1239
 
1205
- _this2.fire('dragged', {
1206
- dragstart: _this2._data[start],
1207
- dragend: _this2._data[end]
1240
+ _this3.fire('dragged', {
1241
+ dragstart: _this3._data[start],
1242
+ dragend: _this3._data[end]
1208
1243
  });
1209
1244
  }
1210
1245
  };
1211
1246
 
1212
1247
  var focus = function focus(e) {
1213
- if (!_this2._data.length) return;
1248
+ if (!_this3._data.length) return;
1214
1249
  if (e.type == 'brush' && !e.sourceEvent) return;
1215
1250
 
1216
- var rect = _this2._chart.panes.brush.select('.overlay').node();
1251
+ var rect = _this3._chart.panes.brush.select('.overlay').node();
1217
1252
 
1218
1253
  var coords = d3.pointers(e, rect)[0];
1219
1254
  var xCoord = coords[0];
1220
1255
 
1221
- var item = _this2._data[_this2._findIndexForXCoord(xCoord)];
1256
+ var item = _this3._data[_this3._findIndexForXCoord(xCoord)];
1222
1257
 
1223
- _this2.fire("mouse_move", {
1258
+ _this3.fire("mouse_move", {
1224
1259
  item: item,
1225
1260
  xCoord: xCoord
1226
1261
  });
1227
1262
  };
1228
1263
 
1229
1264
  this._brush.filter(function (e) {
1230
- return _this2._brushEnabled && !e.shiftKey && !e.button;
1265
+ return _this3._brushEnabled && !e.shiftKey && !e.button;
1231
1266
  }).on("end.update", brush).on("brush.update", focus);
1232
1267
 
1233
1268
  this._chart.panes.brush.on("mouseenter.focus touchstart.focus", this.fire.bind(this, "mouse_enter")).on("mouseout.focus touchend.focus", this.fire.bind(this, "mouse_out")).on("mousemove.focus touchmove.focus", focus);
@@ -1237,7 +1272,7 @@
1237
1272
  * Initialize "d3-zoom"
1238
1273
  */
1239
1274
  _initClipper: function _initClipper() {
1240
- var _this3 = this;
1275
+ var _this4 = this;
1241
1276
 
1242
1277
  var svg = this._container;
1243
1278
  var margin = this.options.margins;
@@ -1247,42 +1282,52 @@
1247
1282
  if (e.sourceEvent && e.sourceEvent.type == "mousedown") svg.style('cursor', 'grabbing');
1248
1283
 
1249
1284
  if (e.transform.k == 1 && e.transform.x == 0) {
1250
- _this3._container.classed('zoomed', true);
1285
+ _this4._container.classed('zoomed', true); // Apply d3-zoom (bind <clipPath> mask)
1286
+
1287
+
1288
+ if (_this4._mask) {
1289
+ _this4._point.attr('mask', 'url(#' + _this4._mask.attr('id') + ')');
1290
+ }
1251
1291
  }
1252
1292
 
1253
- _this3.zooming = true;
1293
+ _this4.zooming = true;
1254
1294
  };
1255
1295
 
1256
1296
  var onEnd = function onEnd(e) {
1257
1297
  if (e.transform.k == 1 && e.transform.x == 0) {
1258
- _this3._container.classed('zoomed', false);
1298
+ _this4._container.classed('zoomed', false); // Apply d3-zoom (bind <clipPath> mask)
1299
+
1300
+
1301
+ if (_this4._mask) {
1302
+ _this4._point.attr('mask', null);
1303
+ }
1259
1304
  }
1260
1305
 
1261
- _this3.zooming = false;
1306
+ _this4.zooming = false;
1262
1307
  svg.style('cursor', '');
1263
1308
  };
1264
1309
 
1265
1310
  var onZoom = function onZoom(e) {
1266
1311
  // TODO: find a faster way to redraw the chart.
1267
- _this3.zooming = false;
1312
+ _this4.zooming = false;
1268
1313
 
1269
- _this3._updateScale(); // hacky way for restoring x scale when zooming out
1314
+ _this4._updateScale(); // hacky way for restoring x scale when zooming out
1270
1315
 
1271
1316
 
1272
- _this3.zooming = true;
1273
- _this3._scales.distance = _this3._x = e.transform.rescaleX(_this3._x); // calculate x scale at zoom level
1317
+ _this4.zooming = true;
1318
+ _this4._scales.distance = _this4._x = e.transform.rescaleX(_this4._x); // calculate x scale at zoom level
1274
1319
 
1275
- _this3._resetDrag();
1320
+ _this4._resetDrag();
1276
1321
 
1277
1322
  if (e.sourceEvent && e.sourceEvent.type == "mousemove") {
1278
- _this3._hideDiagramIndicator();
1323
+ _this4._hideDiagramIndicator();
1279
1324
  }
1280
1325
 
1281
- _this3.fire('zoom');
1326
+ _this4.fire('zoom');
1282
1327
  };
1283
1328
 
1284
1329
  zoom.scaleExtent([1, 10]).extent([[margin.left, 0], [this._width() - margin.right, this._height()]]).translateExtent([[margin.left, -Infinity], [this._width() - margin.right, Infinity]]).filter(function (e) {
1285
- return _this3._zoomEnabled && (e.shiftKey || e.buttons == 4);
1330
+ return _this4._zoomEnabled && (e.shiftKey || e.buttons == 4);
1286
1331
  }).on("start", onStart).on("end", onEnd).on("zoom", onZoom);
1287
1332
  svg.call(zoom); // add zoom functionality to "svg" group
1288
1333
  // d3.select("body").on("keydown.grabzoom keyup.grabzoom", (e) => svg.style('cursor', e.shiftKey ? 'move' : ''));
@@ -1301,7 +1346,7 @@
1301
1346
  * Toggle chart data on legend click
1302
1347
  */
1303
1348
  _initLegend: function _initLegend() {
1304
- var _this4 = this;
1349
+ var _this5 = this;
1305
1350
 
1306
1351
  this._container.on('legend_clicked', function (e) {
1307
1352
  var _e$detail = e.detail,
@@ -1321,9 +1366,9 @@
1321
1366
 
1322
1367
  toggleClass(path, 'leaflet-hidden', enabled);
1323
1368
 
1324
- _this4._updateArea();
1369
+ _this5._updateArea();
1325
1370
 
1326
- _this4.fire("elepath_toggle", {
1371
+ _this5.fire("elepath_toggle", {
1327
1372
  path: path,
1328
1373
  name: name,
1329
1374
  legend: legend,
@@ -1336,7 +1381,7 @@
1336
1381
  * Initialize "ruler".
1337
1382
  */
1338
1383
  _initRuler: function _initRuler() {
1339
- var _this5 = this;
1384
+ var _this6 = this;
1340
1385
 
1341
1386
  if (!this.options.ruler) return; // const yMax = this._height();
1342
1387
 
@@ -1344,35 +1389,35 @@
1344
1389
  var drag = this._drag;
1345
1390
 
1346
1391
  var label = function label(e, d) {
1347
- var yMax = _this5._height();
1392
+ var yMax = _this6._height();
1348
1393
 
1349
- var y = _this5._ruler.data()[0].y;
1394
+ var y = _this6._ruler.data()[0].y;
1350
1395
 
1351
- if (y >= yMax || y <= 0) _this5._ruler.select(".horizontal-drag-label").text('');
1396
+ if (y >= yMax || y <= 0) _this6._ruler.select(".horizontal-drag-label").text('');
1352
1397
 
1353
- _this5._hideDiagramIndicator();
1398
+ _this6._hideDiagramIndicator();
1354
1399
  };
1355
1400
 
1356
1401
  var position = function position(e, d) {
1357
- var yMax = _this5._height();
1402
+ var yMax = _this6._height();
1358
1403
 
1359
- var yCoord = d3.pointers(e, _this5._area.node())[0][1];
1404
+ var yCoord = d3.pointers(e, _this6._area.node())[0][1];
1360
1405
  var y = yCoord > 0 ? yCoord < yMax ? yCoord : yMax : 0;
1361
1406
 
1362
- var z = _this5._y.invert(y);
1407
+ var z = _this6._y.invert(y);
1363
1408
 
1364
- var data = L.extend(_this5._ruler.data()[0], {
1409
+ var data = L.extend(_this6._ruler.data()[0], {
1365
1410
  y: y
1366
1411
  });
1367
1412
 
1368
- _this5._ruler.data([data]).attr("transform", function (d) {
1413
+ _this6._ruler.data([data]).attr("transform", function (d) {
1369
1414
  return "translate(" + d.x + "," + d.y + ")";
1370
1415
  }).classed('active', y < yMax);
1371
1416
 
1372
- _this5._container.select(".horizontal-drag-label").text(formatNum(z) + " " + (_this5.options.imperial ? 'ft' : 'm'));
1417
+ _this6._container.select(".horizontal-drag-label").text(formatNum(z) + " " + (_this6.options.imperial ? 'ft' : 'm'));
1373
1418
 
1374
- _this5.fire('ruler_filter', {
1375
- coords: yCoord < yMax && yCoord > 0 ? _this5._findCoordsForY(yCoord) : []
1419
+ _this6.fire('ruler_filter', {
1420
+ coords: yCoord < yMax && yCoord > 0 ? _this6._findCoordsForY(yCoord) : []
1376
1421
  });
1377
1422
  };
1378
1423
 
@@ -1545,12 +1590,30 @@
1545
1590
  });
1546
1591
  },
1547
1592
  _updateClipper: function _updateClipper() {
1593
+ var _this7 = this;
1594
+
1548
1595
  var margin = this.options.margins;
1549
1596
 
1550
- this._zoom.scaleExtent([1, 10]).extent([[margin.left, 0], [this._width() - margin.right, this._height()]]).translateExtent([[margin.left, -Infinity], [this._width() - margin.right, Infinity]]);
1597
+ this._zoom.scaleExtent([1, 10]).extent([[margin.left, 0], [this._width() - margin.right, this._height()]]).translateExtent([[margin.left, -Infinity], [this._width() - margin.right, Infinity]]); // Apply svg mask on multi-track segments (BETA)
1598
+
1599
+
1600
+ this._mask.selectAll(".gap").remove();
1601
+
1602
+ this._maskGaps.forEach(function (d, i) {
1603
+ if (i >= _this7._maskGaps.length - 2) return;
1604
+ var d1 = _this7._data[_this7._maskGaps[i]];
1605
+ var d2 = _this7._data[_this7._maskGaps[i + 1]];
1606
+
1607
+ var x1 = _this7._x(_this7._data[_this7._findIndexForLatLng(d1.latlng)].dist);
1608
+
1609
+ var x2 = _this7._x(_this7._data[_this7._findIndexForLatLng(d2.latlng)].dist);
1610
+
1611
+ _this7._mask.append("rect").attr("x", x1).attr("y", 0).attr("width", x2 - x1).attr("height", _this7._height()).attr('class', 'gap').attr('fill-opacity', '0.8').attr("fill", 'black'); // black = hide
1612
+
1613
+ });
1551
1614
  },
1552
1615
  _updateLegend: function _updateLegend() {
1553
- var _this6 = this;
1616
+ var _this8 = this;
1554
1617
 
1555
1618
  if (this.options.legend === false) return;
1556
1619
  var legends = this._props.legendItems;
@@ -1606,21 +1669,21 @@
1606
1669
  var legend = d3.select(n[i]);
1607
1670
  var rect = legend.select('rect');
1608
1671
  var name = legend.attr('data-name');
1609
- var path = _this6._paths[name];
1672
+ var path = _this8._paths[name];
1610
1673
  var tx = v[i] * 55;
1611
1674
  var ty = xAxesB * 2;
1612
1675
  legend // Adjust legend item positions
1613
1676
  .attr("transform", "translate(" + tx + ", " + ty + ")"); // Set initial state (disabled controls)
1614
1677
 
1615
- if (name in _this6.options && _this6.options[name] == 'disabled') {
1678
+ if (name in _this8.options && _this8.options[name] == 'disabled') {
1616
1679
  path.classed('leaflet-hidden', true);
1617
1680
  legend.select('text').style('text-decoration-line', 'line-through');
1618
1681
  legend.select('rect').style('fill-opacity', '0');
1619
1682
  } // Apply d3-zoom (bind <clipPath> mask)
1620
1683
 
1621
1684
 
1622
- if (_this6._clipPath) {
1623
- path.attr('clip-path', 'url(#' + _this6._clipPath.attr('id') + ')');
1685
+ if (_this8._mask) {
1686
+ path.attr('mask', 'url(#' + _this8._mask.attr('id') + ')');
1624
1687
  }
1625
1688
  });
1626
1689
  },
@@ -1689,10 +1752,10 @@
1689
1752
  * Finds a data entry for a given x-coordinate of the diagram
1690
1753
  */
1691
1754
  _findIndexForXCoord: function _findIndexForXCoord(x) {
1692
- var _this7 = this;
1755
+ var _this9 = this;
1693
1756
 
1694
1757
  return d3.bisector(function (d) {
1695
- return d[_this7.options.xAttr];
1758
+ return d[_this9.options.xAttr];
1696
1759
  }).left(this._data || [0, 1], this._x.invert(x));
1697
1760
  },
1698
1761
 
@@ -1994,7 +2057,7 @@
1994
2057
  __TOGEOJSON: 'https://unpkg.com/@tmcw/togeojson@4.3.0/dist/togeojson.umd.js',
1995
2058
  __LGEOMUTIL: 'https://unpkg.com/leaflet-geometryutil@0.9.3/src/leaflet.geometryutil.js',
1996
2059
  __LALMOSTOVER: 'https://unpkg.com/leaflet-almostover@1.0.1/src/leaflet.almostover.js',
1997
- __LDISTANCEM: 'https://unpkg.com/@raruto/leaflet-elevation@1.7.5/libs/leaflet-distance-marker.min.js',
2060
+ __LDISTANCEM: 'https://unpkg.com/@raruto/leaflet-elevation@1.8.3/libs/leaflet-distance-marker.min.js',
1998
2061
 
1999
2062
  /*
2000
2063
  * Add data to the diagram either from GPX or GeoJSON and update the axis domain and data