I'd like to restrict the panning of my leaflet map in Drupal.

The Leaflet documentation mentions the maxBounds option

And I'd like to know the best way to implement it for my map.

  • You need to provide more details and show some initiative on your end. What have you tried? What is the issue you are running into? Are you using Leaflet contrib module? Aug 13 '14 at 17:21

Got it working. Override the leaflet.drupal.js file as follows. See the leaflet markercluster module for how to override in an 'As You Like it kind of way.' in a custom module. Pretty useful.

// instantiate our new map
  var lMap = new L.Map(this.mapId, settings);
//note, the comma (NOT A semi-colon) at the end of the next line - this is  important.
  lMap.bounds = [],
// Now set your maxbounds, see the leaflet documentation for reference.
      [40.712, -74.227],
      [40.774, -74.125]

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.