Custom inline summary
haldo98 opened this issue · 1 comments
haldo98 commented
Hi...
I cannot find examples or solutions (i'm a newbie) to set up a custom summary in a non detached elevation summary.
I found examples only for the detached ones
Can you please help?
Thank You
Raruto commented
i'm a newbie
Hi @haldo98,
you can start to edit the following example:
leaflet-elevation/examples/leaflet-elevation_custom-summary.html
Lines 1 to 152 in 8681792
and try to edit it as follows:
<template> <!-- wrap your custom "data-summary" around this node -->
<div id="data-summary" class="data-summary">
<div class="data-row">
<span class="totlen">
<span class="summarylabel">Total Length: </span>
<span class="summaryvalue">0</span>
</span>
<span class="maxele">
<span class="summarylabel">Max Elevation: </span>
<span class="summaryvalue">0</span>
</span>
<span class="minele">
<span class="summarylabel">Min Elevation: </span>
<span class="summaryvalue">0</span>
</span>
</div>
<div class="data-row">
<span class="gain">
<span class="summarylabel">Gain: </span>
<span class="summaryvalue">0</span>
</span>
<span class="loss">
<span class="summarylabel">Loss: </span>
<span class="summaryvalue">0</span>
</span>
</div>
</div>
</template>// Inline summary (detached: false)
let controlElevation = L.control.elevation({detached: false, ...}).addTo(map);
// Custom Summary info ("inline-summary")
controlElevation.on('eledata_loaded', ({layer, name, track_info}) => {
let q = document.querySelector.bind(document);
q('template .totlen .summaryvalue').innerHTML = track_info.distance.toFixed(2) + " km";
q('template .maxele .summaryvalue').innerHTML = track_info.elevation_max.toFixed(2) + " m";
q('template .minele .summaryvalue').innerHTML = track_info.elevation_min.toFixed(2) + " m";
q('template .gain .summaryvalue').innerHTML = "+" + track_info.ascent.toFixed(0) + " m";
q('template .loss .summaryvalue').innerHTML = "-" + track_info.descent.toFixed(0) + " m";
// append your <template> content as a DOM Element
q('.elevation-summary.inline-summary').innerHTML = q('template').cloneNode(true).innerHTML;
});
controlElevation.load(opts.elevationControl.data);Doing this way you can manually build the desired HTML structure instead of trying to directly altering the DOM just via JS (eg. through document.createElement or similar)
For more info:
👋 Raruto