use Google Maps custom styling for the WordPress Flexible Map plugin -- see http://flexible-map.webaware.net.au/manual/styled-maps/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Flxmap custom styling | |
Plugin URI: https://gist.github.com/webaware/3808eb1cac17cb32a294 | |
Description: use Google Maps custom styling for a map | |
Version: 1.0.1 | |
Author: WebAware | |
Author URI: http://webaware.com.au/ | |
*/ | |
/** | |
* register custom map types with WP Flexible Map plugin | |
* | |
* references and examples: | |
* @link http://flexible-map.webaware.net.au/manual/styled-maps/ | |
* @link https://developers.google.com/maps/documentation/javascript/styling | |
* @link https://developers.google.com/maps/documentation/javascript/examples/maptype-styled-simple | |
* @link http://gmaps-samples-v3.googlecode.com/svn/trunk/styledmaps/wizard/index.html | |
* @link https://snazzymaps.com/ | |
* | |
* @param array $mapTypes registered custom map types, keyed by mapTypeId | |
* @param array $attrs shortcode attributes for current map | |
* @return array | |
*/ | |
add_filter('flexmap_custom_map_types', function($mapTypes, $attrs) { | |
// nothing to register if map type isn't specified | |
if (empty($attrs['maptype'])) { | |
return $mapTypes; | |
} | |
// check for map using custom map type | |
// https://snazzymaps.com/style/18/retro | |
if ($attrs['maptype'] == 'flexible1' && empty($mapTypes['flexible1'])) { | |
$custom_type = '{ | |
"styles" : [{"featureType":"administrative","stylers":[{"visibility":"off"}]},{"featureType":"poi","stylers":[{"visibility":"simplified"}]},{"featureType":"road","elementType":"labels","stylers":[{"visibility":"simplified"}]},{"featureType":"water","stylers":[{"visibility":"simplified"}]},{"featureType":"transit","stylers":[{"visibility":"simplified"}]},{"featureType":"landscape","stylers":[{"visibility":"simplified"}]},{"featureType":"road.highway","stylers":[{"visibility":"off"}]},{"featureType":"road.local","stylers":[{"visibility":"on"}]},{"featureType":"road.highway","elementType":"geometry","stylers":[{"visibility":"on"}]},{"featureType":"water","stylers":[{"color":"#84afa3"},{"lightness":52}]},{"stylers":[{"saturation":-17},{"gamma":0.36}]},{"featureType":"transit.line","elementType":"geometry","stylers":[{"color":"#3f518c"}]}], | |
"options" : { | |
"name" : "Retro" | |
} | |
}'; | |
$mapTypes['flexible1'] = json_decode($custom_type); | |
} | |
return $mapTypes; | |
}, 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment