Search in sources :

Example 1 with GeoJsonOptions

use of com.mapbox.mapboxsdk.style.sources.GeoJsonOptions in project mapbox-navigation-android by mapbox.

the class MapUtils method updateMapSourceFromFeatureCollection.

/**
 * Takes a {@link FeatureCollection} and creates a map GeoJson source using the sourceId also
 * provided.
 *
 * @param mapboxMap  that the current mapView is using
 * @param collection the feature collection to be added to the map style
 * @param sourceId   the source's id for identifying it when adding layers
 * @since 0.8.0
 */
public static void updateMapSourceFromFeatureCollection(@NonNull MapboxMap mapboxMap, @Nullable FeatureCollection collection, @NonNull String sourceId) {
    if (collection == null) {
        collection = FeatureCollection.fromFeatures(new Feature[] {});
    }
    GeoJsonSource source = mapboxMap.getSourceAs(sourceId);
    if (source == null) {
        GeoJsonOptions routeGeoJsonOptions = new GeoJsonOptions().withMaxZoom(16);
        GeoJsonSource routeSource = new GeoJsonSource(sourceId, collection, routeGeoJsonOptions);
        mapboxMap.addSource(routeSource);
    } else {
        source.setGeoJson(collection);
    }
}
Also used : GeoJsonSource(com.mapbox.mapboxsdk.style.sources.GeoJsonSource) GeoJsonOptions(com.mapbox.mapboxsdk.style.sources.GeoJsonOptions) Feature(com.mapbox.services.commons.geojson.Feature)

Example 2 with GeoJsonOptions

use of com.mapbox.mapboxsdk.style.sources.GeoJsonOptions in project mapbox-plugins-android by mapbox.

the class LocationLayer method addLocationSource.

// 
// Source actions
// 
private void addLocationSource() {
    FeatureCollection emptyFeature = FeatureCollection.fromFeatures(new Feature[] {});
    GeoJsonSource locationSource = new GeoJsonSource(LOCATION_SOURCE, emptyFeature, new GeoJsonOptions().withMaxZoom(16));
    mapboxMap.addSource(locationSource);
    sourceMap.put(LOCATION_SOURCE, locationSource);
}
Also used : GeoJsonSource(com.mapbox.mapboxsdk.style.sources.GeoJsonSource) GeoJsonOptions(com.mapbox.mapboxsdk.style.sources.GeoJsonOptions) FeatureCollection(com.mapbox.geojson.FeatureCollection)

Aggregations

GeoJsonOptions (com.mapbox.mapboxsdk.style.sources.GeoJsonOptions)2 GeoJsonSource (com.mapbox.mapboxsdk.style.sources.GeoJsonSource)2 FeatureCollection (com.mapbox.geojson.FeatureCollection)1 Feature (com.mapbox.services.commons.geojson.Feature)1