gpt4 book ai didi

android - 向多边形添加孔会移除其填充颜色

转载 作者:行者123 更新时间:2023-11-29 00:53:26 26 4
gpt4 key购买 nike

我创建了一个填满整个 Google map 的多边形。

在我添加了几个洞之后, map 工作正常。使用多边形填充颜色对 map 进行着色,并渲染孔洞。

但是,添加第三个孔后,孔仍然显示多边形的笔划,但多边形填充颜色变得透明。

我的漏洞列表大小是 63,但它可以变化。

多边形可以有多少个洞?或者我怎样才能画出一个有多个孔的多边形?所有的洞都包含在 map 中。

编辑 1

我无法添加我工作中的确切代码 fragment ,但这与我所做的类似。

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)
}

最佳答案

问题似乎在于您的孔的位置。 Google's documentation在多边形上说如下:

If the hole intersects the outline of the polygon, the polygon will be rendered without any fill.

还有 Polygon's reference状态:

Holes

A hole must be fully contained within the outline. Multiple holes can be specified, however overlapping holes are not supported.

Fill Color

The default value is transparent (0x00000000). If the polygon geometry is not specified correctly (see above for Outline and Holes), then no fill will be drawn.

希望这对您有所帮助!

关于android - 向多边形添加孔会移除其填充颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57299871/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com