3

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.

1
  • 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? Commented Aug 13, 2014 at 17:21

1 Answer 1

3

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.
    lMap.setMaxBounds([
      [40.712, -74.227],
      [40.774, -74.125]
    ]);
0

Your Answer

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

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