33import android .content .Intent ;
44import android .graphics .BitmapFactory ;
55import android .os .Bundle ;
6+ import android .view .View ;
67import android .widget .Toast ;
78
89import androidx .annotation .NonNull ;
1314import com .mapbox .maps .CameraOptions ;
1415import com .mapbox .maps .MapView ;
1516import com .mapbox .maps .Style ;
17+ import com .mapbox .maps .plugin .annotation .AnnotationConfig ;
1618import com .mapbox .maps .plugin .annotation .AnnotationPlugin ;
1719import com .mapbox .maps .plugin .annotation .AnnotationPluginImplKt ;
1820import com .mapbox .maps .plugin .annotation .generated .PointAnnotationManager ;
@@ -27,12 +29,16 @@ public class MapsActivity extends AppCompatActivity implements Style.OnStyleLoad
2729 private String action ;
2830 private Place currentPlace ;
2931 private List <Place > allPlaces ;
32+ private AnnotationConfig annotationConfig ;
33+ private PointAnnotationManager pointAnnotationManager ;
3034
3135 @ Override
3236 protected void onCreate (Bundle savedInstanceState ) {
3337 super .onCreate (savedInstanceState );
3438 setContentView (R .layout .activity_maps );
3539
40+
41+
3642 Intent intent = getIntent ();
3743 action = intent .getStringExtra ("action" );
3844 if (action .equals ("show_place" )) {
@@ -44,6 +50,10 @@ protected void onCreate(Bundle savedInstanceState) {
4450 mapView = findViewById (R .id .mapView );
4551 mapView .getMapboxMap ().loadStyleUri (Style .MAPBOX_STREETS , this );
4652
53+ AnnotationPlugin annotationPlugin = AnnotationPluginImplKt .getAnnotations (mapView );
54+ annotationConfig = new AnnotationConfig ();
55+ pointAnnotationManager = PointAnnotationManagerKt .createPointAnnotationManager (annotationPlugin , annotationConfig );
56+
4757 setMarkerClickListener ();
4858 }
4959
@@ -64,13 +74,12 @@ public void onStyleLoaded(@NonNull Style style) {
6474 }
6575
6676 private void addMarker (Place place ) {
67- AnnotationPlugin annotationPlugin = AnnotationPluginImplKt .getAnnotations (mapView );
68- PointAnnotationManager pointAnnotationManager = PointAnnotationManagerKt .createPointAnnotationManager (annotationPlugin , mapView );
6977 PointAnnotationOptions pointAnnotationOptions = new PointAnnotationOptions ()
7078 .withPoint (Point .fromLngLat (place .getLongitude (), place .getLatitude ()))
7179 .withIconImage (BitmapFactory .decodeResource (getResources (), R .mipmap .red_marker ))
7280 .withTextField (place .getName ());
7381 pointAnnotationManager .create (pointAnnotationOptions );
82+ Toast .makeText (this , " " + pointAnnotationManager .getAnnotations ().size (), Toast .LENGTH_LONG ).show ();
7483 }
7584
7685 private void setCameraPosition (double latitude , double longitude ) {
@@ -84,17 +93,18 @@ private void setCameraPosition(double latitude, double longitude) {
8493 }
8594
8695 private void removeAllMarkers () {
87- AnnotationPlugin annotationPlugin = AnnotationPluginImplKt .getAnnotations (mapView );
88- PointAnnotationManager pointAnnotationManager = PointAnnotationManagerKt .createPointAnnotationManager (annotationPlugin , mapView );
8996 pointAnnotationManager .deleteAll ();
9097 }
9198
9299 private void setMarkerClickListener () {
93- AnnotationPlugin annotationPlugin = AnnotationPluginImplKt .getAnnotations (mapView );
94- PointAnnotationManager pointAnnotationManager = PointAnnotationManagerKt .createPointAnnotationManager (annotationPlugin , mapView );
95100 pointAnnotationManager .addClickListener ((pointAnnotation ) -> {
96101 Toast .makeText (this , "Click" , Toast .LENGTH_LONG ).show ();
97102 return true ;
98103 });
99104 }
105+
106+ public void removeAllMarkers (View view ) {
107+ removeAllMarkers ();
108+ Toast .makeText (this , "Markers eliminados" , Toast .LENGTH_LONG ).show ();
109+ }
100110}
0 commit comments