Is there a way, either through PHP or JS, to adjust the amount of padding that markers are given when the map's centering is set to Auto-box? The problem is that some of the maps show only the marker's tip and not the whole marker, effectively making the marker invisible. I need to map's bounds to be increased to show the whole marker. I'm using Leaflet.

Comments

rdeboer’s picture

Project: IP Geolocation Views & Maps » Leaflet
Version: 7.x-1.9 » 7.x-1.0-beta1

Hi okeedoak,
I feel this is very much a question for the Leaflet module issue queue.
Reassigning.

pvhee’s picture

Status: Active » Closed (won't fix)

This is caused by Leaflet, not by the module.

If you want to manually fix the fitting of the markers in a custom module, you could register the following javascript:

<em></em>
  // Overwrite fitbounds with a custom function
  Drupal.leaflet.fitbounds = function(lMap) {
    if (this.bounds.length > 0) {
      var bounds = new L.LatLngBounds(this.bounds);
      var zoom = lMap.getBoundsZoom(bounds, 0);
      var center = L.latLngBounds(bounds).getCenter();
      if (zoom == 5) { // offset manually so the fitting is better at zoom level 5
        center.lat += 1;
      }
      lMap.setView(center, zoom);
    }
  }
okeedoak’s picture

Thanks, I'll try this out.

codenamerhubarb’s picture

Issue summary: View changes

A quick hack solution for me was to edit leaflet.js (sites/all/libraries/leaflet/leaflet.js)...

Replace the 2 occurrences of "e.padding||[0,0]" with "e.padding||[50,50]"

mstrelan’s picture

Version: 7.x-1.0-beta1 » 7.x-1.x-dev
Status: Closed (won't fix) » Active

I'm reopening this because leaflet has a native way of supporting this and no hacks are required. The fitBounds() function can take padding as an argument. See http://leafletjs.com/reference.html#map-padding.

#2348449: options not passed to several Leaflet JavaScript functions seems to touch on this, but we need somewhere to set options to be passed to fitBounds.

For now I will override Drupal.leaflet.fitBounds.

    fitbounds:function (lMap) {
      if (lMap.bounds.length > 0) {
        lMap.fitBounds(new L.LatLngBounds(lMap.bounds), {padding: [20, 20]});
      }
    }
chucksimply’s picture

#5 worked for me when overrides were made to the actual leaflet module in leaflet.drupal.js