1

I am using the module Leaflet and its sub-module "Leaflet views"" in order to get a map displaying markers based on taxonomy terms.

I am able to show a popup displaying the term page while I click on a marker.

Now, my actual requirement is when I click on the marker, the map is zoomed on the clicked marker (zoom of maximum 3 levels) and just after the popup is displayed. So, my map behavior on the marker click event contains two steps: zooming and popup opening.

How can I hook the module in order to enrich my views?

1 Answer 1

1

Install and enable jQuery update. Set the jQuery version to >= 1.7.

Create a module, then create a zoom.js JavaScript file and paste this:

(function ($) {
  Drupal.behaviors.MYMODULE = {
    attach: function (context, settings) {
      $(document).bind('leaflet.feature', function(e, lFeature, feature) {
        lFeature.on('click', function(e) {
          var lMap = Drupal.settings.leaflet[0].lMap;
          lMap.setView(e.latlng,8);
        })
      });

    }
  }
})(jQuery);

Use your module name instead of MYMODULE

Then use drupal_add_js() in your module to include zoom.js. Note the weight option:

  drupal_add_js(drupal_get_path('module', 'MYMODULE') .'/zoom.js',array('group' => JS_DEFAULT, 'weight' => -5));

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.