com.mapbox.mapboxsdk.style.sources.GeoJsonOptions Java Examples

The following examples show how to use com.mapbox.mapboxsdk.style.sources.GeoJsonOptions. 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: MapUtils.java    From graphhopper-navigation-android with MIT License 6 votes vote down vote up
/**
 * Takes a {@link FeatureCollection} and creates a map GeoJson source using the sourceId also
 * provided.
 *
 * @param mapboxMap  that the current mapView is using
 * @param collection the feature collection to be added to the map style
 * @param sourceId   the source's id for identifying it when adding layers
 * @since 0.8.0
 */
public static void updateMapSourceFromFeatureCollection(@NonNull MapboxMap mapboxMap,
                                                        @Nullable FeatureCollection collection,
                                                        @NonNull String sourceId) {
  if (collection == null) {
    collection = FeatureCollection.fromFeatures(new Feature[] {});
  }

  GeoJsonSource source = mapboxMap.getSourceAs(sourceId);
  if (source == null) {
    GeoJsonOptions routeGeoJsonOptions = new GeoJsonOptions().withMaxZoom(16);
    GeoJsonSource routeSource = new GeoJsonSource(sourceId, collection, routeGeoJsonOptions);
    mapboxMap.addSource(routeSource);
  } else {
    source.setGeoJson(collection);
  }
}
 
Example #2
Source File: AnnotationManager.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void initializeSourcesAndLayers(GeoJsonOptions geoJsonOptions) {
  geoJsonSource = coreElementProvider.getSource(geoJsonOptions);
  layer = coreElementProvider.getLayer();

  style.addSource(geoJsonSource);
  if (belowLayerId == null) {
    style.addLayer(layer);
  } else {
    style.addLayerBelow(layer, belowLayerId);
  }

  initializeDataDrivenPropertyMap();
  layer.setProperties(constantPropertyUsageMap.values().toArray(new PropertyValue[0]));
  if (layerFilter != null) {
    setFilter(layerFilter);
  }

  updateSource();
}
 
Example #3
Source File: ProgramEventDetailActivity.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void setMap(FeatureCollection featureCollection, BoundingBox boundingBox) {
        if (map == null) {
            binding.mapView.getMapAsync(mapbox -> {
                map = mapbox;
                if (map.getStyle() == null){
                    map.setStyle(Style.MAPBOX_STREETS, style -> {
                        map.addOnMapClickListener(this);
                        style.addImage("ICON_ID", BitmapFactory.decodeResource(getResources(), R.drawable.mapbox_marker_icon_default));
                        setSource(style, featureCollection);
                        setLayer(style);

                        initCameraPosition(map,this,boundingBox);

                        markerViewManager = new MarkerViewManager(binding.mapView, map);
                        symbolManager = new SymbolManager(binding.mapView, map, style, null,
                                new GeoJsonOptions().withTolerance(0.4f));

                        symbolManager.setIconAllowOverlap(true);
                        symbolManager.setTextAllowOverlap(true);
                        symbolManager.create(featureCollection);

                    });
                }
                else {
                    ((GeoJsonSource) mapbox.getStyle().getSource("events")).setGeoJson(featureCollection);
                    initCameraPosition(map,this,boundingBox);
                }
            });
        } else {
            ((GeoJsonSource) map.getStyle().getSource("events")).setGeoJson(featureCollection);
            initCameraPosition(map,this, boundingBox);
        }
}
 
Example #4
Source File: NavigationMapRoute.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void initializeArrowShaft() {
  arrowShaftGeoJsonSource = new GeoJsonSource(
    ARROW_SHAFT_SOURCE_ID,
    arrowShaftGeoJsonFeature,
    new GeoJsonOptions().withMaxZoom(16)
  );
  mapboxMap.addSource(arrowShaftGeoJsonSource);
}
 
Example #5
Source File: NavigationMapRoute.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void initializeArrowHead() {
  arrowHeadGeoJsonSource = new GeoJsonSource(
    ARROW_HEAD_SOURCE_ID,
    arrowShaftGeoJsonFeature,
    new GeoJsonOptions().withMaxZoom(16)
  );
  mapboxMap.addSource(arrowHeadGeoJsonSource);
}
 
