smeijer / leaflet-geosearch

A geocoding/address-lookup library supporting various api providers.
https://smeijer.github.io/leaflet-geosearch/
MIT License
1.02k stars 271 forks source link

Cannot add marker of different icon #279

Closed zcemycl closed 2 years ago

zcemycl commented 3 years ago
let Icon = L.icon({
    iconUrl: icon,
    shadowUrl: iconShadow,
});
const search = new GeoSearchControl({
            style: 'bar',
            marker: Icon,
            provider: new OpenStreetMapProvider(),
          });

I cannot add a new icon to my search result, but can only retain the default one. Does this mean you cannot have multiple icons with different colors or shapes in the map at the same time?

smeijer commented 2 years ago

It's possible to specify a custom marker using the marker option like:

new GeoSearchControl({
  marker: {
    icon: YourCustomIcon,
    draggable: false,
  },
});

For multiple markers, you're looking for the maxMarkers option, but for more advanced scenarios like different colors, you probably want to disable our markers with showMarker: false, while adding your own by listening to the geosearch/showlocation event.