com.mapbox.mapboxsdk.style.layers.SymbolLayer Java Examples

The following examples show how to use com.mapbox.mapboxsdk.style.layers.SymbolLayer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
private void setLayer(Style style) {
    SymbolLayer symbolLayer = new SymbolLayer("POINT_LAYER", "events").withProperties(
            PropertyFactory.iconImage("ICON_ID"),
            iconAllowOverlap(true),
            iconOffset(new Float[]{0f, -9f})
    );
    symbolLayer.setMinZoom(0);
    style.addLayer(symbolLayer);

    if (featureType != FeatureType.POINT)
        style.addLayerBelow(new FillLayer("POLYGON_LAYER", "events").withProperties(
                fillColor(
                        ColorUtils.getPrimaryColorWithAlpha(this, ColorUtils.ColorType.PRIMARY_LIGHT, 150f)
                )
                ), "settlement-label"
        );
}
 
Example #2
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapboxMap.java    License: MIT License 6 votes vote down vote up
private SymbolLayer createWaynameLayer() {
  return new SymbolLayer(MAPBOX_WAYNAME_LAYER, MAPBOX_LOCATION_SOURCE)
    .withProperties(
      iconAllowOverlap(true),
      iconIgnorePlacement(true),
      iconSize(
        interpolate(exponential(1f), zoom(),
          stop(0f, 0.6f),
          stop(18f, 1.2f)
        )
      ),
      iconAnchor(ICON_ANCHOR_TOP),
      iconOffset(WAYNAME_OFFSET),
      iconRotationAlignment(ICON_ROTATION_ALIGNMENT_VIEWPORT)
    );
}
 
Example #3
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapRoute.java    License: MIT License 6 votes vote down vote up
private void initializeUpcomingManeuverArrow() {
  arrowShaftGeoJsonSource = (GeoJsonSource) mapboxMap.getSource(ARROW_SHAFT_SOURCE_ID);
  arrowHeadGeoJsonSource = (GeoJsonSource) mapboxMap.getSource(ARROW_HEAD_SOURCE_ID);

  LineLayer shaftLayer = createArrowShaftLayer();
  LineLayer shaftCasingLayer = createArrowShaftCasingLayer();
  SymbolLayer headLayer = createArrowHeadLayer();
  SymbolLayer headCasingLayer = createArrowHeadCasingLayer();

  if (arrowShaftGeoJsonSource == null && arrowHeadGeoJsonSource == null) {
    initializeArrowShaft();
    initializeArrowHead();

    addArrowHeadIcon();
    addArrowHeadIconCasing();

    mapboxMap.addLayerBelow(shaftCasingLayer, LAYER_ABOVE_UPCOMING_MANEUVER_ARROW);
    mapboxMap.addLayerAbove(headCasingLayer, shaftCasingLayer.getId());

    mapboxMap.addLayerAbove(shaftLayer, headCasingLayer.getId());
    mapboxMap.addLayerAbove(headLayer, shaftLayer.getId());
  }
  initializeArrowLayers(shaftLayer, shaftCasingLayer, headLayer, headCasingLayer);
}
 
Example #4
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapRoute.java    License: MIT License 6 votes vote down vote up
/**
 * Iterate through map style layers backwards till the first not-symbol layer is found.
 */
private void placeRouteBelow() {
  if (belowLayer == null || belowLayer.isEmpty()) {
    List<Layer> styleLayers = mapboxMap.getLayers();
    if (styleLayers == null) {
      return;
    }
    for (int i = 0; i < styleLayers.size(); i++) {
      if (!(styleLayers.get(i) instanceof SymbolLayer)
        // Avoid placing the route on top of the user location layer
        && !styleLayers.get(i).getId().contains("mapbox-location")) {
        belowLayer = styleLayers.get(i).getId();
      }
    }
  }
}
 
