Skip to content

Commit 35cbbe6

Browse files
committed
Changes to manage markers
1 parent 04a64f2 commit 35cbbe6

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

Mapbox/app/src/main/java/com/codeandcoke/mapbox/MapsActivity.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.content.Intent;
44
import android.graphics.BitmapFactory;
55
import android.os.Bundle;
6+
import android.view.View;
67
import android.widget.Toast;
78

89
import androidx.annotation.NonNull;
@@ -13,6 +14,7 @@
1314
import com.mapbox.maps.CameraOptions;
1415
import com.mapbox.maps.MapView;
1516
import com.mapbox.maps.Style;
17+
import com.mapbox.maps.plugin.annotation.AnnotationConfig;
1618
import com.mapbox.maps.plugin.annotation.AnnotationPlugin;
1719
import com.mapbox.maps.plugin.annotation.AnnotationPluginImplKt;
1820
import 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
}
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<com.mapbox.maps.MapView xmlns:mapbox="http://schemas.android.com/apk/res-auto"
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:id="@+id/mapView"
35
android:layout_width="match_parent"
46
android:layout_height="match_parent"
5-
android:orientation="vertical">
7+
mapbox:mapbox_cameraTargetLat="40.7128"
8+
mapbox:mapbox_cameraTargetLng="-74.0060"
9+
mapbox:mapbox_cameraZoom="9.0" >
610

7-
<com.mapbox.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android"
8-
xmlns:tools="http://schemas.android.com/tools"
9-
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
10-
android:id="@+id/mapView"
11-
android:layout_width="match_parent"
12-
android:layout_height="match_parent"
13-
mapbox:mapbox_cameraTargetLat="40.7128"
14-
mapbox:mapbox_cameraTargetLng="-74.0060"
15-
mapbox:mapbox_cameraZoom="9.0"
16-
/>
17-
18-
</androidx.constraintlayout.widget.ConstraintLayout>
11+
<com.google.android.material.floatingactionbutton.FloatingActionButton
12+
android:id="@+id/floatingActionButton"
13+
android:layout_width="wrap_content"
14+
android:layout_height="wrap_content"
15+
android:clickable="true"
16+
android:onClick="removeAllMarkers"
17+
mapbox:srcCompat="@android:drawable/ic_delete" />
18+
</com.mapbox.maps.MapView>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<string name="mapbox_access_token">pk.eyJ1Ijoic2ZhY2kiLCJhIjoiY2xhcGJsZ2dnMTdwNTNwdGFuOG83MzdkbiJ9.a7d9b3gwAgt4L3EXKyhtFQ</string>
3+
<string name="mapbox_access_token">sk.eyJ1Ijoic2ZhY2kiLCJhIjoiY2xhc2tnOXd1MGg1dTQwb3Y3YmtkcnIzYSJ9.XVlUL7Nv27Kyo1T69vnqyQ</string>
44
</resources>

0 commit comments

Comments
 (0)