When calling underlying Leaflet JavaScript functions the leaflet.drupal.js wrapper does not allow the optional hash of options to be passed through.

Example:
lMap.fitBounds(new L.LatLngBounds(lMap.bounds));
could be called as...
lMap.fitBounds(new L.LatLngBounds(lMap.bounds), options);

The following Leaflet functions allow for options, but the wrapper does not pass them through:

  • Marker
  • MultiPolygon
  • MultiPolyline
  • Polygon
  • fitBounds
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

caxy4’s picture

This patch updates the leaflet.drupal.js wrapper around the Leaflet JavaScript library to allow for options to be passed to the functions listed in the description.

caxy4’s picture

Status: Active » Needs review
sano’s picture

The patch in #1 failed at hunk 5, so I made a change to make it work. I was hoping it would address my problem, but it did not. Thanks anyways, maybe it will come handy if I am forced to hack my own solution together to make the autozoom work.

itamair’s picture

Tnx and sorry ... It seems that I am the only active maintainer for the Leaflet module, but actually I am taking care of the 8.x branch,
and not able to follow, fix bugs and face features requests, and even review functionalities.
Actually I don't even have a Drupal 7 playground (and don't have time to set it up) to test them.
Evan I am not able to grant new maintainer privileges.

So ... I would be able just to commit new patches to dev, and just if they are 99% tested and reviewed by you external contributors.
So do that, and eventually under your responsibility ask me to commit to dev if really needed (will try to do that in my spare time).

sano’s picture

@itamair I agree - let's wait and see if more folks find this useful and then the patch can be committed into the dev branch. Thank you for your work.

thfalvar’s picture

Hi there,
I'm using Drpupal 7, leaflet 7.x.1.4, and Leaflet JavaScript Library 1.3.1. I use Drupal but I do not do any coding.
I would simply like to do an "overlay" like this: https://www.mapbox.com/mapbox.js/example/v1.0.0/imageoverlay-georeferenced/
For that I'm just doing a little module with hook_leaflet_map_info ()

function hello_leaflet_map_info() {
  
  $default_settings = array(
    'attributionControl' => TRUE,
    'closePopupOnClick'  => TRUE,
    'doubleClickZoom'    => TRUE,
    'dragging'           => TRUE,
    'fadeAnimation'      => TRUE,
    'layerControl'       => TRUE, // Remplace : map.addControl( L.geoportalControl.LayerSwitcher() );
    'maxZoom'            => 18,
    'minZoom'            => 0,
    'scrollWheelZoom'    => TRUE,
    'touchZoom'          => TRUE,
    'trackResize'        => TRUE,
	// 'zoomDefault'        => 10,
    'zoomAnimation'      => TRUE,
    'zoomControl'        => TRUE,      
  );
  
  $map_info = array();
  
  $map_info['Empire 1812'] = array	(
	'label' => 'Empire 1812',
	'description' => 'Empire 1812',
	'settings' => $default_settings,
	'layers' => array	(
		'OSM' => array	(
			'urlTemplate' => '//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
			'options' => array	(
				'attribution' => 'OSM',
				),
			'layer_type' => 'base',
			),
		'Overlay' => array	(
			'urlTemplate' => '/sites/.../empire.jpg',
			// 'bounds' => '[[53.0, -5.0], [40.58, 19.17]]',    ??????????
			'options' => array (
				// 'bounds' => '[[53.0, -5.0], [40.58, 19.17]]',    ???????????
				'opacity' => '0.4',
				'attribution' => 'My overlay',
				),
			'layer_type' => 'overlay',
			),
	),
  );
  return $map_info;
}

Support for both "urlTemplate" and "layer_type" is good but impossible to set "bounds" as mentioned in leaflet documentation imageBounds = L.latLngBounds ([[53.0, -5.0], [40.58, 19.17]] );
Do you think this is the same problem as you: "options" mismanaged? I tried your patch but it does not change anything.
Have an idea?
Thank you