Example #6
Source File: AnnotationManager.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@UiThread
protected AnnotationManager(MapView mapView, final MapboxMap mapboxMap, Style style,
                            CoreElementProvider<L> coreElementProvider,
                            DraggableAnnotationController<T, D> draggableAnnotationController,
                            String belowLayerId, final GeoJsonOptions geoJsonOptions) {
  this.mapboxMap = mapboxMap;
  this.style = style;
  this.belowLayerId = belowLayerId;
  this.coreElementProvider = coreElementProvider;

  if (!style.isFullyLoaded()) {
    throw new RuntimeException("The style has to be non-null and fully loaded.");
  }

  mapboxMap.addOnMapClickListener(mapClickResolver = new MapClickResolver());
  mapboxMap.addOnMapLongClickListener(mapClickResolver);
  this.draggableAnnotationController = draggableAnnotationController;
  draggableAnnotationController.injectAnnotationManager(this);

  initializeSourcesAndLayers(geoJsonOptions);

  mapView.addOnDidFinishLoadingStyleListener(new MapView.OnDidFinishLoadingStyleListener() {
    @Override
    public void onDidFinishLoadingStyle() {
      mapboxMap.getStyle(new Style.OnStyleLoaded() {
        @Override
        public void onStyleLoaded(@NonNull Style loadedStyle) {
          AnnotationManager.this.style = loadedStyle;
          initializeSourcesAndLayers(geoJsonOptions);
        }
      });
    }
  });
}
 
Example #7
Source File: SearchTEActivity.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void loadDataForStyle(Style style, HashMap<String, FeatureCollection> teiFeatureCollection, BoundingBox bbox) {
    binding.mapLayerButton.setVisibility(View.VISIBLE);
    if (!changingStyle) {
        MapLayerManager.Companion.init(style, "teis", featureType);
        MapLayerManager.Companion.instance().setEnrollmentLayerData(
                presenter.getProgram() != null ?
                        ColorUtils.getColorFrom(presenter.getProgram().style() != null ? presenter.getProgram().style().color() : null, ColorUtils.getPrimaryColor(getContext(), ColorUtils.ColorType.PRIMARY)) :
                        ColorUtils.getPrimaryColor(getContext(), ColorUtils.ColorType.PRIMARY),
                ColorUtils.getPrimaryColor(this, ColorUtils.ColorType.PRIMARY_DARK),
                presenter.getProgram() != null ? presenter.getProgram().featureType() != null ? presenter.getProgram().featureType() : FeatureType.NONE : FeatureType.NONE
        );
        MapLayerManager.Companion.instance().showEnrollmentLayer().observe(this, show -> {
            if (show)
                presenter.getEnrollmentMapData();
        });
    } else {
        MapLayerManager.Companion.instance().updateStyle(style);
    }
    map.addOnMapClickListener(this);

    style.addImage("ICON_ID", MarkerUtils.INSTANCE.getMarker(this, presenter.getSymbolIcon(), presenter.getTEIColor()));
    style.addImage("ICON_ENROLLMENT_ID", MarkerUtils.INSTANCE.getMarker(this, presenter.getEnrollmentSymbolIcon(), presenter.getEnrollmentColor()));

    setSource(style, teiFeatureCollection);

    setLayer(style);

    LatLngBounds bounds = LatLngBounds.from(bbox.north(),
            bbox.east(),
            bbox.south(),
            bbox.west());

    MapboxExtensionKt.initDefaultCamera(map, this, bounds);

    if (markerViewManager == null) {
        markerViewManager = new MarkerViewManager(binding.mapView, map);
    }

    if (symbolManager == null) {
        symbolManager = new SymbolManager(binding.mapView, map, style, null,
                new GeoJsonOptions().withTolerance(0.4f));

        symbolManager.setIconAllowOverlap(true);
        symbolManager.setTextAllowOverlap(true);
        symbolManager.setIconIgnorePlacement(true);
        symbolManager.setTextIgnorePlacement(true);
        symbolManager.setSymbolPlacement("line-center");
        symbolManager.create(teiFeatureCollection.get("TEI"));
    }
}
 
Example #8
Source File: LineManager.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@VisibleForTesting
LineManager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style, @NonNull CoreElementProvider<LineLayer> coreElementProvider, @Nullable String belowLayerId, @Nullable GeoJsonOptions geoJsonOptions, DraggableAnnotationController<Line, OnLineDragListener> draggableAnnotationController) {
  super(mapView, mapboxMap, style, coreElementProvider, draggableAnnotationController, belowLayerId, geoJsonOptions);
}
 
Example #9
Source File: FillElementProvider.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public GeoJsonSource getSource(@Nullable GeoJsonOptions geoJsonOptions) {
  return new GeoJsonSource(sourceId, geoJsonOptions);
}
 
Example #10
Source File: CircleElementProvider.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public GeoJsonSource getSource(@Nullable GeoJsonOptions geoJsonOptions) {
  return new GeoJsonSource(sourceId, geoJsonOptions);
}
 
