I'd like to display a highlighted polygon using Google Maps. The idea is that the polygon in question would be displayed normally and the rest of the map should be darkened a little bit.
Here's an example image what I would like to accomplish with a polygon from Austria: alt text http://a.imagehost.org/0613/google_maps_tint_example.png
Unfortunately, I'm a complete rookie when it comes to Google Maps API's and map stuff in general.
So, is this even possible do this with Google Map API's? If yes, with what version (v2, v3)? Would it be easier to do it with other map toolkits, like openlayers?
PS: One idea I had, was to build an inverse polygon (in this example, the whole world minus the shape of austria) and then display a black colored overlay with transparency using this inverted polygon. But that seems to be quite complicated to me.
USING GEOJSON
incase of external geojson file use
note: google used .json as extension for geojson file and not .geojson https://developers.google.com/maps/documentation/javascript/datalayer
create your geojson here
https://google-developers.appspot.com/maps/documentation/utils/geojson/
working example https://jsfiddle.net/841emtey/5/
Google Maps API v3 lets you draw polygons with holes. Here's Google's Pentagon example. It is much easier than trying to invert a polygon. Basically, create coordinates for a giant polygon that is bigger than you would ever need. That will always be the first polygon in your polygon array. The area you are highlighting will always be the second polygon.
Here's some code to change Google's Bermuda Triangle demo to use a polygon with a hole:
With regard to:
This can be done with with Maps API v3 using Styled Maps.
There's even a Styled Maps Wizard where you can play with the settings, and then press
Show JSON
to get the array to pass as the first argument tonew google.maps.StyledMapType
.To get the effect you want just reduce the
Lightness
for everything, in the wizard you'll want to see this in theMap Style
box on the right:Which will export to:
And look like this.