Example #5
Source Project: graphhopper-navigation-android   Author: graphhopper   File: MapWaynameTest.java    License: MIT License 6 votes vote down vote up
@Test
public void onUpdateWaynameWithPoint_queryRenderedFeaturesIsCalled() {
  WaynameLayoutProvider layoutProvider = mock(WaynameLayoutProvider.class);
  MapLayerInteractor layerInteractor = mock(MapLayerInteractor.class);
  SymbolLayer waynameLayer = mock(SymbolLayer.class);
  when(waynameLayer.getVisibility()).thenReturn(visibility(Property.VISIBLE));
  when(layerInteractor.retrieveLayerFromId(MAPBOX_WAYNAME_LAYER)).thenReturn(waynameLayer);
  WaynameFeatureFinder featureInteractor = mock(WaynameFeatureFinder.class);
  MapPaddingAdjustor paddingAdjustor = mock(MapPaddingAdjustor.class);
  String[] layerIds = {"streetsLayer"};
  PointF point = mock(PointF.class);
  MapWayname mapWayname = new MapWayname(layoutProvider, layerInteractor, featureInteractor, paddingAdjustor);
  mapWayname.updateWaynameVisibility(true, waynameLayer);
  mapWayname.updateWaynameQueryMap(true);

  mapWayname.updateWaynameWithPoint(point, waynameLayer);

  verify(featureInteractor).queryRenderedFeatures(point, layerIds);
}
 
Example #6
Source Project: graphhopper-navigation-android   Author: graphhopper   File: MapWaynameTest.java    License: MIT License 6 votes vote down vote up
@Test
public void onRoadsReturnedFromQuery_layoutIconAdded() {
  String roadName = "roadName";
  PointF point = mock(PointF.class);
  SymbolLayer waynameLayer = mock(SymbolLayer.class);
  List<Feature> roads = new ArrayList<>();
  Feature road = mock(Feature.class);
  when(road.hasNonNullValueForProperty("name")).thenReturn(true);
  when(road.getStringProperty("name")).thenReturn(roadName);
  roads.add(road);
  WaynameLayoutProvider layoutProvider = mock(WaynameLayoutProvider.class);
  when(layoutProvider.generateLayoutBitmap(roadName)).thenReturn(mock(Bitmap.class));
  MapWayname mapWayname = buildMapWayname(point, layoutProvider, waynameLayer, roads);
  mapWayname.updateWaynameVisibility(true, waynameLayer);

  mapWayname.updateWaynameWithPoint(point, waynameLayer);

  verify(layoutProvider, times(1)).generateLayoutBitmap(roadName);
}
 
Example #7
Source Project: graphhopper-navigation-android   Author: graphhopper   File: MapWaynameTest.java    License: MIT License 6 votes vote down vote up
@Test
public void onRoadsReturnedFromQuery_layoutProviderGeneratesBitmap() {
  String roadName = "roadName";
  PointF point = mock(PointF.class);
  SymbolLayer waynameLayer = mock(SymbolLayer.class);
  List<Feature> roads = new ArrayList<>();
  Feature road = mock(Feature.class);
  when(road.hasNonNullValueForProperty("name")).thenReturn(true);
  when(road.getStringProperty("name")).thenReturn(roadName);
  roads.add(road);
  WaynameLayoutProvider layoutProvider = mock(WaynameLayoutProvider.class);
  when(layoutProvider.generateLayoutBitmap(roadName)).thenReturn(mock(Bitmap.class));
  MapWayname mapWayname = buildMapWayname(point, layoutProvider, waynameLayer, roads);
  mapWayname.updateWaynameVisibility(true, waynameLayer);

  mapWayname.updateWaynameWithPoint(point, waynameLayer);

  verify(layoutProvider).generateLayoutBitmap(roadName);
}
 
