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

iconSize ignored when using startIconUrl #144

Closed fogs closed 1 year ago

fogs commented 1 year ago

...same applies to other options, same applies to endIconUrl.

To reproduce, create a new L.GPX with the option iconSize: [330, 500] - the markers now should be huge.

The problem seems to be that

        icon: options.marker_options.startIcon || new L.GPXTrackIcon({iconUrl: options.marker_options.startIconUrl})

only takes into consideration the Url, but not the other default parameters. I could fix it by replacing it with this:

        icon: options.marker_options.startIcon || new L.GPXTrackIcon(
          this._merge_objs(
            options.marker_options,
            {iconUrl: options.marker_options.startIconUrl})
        )

(but I am not sure if this is the right way to do. Also for endIcon it needs to be adapted as well)

mpetazzoni commented 1 year ago

Are you sure you're passing iconSize in the right place? I just tried to reproduce your issue and the icon size is correctly applied when used along startIconUrl.

Note that the iconSize needs to be passed under marker_options in the options object:

        new L.GPX(url, {
          async: true,
          marker_options: {
            startIconUrl: 'pin-icon-start.png',
            endIconUrl:   'pin-icon-end.png',
            shadowUrl:    'pin-shadow.png',
            iconSize:     [16, 22],
          },
        }).on('loaded', function(e) {
          // ...
        });

Feel free to re-open if that still doesn't do it.