Javascript 为谷歌地图中的每个国家赋予不同的颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5698413/
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
Give different color to each country in google map
提问by adhitia hidayat
Does anyone know how to give a different color to each country in a google map?
有谁知道如何在谷歌地图中为每个国家/地区赋予不同的颜色?
e.g:
例如:
in the world map
在世界地图上
Blue overlay to UK, then RED china...etc
蓝色叠加到英国,然后是红色china...等
I wonder if google provide API to give color to each country
我想知道 google 是否提供 API 来为每个国家/地区赋予颜色
Thanks
谢谢
回答by danii
Using Google Maps this is really not easy, as @oezi said you would need to build overlays of every country you want to color, which frankly sounds like a mess.
使用谷歌地图这真的不容易,因为@oezi 说你需要为你想要着色的每个国家建立叠加层,坦率地说,这听起来很混乱。
But if you don't need all of the functionalities of Google Maps, perhaps you can use a Map Chartfrom the fantastic Google Chart Tools(aka Chart API). You can check and tinker with a working example of a Colored Map (among some others) in the interactive Chart Wizard
但是,如果您不需要 Google Maps 的所有功能,也许您可以使用来自出色的Google Chart Tools(又名Chart API)的Map Chart。您可以在交互式图表向导中检查和修改彩色地图(以及其他一些)的工作示例
2017 UPDATE: This answer is quite old and as such the Map Charts API has been deprecated by Google. You can use the Geochartsfrom the Google Charts APIinstead:
2017 年更新:这个答案已经很老了,因此 Google 已弃用 Map Charts API。您可以使用Geocharts从谷歌图表API,而不是:
https://developers.google.com/chart/interactive/docs/gallery/geochart
https://developers.google.com/chart/interactive/docs/gallery/geochart
Hope this helps!
希望这可以帮助!
回答by Prog Mania
you may check this question,it's the same question you are asking. How to color countries using google maps?
你可以检查这个问题,这和你问的问题是一样的。 如何使用谷歌地图为国家着色?
it's talking about google Geocharts in google maps.
它谈论的是谷歌地图中的谷歌地理图表。
回答by oezi
there is a possibility to change the map style. and there is a very nice interactive example here- but, as far as i can see, it isn't possible to change the style of a specific country using this, so you'll have to build your own overlays using polygons.
有可能更改地图样式。并且有一个非常好的互动的例子在这里-不过,据我所看到的,这是不可能改变一个特定国家采用这种风格,所以你必须建立自己的使用多边形覆盖。
回答by MarkPraschan
First, find the shape file in .kml format. Tip: try googling "kml uk" or "kml china".
首先,找到 .kml 格式的形状文件。提示:尝试谷歌搜索“kml uk”或“kml china”。
Once you have the KMLfile, host it somewhere and then call it as a var
inside your Google Maps API initMap like this:
拥有 KMLfile 后,将其托管在某处,然后将其作为var
Google Maps API initMap 内部调用,如下所示:
var myCustomRegion = new google.maps.KmlLayer({
url: 'FULL_URL_TO_YOUR_SHAPE_FILE',
map: map
});
Now your shape is laid into your map.
现在您的形状已放置在您的地图中。
You can style the shape using the <LineStyle>
and <PolyStyle>
tags inside the KML file itself.
您可以使用KML 文件本身内的<LineStyle>
和<PolyStyle>
标签来设置形状的样式。