我可以在GoogleMaps中显示一个国家(屏蔽掉)吗? [英] Can I show a single country (masked out) in GoogleMaps?

查看:128
本文介绍了我可以在GoogleMaps中显示一个国家(屏蔽掉)吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在GoogleMap中掩盖邻居国家?就我而言,我只想向瑞典展示一种观点。在第二个视图中,只有挪威,丹麦等...

我知道可以绘制多边形线并将其填充到Maps API。问题是,或者结果集变大或者线条变得非常粗糙等等......如果GoogleMaps能够在没有邻居的情况下在当时提供一个国家,那会很好。



有谁知道一个好的坐标数据库和国家边界?

解决方案

如果您以KML文件格式存储它们并将它们加载为 KmlLayers 。 KML是地理数据的基于XML的矢量文件格式。在Google地图中使用KML文件的优点在于,无论原始多边形数据的复杂程度如何,它们都可以在Google服务器上呈现为简单的PNG文件,与当前的地图视图的分辨率和边界框匹配。所以所有的复杂性都是在Google服务器端处理的。



这是一个一个项目样本,我在这里为德国的一个联邦州使用了这种遮罩。 (在这种情况下,周围的环境并没有完全遮挡,只是变暗,但您也可以通过更改KML文件中填充颜色的Alpha值来轻松遮罩它们。)



快速查看KML文件也可以直接加载到Google Maps公共网站(通过在搜索字段中输入它们的URL)。以下是我在上述项目中使用的KML文件,直接加载到Google地图。 (我实际上在这里使用了一个KMZ文件,但这只是一个压缩到ZIP压缩文件中的KML文件,可以用普通的ZIP工具打包和解压缩。)
BEGIN UPDATE 07/2015:不幸的是Google已经删除了在2014年推出其重新设计版本时直接将KML / KMZ文件的网址输入其公开Goog​​le地图的搜索字段的可能性。您仍然可以使用本答案中讨论的所有技术,但不能简单地预览KML文件通过在搜索字段中输入他们的URL。如果您需要上述KMZ作进一步分析,您可以在此处下载。 END UPDATE

请注意Google暗示KML / KMZ文件的大小限制(目前是10 Mb未压缩,3 Mb压缩 - 详情请参阅此处)。如果您的KML文件应该很大,可以使用软件来降低复杂性(请参阅示例此处此处)。

您会在互联网上的许多地方找到免费的地图数据,其中大部分是ESRI shapefile格式。国家地图的一个重要来源是 http://www.gadm.org/ ,它具有提供他们的数据也是KML / KMZ格式。如果您必须将ESRI shapefile转换为KML,请查看伟大(免费) OGR转换器。

请注意,如果您的多边形是静态的(比如瑞典的边框),并且不依赖于任何用户输入,KML文件只是一个解决方案。对于动态多边形,您仍然必须使用Maps API的Polygon类以及您提到的复杂性限制。


Is it possible to mask away neighbor countries in GoogleMap? In my case I just want to show Sweden on one view. On a second view just Norway, Denmark etc etc...

I know it is possible to draw polygon lines and fill them accordingly on to Maps API. Problem is that or the result sets get huge or the lines get very rough etc... Would be nice if GoogleMaps could deliver a country at the time without neighbors.

Does anyone know about a good coordinate database with country borders?

解决方案

You can create very complex polygons in Maps without a drop in performance if you store them in KML file format and load them as KmlLayers. KML is an XML based vector file format for geo data. The beauty of using KML files in Google Maps is that they are rendered on Google servers into simple PNG files, matching the current resolution and bounding box of your Maps view at any time, no matter how complex the original polygon data is. So all complexity is handled server side at Google.

Here is a sample of a project, where I have used such a masking for one of the federal states of Germany. (The surroundings in this case are not fully masked away but only dimmed. But you can also mask them off just as easily by changing the alpha value of the fill color in the KML file.)

For a quick review KML files can also be loaded directly into the Google Maps public website (by entering their URL into the search field). Here is the KML file that I have used in the above project, loaded directly into Google Maps. (I have actually used a KMZ file here, but that is simply a KML file packed into a ZIP archive. You can pack and unpack it with normal ZIP tools.)
BEGIN UPDATE 07/2015: Unfortunately Google has REMOVED the possibility to directly enter the URL of a KML/KMZ file into the search field of their public Google Maps when they launched its redesigned version in 2014. You can still use all techniques discussed in this answer but you cannot simply preview KML files by entering their URL in the search field anymore. If you need the KMZ mentioned above for further analysis, you can download it here. END UPDATE

Please be aware that Google implies a size limit to KML/KMZ files (currently 10 Mb uncompressed, 3 Mb compressed - details see here). If your KML files should be to large, there is software available to reduce the complexity (see examples here and here).

You will find free map data at many places on the Internet, most of them being in ESRI shapefile format. A great source for country maps is http://www.gadm.org/ with the big advantage of providing their data in KML/KMZ format too. If you should have to convert ESRI shapefiles to KML, have a look at the great (and free) OGR converter.

Please notice that KML files are only a solution if your polygons are static (like the border of Sweden is) and not depending on any user input. For dynamic polygons you will still have to use the Polygon class of the Maps API with the complexity restrictions that you have mentioned.

这篇关于我可以在GoogleMaps中显示一个国家(屏蔽掉)吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