Example #8
Source Project: graphhopper-navigation-android   Author: graphhopper   File: MapWaynameTest.java    License: MIT License 6 votes vote down vote up
@Test
public void onUpdateWaynameLayer_layerImageIsAdded() {
  String roadName = "roadName";
  SymbolLayer waynameLayer = mock(SymbolLayer.class);
  when(waynameLayer.getVisibility()).thenReturn(visibility(Property.VISIBLE));
  MapLayerInteractor layerInteractor = mock(MapLayerInteractor.class);
  when(layerInteractor.retrieveLayerFromId(MAPBOX_WAYNAME_LAYER)).thenReturn(waynameLayer);
  Bitmap bitmap = mock(Bitmap.class);
  WaynameLayoutProvider layoutProvider = mock(WaynameLayoutProvider.class);
  when(layoutProvider.generateLayoutBitmap(roadName)).thenReturn(bitmap);
  MapWayname mapWayname = buildMapWayname(layoutProvider, layerInteractor);

  mapWayname.updateWaynameLayer(roadName, waynameLayer);

  verify(layerInteractor).addLayerImage(MAPBOX_WAYNAME_ICON, bitmap);
}
 
Example #9
Source Project: graphhopper-navigation-android   Author: graphhopper   File: MapWaynameTest.java    License: MIT License 6 votes vote down vote up
@NonNull
private MapWayname buildMapWayname(PointF point, SymbolLayer waynameLayer, List<Feature> roads) {
  String roadName = "roadName";
  String[] layerIds = {"streetsLayer"};
  WaynameLayoutProvider layoutProvider = mock(WaynameLayoutProvider.class);
  when(layoutProvider.generateLayoutBitmap(roadName)).thenReturn(mock(Bitmap.class));
  MapLayerInteractor layerInteractor = mock(MapLayerInteractor.class);
  when(waynameLayer.getVisibility()).thenReturn(visibility(Property.VISIBLE));
  when(layerInteractor.retrieveLayerFromId(MAPBOX_WAYNAME_LAYER)).thenReturn(waynameLayer);
  WaynameFeatureFinder featureInteractor = mock(WaynameFeatureFinder.class);
  when(featureInteractor.queryRenderedFeatures(point, layerIds)).thenReturn(roads);
  MapPaddingAdjustor paddingAdjustor = mock(MapPaddingAdjustor.class);
  MapWayname mapWayname = new MapWayname(layoutProvider, layerInteractor, featureInteractor, paddingAdjustor);
  mapWayname.updateWaynameQueryMap(true);
  return mapWayname;

}
 
Example #10
Source Project: AirMapSDK-Android   Author: airmap   File: PolygonContainer.java    License: Apache License 2.0 6 votes vote down vote up
public boolean checkForIntersections() {
    List<LatLng> points = PointMath.findIntersections(path);
    if (points.isEmpty()) {
        return false;
    }

    List<Point> intersections = latLngsToPositions(points);
    if (map.getStyle().getLayer(INTERSECTION_LAYER) == null) {
        Source intersectionSource = new GeoJsonSource(INTERSECTION_SOURCE, Feature.fromGeometry(MultiPoint.fromLngLats(intersections)));
        map.getStyle().addSource(intersectionSource);
        Layer intersectionLayer = new SymbolLayer(INTERSECTION_LAYER, INTERSECTION_SOURCE)
                .withProperties(PropertyFactory.iconImage(INTERSECTION_IMAGE));
        map.getStyle().addLayer(intersectionLayer);
    } else {
        GeoJsonSource intersectionsSource = map.getStyle().getSourceAs(INTERSECTION_SOURCE);
        intersectionsSource.setGeoJson(Feature.fromGeometry(MultiPoint.fromLngLats(intersections)));
    }

    return true;
}
 
