Skip to content
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

ruler on leaflet-elevation_hoverable-tracks.html #290

Open
hupe13 opened this issue May 25, 2024 · 1 comment
Open

ruler on leaflet-elevation_hoverable-tracks.html #290

hupe13 opened this issue May 25, 2024 · 1 comment

Comments

@hupe13
Copy link
Contributor

hupe13 commented May 25, 2024

Hi Raruto,

please see your example loading multiple .gpx tracks (hover to toggle ).
You move with the mouse over a track, the chart and the ruler appear. Now you click on any track on the map, the chart disappears. Next you move with the mouse over a track again, the chart appears, the ruler doesn't.

How to fix this?

@Raruto
Copy link
Owner

Raruto commented May 27, 2024

Hi @hupe13,

basically the control doesn't redraw the Ruler after calling remove()addTo(map)

_onSelectionChanged: function(e) {
var elevation = this._elevation;
var eleDiv = elevation.getContainer();
var route = this.getSelection();
elevation.clear();
if (route && route.isSelected()) {
if (!eleDiv) {
elevation.addTo(this._map);
}
route.getLayers().forEach(function(layer) {
if (layer instanceof L.Polyline) {
elevation.addData(layer, false);
layer.bringToFront();
}
});
} else {
if (eleDiv) {
elevation.remove();
}
}
},

/**
* Hacky way for handling chart resize. Deletes it and redraw chart.
*/
_resizeChart() {
if (this._container && _.style(this._container, "display") != "none") {
let opts = this.options;
let newWidth = opts.detached ? (this.eleDiv || this._container).offsetWidth : _.clamp(opts._maxWidth, [0, this._map.getContainer().clientWidth - 30]);
if (newWidth) {
opts.width = newWidth;
if (this._chart && this._chart._chart) {
this._chart._chart._resize(opts);
this._updateChart();
}
}
this._updateMapSegments();
}
},

chart._resize = ({
width,
height,
margins = {},
ruler,
}) => {
const w = width - margins.left - margins.right;
const h = height - margins.top - margins.bottom;
svg .attr("width", width).attr("height", height).attr("viewBox", `0 0 ${width} ${height}`);
g .attr("transform", "translate(" + margins.left + "," + margins.top + ")");
// Fix: https://github.com/Raruto/leaflet-elevation/issues/123
// Fix: https://github.com/Raruto/leaflet-elevation/issues/232
if (
/Mac|iPod|iPhone|iPad/.test(navigator.platform) &&
/AppleWebkit/i.test(navigator.userAgent) &&
!/Chrome/.test(navigator.userAgent)
) {
canvas .style("transform", "translate(" + margins.left + "px," + margins.top + "px)");
}
maskRect .attr("width", w).attr("height", h).attr("x", 0).attr("y", 0);
foreignObject.attr('width', w).attr('height', h);
canvas .attr('width', w).attr('height', h);
if (ruler) {
panes.ruler.call(Ruler({ height: h, width: w }));
}
panes.brush.call(brush.extent( [ [0,0], [w, h] ] ));
panes.brush.select(".overlay").attr('cursor', null);
chart._width = w;
chart._height = h;
chart.svg.dispatch('resize', { detail: { width: w, height: h } } );
};


Below some offending lines:

  • eleDiv may never change on subsequent call to addTo(map)

if (!this.eleDiv) this.eleDiv = container;

let newWidth = opts.detached ? (this.eleDiv || this._container).offsetWidth : _.clamp(opts._maxWidth, [0, this._map.getContainer().clientWidth - 30]);

  • opts.ruler may be undefined

this._chart._chart._resize(opts);

if (ruler) {
panes.ruler.call(Ruler({ height: h, width: w }));
}

chart._resize({ width, height, margins});

👋 Raruto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants