Search in sources :

Example 1 with VectorSource

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

the class TrafficPlugin method addTrafficSource.

/**
 * Adds traffic source to the map.
 */
private void addTrafficSource() {
    VectorSource trafficSource = new VectorSource(TrafficData.SOURCE_ID, TrafficData.SOURCE_URL);
    mapboxMap.addSource(trafficSource);
}
Also used : VectorSource(com.mapbox.mapboxsdk.style.sources.VectorSource)

Example 2 with VectorSource

use of com.mapbox.mapboxsdk.style.sources.VectorSource in project collect by opendatakit.

the class MapboxMapFragment method addMbtiles.

@SuppressWarnings("TimberExceptionLogging")
private void addMbtiles(String id, File file) {
    MbtilesFile mbtiles;
    try {
        mbtiles = new MbtilesFile(file);
    } catch (MbtilesException e) {
        Timber.w(e.getMessage());
        return;
    }
    TileSet tileSet = createTileSet(mbtiles, tileServer.getUrlTemplate(id));
    tileServer.addSource(id, mbtiles);
    if (mbtiles.getLayerType() == LayerType.VECTOR) {
        addOverlaySource(new VectorSource(id, tileSet));
        List<MbtilesFile.VectorLayer> layers = mbtiles.getVectorLayers();
        for (MbtilesFile.VectorLayer layer : layers) {
            // Pick a colour that's a function of the filename and layer name.
            // The colour will appear essentially random; the only purpose here
            // is to try to assign different colours to different layers, such
            // that each individual layer appears in its own consistent colour.
            int hue = (((id + "." + layer.name).hashCode()) & 0x7fffffff) % 360;
            addOverlayLayer(new LineLayer(id + "/" + layer.name, id).withProperties(lineColor(Color.HSVToColor(new float[] { hue, 0.7f, 1 })), lineWidth(1f), lineOpacity(0.7f)).withSourceLayer(layer.name));
        }
    }
    if (mbtiles.getLayerType() == LayerType.RASTER) {
        addOverlaySource(new RasterSource(id, tileSet));
        addOverlayLayer(new RasterLayer(id + ".raster", id));
    }
    Timber.i("Added %s as a %s layer at /%s", file, mbtiles.getLayerType(), id);
}
Also used : VectorSource(com.mapbox.mapboxsdk.style.sources.VectorSource) RasterLayer(com.mapbox.mapboxsdk.style.layers.RasterLayer) MbtilesException(org.odk.collect.android.geo.MbtilesFile.MbtilesException) RasterSource(com.mapbox.mapboxsdk.style.sources.RasterSource) TileSet(com.mapbox.mapboxsdk.style.sources.TileSet) LineLayer(com.mapbox.mapboxsdk.style.layers.LineLayer) MapPoint(org.odk.collect.geo.maps.MapPoint) SuppressLint(android.annotation.SuppressLint)

Example 3 with VectorSource

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

the class RegionSelectionFragment method getOfflineRegionName.

public String getOfflineRegionName() {
    List<Feature> featureList = mapboxMap.queryRenderedFeatures(boundingBox, LAYER_IDS);
    if (featureList.isEmpty()) {
        Timber.v("Rendered features empty, attempting to query vector source.");
        VectorSource source = mapboxMap.getSourceAs("composite");
        if (source != null) {
            featureList = source.querySourceFeatures(SOURCE_LAYER_IDS, null);
        }
    }
    if (!featureList.isEmpty() && featureList.get(0).properties().has("name")) {
        return featureList.get(0).getStringProperty("name");
    }
    return getString(R.string.mapbox_offline_default_region_name);
}
Also used : VectorSource(com.mapbox.mapboxsdk.style.sources.VectorSource) Feature(com.mapbox.geojson.Feature)

Aggregations

VectorSource (com.mapbox.mapboxsdk.style.sources.VectorSource)3 SuppressLint (android.annotation.SuppressLint)1 Feature (com.mapbox.geojson.Feature)1 LineLayer (com.mapbox.mapboxsdk.style.layers.LineLayer)1 RasterLayer (com.mapbox.mapboxsdk.style.layers.RasterLayer)1 RasterSource (com.mapbox.mapboxsdk.style.sources.RasterSource)1 TileSet (com.mapbox.mapboxsdk.style.sources.TileSet)1 MbtilesException (org.odk.collect.android.geo.MbtilesFile.MbtilesException)1 MapPoint (org.odk.collect.geo.maps.MapPoint)1