1

Trying to add to Leaflet map marker from the custom module. Leaflet map created with IP Geolocation Views & Maps module. I try to connect to the map as described here http://dripl.nl/blog/taming-leaflet-maps-drupal The message alert appears with the coordinates, but the map does not increase the zoom. What could be the reason?

I also tried to replace the string myMap = lMap; with var myMap = Drupal.settings.leaflet [0] .lMap; not help.

test_module.module

function test_module_form_article_node_form_alter(&$form, &$form_state, $form_id) {
    $form['field_photo']['#element_validate'][] = 'test_module_validate_function';
}

function test_module_validate_function($element, &$form, &$form_state){
    $marker = [49.055688666667,34.338167222222];
    test_module_add_marker($marker);

}

function test_module_add_marker($marker) {
    drupal_add_js(drupal_get_path('module', 'test_module').'/test_module.js'); 
    drupal_add_js(array('test_module' => array('marker' => $marker)), array('type' => 'setting'));
}

test_module.js

(function($) {
  $(document).bind('leaflet.map', function(e, map, lMap){
    myMap = lMap;
  });

    Drupal.behaviors.test_module = {
        attach: function (context, settings) {
            latlon = settings.test_module.marker;
            alert(latlon);
            myMap.setView(latlon, 14);  
        }
    };

})(jQuery); 

1 Answer 1

1

I managed to solve the problem in the following way, I hope it save someone time:

(function($) {

var lMap = Drupal.settings.leaflet[0].lMap;

    Drupal.behaviors.test_module = {
        attach: function (context, settings) {
            latlon = settings.test_module.marker;
            //alert(latlon);
            lMap.setView(latlon, 14);
        }
    };

})(jQuery); 

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.