Search in sources :

Example 1 with PolygonOptions

use of com.mapbox.mapboxsdk.annotations.PolygonOptions 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 PolygonOptions

use of com.mapbox.mapboxsdk.annotations.PolygonOptions 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)

Aggregations

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