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

The following examples show how to use com.mapbox.mapboxsdk.style.sources.GeoJsonSource. 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: NavigationMapRoute.java    From graphhopper-navigation-android with 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 #3
Source File: MapDataManager.java    From deltachat-android with 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 #4
Source File: CircleContainer.java    From AirMapSDK-Android with Apache License 2.0 6 votes vote down vote up
public void move(LatLng center) {
    this.center = center;
    this.points = calculateCirclePoints(center, radius);

    List<Point> positions = latLngsToPositions(points);
    List<List<Point>> coordinates = new ArrayList<>();
    coordinates.add(positions);

    List<Point> lineString = new ArrayList<>(positions);
    lineString.add(positions.get(0));

    GeoJsonSource pointSource = map.getStyle().getSourceAs(POINT_SOURCE);
    pointSource.setGeoJson(Feature.fromGeometry(Point.fromLngLat(center.getLongitude(), center.getLatitude())));

    GeoJsonSource polygonSource = map.getStyle().getSourceAs(POLYGON_SOURCE);
    polygonSource.setGeoJson(Feature.fromGeometry(Polygon.fromLngLats(coordinates)));

    FillLayer polygonFill = map.getStyle().getLayerAs(Container.POLYGON_LAYER);
    polygonFill.setProperties(PropertyFactory.fillColor(ContextCompat.getColor(context, R.color.colorAccent)));

    GeoJsonSource polylineSource = map.getStyle().getSourceAs(POLYLINE_SOURCE);
    polylineSource.setGeoJson(Feature.fromGeometry(LineString.fromLngLats(lineString)));
}
 
Example #5
Source File: PolygonContainer.java    From AirMapSDK-Android with 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 #6
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 #7
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 #8
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 #9
Source File: MapDataManager.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
private void initInfoWindowLayer() {
    Expression iconOffset = switchCase(
            toBool(get(LAST_LOCATION)), literal(new Float[] {-2f, -25f}),
            literal(new Float[] {-2f, -20f}));
    GeoJsonSource infoWindowSource = new GeoJsonSource(INFO_WINDOW_SRC);
    mapboxStyle.addSource(infoWindowSource);
    mapboxStyle.addLayer(new SymbolLayer(INFO_WINDOW_LAYER, INFO_WINDOW_SRC).withProperties(
            iconImage(INFO_WINDOW_ID),
            iconAnchor(ICON_ANCHOR_BOTTOM_LEFT),
                 /* all info window and marker image to appear at the same time*/
            iconAllowOverlap(true),
                /* offset the info window to be above the marker */
            iconOffset(iconOffset)
    ));
}
 
Example #10
Source File: MapDataManager.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Invoked when the bitmaps have been generated from a view.
 */
@Override
public void setInfoWindowResults(Bitmap result) {
    mapboxStyle.addImage(INFO_WINDOW_ID, result);
    GeoJsonSource infoWindowSource = (GeoJsonSource) mapboxStyle.getSource(INFO_WINDOW_SRC);
    infoWindowSource.setGeoJson(selectedFeature);
}
 
Example #11
Source File: MapDataManager.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
public boolean unselectMarker() {
    if (selectedFeature != null) {
        selectedFeature.addBooleanProperty(MARKER_SELECTED, false);
        refreshSource(selectedFeature.getNumberProperty(CONTACT_ID).intValue());
        selectedFeature = null;
        GeoJsonSource source = (GeoJsonSource) mapboxStyle.getSource(INFO_WINDOW_SRC);
        source.setGeoJson(FeatureCollection.fromFeatures(new ArrayList<>()));
        return true;
    }
    return false;
}
 
Example #12
Source File: MapDataManager.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
public void refreshSource(int contactId) {
    MapSource source = contactMapSources.get(contactId);
    LinkedList<Feature> collection = featureCollections.get(source.getMarkerFeatureCollection());
    GeoJsonSource pointSource = (GeoJsonSource) mapboxStyle.getSource(source.getMarkerSource());
    pointSource.setGeoJson(FeatureCollection.fromFeatures(collection));
    LinkedList<Feature> lineFeatures = featureCollections.get(source.getLineFeatureCollection());
    GeoJsonSource lineSource = (GeoJsonSource) mapboxStyle.getSource(source.getLineSource());
    lineSource.setGeoJson(FeatureCollection.fromFeatures(lineFeatures));
    GeoJsonSource lastPostionSource = (GeoJsonSource) mapboxStyle.getSource(LAST_POSITION_SOURCE);
    lastPostionSource.setGeoJson(FeatureCollection.fromFeatures(new LinkedList<>(lastPositions.values())));
}
 
