#2283 - Supporting custom InfoWindow touch listeners via Marker.setInfoWindowOnTouchListener(). Added Test to Custom Annotations in TestApp's MainActivity.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.mapbox.mapboxgl.annotations;
|
||||
|
||||
import android.graphics.Point;
|
||||
import android.view.View;
|
||||
import com.mapbox.mapboxgl.geometry.LatLng;
|
||||
import com.mapbox.mapboxgl.views.R;
|
||||
|
||||
@@ -145,13 +146,32 @@ public class Marker extends Annotation {
|
||||
return;
|
||||
}
|
||||
|
||||
getInfoWindow().open(this, getPosition(), (int) anchorU, (int) anchorV);
|
||||
getInfoWindow().setBoundMarker(this);
|
||||
infoWindowShown = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use to set a custom OnTouchListener for the InfoWindow.
|
||||
* By default the InfoWindow will close on touch.
|
||||
* @param listener Custom OnTouchListener
|
||||
*/
|
||||
public void setInfoWindowOnTouchListener(View.OnTouchListener listener) {
|
||||
if (listener == null) {
|
||||
return;
|
||||
}
|
||||
getInfoWindow().setOnTouchListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Common internal InfoWindow initialization method
|
||||
* @return InfoWindow for Marker
|
||||
*/
|
||||
private InfoWindow getInfoWindow() {
|
||||
if (infoWindow == null) {
|
||||
infoWindow = new InfoWindow(R.layout.infowindow, mapView);
|
||||
}
|
||||
|
||||
infoWindow.open(this, getPosition(), (int)anchorU, (int)anchorV);
|
||||
infoWindow.setBoundMarker(this);
|
||||
infoWindowShown = true;
|
||||
return infoWindow;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -8,10 +8,7 @@ import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.RectF;
|
||||
import android.hardware.GeomagneticField;
|
||||
@@ -29,7 +26,6 @@ import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.view.GestureDetectorCompat;
|
||||
import android.support.v4.view.ScaleGestureDetectorCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.Gravity;
|
||||
import android.view.ScaleGestureDetector;
|
||||
@@ -483,6 +479,9 @@ public class MapView extends FrameLayout implements LocationListener {
|
||||
private void removeAnnotationsWithId(long annotationId){
|
||||
for (Iterator<Annotation> iterator = mAnnotations.iterator(); iterator.hasNext();) {
|
||||
Annotation annotation = iterator.next();
|
||||
if (annotation instanceof Marker) {
|
||||
((Marker)annotation).hideInfoWindow();
|
||||
}
|
||||
if (annotation.getId() == annotationId) {
|
||||
iterator.remove();
|
||||
}
|
||||
@@ -490,6 +489,9 @@ public class MapView extends FrameLayout implements LocationListener {
|
||||
}
|
||||
|
||||
public void removeAnnotation(Annotation annotation) {
|
||||
if (annotation instanceof Marker) {
|
||||
((Marker)annotation).hideInfoWindow();
|
||||
}
|
||||
long id = annotation.getId();
|
||||
mNativeMapView.removeAnnotation(id);
|
||||
mAnnotations.remove(annotation);
|
||||
@@ -503,8 +505,12 @@ public class MapView extends FrameLayout implements LocationListener {
|
||||
public void removeAnnotations() {
|
||||
long[] ids = new long[mAnnotations.size()];
|
||||
for(int i = 0; i < mAnnotations.size(); i++) {
|
||||
long id = mAnnotations.get(i).getId();
|
||||
Annotation annotation = mAnnotations.get(i);
|
||||
long id = annotation.getId();
|
||||
ids[i] = id;
|
||||
if (annotation instanceof Marker) {
|
||||
((Marker)annotation).hideInfoWindow();
|
||||
}
|
||||
}
|
||||
mNativeMapView.removeAnnotations(ids);
|
||||
mAnnotations.clear();
|
||||
|
||||
@@ -22,7 +22,9 @@ import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import com.crashlytics.android.Crashlytics;
|
||||
import com.mapbox.mapboxgl.annotations.Marker;
|
||||
import com.mapbox.mapboxgl.annotations.MarkerOptions;
|
||||
import com.mapbox.mapboxgl.annotations.PolygonOptions;
|
||||
import com.mapbox.mapboxgl.annotations.PolylineOptions;
|
||||
@@ -395,10 +397,18 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private void addMarkers() {
|
||||
LatLng backLot = new LatLng(38.649441, -121.369064);
|
||||
mMapView.addMarker(new MarkerOptions()
|
||||
final Marker marker = mMapView.addMarker(new MarkerOptions()
|
||||
.position(backLot)
|
||||
.title("Back Lot")
|
||||
.snippet("The back lot behind my house"));
|
||||
marker.setInfoWindowOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||
Toast.makeText(getApplicationContext(), "Custom Info Touch Listener!!", Toast.LENGTH_SHORT).show();
|
||||
marker.hideInfoWindow();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
LatLng cheeseRoom = new LatLng(38.531577,-122.010646);
|
||||
mMapView.addMarker(new MarkerOptions()
|
||||
|
||||
Reference in New Issue
Block a user