In the following how would I customize the popup options? I want to add in the option for the keepInView to be true.

var myLayer = L.geoJson(polygon, { onEachFeature: yourOnEachFeatureFunction }).addTo(map);

function yourOnEachFeatureFunction(feature, layer){ if (feature.properties.name) { layer.bindPopup(feature.properties.name); } }


Check out the Leaflet Documentation.

Here's the bit you want:

L.popup( <Popup options> options?, <ILayer> source? )

You can implement like this:

//set up a standalone popup (use a popup as a layer)
var popup = L.popup({keepInView:true})
     .setLatLng([51.5, -0.09])
     .setContent("I am a standalone popup.")

Or in your example:

function yourOnEachFeatureFunction(feature, layer){ if (feature.properties.name) { layer.bindPopup(feature.properties.name,{keepInView:true}); } }

(This is passing in an object, which is composed of 'attribute:value' pairs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.