Taking advantage of the recently added functions to trigger events on features and maps from outside of the Leaflet Markeclusterer context (http://drupal.org/commitlog/commit/42060/6e211c3f4271ed822d3ade2db18048b...)

I implemented this very successfully on this page (work in progress …):

http://www.italomairo.com/geoblogcms/en/ip-locations-leaflet

Just try to mouseover and mouseout the "zoom in map" highlighted in the left list … to see how this (successfully) works.

In this case the map view is generated by the ip_geoloc module (http://drupal.org/project/ip_geoloc), that made me able to change the icons on dynamic values of the features themselves … but the logic is the same with the Leaflet (& Markercluster) Module itself for interaction.

It is awesome and now works great! …
but it took "not just a while" to figure out how to do that. More details on this solution is explained here: http://drupal.org/node/1998596

For me this now both works with the Leaflet Module and the Leaflet Markercluster one , but to make it working I needed to alter the js files of both the modules, as I needed to access also to the initial map.center and the map.zoom of the created Leaflet Map … and on the Markercluster one to the map itself (not yet implemented seems ..:)

In the Leaflet Markerclusterer Module, I had to make some fine integration to the "leaflet_markercluster.drupal.js", just with the following few lines of code … (diff file attached)

@@ -143,6 +143,10 @@
           Drupal.leaflet.fitbounds(lMap);
         }
 
+        //Associate the center and zoom level proprerties to the built lMap (useful to after interaction with it, otherwise would be difficult to get them outside of this context ...)
+        lMap.center = lMap.getCenter();
+        lMap.zoom = lMap.getZoom();
+
         // add attribution
         if (this.map.settings.attributionControl && this.map.attribution) {
           lMap.attributionControl.setPrefix(this.map.attribution.prefix);
@@ -151,6 +155,10 @@
 
         // add the leaflet map to our settings object to make it accessible
         this.lMap = lMap;
+        
+        // allow other modules to get access to the map object using jQuery's trigger method
+        $(document).trigger('leaflet.map', [this.map, lMap]);
+        
         // Destroy features so that an AJAX reload does not get parts of the old set.
         // Required when the View has "Use AJAX" set to Yes.
         this.features = null;

Available for more clarifications, I am looking forward to seeing this integrated/committed soon in the last dev of the Leaflet Markeclusterer module …

PS : parallel and very similar issue has been posted right now in the Leaflet Module (http://drupal.org/node/2005328/edit)

Comments

berliner’s picture

Status: Needs review » Reviewed & tested by the community

This is basically the same change made to the leaflet module in commit 782027b.

I'm not sure why the following is introduced:

+        //Associate the center and zoom level proprerties to the built lMap (useful to after interaction with it, otherwise would be difficult to get them outside of this context ...)
+        lMap.center = lMap.getCenter();
+        lMap.zoom = lMap.getZoom();
+

I successfully applied the patch to leaflet_markercluster-7.x-1.x-beta1 and it works as expected.
This issue is kind of critical to keep compatibility with the leaflet module, as submodules that depend on the "leaflet.map" event will not work properly anymore when installing leaflet_markercluster.

itamair’s picture

Have a look to this: https://drupal.org/node/2056557

aaronbauman’s picture

rtbc++
bump

also, cross-posting #2090473: Support leaflet.feature event

rdeboer’s picture

Issue summary: View changes

Diff applied.
Thanks Italo.
Rik

rdeboer’s picture

Assigned: Unassigned » rdeboer
Status: Reviewed & tested by the community » Closed (fixed)

Available in latest official release.