Android Google Maps GeoJson, as a shade of the entire map of the same color

I am currently working with the Android Google Maps utility. I get the geojson of this area through an API call and should display this area on the map.

I do it by calling

GeoJsonLayer layer = new GeoJsonLayer(getMap(), geoJsonData);
layer.addLayerToMap()

where getMap () returns a GoogleMap object, and geoJsonData is a JSONObject. This code draws a border around the area associated with geojson.

The code below draws a red frame around the area and fills it with yellow.

GeoJsonLayer layer = new GeoJsonLayer(getMap(), geoJsonData);            
GeoJsonPolygonStyle polygonStyle = layer.getDefaultPolygonStyle();
polygonStyle.setStrokeColor(ContextCompat.getColor(this, R.color.red));
polygonStyle.setFillColor(ContextCompat.getColor(this, R.color.yellow));
layer.addLayerToMap();

I am having problems with the style of this GeoJsonLayer, where the entire map is yellow, the border of the area is red, and the fill color of the area is the normal color.

- , Android, GeoJson? . , , , , , geojson.

, - , GeoJsonLayer , geojson.

+4
1

, :

" , , , , , geojson"

GeoJSON "" , GeoJSON " ",

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              -179.99,
              89.99
            ],
            [
              -179.99,
              0
            ],
            [
              -179.99,
              -89.99
            ],
            [
              0,
              -89.99
            ],
            [
              179.99,
              -89.99
            ],
            [
              179.99,
              0
            ],
            [
              179.99,
              89.99
            ],
            [
              0,
              89.99
            ],
            [
              -179.99,
              89.99
            ]
          ],
          [
            [
              -0.191208,
              51.509869
            ],
            [
              -0.158464,
              51.513287
            ],
            [
              -0.151769,
              51.50554
            ],
            [
              -0.174471,
              51.502178
            ],
            [
              -0.187989,
              51.502444
            ],
            [
              -0.191208,
              51.509869
            ]
          ]
        ],
        "properties": {
          "Territoire": 2
        }
      },
      "properties": {
        "name": "Hyde Park"
      }
    }
  ]
}

- :

GeoJSON Polygon with Hole

, GeoJSON, , " "

[
    [
      -179.99,
      89.99
    ],
    [
      -179.99,
      0
    ],
    [
      -179.99,
      -89.99
    ],
    [
      0,
      -89.99
    ],
    [
      179.99,
      -89.99
    ],
    [
      179.99,
      0
    ],
    [
      179.99,
      89.99
    ],
    [
      0,
      89.99
    ],
    [
      -179.99,
      89.99
    ]
]

0 ( ) coordinates :

JSONObject featureCollection = geoJsonData;
JSONArray features = featureCollection.getJSONArray("features");
for(int i = 0; i < features.length(); i++) {
    JSONObject feature = features.getJSONObject(i);
    JSONObject geometry = feature.getJSONObject("geometry");
    String geometryType = geometry.getString("type");
    if ("Polygon".equals(geometryType)) {
        JSONArray coordinates = geometry.getJSONArray("coordinates");
        if (coordinates.length() == 1) {
            coordinates.put(coordinates.get(0));
            JSONArray wholeMap = new JSONArray(
                    "[\n" +
                            "            [\n" +
                            "              -179.99,\n" +
                            "              89.99\n" +
                            "            ],\n" +
                            "            [\n" +
                            "              -179.99,\n" +
                            "              0\n" +
                            "            ],\n" +
                            "            [\n" +
                            "              -179.99,\n" +
                            "              -89.99\n" +
                            "            ],\n" +
                            "            [\n" +
                            "              0,\n" +
                            "              -89.99\n" +
                            "            ],\n" +
                            "            [\n" +
                            "              179.99,\n" +
                            "              -89.99\n" +
                            "            ],\n" +
                            "            [\n" +
                            "              179.99,\n" +
                            "              0\n" +
                            "            ],\n" +
                            "            [\n" +
                            "              179.99,\n" +
                            "              89.99\n" +
                            "            ],\n" +
                            "            [\n" +
                            "              0,\n" +
                            "              89.99\n" +
                            "            ],\n" +
                            "            [\n" +
                            "              -179.99,\n" +
                            "              89.99\n" +
                            "            ]\n" +
                            "          ]"
            );
            coordinates.put(0, wholeMap);
        } else {
            Log.d("OAA", "No need insert");
        }
    }
}

geoJsonData - GeoJSON " ", :

JSONObject geoJsonData = new JSONObject(
    "{\n" +
            "  \"type\": \"FeatureCollection\",\n" +
            "  \"features\": [\n" +
            "    {\n" +
            "      \"type\": \"Feature\",\n" +
            "      \"geometry\": {\n" +
            "        \"type\": \"Polygon\",\n" +
            "        \"coordinates\": [\n" +
            "          [\n" +
            "            [\n" +
            "              -0.191208,\n" +
            "              51.509869\n" +
            "            ],\n" +
            "            [\n" +
            "              -0.158464,\n" +
            "              51.513287\n" +
            "            ],\n" +
            "            [\n" +
            "              -0.151769,\n" +
            "              51.50554\n" +
            "            ],\n" +
            "            [\n" +
            "              -0.174471,\n" +
            "              51.502178\n" +
            "            ],\n" +
            "            [\n" +
            "              -0.187989,\n" +
            "              51.502444\n" +
            "            ]\n" +
            "          ]\n" +
            "        ],\n" +
            "        \"properties\": {\n" +
            "          \"Territoire\": 2\n" +
            "        }\n" +
            "      },\n" +
            "      \"properties\": {\n" +
            "        \"name\": \"Hyde Park\"\n" +
            "      }\n" +
            "    }\n" +
            "  ]\n" +
            "}"
    );

GeoJSON "", GeoJSON 2 "" Hyde Regent:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              -179.99,
              89.99
            ],
            [
              -179.99,
              0
            ],
            [
              -179.99,
              -89.99
            ],
            [
              0,
              -89.99
            ],
            [
              179.99,
              -89.99
            ],
            [
              179.99,
              0
            ],
            [
              179.99,
              89.99
            ],
            [
              0,
              89.99
            ],
            [
              -179.99,
              89.99
            ]
          ],
          [
            [
              -0.191208,
              51.509869
            ],
            [
              -0.158464,
              51.513287
            ],
            [
              -0.151769,
              51.50554
            ],
            [
              -0.174471,
              51.502178
            ],
            [
              -0.187989,
              51.502444
            ],
            [
              -0.191208,
              51.509869
            ]
          ],
          [
            [
              -0.167685,
              51.530226
            ],
            [
              -0.163737,
              51.534924
            ],
            [
              -0.151849,
              51.537566
            ],
            [
              -0.151849,
              51.537566
            ],
            [
              -0.146914,
              51.535964
            ],
            [
              -0.145625,
              51.525325
            ],
            [
              -0.155538,
              51.523589
            ],
            [
              -0.167685,
              51.530226
            ]
          ]
        ],
        "properties": {
          "Territoire": 2
        }
      },
      "properties": {
        "name": "Hyde Park"
      }
    }
  ]
}
+1

Source: https://habr.com/ru/post/1696167/


All Articles