3

I want to get all features from a GeoJsonSource, my code is:

GeoJsonSource geoJsonSource = new GeoJsonSource("source", loadJsonFromRaw());

for (Feature feature : geoJsonSource.querySourceFeatures(null)) {
    Log.d(TAG, "onMapReady: " + feature.toJson());
}

but it always returns an empty list of Feature

Does anyone know how to get all features from a GeoJsonSource ?

My GeoJson file is something likes this:

{   "type": "FeatureCollection",   "features": [
    {
      "type": "Feature",
      "properties": {
        "edge_id": 1,
        "detailed": "no",
        "distance": 3106,
        "type": "normal"
      },
      "geometry": {
        "type": "LineString",
        "coordinates": [
          [
            6.579816,
            46.72714
          ],
          [
            6.580883,
            46.728004
          ],
          [
            6.582048,
            46.728982
          ],
          [
            6.583276,
            46.730096
          ],
          [
            6.584309,
            46.731073
          ],
          [
            6.58524,
            46.73232
          ],
          [
            6.586203,
            46.733657
          ],
          [
            6.5871,
            46.734926
          ],
          [
            6.58787,
            46.735991
          ],
          [
            6.588547,
            46.73674
          ],
          [
            6.589222,
            46.737624
          ],
          [
            6.590613,
            46.738806
          ],
          [
            6.591552,
            46.739512
          ],
          [
            6.593013,
            46.740425
          ],
          [
            6.594249,
            46.74111
          ],
          [
            6.59627,
            46.741869
          ],
          [
            6.599075,
            46.742814
          ],
          [
            6.599074,
            46.742836
          ],
          [
            6.601293,
            46.743506
          ],
          [
            6.60276,
            46.744081
          ],
          [
            6.604356,
            46.744768
          ],
          [
            6.60556,
            46.745363
          ],
          [
            6.607537,
            46.746509
          ]
        ]
      }
    },
    ...   ] }
Norutan
  • 1,480
  • 2
  • 14
  • 27

1 Answers1

0

You can query for all Features in the source by using: source.querySourceFeatures(Expression.all())

Mars
  • 4,197
  • 11
  • 39
  • 63