Search in sources :

Example 6 with SymbolLayer

use of com.mapbox.mapboxsdk.style.layers.SymbolLayer in project mapbox-plugins-android by mapbox.

the class TrafficPlugin method placeLayerBelow.

/**
 * Attempts to find the layer which the traffic should be placed below. Depending on the style, this might not always
 * be accurate.
 */
private String placeLayerBelow() {
    if (belowLayer == null || belowLayer.isEmpty()) {
        List<Layer> styleLayers = mapboxMap.getLayers();
        Layer layer;
        for (int i = styleLayers.size() - 1; i >= 0; i--) {
            layer = styleLayers.get(i);
            if (!(layer instanceof SymbolLayer)) {
                return layer.getId();
            }
        }
    }
    return belowLayer;
}
Also used : SymbolLayer(com.mapbox.mapboxsdk.style.layers.SymbolLayer) LineLayer(com.mapbox.mapboxsdk.style.layers.LineLayer) Layer(com.mapbox.mapboxsdk.style.layers.Layer) SymbolLayer(com.mapbox.mapboxsdk.style.layers.SymbolLayer)

Example 7 with SymbolLayer

use of com.mapbox.mapboxsdk.style.layers.SymbolLayer in project mapbox-plugins-android by mapbox.

the class LocalizationPlugin method setMapLanguage.

/**
 * You can pass in a {@link MapLocale} directly into this method which uses the language defined
 * in it to represent the language found on the map.
 *
 * @param mapLocale the {@link MapLocale} object which contains the desired map language
 * @since 0.1.0
 */
public void setMapLanguage(@NonNull MapLocale mapLocale) {
    this.mapLocale = mapLocale;
    List<Layer> layers = mapboxMap.getLayers();
    for (Source source : mapboxMap.getSources()) {
        if (sourceIsFromMapbox(source)) {
            for (Layer layer : layers) {
                if (layerHasAdjustableTextField(layer)) {
                    String textField = ((SymbolLayer) layer).getTextField().getValue();
                    if (textField != null && (textField.contains("{name") || textField.contains("{abbr}"))) {
                        textField = textField.replaceAll("[{]((name).*?)[}]", String.format("{%s}", mapLocale.getMapLanguage()));
                        layer.setProperties(textField(textField));
                    }
                }
            }
        }
    }
}
Also used : SymbolLayer(com.mapbox.mapboxsdk.style.layers.SymbolLayer) Layer(com.mapbox.mapboxsdk.style.layers.Layer) Source(com.mapbox.mapboxsdk.style.sources.Source) VectorSource(com.mapbox.mapboxsdk.style.sources.VectorSource)

Example 8 with SymbolLayer

use of com.mapbox.mapboxsdk.style.layers.SymbolLayer in project mapbox-plugins-android by mapbox.

the class LocationLayerTest method whenMapCameraInitializesTilted_iconsGetPlacedWithCorrectOffset.

@Test
public void whenMapCameraInitializesTilted_iconsGetPlacedWithCorrectOffset() throws Exception {
    executeLocationLayerTest((locationLayerPlugin, mapboxMap, uiController, context) -> {
        mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder().tilt(60).build()));
        locationLayerPlugin.setRenderMode(RenderMode.NORMAL);
        locationLayerPlugin.forceLocationUpdate(location);
        SymbolLayer layer = mapboxMap.getLayerAs(FOREGROUND_LAYER);
        uiController.loopMainThreadForAtLeast(200);
        Float[] value = layer.getIconOffset().getValue();
        Assert.assertEquals((-0.05 * 60), value[1], 0.1);
    });
}
Also used : SymbolLayer(com.mapbox.mapboxsdk.style.layers.SymbolLayer) Test(org.junit.Test)

Example 9 with SymbolLayer

use of com.mapbox.mapboxsdk.style.layers.SymbolLayer in project androidApp by InspectorIncognito.

the class LocationLayer method createLayer.

