mpetazzoni / leaflet-gpx

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

Changing colors for a track (or changing visibility) #164

Closed ChrilleSchappe closed 1 month ago

ChrilleSchappe commented 1 month ago

I want to be able to change color for an existing track... Something like this:

var gpx = new L.GPX(url); gpx.setColor(color); gpx.reload();

In my case to be able to make it invisible and the visible again. (setInvisible(), setVisible() could be another way. I can't find this functionality!

mpetazzoni commented 1 month ago

@ChrilleSchappe I'd recommend you control visibility at the layer level. L.GPX is a layer added to your Leaflet map, so you can use layer controls to show/hide the track.

If you're looking at configuring the track's color, use polyline_options:

new L.GPX(url, {
  polyline_options: {
    color: 'green',
    opacity: 0.75,
  }
})...