You are here

README.txt in Get Locations 7

Extending the geocoder functionality.
The geocoder for each map can be accessed in the javascript global variable
getlocations_leaflet_geocoder[key]
where 'key' is the key of the current map, eg 'key_1'

Here is an example of some javascript that could be run in a theme.
It replaces the default result actions with something else, in this case it
makes a polygon that describes the bounds of the search result.
Replace 'mytheme' with the name of your theme and add it to your theme's javascript

(function ($) {
  Drupal.behaviors.mytheme = {
    attach: function() {

      // edit this line to suit your use case
      if ($(".view-display-id-page_2").is('div') && $("#getlocations_leaflet_wrapper_key_1").is('div')) {
        var key = 'key_1';
        getlocations_leaflet_geocoder[key].markGeocode = function(result) {
          var bbox = result.bbox;
          this._map.fitBounds(bbox);
          if (this._lpolygon) {
            this._map.removeLayer(this._lpolygon);
          }
          this._lpolygon = L.polygon(
            [bbox.getSouthEast(), bbox.getNorthEast(), bbox.getNorthWest(), bbox.getSouthWest()],
            {
              'color': '#A0A0A0',
              'opacity': 0.8,
              'weight': 2,
              'fillColor': '#C0C0C0',
              'fillOpacity': 0.3,
              'clickable': true
            }
          );
          this._lpolygon.bindPopup(result.name).addTo(this._map);
        };
      }

    }
  };
})(jQuery);

File

modules/getlocations_leaflet/plugins/geocoder/README.txt
View source
  1. Extending the geocoder functionality.
  2. The geocoder for each map can be accessed in the javascript global variable
  3. getlocations_leaflet_geocoder[key]
  4. where 'key' is the key of the current map, eg 'key_1'
  5. Here is an example of some javascript that could be run in a theme.
  6. It replaces the default result actions with something else, in this case it
  7. makes a polygon that describes the bounds of the search result.
  8. Replace 'mytheme' with the name of your theme and add it to your theme's javascript
  9. (function ($) {
  10. Drupal.behaviors.mytheme = {
  11. attach: function() {
  12. // edit this line to suit your use case
  13. if ($(".view-display-id-page_2").is('div') && $("#getlocations_leaflet_wrapper_key_1").is('div')) {
  14. var key = 'key_1';
  15. getlocations_leaflet_geocoder[key].markGeocode = function(result) {
  16. var bbox = result.bbox;
  17. this._map.fitBounds(bbox);
  18. if (this._lpolygon) {
  19. this._map.removeLayer(this._lpolygon);
  20. }
  21. this._lpolygon = L.polygon(
  22. [bbox.getSouthEast(), bbox.getNorthEast(), bbox.getNorthWest(), bbox.getSouthWest()],
  23. {
  24. 'color': '#A0A0A0',
  25. 'opacity': 0.8,
  26. 'weight': 2,
  27. 'fillColor': '#C0C0C0',
  28. 'fillOpacity': 0.3,
  29. 'clickable': true
  30. }
  31. );
  32. this._lpolygon.bindPopup(result.name).addTo(this._map);
  33. };
  34. }
  35. }
  36. };
  37. })(jQuery);