Example #11
Source Project: deltachat-android   Author: deltachat   File: MapDataManager.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void initLastPositionLayer() {
    GeoJsonSource lastPositionSource = new GeoJsonSource(LAST_POSITION_SOURCE);
    mapboxStyle.addSource(lastPositionSource);
    Expression markerSize =
            switchCase(toBool(get(MARKER_SELECTED)), literal(1.75f), literal(1.25f));
    mapboxStyle.addLayerBelow(new SymbolLayer(LAST_POSITION_LAYER, LAST_POSITION_SOURCE).withProperties(
            iconImage(get(LAST_POSITION_ICON)),
                 /* all info window and marker image to appear at the same time*/
            iconAllowOverlap(true),
            iconIgnorePlacement(true),
            iconSize(markerSize),
            textField(get(LAST_POSITION_LABEL)),
            textAnchor(TEXT_ANCHOR_TOP),
            textOffset(new Float[]{0.0f, 1.0f}),
            textAllowOverlap(true),
            textIgnorePlacement(true)
    ).withFilter(filterProvider.getTimeFilter()), INFO_WINDOW_LAYER);
}
 
Example #12
private void setLayer(Style style) {

        SymbolLayer symbolLayer = new SymbolLayer("POINT_LAYER", "teis").withProperties(
                PropertyFactory.iconImage(get("teiImage")),
                iconOffset(new Float[]{0f, -25f}),
                iconAllowOverlap(true),
                textAllowOverlap(true)
        );

        symbolLayer.setFilter(eq(literal("$type"), literal("Point")));

        style.addLayer(symbolLayer);

        if (featureType != FeatureType.POINT) {
            style.addLayerBelow(new FillLayer("POLYGON_LAYER", "teis")
                            .withProperties(
                                    fillColor(
                                            ColorUtils.getPrimaryColorWithAlpha(this, ColorUtils.ColorType.PRIMARY_LIGHT, 150f)
                                    ))
                            .withFilter(eq(literal("$type"), literal("Polygon"))),
                    "POINT_LAYER"
            );
            style.addLayerAbove(new LineLayer("POLYGON_BORDER_LAYER", "teis")
                            .withProperties(
                                    lineColor(
                                            ColorUtils.getPrimaryColor(this, ColorUtils.ColorType.PRIMARY_DARK)
                                    ),
                                    lineWidth(2f))
                            .withFilter(eq(literal("$type"), literal("Polygon"))),
                    "POLYGON_LAYER"

            );
        }
    }
 
Example #13
Source Project: graphhopper-navigation-android   Author: graphhopper   File: MapWayname.java    License: MIT License 5 votes vote down vote up
void updateWaynameWithPoint(PointF point, SymbolLayer waynameLayer) {
  if (!isAutoQueryEnabled || !isVisible) {
    return;
  }
  List<Feature> roads = findRoadLabelFeatures(point);
  boolean shouldBeVisible = !roads.isEmpty();
  adjustWaynameVisibility(shouldBeVisible, waynameLayer);
  adjustMapPadding(shouldBeVisible);
  if (!shouldBeVisible) {
    return;
  }
  updateLayerWithRoadLabelFeatures(roads, waynameLayer);
}
 
Example #14
Source Project: graphhopper-navigation-android   Author: graphhopper   File: MapWayname.java    License: MIT License 5 votes vote down vote up
void updateWaynameVisibility(boolean isVisible, SymbolLayer waynameLayer) {
  this.isVisible = isVisible;
  adjustMapPadding(isVisible);
  if (checkWaynameVisibility(isVisible, waynameLayer)) {
    return;
  }
  adjustWaynameVisibility(isVisible, waynameLayer);
}
 
Example #15
Source Project: graphhopper-navigation-android   Author: graphhopper   File: MapWayname.java    License: MIT License 5 votes vote down vote up
private void updateLayerWithRoadLabelFeatures(List<Feature> roads, SymbolLayer waynameLayer) {
  boolean isValidFeatureList = !roads.isEmpty();
  if (isValidFeatureList) {
    Feature roadFeature = roads.get(FIRST_ROAD_FEATURE);
    updateWaynameLayerWithNameProperty(waynameLayer, roadFeature);
  } else {
    updateWaynameVisibility(false, waynameLayer);
  }
}
 
