【发布时间】:2019-07-31 23:05:20
【问题描述】:
我创建了一个填充整个 Google 地图的多边形。
添加几个洞后,地图工作正常。地图被多边形填充颜色着色,并且孔被渲染。
但是,添加第三个孔后,孔仍然显示多边形的笔触,但多边形填充颜色变为透明。
我的洞列表大小是 63,但它可能会有所不同。
多边形可以有的孔有任何限制吗?或者如何绘制一个带有多个孔的多边形?所有的洞都包含在地图中。
编辑 1
我无法添加我工作中的确切代码 sn-p,但这与我正在做的事情相似。
fun GoogleMap.render(geoJSONS: List<JSONObject>) {
val wholeMapPolygon = 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)
).strokeColor(Color.BLACK)
.fillColor(Color.WHITE)
val layers = createGeoJSONLayers(this, geoJSONS)
val holes = getPolygonsFromGeoJsonLayers()
for(hole in holes) {
wholeMapPolygon.addHole(hole) // Here, adding more that 3 makes the wholeMapPolygon fill color dissapear.
}
addPolygon(wholeMapPolygon)
}
/**
* In this function, some other functions get called to extract each list of coordinates for each layer polygon.
**/
private fun getPolygonsFromGeoJsonLayers(layers: List<GeoJsonLayer>): List<List<LatLng>> {
val holes = mutableListOf<List<LatLng>>()
for(layer in layers) {
val polygonFeatures = getGeoJsonLayerPolygonFeatures()
for(polygonFeature in polygonFeatures) {
holes.addAll(getCoordinatesFromFeature(polygonFeature))
}
}
return holes
}
private fun getGeoJsonLayerPolygonFeatures(features: List<GeoJsonFeature>): List<GeoJsonFeature> = features.filter { feature ->
feature.geometry.geometryType == "Polygon"
}
private fun getCoordinatesFromFeature(feature: GeoJSONFeature): List<LatLng> {
val coordinates = mutableListOf<LatLng>()
(geometry as? GeoJsonPolygon)?.coordinates?.filter {
it.isNotEmpty()
}?.forEach {
coordinates.addAll(it)
}
return coordinates
}
private fun createGeoJSONLayers(map: GoogleMap, data: List<JSONObject>) = data?.map { jsonObject ->
GeoJsonLayer(map, jsonObject)
}
【问题讨论】:
-
贴一些代码和一些截图
-
我无法发布确切的代码,因为它来自我公司,我会发布类似的内容
标签: android google-maps kotlin