The leaflet documention shows you can add a popup to a marker with
marker.bindPopup("<b>Hello world!</b><br>I am a popup.").openPopup();
or create a standalone popup with
var popup = L.popup() .setLatLng([51.5, -0.09]) .setContent("I am a standalone popup.") .openOn(map);
Is there no way to set popup options and bind it to a marker? I want to be able to set my own maxwidth for popups and have them open/close when you click a marker.
LeafletJS - Markers 1 Adding a Simple Marker. Step 1 − Create a Map object by passing a < div > element (String or object) and map options (optional). 2 Binding Pop-ups to the Marker. Step 1 − Create a Map object by passing a < div > element (String or object) and map options (optional). 3 Marker Options. ... 4 Marker Custom Icons. ...
Are you sure that you're reading the Leaflet reference documentation? It specifies that you can bind a popup with options by creating it and calling .bindPopup with it. For instance,
To bind a simple popup displaying a message to a marker, follow the steps given below −. Step 1 − Create a Map object by passing a < div > element (String or object) and map options (optional). Step 2 − Create a Layer object by passing the URL of the desired tile. Step 3 − Add the layer object to the map using the addLayer () ...
Leaflet.js is an open-source library using which we can deploy simple, interactive, lightweight web maps. Leaflet JavaScript library allows you to use layers such as Tile layers, WMS, Markers, Popups, Vector layers (polylines, polygons, circles, etc.), Image overlays and GeoJSON.
Are you sure that you're reading the Leaflet reference documentation? It specifies that you can bind a popup with options by creating it and calling .bindPopup with it. For instance,
var popup = L.popup() .setContent("I am a standalone popup."); marker.bindPopup(popup).openPopup();
You can pass an object of popup options as the second argument of bindPopup, like this:
marker.bindPopup("<strong>Hello world!</strong><br />I am a popup.", {maxWidth: 500});
I've tested this in Leaflet 1.4, and it also seems be available in earlier versions of bindPopup.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With