Example #16
Source Project: graphhopper-navigation-android   Author: graphhopper   File: MapWayname.java    License: MIT License 5 votes vote down vote up
private void updateWaynameLayerWithNameProperty(SymbolLayer waynameLayer, Feature roadFeature) {
  boolean hasValidNameProperty = roadFeature.hasNonNullValueForProperty(NAME_PROPERTY);
  if (hasValidNameProperty) {
    String currentWayname = roadFeature.getStringProperty(NAME_PROPERTY);
    boolean newWayname = !wayname.contentEquals(currentWayname);
    if (newWayname) {
      wayname = currentWayname;
      updateWaynameVisibility(true, waynameLayer);
      updateWaynameLayer(wayname, waynameLayer);
    }
  }
}
 
Example #17
Source Project: graphhopper-navigation-android   Author: graphhopper   File: MapLayerInteractor.java    License: MIT License 5 votes vote down vote up
private String retrieveSourceLayerId(Layer layer) {
  String sourceIdentifier;
  if (layer instanceof LineLayer) {
    sourceIdentifier = ((LineLayer) layer).getSourceLayer();
  } else {
    sourceIdentifier = ((SymbolLayer) layer).getSourceLayer();
  }
  return sourceIdentifier;
}
 
Example #18
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapRoute.java    License: MIT License 5 votes vote down vote up
private SymbolLayer createArrowHeadLayer() {
  SymbolLayer headLayer = (SymbolLayer) mapboxMap.getLayer(ARROW_HEAD_LAYER_ID);
  if (headLayer != null) {
    return headLayer;
  }
  return new SymbolLayer(ARROW_HEAD_LAYER_ID, ARROW_HEAD_SOURCE_ID)
    .withProperties(
      PropertyFactory.iconImage(ARROW_HEAD_ICON),
      iconAllowOverlap(true),
      iconIgnorePlacement(true),
      PropertyFactory.iconSize(interpolate(linear(), zoom(),
        stop(MIN_ARROW_ZOOM, MIN_ZOOM_ARROW_HEAD_SCALE),
        stop(MAX_ARROW_ZOOM, MAX_ZOOM_ARROW_HEAD_SCALE)
        )
      ),
      PropertyFactory.iconOffset(ARROW_HEAD_OFFSET),
      PropertyFactory.iconRotationAlignment(ICON_ROTATION_ALIGNMENT_MAP),
      PropertyFactory.iconRotate(get(ARROW_BEARING)),
      PropertyFactory.visibility(NONE),
      PropertyFactory.iconOpacity(
        step(zoom(), OPAQUE,
          stop(
            ARROW_HIDDEN_ZOOM_LEVEL, TRANSPARENT
          )
        )
      )
    );
}
 
Example #19
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapRoute.java    License: MIT License 5 votes vote down vote up
private SymbolLayer createArrowHeadCasingLayer() {
  SymbolLayer headCasingLayer = (SymbolLayer) mapboxMap.getLayer(ARROW_HEAD_CASING_LAYER_ID);
  if (headCasingLayer != null) {
    return headCasingLayer;
  }
  return new SymbolLayer(ARROW_HEAD_CASING_LAYER_ID, ARROW_HEAD_SOURCE_ID).withProperties(
    PropertyFactory.iconImage(ARROW_HEAD_ICON_CASING),
    iconAllowOverlap(true),
    iconIgnorePlacement(true),
    PropertyFactory.iconSize(interpolate(
      linear(), zoom(),
      stop(MIN_ARROW_ZOOM, MIN_ZOOM_ARROW_HEAD_CASING_SCALE),
      stop(MAX_ARROW_ZOOM, MAX_ZOOM_ARROW_HEAD_CASING_SCALE)
    )),
    PropertyFactory.iconOffset(ARROW_HEAD_CASING_OFFSET),
    PropertyFactory.iconRotationAlignment(ICON_ROTATION_ALIGNMENT_MAP),
    PropertyFactory.iconRotate(get(ARROW_BEARING)),
    PropertyFactory.visibility(NONE),
    PropertyFactory.iconOpacity(
      step(zoom(), OPAQUE,
        stop(
          ARROW_HIDDEN_ZOOM_LEVEL, TRANSPARENT
        )
      )
    )
  );
}
 
