Java Code Examples for com.mapbox.mapboxsdk.style.expressions.Expression#eq()

The following examples show how to use com.mapbox.mapboxsdk.style.expressions.Expression#eq() . 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
Source File: CircleManagerTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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);
}
 
Example 2
Source File: FillManagerTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testFillLayerFilter() {
  fillManager = new FillManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  Expression expression = Expression.eq(Expression.get("test"), "selected");
  verify(fillLayer, times(0)).setFilter(expression);

  fillManager.setFilter(expression);
  verify(fillLayer, times(1)).setFilter(expression);

  when(fillLayer.getFilter()).thenReturn(expression);
  assertEquals(expression, fillManager.getFilter());
  assertEquals(expression, fillManager.layerFilter);
}
 
Example 3
Source File: SymbolManagerTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testSymbolLayerFilter() {
  symbolManager = new SymbolManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  Expression expression = Expression.eq(Expression.get("test"), "selected");
  verify(symbolLayer, times(0)).setFilter(expression);

  symbolManager.setFilter(expression);
  verify(symbolLayer, times(1)).setFilter(expression);

  when(symbolLayer.getFilter()).thenReturn(expression);
  assertEquals(expression, symbolManager.getFilter());
  assertEquals(expression, symbolManager.layerFilter);
}
 
Example 4
Source File: LineManagerTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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);
}
 
Example 5
Source File: MapStyleController.java    From AirMapSDK-Android with Apache License 2.0 5 votes vote down vote up
public void hideInactiveAirspace(){
    Expression hasActive = Expression.has("active");
    Expression activeIsTrue = Expression.eq(Expression.get("active"), true);
    Expression active = Expression.all(hasActive, activeIsTrue);
    map.getMap().getStyle(style -> {
        for(Layer layer : Objects.requireNonNull(style.getLayers())){
            if(layer.getId().contains("airmap")){
                if(layer instanceof FillLayer){
                    if(((FillLayer) layer).getFilter() != null){
                        ((FillLayer) layer).setFilter(Expression.any(((FillLayer) layer).getFilter(), active));
                    } else {
                        ((FillLayer) layer).setFilter(active);
                    }

                } else if (layer instanceof  LineLayer){
                    if(((LineLayer) layer).getFilter() != null){
                        ((LineLayer) layer).setFilter(Expression.any(((LineLayer) layer).getFilter(), active));
                    } else {
                        ((LineLayer) layer).setFilter(active);
                    }

                } else if(layer instanceof  SymbolLayer){
                    if(((SymbolLayer) layer).getFilter() != null){
                        ((SymbolLayer) layer).setFilter(Expression.any(((SymbolLayer) layer).getFilter(), active));
                    } else {
                        ((SymbolLayer) layer).setFilter(active);
                    }

                } else {
                    Timber.e("Unknown layer");

                }
            }
        }
    });
}
 
Example 6
Source File: MapStyleController.java    From AirMapSDK-Android with Apache License 2.0 4 votes vote down vote up
public void addMapLayers(AirMapRuleset ruleset, boolean useSIMeasurements) {
    String sourceId = ruleset.getId();
    List<String> layers = ruleset.getLayers();
    // check if source is already added to map
    Calendar cal1 = Calendar.getInstance();
    Calendar cal2 = Calendar.getInstance();
    if(temporalFilter != null){
        switch (temporalFilter.getType()){
            case NOW:
                switch (temporalFilter.getRange()){

                    case ONE_HOUR:
                        cal2.roll(Calendar.HOUR_OF_DAY, 1);
                        break;
                    case FOUR_HOUR:
                        cal2.roll(Calendar.HOUR_OF_DAY, 4);
                        break;
                    case EIGHT_HOUR:
                        cal2.roll(Calendar.HOUR_OF_DAY, 8);
                        break;
                    case TWELVE_HOUR:
                        cal2.roll(Calendar.HOUR_OF_DAY, 12);
                        break;
                }
                break;
            case CUSTOM:
                cal1.setTime(temporalFilter.getFutureDate());
                cal2.setTime(temporalFilter.getFutureDate());

                cal1.set(Calendar.HOUR_OF_DAY, temporalFilter.getStartHour());
                cal1.set(Calendar.MINUTE, temporalFilter.getStartMinute());

                cal2.set(Calendar.HOUR_OF_DAY, temporalFilter.getEndHour());
                cal2.set(Calendar.MINUTE, temporalFilter.getEndMinute());
                break;
        }
    }

    if (map.getMap().getStyle().getSource(sourceId) != null) {
        Timber.e("Source already added for: %s", sourceId);
    } else {
        String urlTemplates;
        if(temporalFilter == null){
            urlTemplates = AirMap.getRulesetTileUrlTemplate(sourceId, layers, useSIMeasurements);
        } else {
            urlTemplates = AirMap.getRulesetTileUrlTemplate(sourceId, layers, useSIMeasurements, cal1.getTime(), cal2.getTime());
        }
        TileSet tileSet = new TileSet(tileJsonSpecVersion, urlTemplates);
        tileSet.setMaxZoom(12f);
        tileSet.setMinZoom(8f);
        VectorSource tileSource = new VectorSource(sourceId, tileSet);
        map.getMap().getStyle().addSource(tileSource);
    }

    for (String sourceLayer : layers) {
        for (AirMapLayerStyle layerStyle : mapStyle.getLayerStyles(sourceLayer)) {
            // check if layer is already added to map
            if (map.getMap().getStyle().getLayer(layerStyle.id + "|" + sourceId + "|new") != null) {
                continue;
            }

            // use layer from styles as a template
            Layer layerToClone = map.getMap().getStyle().getLayer(layerStyle.id);

            Layer layer = layerStyle.toMapboxLayer(layerToClone, sourceId);

            // add temporal filter if applicable
            if (layer.getId().contains("airmap|tfr") || layer.getId().contains("notam")) {
                addTemporalFilter(layer);
            }

            if (airspaceTypeListener != null) {
                String typeKey = layerStyle.id.split("\\|")[1];
                AirMapAirspaceType airspaceType = MappingService.AirMapAirspaceType.fromString(typeKey);
                airspaceTypeListener.onAirspaceTypeAdded(ruleset, airspaceType, layer);
            }
            map.getMap().getStyle().addLayerAbove(layer, layerStyle.id);
        }
    }

    // add highlight layer
    if (map.getMap().getStyle().getLayer("airmap|highlight|line|" + sourceId) == null) {
        LineLayer highlightLayer = new LineLayer("airmap|highlight|line|" + sourceId, sourceId);
        highlightLayer.setProperties(PropertyFactory.lineColor("#f9e547"));
        highlightLayer.setProperties(PropertyFactory.lineWidth(4f));
        highlightLayer.setProperties(PropertyFactory.lineOpacity(0.9f));
        Expression filter = Expression.eq(Expression.get("id"), "x");

        try {
            highlightLayer.setFilter(filter);
            map.getMap().getStyle().addLayer(highlightLayer);
        } catch (Throwable t) {
            // https://github.com/mapbox/mapbox-gl-native/issues/10947
            // https://github.com/mapbox/mapbox-gl-native/issues/11264
            // A layer is associated with a style, not the mapView/mapbox
            Analytics.report(new Exception(t));
            t.printStackTrace();
        }
    }
}