Android GeoJson突出显示Polygon的反向区域

时间:2018-01-24 01:58:53

标签: android kml geojson

我正在尝试使用KML和GeoJson for Android,我试图展示某些图层而不是其他图层。 KML似乎不允许GeoJson的灵活性。

GeoJson允许我根据特定条件添加/删除功能。例如,我可能想要始终显示基本区域(多边形),但由于屏幕上有许多多边形的滞后,仅显示某些缩放级别的其他区域。

我目前正在尝试使用GeoJson来突出显示区域的反转。在car2go app

中可以看到一个很好的例子

2 个答案:

答案 0 :(得分:2)

我找到了另一篇帖子here

的答案
// World boundary. Can't make -90 otherwise rendering error
val polygon = PolygonOptions().add(
        LatLng(-89.999999999999, -180.0),
        LatLng(89.99999999999, -180.0),
        LatLng(89.99999999999, 179.99999999),
        LatLng(-89.99999999999, 179.99999999),
        LatLng(-89.99999999999, 0.0))

// Test hole of Europe
polygon.addHole(listOf(
        LatLng(29.68224948021748, -23.676965750000022),
        LatLng(29.68224948021748, 44.87772174999998),
        LatLng(71.82725578445813, 44.87772174999998),
        LatLng(71.82725578445813, -23.676965750000022)))

polygon.fillColor(Color.argb(75, 125, 125, 220))
polygon.strokeColor(Color.argb(205, 125, 125, 220))
polygon.strokeWidth(2.0f)

map?.addPolygon(polygon)

答案 1 :(得分:0)

这里是GeoJson的代码段,用于向坐标添加世界矩形。这将在geoJson中剪切/反转/反转多边形。

geoJson.geometry.coordinates[0].unshift([[180, -90], [180, 90], [-180, 90], [-180, -90]]);