Example #20
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapRoute.java    License: MIT License 5 votes vote down vote up
private void initializeArrowLayers(LineLayer shaftLayer, LineLayer shaftCasingLayer, SymbolLayer headLayer,
                                   SymbolLayer headCasingLayer) {
  arrowLayers = new ArrayList<>();
  arrowLayers.add(shaftCasingLayer);
  arrowLayers.add(shaftLayer);
  arrowLayers.add(headCasingLayer);
  arrowLayers.add(headLayer);
}
 
Example #21
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapRoute.java    License: MIT License 5 votes vote down vote up
private void drawWaypointMarkers(@NonNull MapboxMap mapboxMap, @Nullable Drawable originMarker,
                                 @Nullable Drawable destinationMarker) {
  if (originMarker == null || destinationMarker == null) {
    return;
  }

  SymbolLayer waypointLayer = mapboxMap.getLayerAs(WAYPOINT_LAYER_ID);
  if (waypointLayer == null) {
    Bitmap bitmap = MapImageUtils.getBitmapFromDrawable(originMarker);
    mapboxMap.addImage("originMarker", bitmap);
    bitmap = MapImageUtils.getBitmapFromDrawable(destinationMarker);
    mapboxMap.addImage("destinationMarker", bitmap);

    waypointLayer = new SymbolLayer(WAYPOINT_LAYER_ID, WAYPOINT_SOURCE_ID).withProperties(
      PropertyFactory.iconImage(match(
        Expression.toString(get("waypoint")), literal("originMarker"),
        stop("origin", literal("originMarker")),
        stop("destination", literal("destinationMarker"))
        )
      ),
      PropertyFactory.iconSize(interpolate(
        exponential(1.5f), zoom(),
        stop(22f, 2.8f),
        stop(12f, 1.3f),
        stop(10f, 0.8f),
        stop(0f, 0.6f)
      )),
      PropertyFactory.iconPitchAlignment(Property.ANCHOR_MAP),
      PropertyFactory.iconAllowOverlap(true),
      PropertyFactory.iconIgnorePlacement(true)
    );
    layerIds.add(WAYPOINT_LAYER_ID);
    MapUtils.addLayerToMap(mapboxMap, waypointLayer, belowLayer);
  }
}
 
Example #22
Source Project: graphhopper-navigation-android   Author: graphhopper   File: MapLayerInteractorTest.java    License: MIT License 5 votes vote down vote up
@Test
public void updateLayerVisibility_visibilityIsNotSet() {
  SymbolLayer anySymbolOrLineLayer = mock(SymbolLayer.class);
  when(anySymbolOrLineLayer.getSourceLayer()).thenReturn("any");
  List<Layer> layers = buildLayerListWith(anySymbolOrLineLayer);
  MapboxMap map = mock(MapboxMap.class);
  when(map.getLayers()).thenReturn(layers);
  MapLayerInteractor layerInteractor = new MapLayerInteractor(map);

  layerInteractor.updateLayerVisibility(true, "random");

  verify(anySymbolOrLineLayer, times(0)).setProperties(any(PropertyValue.class));
}
 
