Change map background when interacting with map

In this example we created a custom javascript snippet to change the background of the map when a region is clicked.


This is only possible with the Pro version of the plugin.
To achieve this you will need to do the following:

  • Add the regions and in the ‘Action Content’ field, add the URL to the image you want to associate with that region;
  • The regions added should leave the option to ‘use defaults’ enabled;
  • In the region Defaults, set the click action to ‘custom’.
  • Add the following code to the javascript custom action field:
var mapwrapper = document.getElementById('map_wrapper_20884');
mapwrapper.style.backgroundImage = "url('" + data.content + "')";
mapwrapper.style.backgroundSize = "contain";
  • Consider the map_wrapper_20884 is the id of the current map wrapper. You can change this to any other element ID on your page. 20884 in this example is the ID of the map above.

The custom code can be enhanced for improvements or to trigger any other style change.

Some screenshots of the map edit screen for the relevant options:

Change map background when interacting with map
Change map background when interacting with map

If you have any question feel free to leave a comment below or contact me.

Posted by Carlos Moreira

Lead developer of Interactive Geo Maps plugin.

Leave a Reply

Your email address will not be published. Required fields are marked *