Commit 2314d53c authored by Clouard Regis's avatar Clouard Regis
Browse files

Fixed bug add/remove legend for tracks.

parent f5c53818
......@@ -117,6 +117,10 @@ function addDownloadButton(event, pseudo, track, div) {
icon.className = "fa fa-download";
button.prepend(icon);
div.appendChild(button);
let handler1 = function (e) {
downloadFile(pseudo + ".gpx", track);
};
button.addEventListener("click", handler1);
return button;
}
......
......@@ -69,7 +69,8 @@ var _DEFAULT_GPX_OPTS = {
joinTrackSegments: true
};
var legend;
let legend;
let legendCount = 0;
L.GPX = L.FeatureGroup.extend({
initialize: function (gpx, options) {
......@@ -98,30 +99,24 @@ L.GPX = L.FeatureGroup.extend({
get_duration_string: function (duration, hidems) {
var s = '';
if (duration >= _DAY_IN_MILLIS) {
s += Math.floor(duration / _DAY_IN_MILLIS) + 'd ';
duration = duration % _DAY_IN_MILLIS;
}
if (duration >= _HOUR_IN_MILLIS) {
s += Math.floor(duration / _HOUR_IN_MILLIS) + ':';
duration = duration % _HOUR_IN_MILLIS;
}
var mins = Math.floor(duration / _MINUTE_IN_MILLIS);
duration = duration % _MINUTE_IN_MILLIS;
if (mins < 10) s += '0';
s += mins + '\'';
var secs = Math.floor(duration / _SECOND_IN_MILLIS);
duration = duration % _SECOND_IN_MILLIS;
if (secs < 10) s += '0';
s += secs;
if (!hidems && duration > 0) s += '.' + Math.round(Math.floor(duration) * 1000) / 1000;
else s += '"';
return s;
},
......@@ -636,52 +631,55 @@ L.GPX = L.FeatureGroup.extend({
coords_local.push(ll); // Added by Martin Féaux De Lacroix
}
// add track
var l = new L.Polyline(coords, this._extract_styling(line, polyline_options, options.polyline_options));
// Added by Martin Féaux De Lacroix
l.on("mouseover", function (e) {
e.sourceTarget.setStyle({opacity: 0});
addColorLegend(map);
hover_layers.forEach(function (hl) {
//hl.bringToFront(); // TODO Pourquoi pas ?
hl.setStyle({opacity: 1});
});
var l = new L.Polyline(coords, this._extract_styling(line, polyline_options, options.polyline_options));
l.value = 0;
l.on("remove", function (e) {
if (this.value > 0) {
removeColorLegend(map);
}
});
l.on("mouseout", function (e) {
e.sourceTarget.setStyle({opacity: 1});
removeColorLegend(map);
hover_layers.forEach(function (hl) {
hl.setStyle({opacity: 0});
});
l.on("click", function (e) {
const polyline = this;
if (polyline.value > 0) {
polyline.value = 0;
removeColorLegend(map);
e.sourceTarget.setStyle({opacity: 1});
hover_layers.forEach(function (hl) {
hl.setStyle({opacity: 0});
});
} else {
polyline.value = 1;
addColorLegend(map);
e.sourceTarget.setStyle({opacity: 0});
hover_layers.forEach(function (hl) {
hl.setStyle({opacity: 1});
});
}
});
this.fire('addline', {line: l, element: line});
layers.push(l);
if (options.marker_options.startIcon || options.marker_options.startIconUrl) {
// add start pin
var marker = new L.Marker(coords[0], {
let startMarker = new L.Marker(coords[0], {
clickable: options.marker_options.clickable,
icon: options.marker_options.startIcon || new L.GPXTrackIcon({iconUrl: options.marker_options.startIconUrl})
});
this.fire('addpoint', {point: marker, point_type: 'start', element: el[0]});
layers.push(marker);
this.fire('addpoint', {point: startMarker, point_type: 'start', element: el[0]});
layers.push(startMarker);
}
if (options.marker_options.endIcon || options.marker_options.endIconUrl) {
// add end pin
var marker = new L.Marker(coords[coords.length - 1], {
var endMarker = new L.Marker(coords[coords.length - 1], {
clickable: options.marker_options.clickable,
icon: options.marker_options.endIcon || new L.GPXTrackIcon({iconUrl: options.marker_options.endIconUrl})
});
this.fire('addpoint', {point: marker, point_type: 'end', element: el[el.length - 1]});
layers.push(marker);
this.fire('addpoint', {point: endMarker, point_type: 'end', element: el[el.length - 1]});
layers.push(endMarker);
}
// add named markers
for (var i = 0; i < markers.length; i++) {
for (let i = 0; i < markers.length; i++) {
var marker = new L.Marker(markers[i].coords, {
clickable: options.marker_options.clickable,
title: markers[i].label,
......@@ -709,7 +707,6 @@ L.GPX = L.FeatureGroup.extend({
}
return this._merge_objs(style, overrides)
},
_dist2d: function (a, b) {
var R = 6371000;
var dLat = this._deg2rad(b.lat - a.lat);
......@@ -721,47 +718,47 @@ L.GPX = L.FeatureGroup.extend({
Math.sin(dLon / 2) *
Math.sin(dLon / 2);
var c = 2 * Math.atan2(Math.sqrt(r), Math.sqrt(1 - r));
var d = R * c;
return d;
return R * c;
},
_dist3d: function (a, b) {
var planar = this._dist2d(a, b);
var height = Math.abs(b.meta.ele - a.meta.ele);
return Math.sqrt(Math.pow(planar, 2) + Math.pow(height, 2));
},
_deg2rad: function (deg) {
return deg * Math.PI / 180;
}
});
function addColorLegend(map) {
legend = L.control({position: 'bottomleft'});
legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend');
/*
let speeds = ['&le; 2 km/h', '&le; 6 km/h', '&le; 10 km/h', '&le; 13 km/h', '&gt; 13 km/h'],
*/
let speeds = ['&le; 30 min/km', '&le; 10 min/km', '&le; 6 min/km', '&le; 4.61 min/km', '&gt; 4.61 min/km'],
colors = ['red', 'orange', 'yellow', 'greenyellow', 'green'];
div.style.backgroundColor = "white";
div.style.lineHeight = "18px";
div.style.color = "#555";
div.style.padding = "5px";
div.style.borderRadius= "5px";
for (let i = 0; i < speeds.length; i++) {
div.innerHTML += '<i style="width: 18px; height: 18px; float: left; margin-right: 8px; opacity:0.7; background:' + colors[i] + '"></i> ' + speeds[i] + ' <br>';
}
return div;
};
legend.addTo(map);
if (legendCount === 0) {
legend = L.control({position: 'bottomleft'});
legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend');
let speeds = ['&le; 30 min/km (jardinage)', '&le; 10 min/km (marche)', '&le; 6 min/km (mixte)', '&le; 4.61 min/km (course)', '&gt; 4.61 min/km (vitesse)'],
colors = ['red', 'orange', 'yellow', 'greenyellow', 'green'];
div.style.backgroundColor = "white";
div.style.lineHeight = "18px";
div.style.color = "#555";
div.style.padding = "5px";
div.style.borderRadius = "5px";
for (let i = 0; i < speeds.length; i++) {
div.innerHTML += '<p style="margin: 0.1em"><i style="width: 18px; height: 18px; float: left; margin-right: 8px; opacity:0.7; background:' + colors[i] + '"></i> ' + speeds[i] + '</p>';
}
return div;
};
legend.addTo(map);
}
legendCount++;
}
function removeColorLegend(map) {
legend.remove();
if (legendCount === 1) {
legend.remove();
legend = null;
}
legendCount--;
}
if (typeof module === 'object' && typeof module.exports === 'object') {
......
......@@ -14,11 +14,10 @@
border-bottom: 0;
border-right: 20px solid white;
padding: 10px 5px;
margin-bottom: 10px;
margin-bottom: 2px;
font-size: 14px;
cursor: pointer;
color: var(--primary);
box-shadow: 0 0 2pt 2pt var(--primary);
}
/* Style the tab */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment