我是android中的GeoJson图层的初学者。我想在GeoJson图层上绘制填充一些颜色的多边形。问题是我无法在GeoJson图层上用多余的线条填充多边形的颜色。
这是我的代码。
heatMapLayer = GeoJsonLayer(map, [2]JSONObject(Gson().toJson(featureCollection)))
heatMapLayer?.features?.forEach {
var colorIndex = it.getProperty("temp").toDouble().toInt()
if (colorIndex < -10) {
colorIndex = -10
}
if (colorIndex > 40) {
colorIndex = 40
}
val polygonStyle = GeoJsonPolygonStyle()
polygonStyle?.fillColor = Utils.hex2ARgb(170, Constants.heatMapColor[colorIndex] ?: error(""))
polygonStyle?.strokeWidth = 0f
it.polygonStyle = polygonStyle
val pointStyle = GeoJsonPointStyle()
pointStyle.isDraggable = true
it.pointStyle = pointStyle
}
我想用颜色显示所有多边形。
这是GeoJson样本数据。
{ “ type”:“ FeatureCollection”, “特征”: [ { “ type”:“功能”, “属性”:{ “温度”:28.0, “ defaultUnit”:“°C” }, “几何”:{ “ type”:“多边形”, “坐标”:[ [ [ 106.70791799658124, 10.575534789370789 ], [ 106.707923201947, 10.539230085503078 ], [ 106.75196848603105, 10.514232576383892 ], [ 106.79601377011508, 10.539230085503078 ], [ 106.7960209392707, 10.589231196662963 ], [ 106.76782493975878, 10.605234887615962 ], [ 106.76111674178632, 10.601428713580317 ], [ 106.76111586436221, 10.595343333584946 ], [ 106.71706253230332, 10.570345841048965 ], [ 106.70791799658124, 10.575534789370789 ] ] ] } }, { “ type”:“功能”, “属性”:{ “温度”:28.0, “ defaultUnit”:“°C” }, “几何”:{ “ type”:“多边形”, “坐标”:[ [ [ 106.74952463777162, 10.594851453114759 ], [ 106.76782493975878, 10.605234887615964 ], [ 106.76111783947686, 10.609041752489026 ], [ 106.76111674178633, 10.601428713580317 ], [ 106.74952463777162, 10.594851453114759 ] ] ] } } ] }
答案 0 :(得分:0)
尝试
heatMapLayer = new GeoJsonLayer(googleMap, new JSONObject(airMapGeoJsonLayer.geoJson));
GeoJsonPolygonStyle style = heatMapLayer.getDefaultPolygonStyle();
style.setStrokeColor(airMapGeoJsonLayer.strokeColor);
style.setStrokeWidth(airMapGeoJsonLayer.strokeWidth);
style.setFillColor(airMapGeoJsonLayer.fillColor);
heatMapLayer .addLayerToMap();
或者您也可以尝试
GeoJsonPolygonStyle polyStyle = layer.getDefaultPolygonStyle();
polyStyle.setFillColor(FILL_GREY);
polyStyle.setStrokeColor(STROKE_GREY);
polyStyle.setStrokeWidth(4f);