1

I have a filterable map on my Wordpress site which I've made with the LocateandFilter plugin on Wordpress that uses a Leaflet map with a Google Maps overlay. I want the map to zoom on on the state when the associated state checkbox is clicked on the left pane. I'm decent at using wordpress, coding including javascript and since this isn't an included functionality of the plugin I thought I'd be able to hack it. I know that I need to locate the map variable (which does not appear to be map) and change the options based on a click - I can't figure out how to select the map and change it's options. I've been researching for a few hours now and I'm realizing I just don't have the background to figure this out. However I'm in too deep now to switch plugins. Can anyone help?

here is the page: https://armor-pt.com/locations/

If I could figure out how to select the map/what the map variable was I would write some code like this:

function zoomArizona(){
 if (document.querySelector('div.la-filter-261 input').checked){
  mymap.flyTo([34, 111], 5);
  } else {
   mymap.flyTo([37, 95], 0);
   }
}
1
  • Coding question on GIS SE site should include relevant existing code, otherwise it's most likely to be closed as not compliant with the site policy. Please edit your question and add relevant existing code.
    – TomazicM
    Commented Dec 9, 2021 at 8:36

1 Answer 1

1

Piece of the code where map is created looks like this:

var map_instance="locate_anything_map_"+map_id;
/* instanciate filter class */
eval("var "+map_instance+"=new leaflet_filters_class(params);");                 
/* loading ... */                       
eval(map_instance).showLoader(true);
/* Initialize Map  */   
eval(map_instance).createMap();

If you examine content of the eval(map_instance) object after eval(map_instance).createMap() call, you'll notice map property which points to Leaflet map object.

So to get Leaflet plugin map variable in Wordpress environment, you can use the following expression:

var leafletMap = eval(map_instance).map;

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.