Search in sources :

Example 1 with LocationMarkerView

use of io.jawg.osmcontributor.ui.utils.views.map.marker.LocationMarkerView 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;
        }
    });
}
Also used : WayMarker(io.jawg.osmcontributor.ui.utils.views.map.marker.WayMarker) Marker(com.mapbox.mapboxsdk.annotations.Marker) ValueAnimator(android.animation.ValueAnimator) ZoomAnimationGestureDetector(io.jawg.osmcontributor.ui.utils.ZoomAnimationGestureDetector) LocationMarkerView(io.jawg.osmcontributor.ui.utils.views.map.marker.LocationMarkerView) MapView(com.mapbox.mapboxsdk.maps.MapView) View(android.view.View) LocationMarkerView(io.jawg.osmcontributor.ui.utils.views.map.marker.LocationMarkerView) MotionEvent(android.view.MotionEvent) CameraPosition(com.mapbox.mapboxsdk.camera.CameraPosition) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) ScaleGestureDetector(android.view.ScaleGestureDetector) MapboxMap(com.mapbox.mapboxsdk.maps.MapboxMap) WayMarker(io.jawg.osmcontributor.ui.utils.views.map.marker.WayMarker)

Example 2 with LocationMarkerView

use of io.jawg.osmcontributor.ui.utils.views.map.marker.LocationMarkerView in project osm-contributor by jawg.

the class MapFragmentPresenter method onLoaded.

private void onLoaded(List<MapElement> mapElements, LocationMarkerView.MarkerType markerType) {
    LocationMarkerView markerSelected = mapFragment.getMarkerSelected();
    for (MapElement mapElement : mapElements) {
        ids.add(mapElement.getId());
        LocationMarkerViewOptions markerOptions = mapFragment.getMarkerOptions(markerType, mapElement.getId());
        boolean selected = false;
        if (markerOptions == null) {
            markerOptions = new LocationMarkerViewOptions<>().relatedObject(mapElement).position(mapElement.getPosition());
            if (mapFragment.getSelectedMarkerType().equals(markerType) && mapElement.getId().equals(mapFragment.getMarkerSelectedId())) {
                selected = true;
                mapFragment.setMarkerSelected(markerOptions.getMarker());
            } else if (mapFragment.getSelectedMarkerType().equals(LocationMarkerView.MarkerType.POI) && markerSelected != null && mapElement.getId().equals(((Poi) markerSelected.getRelatedObject()).getId())) {
                selected = true;
            }
            // the poi in edition should be hidden
            if (!(markerSelected != null && mapFragment.getMapMode() == MapMode.POI_POSITION_EDITION && markerSelected.equals(markerOptions.getMarker())) && (mapElement instanceof Poi && !((Poi) mapElement).getToDelete())) {
                setIcon(markerOptions, mapElement, selected);
                mapFragment.addPoi(markerOptions);
            }
            if (markerType == LocationMarkerView.MarkerType.NOTE) {
                if (mapFragment.getSelectedMarkerType().equals(LocationMarkerView.MarkerType.NOTE) && mapElement.getId().equals(mapFragment.getMarkerSelectedId())) {
                    mapFragment.setMarkerSelected(markerOptions.getMarker());
                }
                setIcon(markerOptions, mapElement, false);
                mapFragment.addNote(markerOptions);
            }
        } else {
            if (markerType == LocationMarkerView.MarkerType.POI) {
                Poi poi = (Poi) mapElement;
                Poi oldPoi = (Poi) markerOptions.getMarker().getRelatedObject();
                oldPoi.setName(poi.getName());
                oldPoi.setUpdated(poi.getUpdated());
                selected = false;
                if (mapFragment.getSelectedMarkerType().equals(LocationMarkerView.MarkerType.POI) && (mapElement.getId().equals(mapFragment.getMarkerSelectedId()) || markerSelected != null && mapElement.getId().equals(((Poi) markerSelected.getRelatedObject()).getId()))) {
                    selected = true;
                }
                setIcon(markerOptions, oldPoi, selected);
            } else {
                if (mapFragment.getSelectedMarkerType().equals(LocationMarkerView.MarkerType.NOTE) && markerSelected != null && mapElement.getId().equals(((Note) markerSelected.getRelatedObject()).getId())) {
                    selected = true;
                }
                setIcon(markerOptions, mapElement, selected);
            }
            // update the detail banner data
            if (selected) {
                if (mapFragment.getMapMode() == MapMode.DETAIL_NOTE) {
                    eventBus.post(new PleaseChangeValuesDetailNoteFragmentEvent((Note) mapElement));
                } else {
                    Poi poi = (Poi) mapElement;
                    eventBus.post(new PleaseChangeValuesDetailPoiFragmentEvent(poi));
                }
            }
        }
    }
    if ((mapFragment.getMapMode() == MapMode.DEFAULT || mapFragment.getMapMode() == MapMode.POI_CREATION)) {
        mapFragment.reselectMarker();
    }
    if (mapFragment.getSelectedMarkerType().equals(markerType) && markerSelected == null) {
        mapFragment.setMarkerSelectedId(-1L);
    }
}
Also used : MapElement(io.jawg.osmcontributor.utils.core.MapElement) LocationMarkerViewOptions(io.jawg.osmcontributor.ui.utils.views.map.marker.LocationMarkerViewOptions) Note(io.jawg.osmcontributor.model.entities.Note) PleaseChangeValuesDetailPoiFragmentEvent(io.jawg.osmcontributor.ui.events.map.PleaseChangeValuesDetailPoiFragmentEvent) Poi(io.jawg.osmcontributor.model.entities.Poi) LocationMarkerView(io.jawg.osmcontributor.ui.utils.views.map.marker.LocationMarkerView) PleaseChangeValuesDetailNoteFragmentEvent(io.jawg.osmcontributor.ui.events.map.PleaseChangeValuesDetailNoteFragmentEvent)

Aggregations

LocationMarkerView (io.jawg.osmcontributor.ui.utils.views.map.marker.LocationMarkerView)2 ValueAnimator (android.animation.ValueAnimator)1 MotionEvent (android.view.MotionEvent)1 ScaleGestureDetector (android.view.ScaleGestureDetector)1 View (android.view.View)1 Marker (com.mapbox.mapboxsdk.annotations.Marker)1 CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)1 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)1 MapView (com.mapbox.mapboxsdk.maps.MapView)1 MapboxMap (com.mapbox.mapboxsdk.maps.MapboxMap)1 Note (io.jawg.osmcontributor.model.entities.Note)1 Poi (io.jawg.osmcontributor.model.entities.Poi)1 PleaseChangeValuesDetailNoteFragmentEvent (io.jawg.osmcontributor.ui.events.map.PleaseChangeValuesDetailNoteFragmentEvent)1 PleaseChangeValuesDetailPoiFragmentEvent (io.jawg.osmcontributor.ui.events.map.PleaseChangeValuesDetailPoiFragmentEvent)1 ZoomAnimationGestureDetector (io.jawg.osmcontributor.ui.utils.ZoomAnimationGestureDetector)1 LocationMarkerViewOptions (io.jawg.osmcontributor.ui.utils.views.map.marker.LocationMarkerViewOptions)1 WayMarker (io.jawg.osmcontributor.ui.utils.views.map.marker.WayMarker)1 MapElement (io.jawg.osmcontributor.utils.core.MapElement)1