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.

Modified maps of Portugal

The plugin comes with more than 200 maps created automatically with real geographic data. However some countries might not be composed of a unified mass of land, they include islands or other territories. This is the case for the US (Alaska and Hawaii) and also for Portugal, which includes some islands in the middle of the Atlantic ocean. For this reason I have included some modified maps of Portugal in the plugin. Below are some examples.


Districts

Municipalities


Original Map

If you compare the maps above with the original map below, with real positioning of the islands, you’ll understand why having a custom modified map is important to improve the way the map displays and the user interacts with it.

However, these modified maps have a small disadvantage: if you plot markers using coordinates for the real location of a city in one of the islands, the marker will not display. You will need to use the adjusted coordinates of the ‘new’ location of the islands. But this can be easily done when creating the map by simply clicking the location where you want the marker to be placed. The map edit interface will give you the coordinates of the location clicked.

In addition to the modified maps above, I also included some maps for specific cities. The plugin includes maps with the ‘regions’ of the 2 biggest Portuguese cities: Porto and Lisbon.

Porto

Lisbon

These are just examples of what’s possible to do with the plugin. In any of the above maps you can set click actions, change the region colours and set hover colours. See the full list of included features.

Future versions of the plugin will probably include even more maps for Portugal. If you have any special request of a city or region in Portugal, feel free to leave a comment below or contact me.