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

Question: can I get a timestamp from mouseover on gpx track #147

Open
marcobergman opened this issue Oct 30, 2023 · 3 comments
Open

Question: can I get a timestamp from mouseover on gpx track #147

marcobergman opened this issue Oct 30, 2023 · 3 comments

Comments

@marcobergman
Copy link

I'd like to show timestamp information about the gpx position on mouseover, but I cannot find this in the event. Is it available? Thx!

@mpetazzoni
Copy link
Owner

I don't believe that would be possible, since the only thing rendered is the polyline itself, and none of the individual points – presumably you'd need those to be rendered as distinct elements to have mouseover on each point to get its information and timestamp.

Maybe you could work something out with Polyline.closestLayerPoint()? But that still wouldn't give you access to the additional information about that point of the line.

@queueseven
Copy link

I implemented this feature today by changing the code a little bit.

By changing

 // add track
 var l = new L.Polyline(coords, this._extract_styling(line, base_style, polyline_options));

to

 // add track
 tmp = this._extract_styling(line, base_style, polyline_options)
 tmp.custom = coords;
 var l = new L.Polyline(coords, tmp);

you're able to access the parsed coordinate objects, which contain not only the location but also the timestamp etc.

Then you can search for the Polyline layer and add invisible Markers for each coordinate, like this:

polyline_layer.options.custom.forEach(ll => 
    L.marker([ll.lat, ll.lng], { clickable: false })
        .bindPopup('Timestamp: ' + ll.meta.time.toLocaleTimeString())
        .on('mouseover', function (e) {
            this.openPopup();
        })
        .on('mouseout', function (e) {
            this.closePopup();
        })
        .setOpacity(0)
        .addTo(map);
);

It would be awesome if leaflet-gpx could raise an event for every trkpt or let us access the coords with the meta data easily.

@mpetazzoni
Copy link
Owner

I didn't do that because I'm worried about the performance impact of raising an event for every point on the track (could be thousands). Maybe as an opt-in?

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

3 participants