javascript Google Maps Api V3 - 样式化国家或城市

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7714035/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 01:02:38  来源:igfitidea点击:

Google Maps Api V3 - Styling countries or cities

javascriptgoogle-mapsgoogle-maps-api-3

提问by Kedor

I am trying to make a map, just for selected area, lets say country, and get rid of some of the labels and stuff that are on the map. I found a styles wizard: http://gmaps-samples-v3.googlecode.com/svn/trunk/styledmaps/wizard/index.htmlBut my question is, if u can somehow hide smaller cities, or other countries than my selected one?

我正在尝试制作地图,仅针对选定区域,比如说国家,并删除地图上的一些标签和内容。我找到了一个样式向导:http: //gmaps-samples-v3.googlecode.com/svn/trunk/styledmaps/wizard/index.html但我的问题是,如果你能以某种方式隐藏较小的城市或其他国家而不是我选择的国家一?

I know i can hide all cities at once, or that i can hide borders, but i am curious if i can leave main cities visible, and for example gray out other countries than USA or i would have to manually create biggest polygon ever everywhere except USA? o.o

我知道我可以一次隐藏所有城市,或者我可以隐藏边界,但我很好奇我是否可以让主要城市可见,例如将美国以外的其他国家涂灰,或者我必须手动创建有史以来最大的多边形,除了美国?哦

回答by Tomik

Unfortunately, Google Maps API doesn't offer a way to selectively hide labels in an area. You can only remove labels for the whole map in several categories - e.g. using MapTypeStylecontaining:

不幸的是,Google Maps API 没有提供一种方法来选择性地隐藏某个区域的标签。您只能在几个类别中删除整个地图的标签 - 例如使用MapTypeStyle包含:

{
    featureType: "administrative.country",
    elementType: "labels",
    stylers: [
        { visibility: "off" }
    ]
}

hides labels with country names.

隐藏带有国家名称的标签。

To hide an area you have to create your own overlay - some polygon or overlay map type.

要隐藏一个区域,您必须创建自己的叠加层 - 一些多边形或叠加层地图类型。

When you want to show only an area of the map, it might be also a good idea to limit viewable area of the map.

当您只想显示地图的一个区域时,限制地图的可见区域可能也是一个好主意。