How to get all features from geoJson source Mapbox
Asked Answered
T

0

6

I have loaded a geoJson source into my mapView. I have a search bar in my activity. So my plan is that I want to populate my searchBar suggestions with feature types from the geoJson source added to my map. I would like to do this from onMapStyleLoaded method.

So, is there a way to fetch details of all geoJson properties e.g 'name' and add all to an arrayList while the map is loaded?

@Override
    public void onMapReady(@NonNull final MapboxMap mapboxMap) {
        SearchActivity.this.mapboxMap = mapboxMap;
        mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> {
            mapboxMap.addOnMapClickListener(SearchActivity.this);
            addGeoJsonSourceToMap(style);
// Create FillLayer with GeoJSON source and add the FillLayer to the map
            style.addLayer(new FillLayer(geoJsonLayerId, geoJsonSourceId)
                    .withProperties(fillOpacity(0.5f)));
                    GeoJsonSource source = style.getSourceAs(geoJsonSourceId);
                    if (source != null){
                        List<Feature> features = source.querySourceFeatures(Expression.get("name"));
                        //I want to all the features of my geoJson source so I can pass them to an arrayList.

                    }
        });
    }
Third answered 8/1, 2020 at 6:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.