2

My Current Android application employs the excellent Mapbox SDK

implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:8.0.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v7:0.6.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-localization-v7:0.9.0'

My application displays approx 50,000 markers and I am using CircleLayer clustering.

The application works as required/expected apart from the fact I cannot see how to detect when my user clicks on any of the low level markers.

All the "Marker" related mapboxMap methods are all deprecated and direct the developer to employ

use <a href="https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-annotation">
   * Mapbox Annotation Plugin

However I cannot see how to use plugin-annotation to detect clicks on my low level markers.

What am I missing?

Hector
  • 4,016
  • 21
  • 112
  • 211

1 Answers1

1

To detect any click on your CircleLayer you need first to implement the onMapClick or onMapLongClick methods. Then on every detected click, you need to query your source layer and see if there any features near that location. If so, then you can get the N nearest features and handle their behaviour. It should look like this:

@Override
public boolean onMapClick(@NonNull LatLng point) {

 // Get the clicked point coordinates
 PointF screenPoint = mapboxMap.getProjection().toScreenLocation(point);

 // Query the source layer in that location
 List<Feature> features = mapboxMap.queryRenderedFeatures(screenPoint, "MY_SOURCE_LAYER_ID");

 if (!features.isEmpty()) {

  // get the first feature in the list
  Feature feature = features.get(0);

  // do stuff...
 }

 return true;
}

This is a very basic way of handling clicks on your layers data. You can find this example I have slightly modified here.

philoez98
  • 493
  • 4
  • 13