Example #13
Source File: ProgramEventDetailActivity.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void setSource(Style style, FeatureCollection featureCollection) {
    style.addSource(new GeoJsonSource("events", featureCollection));
}
 
Example #14
Source File: MapDataManager.java    From deltachat-android with GNU General Public License v3.0 4 votes vote down vote up
private void initContactBasedLayers(MapSource source) {
    if (mapboxStyle.getLayer(source.getMarkerLayer()) != null) {
        return;
    }

    GeoJsonSource markerPositionSource = new GeoJsonSource(source.getMarkerSource());
    GeoJsonSource linePositionSource = new GeoJsonSource(source.getLineSource());

    try {
        mapboxStyle.addSource(markerPositionSource);
        mapboxStyle.addSource(linePositionSource);
    } catch (RuntimeException e) {
        //TODO: specify exception more
        Log.e(TAG, "Unable to init GeoJsonSources. Already added to mapBoxMap? " + e.getMessage());
    }

    mapboxStyle.addImage(source.getMarkerLastPositon(),
            generateColoredLastPositionIcon(source.getColorArgb()));
    mapboxStyle.addImage(source.getMarkerIcon(),
            generateColoredLocationIcon(source.getColorArgb()));
    mapboxStyle.addImage(source.getMarkerPoi(),
            generateColoredPoiIcon(source.getColorArgb()));

    Expression markerSize =
            switchCase(
                    neq(length(get(MARKER_CHAR)), literal(0)),
                        switchCase(toBool(get(MARKER_SELECTED)), literal(2.25f), literal(2.0f)),
                    neq(get(MESSAGE_ID), literal(0)),
                        switchCase(toBool(get(MARKER_SELECTED)), literal(2.25f), literal(2.0f)),
                    switchCase(toBool(get(MARKER_SELECTED)), literal(1.1f), literal(0.7f)));
    Expression markerIcon = get(MARKER_ICON);

    mapboxStyle.addLayerBelow(new LineLayer(source.getLineLayer(), source.getLineSource())
            .withProperties(PropertyFactory.lineCap(Property.LINE_CAP_ROUND),
                    lineJoin(Property.LINE_JOIN_ROUND),
                    lineWidth(3f),
                    lineOpacity(0.5f),
                    lineColor(source.getColorArgb()),
                    visibility(NONE)
            )
            .withFilter(filterProvider.getTimeFilter()),
            LAST_POSITION_LAYER);


    Expression textField = switchCase(eq(length(get(MARKER_CHAR)), 1), get(MARKER_CHAR),
            get(POI_LONG_DESCRIPTION));
    Float[] offset = new Float[] {0.0f, 1.25f};
    Float[] zeroOffset = new Float[] {0.0f, 0.0f};
    Expression textOffset = switchCase(
            has(POI_LONG_DESCRIPTION), literal(offset),
            literal(zeroOffset));
    Expression textColor = switchCase(
            has(POI_LONG_DESCRIPTION), literal("#000000"),
            literal("#FFFFFF")
    );
    Expression textAnchor = switchCase(
            has(POI_LONG_DESCRIPTION), literal(TEXT_ANCHOR_TOP),
            literal(TEXT_ANCHOR_CENTER)
    );
    Expression textSize = switchCase(
            has(POI_LONG_DESCRIPTION), literal(12.0f),
            literal(15.0f)
    );

    mapboxStyle.addLayerBelow(new SymbolLayer(source.getMarkerLayer(), source.getMarkerSource())
                    .withProperties(
                            iconImage(markerIcon),
                            iconSize(markerSize),
                            iconIgnorePlacement(false),
                            iconAllowOverlap(false),
                            textField(textField),
                            textOffset(textOffset),
                            textAnchor(textAnchor),
                            textSize(textSize),
                            textColor(textColor))
                    .withFilter(all(filterProvider.getMarkerFilter(),
                            not(get(LAST_LOCATION)))),
            LAST_POSITION_LAYER);
}
 
Example #15
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 #16
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 #17
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 #18
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 #19
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 setSource(Style style, HashMap<String, FeatureCollection> featCollectionMap) {
    style.addSource(new GeoJsonSource("teis", featCollectionMap.get("TEI")));
    style.addSource(new GeoJsonSource("enrollments", featCollectionMap.get("ENROLLMENT")));
}
 
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);