Su Thiri Khit
Su Thiri Khit

Reputation: 23

How to fill color polygon with extra line in GeoJSON layer?

I am a beginner with GeoJson layer in android. I want to draw polygons with filling some color on GeoJson layer. The problem is that I can't fill color in polygon with extra line on GeoJson layer.

Here is my code.

 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
        }

I want to show all polygons with colors.

Here is sample GeoJson data.

{ "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": { "temp": 28.0, "defaultUnit": "°C" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 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": "Feature", "properties": { "temp": 28.0, "defaultUnit": "°C" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 106.74952463777162, 10.594851453114759 ], [ 106.76782493975878, 10.605234887615964 ], [ 106.76111783947686, 10.609041752489026 ], [ 106.76111674178633, 10.601428713580317 ], [ 106.74952463777162, 10.594851453114759 ] ] ] } } ] }

Here is the result I want to show

Upvotes: 1

Views: 1354

Answers (1)

Sagar Dangi
Sagar Dangi

Reputation: 161

try this

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();

or you can try this too

GeoJsonPolygonStyle polyStyle = layer.getDefaultPolygonStyle();
polyStyle.setFillColor(FILL_GREY);
polyStyle.setStrokeColor(STROKE_GREY);
polyStyle.setStrokeWidth(4f);

Upvotes: 1

Related Questions