Example #23
Source Project: graphhopper-navigation-android   Author: graphhopper   File: MapLayerInteractorTest.java    License: MIT License 5 votes vote down vote up
@Test
public void isLayerVisible_visibleReturnsTrue() {
  SymbolLayer anySymbolOrLineLayer = mock(SymbolLayer.class);
  when(anySymbolOrLineLayer.getSourceLayer()).thenReturn("any");
  when(anySymbolOrLineLayer.getVisibility()).thenReturn(visibility(Property.VISIBLE));
  List<Layer> layers = buildLayerListWith(anySymbolOrLineLayer);
  MapboxMap map = mock(MapboxMap.class);
  when(map.getLayers()).thenReturn(layers);
  MapLayerInteractor layerInteractor = new MapLayerInteractor(map);

  boolean isVisible = layerInteractor.isLayerVisible("any");

  assertTrue(isVisible);
}
 
Example #24
Source Project: graphhopper-navigation-android   Author: graphhopper   File: MapWaynameTest.java    License: MIT License 5 votes vote down vote up
@Test
public void onFeatureWithoutNamePropertyReturned_updateIsIgnored() {
  PointF point = mock(PointF.class);
  SymbolLayer waynameLayer = mock(SymbolLayer.class);
  List<Feature> roads = new ArrayList<>();
  Feature road = mock(Feature.class);
  roads.add(road);
  MapWayname mapWayname = buildMapWayname(point, waynameLayer, roads);

  mapWayname.updateWaynameWithPoint(point, waynameLayer);

  verify(waynameLayer, times(0)).setProperties(any(PropertyValue.class));
}
 
Example #25
Source Project: graphhopper-navigation-android   Author: graphhopper   File: MapWaynameTest.java    License: MIT License 5 votes vote down vote up
@Test
public void onVisibiltySetToFalse_paddingIsAdjusted() {
  SymbolLayer waynameLayer = mock(SymbolLayer.class);
  when(waynameLayer.getVisibility()).thenReturn(visibility(Property.VISIBLE));
  MapLayerInteractor layerInteractor = mock(MapLayerInteractor.class);
  when(layerInteractor.retrieveLayerFromId(MAPBOX_WAYNAME_LAYER)).thenReturn(waynameLayer);
  MapPaddingAdjustor paddingAdjustor = mock(MapPaddingAdjustor.class);
  MapWayname mapWayname = buildMapWayname(layerInteractor, paddingAdjustor);

  mapWayname.updateWaynameVisibility(false, waynameLayer);

  verify(paddingAdjustor).updateTopPaddingWithDefault();
}
 
Example #26
Source Project: graphhopper-navigation-android   Author: graphhopper   File: MapWaynameTest.java    License: MIT License 5 votes vote down vote up
@Test
public void onVisibiltySetToTrue_paddingIsAdjusted() {
  SymbolLayer waynameLayer = mock(SymbolLayer.class);
  when(waynameLayer.getVisibility()).thenReturn(visibility(Property.NONE));
  MapLayerInteractor layerInteractor = mock(MapLayerInteractor.class);
  when(layerInteractor.retrieveLayerFromId(MAPBOX_WAYNAME_LAYER)).thenReturn(waynameLayer);
  MapPaddingAdjustor paddingAdjustor = mock(MapPaddingAdjustor.class);
  MapWayname mapWayname = buildMapWayname(layerInteractor, paddingAdjustor);

  mapWayname.updateWaynameVisibility(true, waynameLayer);

  verify(paddingAdjustor).updateTopPaddingWithWayname();
}
 
Example #27
Source Project: graphhopper-navigation-android   Author: graphhopper   File: MapWaynameTest.java    License: MIT License 5 votes vote down vote up
@Test
public void onVisibiltySetToFalse_isVisibleReturnsFalse() {
  SymbolLayer waynameLayer = mock(SymbolLayer.class);
  when(waynameLayer.getVisibility()).thenReturn(visibility(Property.VISIBLE));
  MapLayerInteractor layerInteractor = mock(MapLayerInteractor.class);
  when(layerInteractor.retrieveLayerFromId(MAPBOX_WAYNAME_LAYER)).thenReturn(waynameLayer);
  MapPaddingAdjustor paddingAdjustor = mock(MapPaddingAdjustor.class);
  MapWayname mapWayname = buildMapWayname(layerInteractor, paddingAdjustor);

  mapWayname.updateWaynameVisibility(false, waynameLayer);

  assertFalse(mapWayname.isVisible());
}
 
