15

map sample image

I am trying achieve a map like the above image using google map. I made the map grayscale by giving saturation to -100 in StyledMapType object and drawn a radius around the marker using Circle object. Now the whole map is grayscle as i cannot set another saturation level inside the circle. Is there any way to achieve this ?

Community
  • 1
  • 1
Ajmal VH
  • 1,691
  • 1
  • 13
  • 27
  • 2
    I don't believe there is any direct way to accomplish this with the Maps API. You may want to check out http://googlemapsmania.blogspot.com/2011/10/create-cool-mask-effect-on-google-maps.html to overlay a mask over the map. – Bryan Weaver Mar 21 '13 at 13:17

2 Answers2

4

Another idea is to create second map, style it in another way via StyledMapType, make it absolutely positioned, and put it in front of first grayscaled map.

You can make it look round using -webkit-mask like described here

You should also synchronize events between maps, so that they would coincide, i.e. centered to the same position and always have same zoom level. You need also to create some kind of blocker to avoid recursive calls

var block = false;
google.maps.event.addListener (thismap, 'center_changed', function(event) {
    if (block) return;
    block = true;
    othermap.setCenter(thisMap.getCenter());
    block=false;
});

The same should be done for 'center_changed' (to control maps centering) and for 'zoom_changed' (control maps zoom), for both maps

Here I've set up an example

If you will need to create more than one map that way, you'll need to do more work to make them stick to necessary points

Community
  • 1
  • 1
paulitto
  • 4,585
  • 2
  • 22
  • 28
  • To be fair I thought this would have some performance detriment but it works incredibly smoothly and seems to be exactly the solution required. Be aware of map tile usage limits though, this solution will eat them twice as fast. – ChrisSwires May 15 '13 at 15:05
2

As far as I am aware there is no way to accomplish this directly within the API. I have had to achieve a similar effect in the past and the way that I went about it was to create a 'donut' rather than a circle.

Effectively the idea is to create a large shape which excludes a circular area at it's center. This way you can set the opacity on the polygon fairly low in order to highlight the 'area of interest' in this case the central circle.

This is perhaps a good starting point: http://www.geocodezip.com/v3_polygon_example_donut.html

Though obviously in your case your going to want to alter the colors. Also be aware that the size is fixed so unless you limit the map bounds users will be able to zoom out far enough to see the edges (thus ruining the illusion), and polygons distort towards the poles (pesky spherical earth).

Hope this helps.

ChrisSwires
  • 2,713
  • 1
  • 15
  • 28