Example #11
Source File: LineElementProvider.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public GeoJsonSource getSource(@Nullable GeoJsonOptions geoJsonOptions) {
  return new GeoJsonSource(sourceId, geoJsonOptions);
}
 
Example #12
Source File: SymbolManager.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@VisibleForTesting
SymbolManager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style, @NonNull CoreElementProvider<SymbolLayer> coreElementProvider, @Nullable String belowLayerId, @Nullable GeoJsonOptions geoJsonOptions, DraggableAnnotationController<Symbol, OnSymbolDragListener> draggableAnnotationController) {
  super(mapView, mapboxMap, style, coreElementProvider, draggableAnnotationController, belowLayerId, geoJsonOptions);
}
 
Example #13
Source File: FillManager.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@VisibleForTesting
FillManager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style, @NonNull CoreElementProvider<FillLayer> coreElementProvider, @Nullable String belowLayerId, @Nullable GeoJsonOptions geoJsonOptions, DraggableAnnotationController<Fill, OnFillDragListener> draggableAnnotationController) {
  super(mapView, mapboxMap, style, coreElementProvider, draggableAnnotationController, belowLayerId, geoJsonOptions);
}
 
Example #14
Source File: CircleManager.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@VisibleForTesting
CircleManager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style, @NonNull CoreElementProvider<CircleLayer> coreElementProvider, @Nullable String belowLayerId, @Nullable GeoJsonOptions geoJsonOptions, DraggableAnnotationController<Circle, OnCircleDragListener> draggableAnnotationController) {
  super(mapView, mapboxMap, style, coreElementProvider, draggableAnnotationController, belowLayerId, geoJsonOptions);
}
 
Example #15
Source File: SymbolElementProvider.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public GeoJsonSource getSource(@Nullable GeoJsonOptions geoJsonOptions) {
  return new GeoJsonSource(sourceId, geoJsonOptions);
}
 
Example #16
Source File: SymbolManager.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Create a symbol manager, used to manage symbols.
 *
 * @param mapboxMap the map object to add symbols to
 * @param style a valid a fully loaded style object
 * @param belowLayerId the id of the layer above the circle layer
 * @param geoJsonOptions options for the internal source
 */
@UiThread
public SymbolManager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style, @Nullable String belowLayerId, @Nullable GeoJsonOptions geoJsonOptions) {
  this(mapView, mapboxMap, style, new SymbolElementProvider(), belowLayerId, geoJsonOptions, new DraggableAnnotationController<Symbol, OnSymbolDragListener>(mapView, mapboxMap));
}
 
Example #17
Source File: FillManager.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Create a fill manager, used to manage fills.
 *
 * @param mapboxMap the map object to add fills to
 * @param style a valid a fully loaded style object
 * @param belowLayerId the id of the layer above the circle layer
 * @param geoJsonOptions options for the internal source
 */
@UiThread
public FillManager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style, @Nullable String belowLayerId, @Nullable GeoJsonOptions geoJsonOptions) {
  this(mapView, mapboxMap, style, new FillElementProvider(), belowLayerId, geoJsonOptions, new DraggableAnnotationController<Fill, OnFillDragListener>(mapView, mapboxMap));
}
 
Example #18
Source File: CircleManager.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Create a circle manager, used to manage circles.
 *
 * @param mapboxMap the map object to add circles to
 * @param style a valid a fully loaded style object
 * @param belowLayerId the id of the layer above the circle layer
 * @param geoJsonOptions options for the internal source
 */
@UiThread
public CircleManager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style, @Nullable String belowLayerId, @Nullable GeoJsonOptions geoJsonOptions) {
  this(mapView, mapboxMap, style, new CircleElementProvider(), belowLayerId, geoJsonOptions, new DraggableAnnotationController<Circle, OnCircleDragListener>(mapView, mapboxMap));
}
 
Example #19
Source File: LineManager.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Create a line manager, used to manage lines.
 *
 * @param mapboxMap the map object to add lines to
 * @param style a valid a fully loaded style object
 * @param belowLayerId the id of the layer above the circle layer
 * @param geoJsonOptions options for the internal source
 */
@UiThread
public LineManager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style, @Nullable String belowLayerId, @Nullable GeoJsonOptions geoJsonOptions) {
  this(mapView, mapboxMap, style, new LineElementProvider(), belowLayerId, geoJsonOptions, new DraggableAnnotationController<Line, OnLineDragListener>(mapView, mapboxMap));
}
 
Example #20
Source File: CoreElementProvider.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License votes vote down vote up
GeoJsonSource getSource(@Nullable GeoJsonOptions geoJsonOptions);