private Layer createLayer(String layerId, String image, Drawable drawable) {
    Bitmap bitmap = getBitmapFromDrawable(drawable);
    mapboxMap.addImage(image, bitmap);
    return new SymbolLayer(layerId, LocationLayerConstants.LOCATION_SOURCE).withProperties(// PropertyFactory.iconImage(image),
    PropertyFactory.iconImage(Function.property(LocationLayerConstants.PROPERTY_ORIENTATION, Stops.categorical(Stop.stop("NONE", PropertyFactory.iconImage(image)), Stop.stop("LEFT", PropertyFactory.iconImage(image + "-left")), Stop.stop("RIGHT", PropertyFactory.iconImage(image + "-right"))))), PropertyFactory.iconAnchor(Property.ICON_ANCHOR_CENTER), PropertyFactory.iconAllowOverlap(true), PropertyFactory.iconIgnorePlacement(true));
}
Also used : Bitmap(android.graphics.Bitmap) SymbolLayer(com.mapbox.mapboxsdk.style.layers.SymbolLayer)

Example 10 with SymbolLayer

use of com.mapbox.mapboxsdk.style.layers.SymbolLayer in project androidApp by InspectorIncognito.

the class BusLayer method setupAllLayers.

public void setupAllLayers(MapboxMap mapboxMap, String busStopsSource) {
    // MARKER LAYER
    mapboxMap.addLayerBelow(new SymbolLayer(BUS_MARKER_LAYER_ID_LEFT, busStopsSource).withProperties(iconImage("{ID}-left"), iconSize(1.0f), /* allows show all icons */
    iconAllowOverlap(true), iconOffset(new Float[] { BusMarker.MARKER_DX_OFFSET, BusMarker.MARKER_DY_OFFSET })).withFilter(eq(BusMarker.PROPERTY_LOOKING_LEFT, true)), BUS_STOP_SELECTED_MARKER_LAYER_ID);
    // MARKER LAYER
    mapboxMap.addLayerBelow(new SymbolLayer(BUS_MARKER_LAYER_ID_RIGHT, busStopsSource).withProperties(iconImage("{ID}-right"), iconSize(1.0f), /* allows show all icons */
    iconAllowOverlap(true), iconOffset(new Float[] { BusMarker.MARKER_DX_OFFSET, BusMarker.MARKER_DY_OFFSET })).withFilter(eq(BusMarker.PROPERTY_LOOKING_LEFT, false)), BUS_STOP_SELECTED_MARKER_LAYER_ID);
    // MIN INFO WINDOW LAYER
    mapboxMap.addLayerBelow(new SymbolLayer(BUS_INFO_WINDOW_LAYER_ID_MIN, busStopsSource).withProperties(/* show image with id title based on the value of the maximized feature property */
    iconImage("{ID}-min"), /* set anchor of icon to bottom-left */
    iconAnchor("bottom-left"), /* offset icon slightly to match bubble layout */
    iconOffset(new Float[] { BusMarker.MIN_DX_OFFSET, BusMarker.MIN_DY_OFFSET })).withFilter(all(eq(BusMarker.PROPERTY_MAXIMIZED, false), eq(BusMarker.PROPERTY_HAVE_EVENTS, true))), BUS_STOP_SELECTED_MARKER_LAYER_ID);
    // MAX INFO WINDOW LAYER
    mapboxMap.addLayerAbove(new SymbolLayer(BUS_INFO_WINDOW_LAYER_ID_MAX, busStopsSource).withProperties(/* show image with id title based on the value of the maximized feature property */
    iconImage("{ID}-max"), /* set anchor of icon to bottom-left */
    iconAnchor("bottom-left"), iconAllowOverlap(true), /* offset icon slightly to match bubble layout */
    iconOffset(new Float[] { BusMarker.MAX_DX_OFFSET, BusMarker.MAX_DY_OFFSET })).withFilter(eq(BusMarker.PROPERTY_MAXIMIZED, true)), BUS_STOP_INFO_WINDOW_LAYER_ID_MAX);
}
Also used : SymbolLayer(com.mapbox.mapboxsdk.style.layers.SymbolLayer)

Aggregations

SymbolLayer (com.mapbox.mapboxsdk.style.layers.SymbolLayer)11 Layer (com.mapbox.mapboxsdk.style.layers.Layer)5 Bitmap (android.graphics.Bitmap)4 CircleLayer (com.mapbox.mapboxsdk.style.layers.CircleLayer)1 LineLayer (com.mapbox.mapboxsdk.style.layers.LineLayer)1 GeoJsonSource (com.mapbox.mapboxsdk.style.sources.GeoJsonSource)1 Source (com.mapbox.mapboxsdk.style.sources.Source)1 VectorSource (com.mapbox.mapboxsdk.style.sources.VectorSource)1 Test (org.junit.Test)1