3

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);
  }
}

1 Answer 1

3

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.")
     .openOn(map);

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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