-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent shallow copy of default options (multiple charts) #240
Conversation
@flo-schn @hupe13 please let me know if you notice any strange behavior |
works for me only when options.legend = false when options.legend = true, the options.margin.bottom is off again: which btw, was the same case when applying the simple workaround: |
@flo-schn be aware that to test this change you have to compile this pull request code (eg. Personally, I have tested this edit only on this file: • examples/leaflet-elevation_multiple-maps.htmlbut, edited as follows (ie. setting <!DOCTYPE html>
<html>
<head>
<title>leaflet-elevation.js</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<link rel="dns-prefetch" href="https://tile.openstreetmap.org">
<link rel="dns-prefetch preconnect" href="https://unpkg.com" />
<link rel="preload" href="https://unpkg.com/[email protected]/dist/leaflet.js" as="script">
<link rel="preload" href="https://unpkg.com/[email protected]/dist/leaflet-ui.js" as="script">
<style>@import '../libs/fullpage.css';</style>
<!-- leaflet-ui -->
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="https://unpkg.com/[email protected]/dist/leaflet-ui.js"></script>
<!-- leaflet-elevation -->
<link rel="stylesheet" href="../dist/leaflet-elevation.min.css" />
<script src="../dist/leaflet-elevation.min.js"></script>
</head>
<body style="flex-direction: row; flex-wrap: wrap; gap: 10px;">
<div id="map-1" class="leaflet-map" style="flex: calc(50% - 5px);"></div>
<div id="map-2" class="leaflet-map" style="flex: calc(50% - 5px);"></div>
<div id="map-3" class="leaflet-map" style="flex: 100%; height: 50%;"></div>
<script>
let opts = {
map: {
center: [41.4583, 12.7059],
zoom: 5,
preferCanvas: true,
rotate: true,
// bearing: 45,
rotateControl: {
closeOnZeroBearing: true
},
fullscreenControl: false,
minimapControl: false,
searchControl: false,
locateControl: false,
pegmanControl: false,
zoomControl: false,
resizerControl: false,
layersControl: false,
},
elevationControl: {
urls: {
'map-1': "https://raruto.github.io/leaflet-elevation/examples/via-emilia.gpx",
'map-2': "https://raruto.github.io/leaflet-elevation/examples/via-aurelia.gpx",
'map-3': "https://raruto.github.io/leaflet-elevation/examples/demo.tcx",
},
options: {
theme: "lightblue-theme",
collapsed: false,
autohide: false,
autofitBounds: true,
position: "bottomleft",
detached: false,
summary: "inline",
imperial: false,
// altitude: "disabled",
slope: "disabled",
speed: false,
acceleration: false,
time: "summary",
legend: true,
followMarker: true,
almostOver: true,
distanceMarkers: false,
hotline: false,
},
},
layersControl: {
options: {
collapsed: false,
},
},
};
let maps = [], charts = [];
for (const id of ['map-1', 'map-2', 'map-3']) {
opts.elevationControl.options.detached = ['map-3'].includes(id);
let map = L.map(id, opts.map);
let controlElevation = L.control.elevation(opts.elevationControl.options).addTo(map);
let controlLayer = L.control.layers(null, null, opts.layersControl.options);
controlElevation.on('eledata_loaded', ({layer, name}) => controlLayer.addTo(map) && layer.eachLayer((trkseg) => trkseg.feature.geometry.type != "Point" && controlLayer.addOverlay(trkseg, trkseg.feature && trkseg.feature.properties && trkseg.feature.properties.name || name)));
controlElevation.load(opts.elevationControl.urls[id]);
maps.push(map);
charts.push(controlElevation);
}
</script>
<!-- i18n -->
<script>
// Register a custom locale
L.registerLocale('en:18', {
"Acceleration" : "Acceleration",
"Altitude" : "Elevation",
"Slope" : "Slope",
"Speed" : "Velocity",
"Total Length: " : "L: ",
"Max Elevation: " : "E Max: ",
"Min Elevation: " : "E Min: ",
"Avg Elevation: " : "E Avg: ",
"Total Time: " : "T: ",
"Total Ascent: " : "Asc: ",
"Total Descent: " : "Desc: ",
"Min Slope: " : "S Min: ",
"Max Slope: " : "S Max: ",
"Avg Slope: " : "S Avg: ",
"Min Speed: " : "V Min: ",
"Max Speed: " : "V Max: ",
"Avg Speed: " : "V Avg: ",
"Min Acceleration: ": "A Min: ",
"Max Acceleration: ": "A Max: ",
"Avg Acceleration: ": "A Avg: ",
});
// Enable a custom locale
// L.setLocale('en:18');
// You can also override a previously defined object
L.locales['en'] = L.extend({
"y: " : "",
"x: " : "",
"t: " : "",
"T: " : "",
"m: " : "",
"v: " : "",
"a: " : "",
}, L.locales['en']);
// Switch the language
L.setLocale('en');
</script>
<a href="https://github.com/Raruto/leaflet-elevation" class="view-on-github" style="position: fixed;top: 30px;left: calc(50% - 81px);z-index: 9999;"> <img alt="View on Github" src="https://raruto.github.io/img/view-on-github.png" title="View on Github" width="163"> </a>
</body>
</html> 👋 Raruto |
am aware of,
and did via editing file (eg.
|
released in v2.3.0 @flo-schn examples/leaflet-elevation_multiple-maps.html it seems to work fine to me.. BTW, I also added a dedicated test file in case anyone else wants to go deeper:
👋 Raruto |
Before
After
More info:
Closes: #238