Search in sources :

Example 1 with RCTMGLPointAnnotation

use of com.mapbox.rctmgl.components.annotation.RCTMGLPointAnnotation in project maps by rnmapbox.

the class RCTMGLMapView method onMarkerClick.

public void onMarkerClick(@NonNull PointAnnotation symbol) {
    mAnnotationClicked = true;
    final long selectedMarkerID = symbol.getId();
    RCTMGLPointAnnotation activeAnnotation = null;
    RCTMGLPointAnnotation nextActiveAnnotation = null;
    for (String key : mPointAnnotations.keySet()) {
        RCTMGLPointAnnotation annotation = mPointAnnotations.get(key);
        final long curMarkerID = annotation.getMapboxID();
        if (mActiveMarkerID == curMarkerID) {
            activeAnnotation = annotation;
        }
        if (selectedMarkerID == curMarkerID && mActiveMarkerID != curMarkerID) {
            nextActiveAnnotation = annotation;
        }
    }
    if (activeAnnotation != null) {
        deselectAnnotation(activeAnnotation);
    }
    if (nextActiveAnnotation != null) {
        selectAnnotation(nextActiveAnnotation);
    }
}
Also used : RCTMGLPointAnnotation(com.mapbox.rctmgl.components.annotation.RCTMGLPointAnnotation)

Example 2 with RCTMGLPointAnnotation

use of com.mapbox.rctmgl.components.annotation.RCTMGLPointAnnotation in project maps by rnmapbox.

the class RCTMGLMapView method addFeature.

public void addFeature(View childView, int childPosition) {
    AbstractMapFeature feature = null;
    if (childView instanceof RCTSource) {
        RCTSource source = (RCTSource) childView;
        mSources.put(source.getID(), source);
        feature = (AbstractMapFeature) childView;
    } else if (childView instanceof RCTMGLImages) {
        RCTMGLImages images = (RCTMGLImages) childView;
        mImages.add(images);
        feature = (AbstractMapFeature) childView;
    } else if (childView instanceof RCTMGLLight) {
        feature = (AbstractMapFeature) childView;
    } else if (childView instanceof RCTMGLNativeUserLocation) {
        feature = (AbstractMapFeature) childView;
    } else if (childView instanceof RCTMGLPointAnnotation) {
        RCTMGLPointAnnotation annotation = (RCTMGLPointAnnotation) childView;
        mPointAnnotations.put(annotation.getID(), annotation);
        feature = (AbstractMapFeature) childView;
    } else if (childView instanceof RCTMGLMarkerView) {
        RCTMGLMarkerView marker = (RCTMGLMarkerView) childView;
        feature = (AbstractMapFeature) childView;
    } else if (childView instanceof RCTMGLCamera) {
        mCamera = (RCTMGLCamera) childView;
        feature = (AbstractMapFeature) childView;
    } else if (childView instanceof RCTLayer) {
        feature = (RCTLayer) childView;
    } else if (childView instanceof ViewGroup) {
        ViewGroup children = (ViewGroup) childView;
        for (int i = 0; i < children.getChildCount(); i++) {
            addFeature(children.getChildAt(i), childPosition);
        }
    }
    if (feature != null) {
        if (mQueuedFeatures == null) {
            feature.addToMap(this);
            mFeatures.add(childPosition, feature);
        } else {
            mQueuedFeatures.add(childPosition, feature);
        }
    }
}
Also used : RCTMGLMarkerView(com.mapbox.rctmgl.components.annotation.RCTMGLMarkerView) RCTMGLLight(com.mapbox.rctmgl.components.styles.light.RCTMGLLight) RCTSource(com.mapbox.rctmgl.components.styles.sources.RCTSource) ViewGroup(android.view.ViewGroup) RCTMGLNativeUserLocation(com.mapbox.rctmgl.components.location.RCTMGLNativeUserLocation) AbstractMapFeature(com.mapbox.rctmgl.components.AbstractMapFeature) RCTMGLImages(com.mapbox.rctmgl.components.images.RCTMGLImages) RCTLayer(com.mapbox.rctmgl.components.styles.layers.RCTLayer) RCTMGLPointAnnotation(com.mapbox.rctmgl.components.annotation.RCTMGLPointAnnotation) RCTMGLCamera(com.mapbox.rctmgl.components.camera.RCTMGLCamera)

Example 3 with RCTMGLPointAnnotation

use of com.mapbox.rctmgl.components.annotation.RCTMGLPointAnnotation in project maps by rnmapbox.

the class RCTMGLMapView method removeFeature.

public void removeFeature(int childPosition) {
    AbstractMapFeature feature = features().get(childPosition);
    if (feature == null) {
        return;
    }
    if (feature instanceof RCTSource) {
        RCTSource source = (RCTSource) feature;
        mSources.remove(source.getID());
    } else if (feature instanceof RCTMGLPointAnnotation) {
        RCTMGLPointAnnotation annotation = (RCTMGLPointAnnotation) feature;
        if (annotation.getMapboxID() == mActiveMarkerID) {
            mActiveMarkerID = -1;
        }
        mPointAnnotations.remove(annotation.getID());
    } else if (feature instanceof RCTMGLImages) {
        RCTMGLImages images = (RCTMGLImages) feature;
        mImages.remove(images);
    }
    feature.removeFromMap(this);
    features().remove(feature);
}
Also used : RCTSource(com.mapbox.rctmgl.components.styles.sources.RCTSource) AbstractMapFeature(com.mapbox.rctmgl.components.AbstractMapFeature) RCTMGLImages(com.mapbox.rctmgl.components.images.RCTMGLImages) RCTMGLPointAnnotation(com.mapbox.rctmgl.components.annotation.RCTMGLPointAnnotation)

