How to invert KML so that area outside of polygon is highlighted

烈酒焚心 提交于 2019-12-12 21:42:26

问题


I have a KML File which is a polygon that overlays the boundaries of a city. Currently my polygon is shaded gray. I would like to invert it, so the rest of the world is greyed out,

Here is a link to the kml, it should take you to Google maps. City of Edmonton

I'm not really sure if this is something I need to change in my KML, or can be accomplished with the Google Maps API.


回答1:


You need to change your KML. Add an outer boundary to the polygon that covers the whole world. Make sure the winding direction of the outer polygon is opposite the winding direction of the inner polygon.

example (state of Virginia).

Note that KML doesn't seem to work with the Google Maps Javascript API v3 KmlLayer renderer, might need to reverse the winding directions.




回答2:


Now google maps provide method addGeoJson to the map so it's better to convert KML to geojson you can this tool for this step https://mapbox.github.io/togeojson/

Then in the coordinates array add this array as a first input in coordinates

[
                    [0, 90],
                    [180, 90],
                    [180, -90],
                    [0, -90],
                    [-180, -90],
                    [-180, 0],
                    [-180, 90],
                    [0, 90]
                ]

It'll do the inversions and you can find examples here https://github.com/minaalfy/city-map



来源:https://stackoverflow.com/questions/26538676/how-to-invert-kml-so-that-area-outside-of-polygon-is-highlighted

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