Skip to content

wpgeo_map_js_preoverlays

Ben Huson edited this page Jul 12, 2014 · 4 revisions

This filter can be used to output more JavaScript after the map JavaScript has been output.
It passes two parameters:

The first is the output. You should append or prepend any output to this. Don't overwrite it as it will then replace any other additional output that has already been added.

The second parameters is the map variable which defines the map in JavaScript.

Example: Styling

The following adds styling to a map.
For further information about styling see the Google Style Maps documentation or to easily create a styles array try this Styled Maps Wizard.

<?php
function my_wpgeo_map_js_preoverlays( $output, $map_var ) {
	$output .= $map_var  . '.setOptions({styles: [ { "stylers": [ { "lightness": 2 }, { "visibility": "simplified" }, { "saturation": -41 }, { "hue": "#00ffee" } ] },{ } ]});';
	return $output;
}
add_filter( 'wpgeo_map_js_preoverlays', 'my_wpgeo_map_js_preoverlays', 10, 2 );
?>

Example: Overlay KML File

The following loads a KML and overlays it over your maps.

<?php
function my_wpgeo_map_js_preoverlays( $output, $map_id ) {
	$output .= "var myMapKML = new google.maps.KmlLayer( {
			url: 'http://kml-samples.googlecode.com/svn/trunk/kml/Model/ResourceMap/macky-alt.kml'
		} );
		myMapKML.setMap(" . $map_id . ");
		";
	return $output;
}
add_filter( 'wpgeo_map_js_preoverlays', 'my_wpgeo_map_js_preoverlays', 10, 2 );
?>
Clone this wiki locally