Example 4 with RCTMGLPointAnnotation

use of com.mapbox.rctmgl.components.annotation.RCTMGLPointAnnotation in project maps by rnmapbox.

the class RCTMGLMapView method createSymbolManager.

public void createSymbolManager(Style style) {
    symbolManager = new SymbolManager(this, mMap, style);
    symbolManager.setIconAllowOverlap(true);
    symbolManager.addClickListener(SymbolClickListenerImpl.annotationClickListener(new SymbolClickListenerImpl.Listener() {

        @Override
        public boolean onAnnotationClick(Symbol symbol) {
            onMarkerClick(symbol);
            return true;
        }
    }));
    symbolManager.addDragListener(new OnSymbolDragListener() {

        @Override
        public void onAnnotationDragStarted(Symbol symbol) {
            mAnnotationClicked = true;
            final long selectedMarkerID = symbol.getId();
            RCTMGLPointAnnotation annotation = getPointAnnotationByMarkerID(selectedMarkerID);
            if (annotation != null) {
                annotation.onDragStart();
            }
        }

        @Override
        public void onAnnotationDrag(Symbol symbol) {
            final long selectedMarkerID = symbol.getId();
            RCTMGLPointAnnotation annotation = getPointAnnotationByMarkerID(selectedMarkerID);
            if (annotation != null) {
                annotation.onDrag();
            }
        }

        @Override
        public void onAnnotationDragFinished(Symbol symbol) {
            mAnnotationClicked = false;
            final long selectedMarkerID = symbol.getId();
            RCTMGLPointAnnotation annotation = getPointAnnotationByMarkerID(selectedMarkerID);
            if (annotation != null) {
                annotation.onDragEnd();
            }
        }
    });
    mMap.addOnMapClickListener(this);
    mMap.addOnMapLongClickListener(this);
}
Also used : OnSymbolClickListener(com.mapbox.mapboxsdk.plugins.annotation.OnSymbolClickListener) OnSymbolDragListener(com.mapbox.mapboxsdk.plugins.annotation.OnSymbolDragListener) LifecycleEventListener(com.facebook.react.bridge.LifecycleEventListener) Symbol(com.mapbox.mapboxsdk.plugins.annotation.Symbol) SymbolManager(com.mapbox.mapboxsdk.plugins.annotation.SymbolManager) OnSymbolDragListener(com.mapbox.mapboxsdk.plugins.annotation.OnSymbolDragListener) RCTMGLPointAnnotation(com.mapbox.rctmgl.components.annotation.RCTMGLPointAnnotation)

Example 5 with RCTMGLPointAnnotation

use of com.mapbox.rctmgl.components.annotation.RCTMGLPointAnnotation in project maps by rnmapbox.

the class RCTMGLMapView method onMarkerClick.

public void onMarkerClick(@NonNull Symbol symbol) {
    mAnnotationClicked = true;
    final long selectedMarkerID = symbol.getId();
    RCTMGLPointAnnotation activeAnnotation = null;
    RCTMGLPointAnnotation nextActiveAnnotation = null;
    for (String key : mPointAnnotations.keySet()) {
        RCTMGLPointAnnotation annotation = mPointAnnotations.get(key);
        final long curMarkerID = annotation.getMapboxID();
        if (mActiveMarkerID == curMarkerID) {
            activeAnnotation = annotation;
        }
        if (selectedMarkerID == curMarkerID && mActiveMarkerID != curMarkerID) {
            nextActiveAnnotation = annotation;
        }
    }
    if (activeAnnotation != null) {
        deselectAnnotation(activeAnnotation);
    }
    if (nextActiveAnnotation != null) {
        selectAnnotation(nextActiveAnnotation);
    }
}
Also used : RCTMGLPointAnnotation(com.mapbox.rctmgl.components.annotation.RCTMGLPointAnnotation)

Aggregations

RCTMGLPointAnnotation (com.mapbox.rctmgl.components.annotation.RCTMGLPointAnnotation)5 AbstractMapFeature (com.mapbox.rctmgl.components.AbstractMapFeature)2 RCTMGLImages (com.mapbox.rctmgl.components.images.RCTMGLImages)2 RCTSource (com.mapbox.rctmgl.components.styles.sources.RCTSource)2 ViewGroup (android.view.ViewGroup)1 LifecycleEventListener (com.facebook.react.bridge.LifecycleEventListener)1 OnSymbolClickListener (com.mapbox.mapboxsdk.plugins.annotation.OnSymbolClickListener)1 OnSymbolDragListener (com.mapbox.mapboxsdk.plugins.annotation.OnSymbolDragListener)1 Symbol (com.mapbox.mapboxsdk.plugins.annotation.Symbol)1 SymbolManager (com.mapbox.mapboxsdk.plugins.annotation.SymbolManager)1 RCTMGLMarkerView (com.mapbox.rctmgl.components.annotation.RCTMGLMarkerView)1 RCTMGLCamera (com.mapbox.rctmgl.components.camera.RCTMGLCamera)1 RCTMGLNativeUserLocation (com.mapbox.rctmgl.components.location.RCTMGLNativeUserLocation)1 RCTLayer (com.mapbox.rctmgl.components.styles.layers.RCTLayer)1 RCTMGLLight (com.mapbox.rctmgl.components.styles.light.RCTMGLLight)1