@raruto/leaflet-elevation 1.8.0 → 1.8.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raruto/leaflet-elevation",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "description": "A Leaflet plugin that allows to add elevation profiles using d3js",
5
5
  "main": "dist/leaflet-elevation.min.js",
6
6
  "module": "src/index.js",
package/src/chart.js CHANGED
@@ -49,7 +49,7 @@ export var Chart = L.Class.extend({
49
49
  this._initScale();
50
50
 
51
51
  // Helpers
52
- this._clipPath = chart.get('clipPath');
52
+ this._mask = chart.get('mask');
53
53
  this._context = chart.get('context');
54
54
  this._brush = chart.get('brush');
55
55
 
@@ -61,6 +61,13 @@ export var Chart = L.Class.extend({
61
61
 
62
62
  // svg.on('resize', (e)=>console.log(e.detail));
63
63
 
64
+ // Handle multi-track segments (BETA)
65
+ this._maskGaps = [];
66
+ control.on('eletrack_added', (e) => {
67
+ this._maskGaps.push(e.index);
68
+ control.once('eledata_updated', (e) => this._maskGaps.push(e.index));
69
+ });
70
+
64
71
  },
65
72
 
66
73
  update: function(props) {
@@ -178,6 +185,10 @@ export var Chart = L.Class.extend({
178
185
  if (e.sourceEvent && e.sourceEvent.type == "mousedown") svg.style('cursor', 'grabbing');
179
186
  if (e.transform.k == 1 && e.transform.x == 0) {
180
187
  this._container.classed('zoomed', true);
188
+ // Apply d3-zoom (bind <clipPath> mask)
189
+ if (this._mask) {
190
+ this._point.attr('mask', 'url(#' + this._mask.attr('id') + ')');
191
+ }
181
192
  }
182
193
  this.zooming = true;
183
194
  };
@@ -185,6 +196,10 @@ export var Chart = L.Class.extend({
185
196
  const onEnd = (e) => {
186
197
  if (e.transform.k ==1 && e.transform.x == 0){
187
198
  this._container.classed('zoomed', false);
199
+ // Apply d3-zoom (bind <clipPath> mask)
200
+ if (this._mask) {
201
+ this._point.attr('mask', null);
202
+ }
188
203
  }
189
204
  this.zooming = false;
190
205
  svg.style('cursor', '');
@@ -497,6 +512,24 @@ export var Chart = L.Class.extend({
497
512
  [this._width() - margin.right, Infinity]
498
513
  ]);
499
514
 
515
+ // Apply svg mask on multi-track segments (BETA)
516
+ this._mask.selectAll(".gap").remove()
517
+ this._maskGaps.forEach((d, i) => {
518
+ if(i >= this._maskGaps.length - 2) return;
519
+ let d1 = this._data[this._maskGaps[i]];
520
+ let d2 = this._data[this._maskGaps[i + 1]];
521
+ let x1 = this._x(this._data[this._findIndexForLatLng(d1.latlng)].dist);
522
+ let x2 = this._x(this._data[this._findIndexForLatLng(d2.latlng)].dist);
523
+ this._mask
524
+ .append("rect")
525
+ .attr("x", x1)
526
+ .attr("y", 0)
527
+ .attr("width", x2 - x1 )
528
+ .attr("height", this._height())
529
+ .attr('class', 'gap')
530
+ .attr('fill-opacity', '0.8')
531
+ .attr("fill", 'black'); // black = hide
532
+ });
500
533
  },
501
534
 
502
535
  _updateLegend: function () {
@@ -573,8 +606,8 @@ export var Chart = L.Class.extend({
573
606
  }
574
607
 
575
608
  // Apply d3-zoom (bind <clipPath> mask)
576
- if (this._clipPath) {
577
- path.attr('clip-path', 'url(#' + this._clipPath.attr('id') + ')');
609
+ if (this._mask) {
610
+ path.attr('mask', 'url(#' + this._mask.attr('id') + ')');
578
611
  }
579
612
 
580
613
  });
package/src/components.js CHANGED
@@ -505,11 +505,11 @@ export const Chart = ({
505
505
  };
506
506
 
507
507
  // SVG Paths
508
- const clipPath = panes.area.append("svg:clipPath").attr("id", 'elevation-clipper');
509
- const clipRect = clipPath.append("svg:rect");
508
+ const mask = panes.area.append("svg:mask").attr("id", 'elevation-clipper').attr('fill-opacity', 1);
509
+ const maskRect = mask.append("svg:rect").attr('class', 'zoom').attr('fill', 'white'); // white = transparent
510
510
 
511
511
  // Canvas Paths
512
- const foreignObject = panes.area.append('svg:foreignObject');
512
+ const foreignObject = panes.area.append('svg:foreignObject').attr('mask', 'url(#' + mask.attr('id') + ')');
513
513
  const canvas = foreignObject.append('xhtml:canvas').attr('class', 'canvas-plot');
514
514
  const context = canvas.node().getContext('2d');
515
515
 
@@ -523,7 +523,7 @@ export const Chart = ({
523
523
  const scale = (opts) => ({ x: Scale(opts.x), y: Scale(opts.y)});
524
524
 
525
525
  let utils = {
526
- clipPath,
526
+ mask,
527
527
  canvas,
528
528
  context,
529
529
  brush,
@@ -560,7 +560,7 @@ export const Chart = ({
560
560
  .style("transform", "translate(" + margins.left + "px," + margins.top + "px)");
561
561
  }
562
562
 
563
- clipRect
563
+ maskRect
564
564
  .attr("x", 0)
565
565
  .attr("y", 0)
566
566
  .attr("width", _width)
package/src/control.js CHANGED
@@ -17,7 +17,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
17
17
  __TOGEOJSON: 'https://unpkg.com/@tmcw/togeojson@4.3.0/dist/togeojson.umd.js',
18
18
  __LGEOMUTIL: 'https://unpkg.com/leaflet-geometryutil@0.9.3/src/leaflet.geometryutil.js',
19
19
  __LALMOSTOVER: 'https://unpkg.com/leaflet-almostover@1.0.1/src/leaflet.almostover.js',
20
- __LDISTANCEM: 'https://unpkg.com/@raruto/leaflet-elevation@1.7.5/libs/leaflet-distance-marker.min.js',
20
+ __LDISTANCEM: 'https://unpkg.com/@raruto/leaflet-elevation@1.8.1/libs/leaflet-distance-marker.min.js',
21
21
 
22
22
  /*
23
23
  * Add data to the diagram either from GPX or GeoJSON and update the axis domain and data
@@ -997,6 +997,7 @@ Elevation.addInitHook(function() {
997
997
  }
998
998
  });
999
999
  }
1000
+
1000
1001
  });
1001
1002
 
1002
1003
  // Basic canvas renderer support.
package/src/index.css CHANGED
@@ -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
  }