@raruto/leaflet-elevation 1.7.2 → 1.7.6

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/utils.js CHANGED
@@ -73,13 +73,13 @@ export function GeoJSONLoader(data, control) {
73
73
  }
74
74
  control = control || this;
75
75
 
76
- let distanceMarkers = (
76
+ let distanceMarkers = (
77
77
  control.options.distanceMarkers === true
78
78
  ? { lazy: true }
79
79
  : L.extend({ lazy: true }, control.options.distanceMarkers)
80
80
  );
81
81
 
82
- let wptIcons = control.options.wptIcons;
82
+ let { wptIcons, wptLabels } = control.options;
83
83
 
84
84
  let layer = L.geoJson(data, {
85
85
  distanceMarkers: distanceMarkers,
@@ -94,24 +94,36 @@ export function GeoJSONLoader(data, control) {
94
94
  if (!control.options.waypoints) return;
95
95
 
96
96
  let prop = feature.properties;
97
- let desc = prop.desc ? prop.desc : '';
98
- let name = prop.name ? prop.name : '';
99
- let sym = (prop.sym ? prop.sym : name).replace(' ', '-').replace('"', '').replace("'", '').toLowerCase();
100
-
101
- // generate and cache appropriate icon symbol
102
- if (!wptIcons.hasOwnProperty(sym)) {
103
- wptIcons[sym] = L.divIcon(
104
- L.extend({}, wptIcons[""].options, { html: '<i class="elevation-waypoint-icon ' + sym + '"></i>' } )
97
+ let desc = prop.desc ?? '';
98
+ let name = prop.name ?? '';
99
+ let sym = (prop.sym ?? name).replace(' ', '-').replace('"', '').replace("'", '').toLowerCase();
100
+
101
+ // Handle chart waypoints (dots)
102
+ if ([true, 'dots'].includes(control.options.waypoints)) {
103
+ control._registerCheckPoint({
104
+ latlng: latlng,
105
+ label: ([true, 'dots'].includes(wptLabels) ? name : '')
106
+ },
107
+ true
105
108
  );
106
109
  }
107
- let marker = L.marker(latlng, { icon: wptIcons[sym] });
108
- if (name || desc) {
109
- marker.bindPopup("<b>" + name + "</b>" + (desc.length > 0 ? '<br>' + desc : '')).openPopup();
110
+
111
+ // Handle map waypoints (markers)
112
+ if ([true, 'markers'].includes(control.options.waypoints) && wptIcons != false) {
113
+ // generate and cache appropriate icon symbol
114
+ if (!wptIcons.hasOwnProperty(sym)) {
115
+ wptIcons[sym] = L.divIcon(
116
+ L.extend({}, wptIcons[""].options, { html: '<i class="elevation-waypoint-icon ' + sym + '"></i>' } )
117
+ );
118
+ }
119
+ let marker = L.marker(latlng, { icon: wptIcons[sym] });
120
+ if ([true, 'markers'].includes(wptLabels) && (name || desc)) {
121
+ marker.bindPopup("<b>" + name + "</b>" + (desc.length > 0 ? '<br>' + desc : '')).openPopup();
122
+ }
123
+ control._addMarker(marker);
124
+ control.fire('waypoint_added', { point: marker, element: latlng, properties: prop });
125
+ return marker;
110
126
  }
111
- control._addMarker(marker);
112
- control._registerCheckPoint({latlng: latlng, label: name}, true);
113
- control.fire('waypoint_added', { point: marker, element: latlng, properties: prop });
114
- return marker;
115
127
  },
116
128
  onEachFeature: (feature, layer) => {
117
129
  if (feature.geometry && feature.geometry.type == 'Point') return;
@@ -138,12 +150,12 @@ export function GeoJSONLoader(data, control) {
138
150
 
139
151
  // Postpone adding the distance markers (lazy: true)
140
152
  if(control.options.distanceMarkers && distanceMarkers.lazy) {
141
- layer.on('add remove', (e) => {
142
- let path = e.target;
143
- if (L.DistanceMarkers && path instanceof L.Polyline) {
153
+ layer.on('add remove', (e) => {
154
+ let path = e.target;
155
+ if (L.DistanceMarkers && path instanceof L.Polyline) {
144
156
  path[e.type + 'DistanceMarkers']();
145
- }
146
- });
157
+ }
158
+ });
147
159
  }
148
160
 
149
161
  control.track_info = L.extend({}, control.track_info, { type: "geojson", name: data.name });
@@ -318,8 +330,8 @@ export function toggleClass(targetNode, className, conditional) {
318
330
  }
319
331
 
320
332
  export function replaceClass(targetNode, removeClassName, addClassName) {
321
- if (removeClassName) removeClass(targetNode, removeClassName);
322
- if (addClassName) addClass(targetNode, addClassName);
333
+ if (removeClassName) removeClass(targetNode, removeClassName);
334
+ if (addClassName) addClass(targetNode, addClassName);
323
335
  }
324
336
 
325
337
  export function style(targetNode, name, value) {
@@ -328,7 +340,7 @@ export function style(targetNode, name, value) {
328
340
  }
329
341
 
330
342
  export function toggleStyle(targetNode, name, value, conditional) {
331
- return style(targetNode, name, conditional ? value : '');
343
+ return style(targetNode, name, conditional ? value : '');
332
344
  }
333
345
 
334
346
  export function toggleEvent(leafletElement, eventName, handler, conditional) {