use of com.mapbox.mapboxsdk.style.expressions.Expression in project mapbox-plugins-android by mapbox.
the class SymbolActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.menu_action_draggable) {
for (int i = 0; i < symbolManager.getAnnotations().size(); i++) {
Symbol symbol = symbolManager.getAnnotations().get(i);
symbol.setDraggable(!symbol.isDraggable());
}
} else if (item.getItemId() == R.id.menu_action_filter) {
Expression expression = eq(toNumber(get("id")), symbol.getId());
Expression filter = symbolManager.getFilter();
if (filter != null && filter.equals(expression)) {
symbolManager.setFilter(not(eq(toNumber(get("id")), -1)));
} else {
symbolManager.setFilter(expression);
}
} else if (item.getItemId() == R.id.menu_action_icon) {
symbol.setIconImage(MAKI_ICON_CAFE);
} else if (item.getItemId() == R.id.menu_action_rotation) {
symbol.setIconRotate(45.0f);
} else if (item.getItemId() == R.id.menu_action_text) {
symbol.setTextField("Hello world!");
} else if (item.getItemId() == R.id.menu_action_anchor) {
symbol.setIconAnchor(Property.ICON_ANCHOR_BOTTOM);
} else if (item.getItemId() == R.id.menu_action_opacity) {
symbol.setIconOpacity(0.5f);
} else if (item.getItemId() == R.id.menu_action_offset) {
symbol.setIconOffset(new PointF(10.0f, 20.0f));
} else if (item.getItemId() == R.id.menu_action_text_anchor) {
symbol.setTextAnchor(Property.TEXT_ANCHOR_TOP);
} else if (item.getItemId() == R.id.menu_action_text_color) {
symbol.setTextColor(Color.WHITE);
} else if (item.getItemId() == R.id.menu_action_text_size) {
symbol.setTextSize(22f);
} else if (item.getItemId() == R.id.menu_action_z_index) {
symbol.setSymbolSortKey(0.0f);
} else if (item.getItemId() == R.id.menu_action_halo) {
symbol.setIconHaloWidth(5.0f);
symbol.setIconHaloColor(Color.RED);
symbol.setIconHaloBlur(1.0f);
} else if (item.getItemId() == R.id.menu_action_animate) {
resetSymbol();
easeSymbol(symbol, new LatLng(6.687337, 0.381457), 180);
return true;
} else {
return super.onOptionsItemSelected(item);
}
symbolManager.update(symbol);
return true;
}
use of com.mapbox.mapboxsdk.style.expressions.Expression in project mapbox-plugins-android by mapbox.
the class CircleManagerTest method testCircleLayerFilter.
@Test
public void testCircleLayerFilter() {
circleManager = new CircleManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
Expression expression = Expression.eq(Expression.get("test"), "selected");
verify(circleLayer, times(0)).setFilter(expression);
circleManager.setFilter(expression);
verify(circleLayer, times(1)).setFilter(expression);
when(circleLayer.getFilter()).thenReturn(expression);
assertEquals(expression, circleManager.getFilter());
assertEquals(expression, circleManager.layerFilter);
}
use of com.mapbox.mapboxsdk.style.expressions.Expression in project mapbox-plugins-android by mapbox.
the class LineManagerTest method testLineLayerFilter.
@Test
public void testLineLayerFilter() {
lineManager = new LineManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
Expression expression = Expression.eq(Expression.get("test"), "selected");
verify(lineLayer, times(0)).setFilter(expression);
lineManager.setFilter(expression);
verify(lineLayer, times(1)).setFilter(expression);
when(lineLayer.getFilter()).thenReturn(expression);
assertEquals(expression, lineManager.getFilter());
assertEquals(expression, lineManager.layerFilter);
}
use of com.mapbox.mapboxsdk.style.expressions.Expression in project mapbox-plugins-android by mapbox.
the class LineManagerTest method testInitializationOnStyleReload.
@Test
public void testInitializationOnStyleReload() {
lineManager = new LineManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
verify(style).addSource(geoJsonSource);
verify(style).addLayer(lineLayer);
assertTrue(lineManager.dataDrivenPropertyUsageMap.size() > 0);
for (Boolean value : lineManager.dataDrivenPropertyUsageMap.values()) {
assertFalse(value);
}
verify(lineLayer).setProperties(lineManager.constantPropertyUsageMap.values().toArray(new PropertyValue[0]));
verify(draggableAnnotationController).onSourceUpdated();
verify(geoJsonSource).setGeoJson(any(FeatureCollection.class));
Expression filter = Expression.literal(false);
lineManager.setFilter(filter);
ArgumentCaptor<MapView.OnDidFinishLoadingStyleListener> loadingArgumentCaptor = ArgumentCaptor.forClass(MapView.OnDidFinishLoadingStyleListener.class);
verify(mapView).addOnDidFinishLoadingStyleListener(loadingArgumentCaptor.capture());
loadingArgumentCaptor.getValue().onDidFinishLoadingStyle();
ArgumentCaptor<Style.OnStyleLoaded> styleLoadedArgumentCaptor = ArgumentCaptor.forClass(Style.OnStyleLoaded.class);
verify(mapboxMap).getStyle(styleLoadedArgumentCaptor.capture());
Style newStyle = mock(Style.class);
when(newStyle.isFullyLoaded()).thenReturn(true);
GeoJsonSource newSource = mock(GeoJsonSource.class);
when(coreElementProvider.getSource(null)).thenReturn(newSource);
LineLayer newLayer = mock(LineLayer.class);
when(coreElementProvider.getLayer()).thenReturn(newLayer);
styleLoadedArgumentCaptor.getValue().onStyleLoaded(newStyle);
verify(newStyle).addSource(newSource);
verify(newStyle).addLayer(newLayer);
assertTrue(lineManager.dataDrivenPropertyUsageMap.size() > 0);
for (Boolean value : lineManager.dataDrivenPropertyUsageMap.values()) {
assertFalse(value);
}
verify(newLayer).setProperties(lineManager.constantPropertyUsageMap.values().toArray(new PropertyValue[0]));
verify(lineLayer).setFilter(filter);
verify(draggableAnnotationController, times(2)).onSourceUpdated();
verify(newSource).setGeoJson(any(FeatureCollection.class));
}
use of com.mapbox.mapboxsdk.style.expressions.Expression in project mapbox-plugins-android by mapbox.
the class LocalizationPlugin method convertExpressionV8.
private void convertExpressionV8(@NonNull MapLocale mapLocale, Layer layer, PropertyValue<?> textFieldProperty) {
Expression textFieldExpression = textFieldProperty.getExpression();
if (textFieldExpression != null) {
String stringExpression = textFieldExpression.toString().replaceAll(EXPRESSION_V8_REGEX_LOCALIZED, EXPRESSION_V8_TEMPLATE_BASE);
String mapLanguage = mapLocale.getMapLanguage();
if (!mapLanguage.equals(MapLocale.ENGLISH)) {
if (mapLanguage.equals("name_zh")) {
mapLanguage = MapLocale.SIMPLIFIED_CHINESE;
}
stringExpression = stringExpression.replaceAll(EXPRESSION_V8_REGEX_BASE, String.format(Locale.US, EXPRESSION_V8_TEMPLATE_LOCALIZED, mapLanguage, mapLanguage));
}
layer.setProperties(textField(raw(stringExpression)));
}
}
Aggregations