use of com.mapbox.mapboxsdk.annotations.Marker in project apps-android-commons by commons-app.
the class NearbyMapFragment method setupMapView.
private void setupMapView(Bundle savedInstanceState) {
MapboxMapOptions options = new MapboxMapOptions().styleUrl(Style.OUTDOORS).camera(new CameraPosition.Builder().target(new LatLng(curLatLng.getLatitude(), curLatLng.getLongitude())).zoom(11).build());
// create map
mapView = new MapView(getActivity(), options);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(MapboxMap mapboxMap) {
mapboxMap.addMarkers(baseMarkerOptions);
mapboxMap.setOnMarkerClickListener(new MapboxMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(@NonNull Marker marker) {
if (marker instanceof NearbyMarker) {
NearbyMarker nearbyMarker = (NearbyMarker) marker;
Place place = nearbyMarker.getNearbyBaseMarker().getPlace();
NearbyInfoDialog.showYourself(getActivity(), place);
}
return false;
}
});
addCurrentLocationMarker(mapboxMap);
}
});
if (PreferenceManager.getDefaultSharedPreferences(getActivity()).getBoolean("theme", true)) {
mapView.setStyleUrl(getResources().getString(R.string.map_theme_dark));
} else {
mapView.setStyleUrl(getResources().getString(R.string.map_theme_light));
}
}
use of com.mapbox.mapboxsdk.annotations.Marker 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;
}
});
}
}
use of com.mapbox.mapboxsdk.annotations.Marker in project osm-contributor by jawg.
the class MapboxListener method listen.
/**
* Register the listener for the map
* @param mapboxMap
*/
public void listen(final MapboxMap mapboxMap, final MapView mapView) {
this.mapboxMap = mapboxMap;
// Listen on map click
mapboxMap.setOnMapClickListener(new MapboxMap.OnMapClickListener() {
@Override
public void onMapClick(@NonNull LatLng point) {
MapboxListener.this.onMapClick();
}
});
// Listen on marker click
mapboxMap.setOnMarkerClickListener(new MapboxMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(@NonNull Marker marker) {
if (marker instanceof WayMarker) {
WayMarker wayMarker = (WayMarker) marker;
MapboxListener.this.onWayMarkerClick(wayMarker);
}
return false;
}
});
// Listen on location and zoom change
mapboxMap.setOnCameraChangeListener(new MapboxMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition position) {
// Location change, call the listener method
if (MapboxListener.this.position != null) {
if (!MapboxListener.this.position.target.equals(position.target)) {
onCameraPositionChange();
}
// Zoom change, call the listener method
if (MapboxListener.this.position.zoom != position.zoom) {
onCameraZoomChange(position.zoom);
}
}
MapboxListener.this.position = position;
}
});
final ScaleGestureDetector scaleGestureDetector = new ScaleGestureDetector(mapFragment.getActivity(), new ZoomAnimationGestureDetector() {
@Override
public void onZoomAnimationEnd(ValueAnimator animator) {
if (zoomValueAnimator != null && zoomValueAnimator.isRunning()) {
zoomValueAnimator.cancel();
}
zoomValueAnimator = animator;
zoomValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
CameraPosition position = mapboxMap.getCameraPosition();
mapboxMap.setCameraPosition(new CameraPosition.Builder().target(position.target).bearing(position.bearing).zoom(position.zoom + (Float) valueAnimator.getAnimatedValue()).build());
}
});
zoomValueAnimator.start();
}
});
mapView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
scaleGestureDetector.onTouchEvent(motionEvent);
return false;
}
});
// Listen on marker view click
mapboxMap.getMarkerViewManager().setOnMarkerViewClickListener(new MapboxMap.OnMarkerViewClickListener() {
@Override
public boolean onMarkerClick(@NonNull Marker marker, @NonNull View view, @NonNull MapboxMap.MarkerViewAdapter adapter) {
if (marker instanceof LocationMarkerView) {
LocationMarkerView locationMarker = (LocationMarkerView) marker;
MapboxListener.this.onLocationMarkerClick(locationMarker);
return false;
}
return false;
}
});
}
use of com.mapbox.mapboxsdk.annotations.Marker in project osm-contributor by jawg.
the class MapFragment method removePoiMarkerInError.
// markers were added on the map the sync failed we remove them
private void removePoiMarkerInError(Long id) {
Marker m = markersPoi.remove(id).getMarker();
if (m != null) {
mapboxMap.removeMarker(m);
}
defaultMap();
}
use of com.mapbox.mapboxsdk.annotations.Marker in project osm-contributor by jawg.
the class MapFragment method removeNoteMarkerInError.
// note was added on the map the sync failed we remove it
private void removeNoteMarkerInError(Long id) {
Marker m = markersNotes.remove(id).getMarker();
if (m != null) {
mapboxMap.removeMarker(m);
}
defaultMap();
}
Aggregations