Toolset Maps allows you to use custom map styles by uploading the related JSON file, created using map customization tools. Besides setting the map styles manually you can also do this programmatically, using custom code.

Toolset Maps features a WordPress filter wpv_map_json_style. It allows you to define a custom function that checks for whatever condition you may want and use a specific style when the conditions are met (or not met). For example, you might check if it is currently night and if so, display the map using “Night” styling.

Let’s consider a simple example where we want to use a certain map style when displaying a map with a specific ID.

The following code checks if current map has an ID of “map-1” and if it does, it defines the URL where the custom map style JSON file is found. For maps with any other ID, it returns a pre-set style.

Example of setting the map style programmatically
add_filter( 'wpv_map_json_style', 'json_style_change', 10, 2);

function json_style_change( $style_json, $map_id ){
  if ($map_id === 'map-1') {
     return '//YOUR-DOMAIN/wp-content/plugins/views-addon-maps/resources/json/Silver.json';

  return $style_json;