Google Map API v3 Color Customization

穿精又带淫゛_ 提交于 2019-12-08 14:50:32

问题


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 ?


回答1:


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




回答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.



来源:https://stackoverflow.com/questions/15547570/google-map-api-v3-color-customization

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!