Search in sources :

Example 1 with PolylineOptions

use of com.mapbox.mapboxsdk.annotations.PolylineOptions in project mapbox-plugins-android by mapbox.

the class GeoJsonPlugin method drawOnMap.

/**
 * Drawing {@link DataModel} element on to the map
 *
 * @param dataModel list of polylines, polygons, and points
 */
private void drawOnMap(DataModel dataModel) {
    if (dataModel != null) {
        List<MarkerData> markers = dataModel.getMarkers();
        if (markers != null) {
            if (!markers.isEmpty()) {
                for (MarkerData markerData : dataModel.getMarkers()) {
                    Marker marker = map.addMarker(new MarkerOptions().position(markerData.getPoint()));
                    markerCollectionHashMap.put(marker, markerData);
                }
            }
        }
        List<PolyData> polygons = dataModel.getPolygons();
        if (polygons != null) {
            if (!polygons.isEmpty()) {
                for (PolyData polyData : polygons) {
                    if (isRandomFillColor) {
                        fillColor = getRandomMaterialColor("400");
                    }
                    if (isRandomStockColor) {
                        stockColor = getRandomMaterialColor("400");
                    }
                    map.addPolygon(new PolygonOptions().addAll(polyData.getPoints()).fillColor(fillColor).strokeColor(stockColor));
                }
            }
        }
        List<PolyData> polylines = dataModel.getPolylines();
        if (polylines != null) {
            if (!polylines.isEmpty()) {
                for (PolyData polyData : polylines) {
                    if (isRandomStockColor) {
                        stockColor = getRandomMaterialColor("400");
                    }
                    map.addPolyline(new PolylineOptions().addAll(polyData.getPoints()).color(stockColor).width(width));
                }
            }
        }
        if (dataModel.getBounds() != null) {
            map.easeCamera(CameraUpdateFactory.newLatLngBounds(dataModel.getBounds(), 50), 500);
        }
        // set onMarkerClick Listener and pass properties of marker to the MarkerEventListener
        map.setOnMarkerClickListener(new MapboxMap.OnMarkerClickListener() {

            @Override
            public boolean onMarkerClick(@NonNull Marker marker) {
                MarkerData markerData = markerCollectionHashMap.get(marker);
                if (markerEventListener != null) {
                    markerEventListener.onMarkerClickListener(marker, markerData.getProperties());
                }
                return false;
            }
        });
    }
}
Also used : PolyData(com.mapbox.mapboxsdk.plugins.geojson.model.PolyData) MarkerData(com.mapbox.mapboxsdk.plugins.geojson.model.MarkerData) MarkerOptions(com.mapbox.mapboxsdk.annotations.MarkerOptions) PolygonOptions(com.mapbox.mapboxsdk.annotations.PolygonOptions) Marker(com.mapbox.mapboxsdk.annotations.Marker) MapboxMap(com.mapbox.mapboxsdk.maps.MapboxMap) PolylineOptions(com.mapbox.mapboxsdk.annotations.PolylineOptions)

Example 2 with PolylineOptions

use of com.mapbox.mapboxsdk.annotations.PolylineOptions in project osm-contributor by jawg.

the class MapFragment method onCameraChangeUpdatePolyline.

public void onCameraChangeUpdatePolyline() {
    if (editionPolyline != null) {
        List<LatLng> points = editionPolyline.getPoints();
        points.set(1, mapboxMap.getCameraPosition().target);
        removePolyline(editionPolyline);
        editionPolyline = new PolylineOptions().addAll(points).alpha(0.4f).width(1.8f).color(Color.parseColor("#F57C00"));
        mapboxMap.addPolyline(editionPolyline);
    }
}
Also used : LatLng(com.mapbox.mapboxsdk.geometry.LatLng) PolylineOptions(com.mapbox.mapboxsdk.annotations.PolylineOptions)

Example 3 with PolylineOptions

use of com.mapbox.mapboxsdk.annotations.PolylineOptions in project androidApp by InspectorIncognito.

the class PolylineEngine method addBusRoutePolyline.

