Search in sources :

Example 1 with MarkerOptions

use of com.mapbox.mapboxsdk.annotations.MarkerOptions in project apps-android-commons by commons-app.

the class NearbyMapFragment method addCurrentLocationMarker.

/**
     * Adds a marker for the user's current position. Adds a
     * circle which uses the accuracy * 2, to draw a circle
     * which represents the user's position with an accuracy
     * of 95%.
     */
public void addCurrentLocationMarker(MapboxMap mapboxMap) {
    MarkerOptions currentLocationMarker = new MarkerOptions().position(new LatLng(curLatLng.getLatitude(), curLatLng.getLongitude()));
    mapboxMap.addMarker(currentLocationMarker);
    List<LatLng> circle = createCircleArray(curLatLng.getLatitude(), curLatLng.getLongitude(), curLatLng.getAccuracy() * 2, 100);
    mapboxMap.addPolygon(new PolygonOptions().addAll(circle).strokeColor(Color.parseColor("#55000000")).fillColor(Color.parseColor("#11000000")));
}
Also used : MarkerOptions(com.mapbox.mapboxsdk.annotations.MarkerOptions) PolygonOptions(com.mapbox.mapboxsdk.annotations.PolygonOptions) LatLng(com.mapbox.mapboxsdk.geometry.LatLng)

Example 2 with MarkerOptions

use of com.mapbox.mapboxsdk.annotations.MarkerOptions 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 3 with MarkerOptions

use of com.mapbox.mapboxsdk.annotations.MarkerOptions in project mapbox-navigation-android by mapbox.

the class RerouteActivity method userOffRoute.

@Override
public void userOffRoute(Location location) {
    Point newOrigin = Point.fromLngLat(location.getLongitude(), location.getLatitude());
    getRoute(newOrigin, destination, location.getBearing());
    Snackbar.make(contentLayout, "User Off Route", Snackbar.LENGTH_SHORT).show();
    mapboxMap.addMarker(new MarkerOptions().position(new LatLng(location.getLatitude(), location.getLongitude())));
}
Also used : MarkerOptions(com.mapbox.mapboxsdk.annotations.MarkerOptions) Point(com.mapbox.geojson.Point) LatLng(com.mapbox.mapboxsdk.geometry.LatLng)

Example 4 with MarkerOptions

use of com.mapbox.mapboxsdk.annotations.MarkerOptions in project mapbox-navigation-android by mapbox.

the class RerouteActivity method onMapClick.

@Override
public void onMapClick(@NonNull LatLng point) {
    if (!running || mapboxMap == null) {
        return;
    }
    mapboxMap.addMarker(new MarkerOptions().position(point));
    mapboxMap.setOnMapClickListener(null);
    Point newDestination = Point.fromLngLat(point.getLongitude(), point.getLatitude());
    mockLocationEngine.moveToLocation(newDestination);
    destination = Point.fromLngLat(point.getLongitude(), point.getLatitude());
    tracking = false;
}
Also used : MarkerOptions(com.mapbox.mapboxsdk.annotations.MarkerOptions) Point(com.mapbox.geojson.Point)

Example 5 with MarkerOptions

use of com.mapbox.mapboxsdk.annotations.MarkerOptions in project mapbox-navigation-android by mapbox.

the class NavigationView method addMarker.

/**
 * Creates a marker based on the
 * {@link Point} destination coordinate.
 *
 * @param position where the marker should be placed
 */
@Override
public void addMarker(Point position) {
    LatLng markerPosition = new LatLng(position.latitude(), position.longitude());
    markers.add(map.addMarker(new MarkerOptions().position(markerPosition).icon(ThemeSwitcher.retrieveMapMarker(getContext()))));
}
Also used : MarkerOptions(com.mapbox.mapboxsdk.annotations.MarkerOptions) LatLng(com.mapbox.mapboxsdk.geometry.LatLng)

Aggregations

MarkerOptions (com.mapbox.mapboxsdk.annotations.MarkerOptions)5 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)3 Point (com.mapbox.geojson.Point)2 PolygonOptions (com.mapbox.mapboxsdk.annotations.PolygonOptions)2 Marker (com.mapbox.mapboxsdk.annotations.Marker)1 PolylineOptions (com.mapbox.mapboxsdk.annotations.PolylineOptions)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