1

I have implemented my own custom MapListener for Polygons and for Markers in Nutiteq and I can show Toasts and change colors of elementsand other things but the listener doesn't react if I click long over a Marker or over a Polygon.

I have already tried with RegisterContextMenu, ContextMenuListener, etc outside my customListener and it was the same, it doesn't work.

My Intention is showing a ContextMenu if I click long over an element(Marker/Polygon).

The code is the following

I have properly overriden the Methods

public class MyFieldEventListener extends MapListener {
    private GeometryLayer layer;
    private Marker clickMarker;
    private MapView mapView;
    private Activity activity;


public MyFieldEventListener(Activity activity, MapView mapView, GeometryLayer layer, Marker clickMarker) {
    this.layer       = layer;
    this.clickMarker = clickMarker;
    this.mapView     = mapView;
    this.activity    = activity;

    // I have also tried with this line commented and it's the same
    mapView.setLongClickable(true); 

    // here I register my ContextMenu
    activity.registerForContextMenu(mapView); 

    // Here I define my ContextMenuListener and create a ContextMenu 
    mapView.setOnCreateContextMenuListener( new View.OnCreateContextMenuListener() {

        @Override
        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
            Log.i("TAG", "WmsMapActivity:: setOnCreateContextMenuListener.onCreateContextMenu");
            menu.setHeaderTitle("Notes");

            menu.add(0, 1, 0, "Write Text Note");                   
        }
    } );        
}

@Override
public void onLabelClicked(VectorElement vectorElement, boolean longClick) {
    if (vectorElement.getLabel() != null) {
        if ( longClick )   
            mapView.showContextMenu();
        else { // Another Stuff... }
}

@Override
public void onVectorElementClicked(VectorElement vectorElement, double x, double y, boolean longClick) {
    if (vectorElement.getLabel() != null) {
        if (longclick)
            mapView.showContextMenu();
        else { // Another Stuff... }
    }       
}
...
}

I would thank you for each Remark, Advise, etc

Kind Regards

Gödel77
  • 839
  • 3
  • 15
  • 27
  • Just a remark, my app recognizes in onLabelClicked and onVectorElementClicked if a longClick is taken place, so that I can show Logs, Toasts and other things. – Gödel77 Jul 08 '14 at 14:07

1 Answers1

1

Perhaps you disable click detection by calling mapView.getOptions().setClickTypeDetection(false) somewhere in your code? Other options should not interfere with click detection.

If that is not the case, I suggest you try Hellomap3D sample - it should show a toast when the displayed marker is clicked, with an indication whether it was a normal click or 'long' click. It works fine with my phone.

MarkT
  • 301
  • 2
  • 2
  • Yes, that was it. When I coded `mapView.getOptions().` I clicked the wrong suggested method and I chose that method. Thank you very much. – Gödel77 Jul 10 '14 at 13:56