Example #28
Source Project: graphhopper-navigation-android   Author: graphhopper   File: MapWaynameTest.java    License: MIT License 5 votes vote down vote up
@Test
public void onVisibiltySetToTrue_isVisibleReturnsTrue() {
  SymbolLayer waynameLayer = mock(SymbolLayer.class);
  when(waynameLayer.getVisibility()).thenReturn(visibility(Property.NONE));
  MapLayerInteractor layerInteractor = mock(MapLayerInteractor.class);
  when(layerInteractor.retrieveLayerFromId(MAPBOX_WAYNAME_LAYER)).thenReturn(waynameLayer);
  MapPaddingAdjustor paddingAdjustor = mock(MapPaddingAdjustor.class);
  MapWayname mapWayname = buildMapWayname(layerInteractor, paddingAdjustor);

  mapWayname.updateWaynameVisibility(true, waynameLayer);

  assertTrue(mapWayname.isVisible());
}
 
Example #29
Source Project: graphhopper-navigation-android   Author: graphhopper   File: MapWaynameTest.java    License: MIT License 5 votes vote down vote up
@NonNull
private MapWayname buildMapWayname(PointF point, WaynameLayoutProvider layoutProvider,
                                   SymbolLayer waynameLayer, List<Feature> roads) {
  String[] layerIds = {"streetsLayer"};
  MapLayerInteractor layerInteractor = mock(MapLayerInteractor.class);
  when(waynameLayer.getVisibility()).thenReturn(visibility(Property.VISIBLE));
  when(layerInteractor.retrieveLayerFromId(MAPBOX_WAYNAME_LAYER)).thenReturn(waynameLayer);
  WaynameFeatureFinder featureInteractor = mock(WaynameFeatureFinder.class);
  when(featureInteractor.queryRenderedFeatures(point, layerIds)).thenReturn(roads);
  MapPaddingAdjustor paddingAdjustor = mock(MapPaddingAdjustor.class);
  MapWayname mapWayname = new MapWayname(layoutProvider, layerInteractor, featureInteractor, paddingAdjustor);
  mapWayname.updateWaynameQueryMap(true);
  return mapWayname;
}
 
Example #30
Source Project: mapbox-plugins-android   Author: mapbox   File: LocalizationPlugin.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * 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;
  if (!style.isFullyLoaded()) {
    // We are in progress of loading a new style
    return;
  }

  List<Layer> layers = style.getLayers();
  for (Source source : style.getSources()) {
    if (sourceIsFromMapbox(source)) {
      boolean isStreetsV8 = sourceIsStreetsV8(source);
      for (Layer layer : layers) {
        if (layer instanceof SymbolLayer) {
          PropertyValue<?> textFieldProperty = ((SymbolLayer) layer).getTextField();
          if (textFieldProperty.isExpression()) {
            if (isStreetsV8) {
              convertExpressionV8(mapLocale, layer, textFieldProperty);
            } else {
              boolean isStreetsV7 = sourceIsStreetsV7(source);
              convertExpression(mapLocale, layer, textFieldProperty, isStreetsV7);
            }
          }
        }
      }
    } else {
      String url = null;
      if (source instanceof VectorSource) {
        url = ((VectorSource) source).getUrl();
      }
      if (url == null) {
        url = "not found";
      }
      Timber.d("The %s (%s) source is not based on Mapbox Vector Tiles. Supported sources:\n %s",
        source.getId(), url, SUPPORTED_SOURCES);
    }
  }
}