@NonNull
public Polyline addBusRoutePolyline(MapboxMap mapboxMap, ArrayList<LatLng> points, int colorId) {
    if (busRouteEndFeature == null) {
        setupPolylineVars(mapboxMap);
    }
    Feature startPoint = Feature.fromGeometry(Point.fromCoordinates(Position.fromCoordinates(points.get(0).getLongitude(), points.get(0).getLatitude())));
    Feature endPoint = Feature.fromGeometry(Point.fromCoordinates(Position.fromCoordinates(points.get(points.size() - 1).getLongitude(), points.get(points.size() - 1).getLatitude())));
    busRouteStartFeature = FeatureCollection.fromFeatures(new Feature[] { startPoint });
    busRouteEndFeature = FeatureCollection.fromFeatures(new Feature[] { endPoint });
    refreshSourceWithFeatures(busRouteStartSource, busRouteStartFeature);
    refreshSourceWithFeatures(busRouteEndSource, busRouteEndFeature);
    return mapboxMap.addPolyline(new PolylineOptions().addAll(points).color(ContextCompat.getColor(TranSappApplication.getAppContext(), colorId)).width(4));
}
Also used : Feature(com.mapbox.services.commons.geojson.Feature) PolylineOptions(com.mapbox.mapboxsdk.annotations.PolylineOptions) NonNull(android.support.annotation.NonNull)

Example 4 with PolylineOptions

use of com.mapbox.mapboxsdk.annotations.PolylineOptions in project osm-contributor by jawg.

the class MapFragment method clearAllNodeRef.

private void clearAllNodeRef() {
    for (WayMarkerOptions locationMarker : markersNodeRef.values()) {
        removeWayMarker(locationMarker);
    }
    for (PolylineOptions polylineOptions : polylinesWays.values()) {
        removePolyline(polylineOptions);
    }
    markersNodeRef.clear();
    polylinesWays.clear();
}
Also used : WayMarkerOptions(io.jawg.osmcontributor.ui.utils.views.map.marker.WayMarkerOptions) PolylineOptions(com.mapbox.mapboxsdk.annotations.PolylineOptions)

Example 5 with PolylineOptions

use of com.mapbox.mapboxsdk.annotations.PolylineOptions in project osm-contributor by jawg.

the class MapFragment method buildEditionPolygon.

private void buildEditionPolygon() {
    // Current selected poiNodeRef
    PoiNodeRef currentPoiNodeRef = wayMarkerSelected.getPoiNodeRef();
    // Polyline related to this poiNodeRef
    PolylineOptions currentPolyline = polylinesWays.get(currentPoiNodeRef.getId());
    // Item of the poiNodeRef in the polilyne
    int indexOfPoiNodeRef = currentPolyline.getPoints().indexOf(new LatLng(currentPoiNodeRef.getLatitude(), currentPoiNodeRef.getLongitude()));
    LatLng previousPoint = currentPolyline.getPoints().get(indexOfPoiNodeRef == 0 ? indexOfPoiNodeRef + 1 : indexOfPoiNodeRef - 1);
    LatLng nextPoint = currentPolyline.getPoints().get(indexOfPoiNodeRef == currentPolyline.getPoints().size() - 1 ? indexOfPoiNodeRef - 1 : indexOfPoiNodeRef + 1);
    editionPolyline = new PolylineOptions().add(previousPoint, currentPolyline.getPoints().get(indexOfPoiNodeRef), nextPoint).alpha(0.4f).width(1.8f).color(Color.parseColor("#F57C00"));
    mapboxMap.addPolyline(editionPolyline);
}
Also used : LatLng(com.mapbox.mapboxsdk.geometry.LatLng) PoiNodeRef(io.jawg.osmcontributor.model.entities.PoiNodeRef) PolylineOptions(com.mapbox.mapboxsdk.annotations.PolylineOptions)

Aggregations

PolylineOptions (com.mapbox.mapboxsdk.annotations.PolylineOptions)8 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)3 Feature (com.mapbox.services.commons.geojson.Feature)3 NonNull (android.support.annotation.NonNull)2 ArrayList (java.util.ArrayList)2 Location (android.location.Location)1 InnerPolyline (cl.smartcities.isci.transportinspector.router.InnerPolyline)1 Point (com.mapbox.geojson.Point)1 Marker (com.mapbox.mapboxsdk.annotations.Marker)1 MarkerOptions (com.mapbox.mapboxsdk.annotations.MarkerOptions)1 PolygonOptions (com.mapbox.mapboxsdk.annotations.PolygonOptions)1 Polyline (com.mapbox.mapboxsdk.annotations.Polyline)1 MapboxMap (com.mapbox.mapboxsdk.maps.MapboxMap)1 MarkerData (com.mapbox.mapboxsdk.plugins.geojson.model.MarkerData)1 PolyData (com.mapbox.mapboxsdk.plugins.geojson.model.PolyData)1 PoiNodeRef (io.jawg.osmcontributor.model.entities.PoiNodeRef)1 WayMarkerOptions (io.jawg.osmcontributor.ui.utils.views.map.marker.WayMarkerOptions)1