mpetazzoni / leaflet-gpx

A GPX track plugin for Leaflet.js
http://mpetazzoni.github.io/leaflet-gpx
BSD 2-Clause "Simplified" License
529 stars 114 forks source link

Make sure that the start pin is always above the other waypoints #70

Closed delitestudio closed 6 years ago

delitestudio commented 6 years ago

Hello and thanks for this great plugin!

Is there a way to make sure the start pin is always above the other waypoints?

mpetazzoni commented 6 years ago

Absolutely!

This plugin fires an event for every marker/pin that is added to the map. When the start pin is added, you'll get a addpoint event with a point_type: 'start' in the event payload, as written at https://github.com/mpetazzoni/leaflet-gpx/blob/master/gpx.js#L339.

This event payload includes the pin object itself as the point, and you can call .setZIndexOffset(...) on it, as documented here: https://leafletjs.com/reference-1.3.0.html#marker-setzindexoffset

So you should be able to write something like this:

new L.GPX(url, {async: true}).on('addpoint', function(e) {
  if (e.point_type === 'start') {
    e.point.setZIndexOffset(1000);
  }
}).addTo(map);
delitestudio commented 6 years ago

Thank you very much for your detailed answer!