[android] #3276 - View Marker model integration
This commit is contained in:
@@ -18,7 +18,6 @@ public abstract class BaseMarkerOptions<U extends Marker, T extends BaseMarkerOp
|
||||
protected String snippet;
|
||||
protected String title;
|
||||
protected Icon icon;
|
||||
protected boolean markerView;
|
||||
|
||||
public T position(LatLng position) {
|
||||
this.position = position;
|
||||
@@ -40,16 +39,8 @@ public abstract class BaseMarkerOptions<U extends Marker, T extends BaseMarkerOp
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public T markerView(boolean isMarkerView) {
|
||||
this.markerView = isMarkerView;
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public abstract T getThis();
|
||||
|
||||
public abstract U getMarker();
|
||||
|
||||
public boolean isViewMarker() {
|
||||
return markerView;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
package com.mapbox.mapboxsdk.annotations;
|
||||
|
||||
import android.graphics.Point;
|
||||
import android.graphics.PointF;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
/**
|
||||
* Abstract builder class for composing custom Marker objects.
|
||||
*
|
||||
* Extending this class requires implementing Parceable interface.
|
||||
*
|
||||
* @param <U> Type of the marker to be composed
|
||||
* @param <T> Type of the builder to be used for composing a custom Marker
|
||||
*/
|
||||
public abstract class BaseMarkerViewOptions<U extends MarkerView, T extends BaseMarkerViewOptions<U, T>> implements Parcelable {
|
||||
|
||||
protected LatLng position;
|
||||
protected String snippet;
|
||||
protected String title;
|
||||
protected Icon icon;
|
||||
protected boolean flat;
|
||||
protected PointF centerOffset;
|
||||
protected Point infoWindowOffset;
|
||||
protected int selectAnimRes;
|
||||
protected int deselectAnimRes;
|
||||
|
||||
public BaseMarkerViewOptions() {
|
||||
centerOffset = new PointF();
|
||||
infoWindowOffset = new Point();
|
||||
}
|
||||
|
||||
public T position(LatLng position) {
|
||||
this.position = position;
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public T snippet(String snippet) {
|
||||
this.snippet = snippet;
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public T title(String title) {
|
||||
this.title = title;
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public T icon(Icon icon) {
|
||||
this.icon = icon;
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public T flat(boolean flat) {
|
||||
this.flat = flat;
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public T centerOffset(PointF centerOffset) {
|
||||
this.centerOffset = centerOffset;
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public T infoWindowOffset(Point infoWindowOffset) {
|
||||
this.infoWindowOffset = infoWindowOffset;
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public T selectAnimRes(int selectAnimRes) {
|
||||
this.selectAnimRes = selectAnimRes;
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public T deselectAnimRes(int deselectAnimRes) {
|
||||
this.deselectAnimRes = deselectAnimRes;
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public LatLng getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public String getSnippet() {
|
||||
return snippet;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public Icon getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public boolean isFlat() {
|
||||
return flat;
|
||||
}
|
||||
|
||||
public PointF getCenterOffset() {
|
||||
return centerOffset;
|
||||
}
|
||||
|
||||
public Point getInfoWindowOffset() {
|
||||
return infoWindowOffset;
|
||||
}
|
||||
|
||||
public int getSelectAnimRes() {
|
||||
return selectAnimRes;
|
||||
}
|
||||
|
||||
public int getDeselectAnimRes() {
|
||||
return deselectAnimRes;
|
||||
}
|
||||
|
||||
public abstract T getThis();
|
||||
|
||||
public abstract U getMarker();
|
||||
|
||||
}
|
||||
@@ -28,8 +28,6 @@ public class Marker extends Annotation {
|
||||
private int topOffsetPixels;
|
||||
private int rightOffsetPixels;
|
||||
|
||||
private boolean markerView;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
@@ -42,7 +40,13 @@ public class Marker extends Annotation {
|
||||
snippet = baseMarkerOptions.snippet;
|
||||
icon = baseMarkerOptions.icon;
|
||||
title = baseMarkerOptions.title;
|
||||
markerView = baseMarkerOptions.markerView;
|
||||
}
|
||||
|
||||
Marker(BaseMarkerViewOptions baseMarkerViewOptions){
|
||||
position = baseMarkerViewOptions.position;
|
||||
snippet = baseMarkerViewOptions.snippet;
|
||||
icon = baseMarkerViewOptions.icon;
|
||||
title = baseMarkerViewOptions.title;
|
||||
}
|
||||
|
||||
public LatLng getPosition() {
|
||||
@@ -57,10 +61,6 @@ public class Marker extends Annotation {
|
||||
return title;
|
||||
}
|
||||
|
||||
public boolean isViewMarker() {
|
||||
return markerView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not use this method. Used internally by the SDK.
|
||||
*/
|
||||
@@ -116,10 +116,6 @@ public class Marker extends Annotation {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
void setMarkerView(boolean isMarkerView){
|
||||
markerView = isMarkerView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not use this method. Used internally by the SDK.
|
||||
*/
|
||||
|
||||
@@ -21,23 +21,17 @@ import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
*/
|
||||
public final class MarkerOptions extends BaseMarkerOptions<Marker, MarkerOptions> implements Parcelable {
|
||||
|
||||
public static final Parcelable.Creator<MarkerOptions> CREATOR
|
||||
= new Parcelable.Creator<MarkerOptions>() {
|
||||
public MarkerOptions createFromParcel(Parcel in) {
|
||||
return new MarkerOptions(in);
|
||||
}
|
||||
private Marker marker;
|
||||
|
||||
public MarkerOptions[] newArray(int size) {
|
||||
return new MarkerOptions[size];
|
||||
}
|
||||
};
|
||||
public MarkerOptions() {
|
||||
marker = new Marker();
|
||||
}
|
||||
|
||||
private MarkerOptions(Parcel in) {
|
||||
protected MarkerOptions(Parcel in) {
|
||||
marker = new Marker();
|
||||
position((LatLng) in.readParcelable(LatLng.class.getClassLoader()));
|
||||
snippet(in.readString());
|
||||
title(in.readString());
|
||||
markerView(in.readByte() != 0);
|
||||
if (in.readByte() != 0) {
|
||||
// this means we have an icon
|
||||
String iconId = in.readString();
|
||||
@@ -63,7 +57,6 @@ public final class MarkerOptions extends BaseMarkerOptions<Marker, MarkerOptions
|
||||
out.writeString(getSnippet());
|
||||
out.writeString(getTitle());
|
||||
Icon icon = getIcon();
|
||||
out.writeByte((byte) (markerView ? 1 : 0));
|
||||
out.writeByte((byte) (icon != null ? 1 : 0));
|
||||
if (icon != null) {
|
||||
out.writeString(getIcon().getId());
|
||||
@@ -71,12 +64,6 @@ public final class MarkerOptions extends BaseMarkerOptions<Marker, MarkerOptions
|
||||
}
|
||||
}
|
||||
|
||||
private Marker marker;
|
||||
|
||||
public MarkerOptions() {
|
||||
marker = new Marker();
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not use this method. Used internally by the SDK.
|
||||
*
|
||||
@@ -87,7 +74,6 @@ public final class MarkerOptions extends BaseMarkerOptions<Marker, MarkerOptions
|
||||
marker.setSnippet(snippet);
|
||||
marker.setTitle(title);
|
||||
marker.setIcon(icon);
|
||||
marker.setMarkerView(markerView);
|
||||
return marker;
|
||||
}
|
||||
|
||||
@@ -107,6 +93,17 @@ public final class MarkerOptions extends BaseMarkerOptions<Marker, MarkerOptions
|
||||
return icon;
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<MarkerOptions> CREATOR
|
||||
= new Parcelable.Creator<MarkerOptions>() {
|
||||
public MarkerOptions createFromParcel(Parcel in) {
|
||||
return new MarkerOptions(in);
|
||||
}
|
||||
|
||||
public MarkerOptions[] newArray(int size) {
|
||||
return new MarkerOptions[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.mapbox.mapboxsdk.annotations;
|
||||
|
||||
import android.graphics.Point;
|
||||
import android.graphics.PointF;
|
||||
|
||||
public class MarkerView extends Marker {
|
||||
|
||||
private PointF centerOffset;
|
||||
private Point infoWindowOffset;
|
||||
private boolean flat;
|
||||
|
||||
private int selectAnimRes;
|
||||
private int deselectAnimRes;
|
||||
|
||||
private float tiltValue;
|
||||
|
||||
MarkerView(){
|
||||
centerOffset = new PointF();
|
||||
infoWindowOffset = new Point();
|
||||
}
|
||||
|
||||
public MarkerView(BaseMarkerViewOptions baseMarkerViewOptions) {
|
||||
super(baseMarkerViewOptions);
|
||||
this.centerOffset = baseMarkerViewOptions.getCenterOffset();
|
||||
this.infoWindowOffset = baseMarkerViewOptions.getInfoWindowOffset();
|
||||
this.flat = baseMarkerViewOptions.isFlat();
|
||||
this.selectAnimRes = baseMarkerViewOptions.getSelectAnimRes();
|
||||
this.deselectAnimRes = baseMarkerViewOptions.getDeselectAnimRes();
|
||||
}
|
||||
|
||||
public PointF getCenterOffset() {
|
||||
return centerOffset;
|
||||
}
|
||||
|
||||
public void setCenterOffset(PointF centerOffset) {
|
||||
this.centerOffset = centerOffset;
|
||||
}
|
||||
|
||||
public Point getInfoWindowOffset() {
|
||||
return infoWindowOffset;
|
||||
}
|
||||
|
||||
public void setInfoWindowOffset(Point infoWindowOffset) {
|
||||
this.infoWindowOffset = infoWindowOffset;
|
||||
}
|
||||
|
||||
public boolean isFlat() {
|
||||
return flat;
|
||||
}
|
||||
|
||||
public void setFlat(boolean flat) {
|
||||
this.flat = flat;
|
||||
}
|
||||
|
||||
public int getSelectAnimRes() {
|
||||
return selectAnimRes;
|
||||
}
|
||||
|
||||
public void setSelectAnimRes(int selectAnimRes) {
|
||||
this.selectAnimRes = selectAnimRes;
|
||||
}
|
||||
|
||||
public int getDeselectAnimRes() {
|
||||
return deselectAnimRes;
|
||||
}
|
||||
|
||||
public void setDeselectAnimRes(int deselectAnimRes) {
|
||||
this.deselectAnimRes = deselectAnimRes;
|
||||
}
|
||||
|
||||
public float getTiltValue() {
|
||||
return tiltValue;
|
||||
}
|
||||
|
||||
public void setTiltValue(float tiltValue) {
|
||||
this.tiltValue = tiltValue;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package com.mapbox.mapboxsdk.annotations;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.PointF;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
public class MarkerViewOptions extends BaseMarkerViewOptions<MarkerView, MarkerViewOptions> {
|
||||
|
||||
private MarkerView marker;
|
||||
|
||||
public MarkerViewOptions() {
|
||||
marker = new MarkerView();
|
||||
}
|
||||
|
||||
protected MarkerViewOptions(Parcel in) {
|
||||
marker = new MarkerView();
|
||||
position((LatLng) in.readParcelable(LatLng.class.getClassLoader()));
|
||||
snippet(in.readString());
|
||||
title(in.readString());
|
||||
flat(in.readByte() != 0);
|
||||
centerOffset((PointF) in.readParcelable(PointF.class.getClassLoader()));
|
||||
infoWindowOffset((Point) in.readParcelable(Point.class.getClassLoader()));
|
||||
selectAnimRes(in.readInt());
|
||||
deselectAnimRes(in.readInt());
|
||||
if (in.readByte() != 0) {
|
||||
// this means we have an icon
|
||||
String iconId = in.readString();
|
||||
Bitmap iconBitmap = in.readParcelable(Bitmap.class.getClassLoader());
|
||||
Icon icon = new Icon(iconId, iconBitmap);
|
||||
icon(icon);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkerViewOptions getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeParcelable(getPosition(), flags);
|
||||
out.writeString(getSnippet());
|
||||
out.writeString(getTitle());
|
||||
out.writeByte((byte) (isFlat() ? 1 : 0));
|
||||
out.writeParcelable(getCenterOffset(),flags);
|
||||
out.writeParcelable(getInfoWindowOffset(),flags);
|
||||
out.writeInt(getSelectAnimRes());
|
||||
out.writeInt(getDeselectAnimRes());
|
||||
Icon icon = getIcon();
|
||||
out.writeByte((byte) (icon != null ? 1 : 0));
|
||||
if (icon != null) {
|
||||
out.writeString(getIcon().getId());
|
||||
out.writeParcelable(getIcon().getBitmap(), flags);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkerView getMarker() {
|
||||
marker.setPosition(position);
|
||||
marker.setSnippet(snippet);
|
||||
marker.setTitle(title);
|
||||
marker.setIcon(icon);
|
||||
marker.setFlat(flat);
|
||||
marker.setCenterOffset(centerOffset);
|
||||
marker.setInfoWindowOffset(infoWindowOffset);
|
||||
marker.setSelectAnimRes(selectAnimRes);
|
||||
marker.setDeselectAnimRes(deselectAnimRes);
|
||||
return marker;
|
||||
}
|
||||
|
||||
public LatLng getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public String getSnippet() {
|
||||
return snippet;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public Icon getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public boolean isFlat() {
|
||||
return flat;
|
||||
}
|
||||
|
||||
public PointF getCenterOffset() {
|
||||
return centerOffset;
|
||||
}
|
||||
|
||||
public Point getInfoWindowOffset() {
|
||||
return infoWindowOffset;
|
||||
}
|
||||
|
||||
public int getSelectAnimRes() {
|
||||
return selectAnimRes;
|
||||
}
|
||||
|
||||
public int getDeselectAnimRes() {
|
||||
return deselectAnimRes;
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<MarkerViewOptions> CREATOR
|
||||
= new Parcelable.Creator<MarkerViewOptions>() {
|
||||
public MarkerViewOptions createFromParcel(Parcel in) {
|
||||
return new MarkerViewOptions(in);
|
||||
}
|
||||
|
||||
public MarkerViewOptions[] newArray(int size) {
|
||||
return new MarkerViewOptions[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
MarkerViewOptions that = (MarkerViewOptions) o;
|
||||
|
||||
return marker != null ? marker.equals(that.marker) : that.marker == null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return marker != null ? marker.hashCode() : 0;
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.annotations;
|
||||
|
||||
import android.graphics.Point;
|
||||
import android.graphics.PointF;
|
||||
import android.support.annotation.AnimatorRes;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
public class MarkerViewSettings {
|
||||
|
||||
private PointF centerOffset;
|
||||
private Point infoWindowOffset;
|
||||
private boolean flat;
|
||||
|
||||
private int selectAnimRes;
|
||||
private int deselectAnimRes;
|
||||
|
||||
private float tiltValue;
|
||||
|
||||
MarkerViewSettings(PointF centerOffset, Point infoWindowOffset, boolean flat, int selectAnimRes, int deselectAnimRes) {
|
||||
this.centerOffset = centerOffset;
|
||||
this.infoWindowOffset = infoWindowOffset;
|
||||
this.flat = flat;
|
||||
this.selectAnimRes = selectAnimRes;
|
||||
this.deselectAnimRes = deselectAnimRes;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public PointF getCenterOffset() {
|
||||
return centerOffset;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Point getInfoWindowOffset() {
|
||||
return infoWindowOffset;
|
||||
}
|
||||
|
||||
@AnimatorRes
|
||||
public int getSelectAnimRes() {
|
||||
return selectAnimRes;
|
||||
}
|
||||
|
||||
@AnimatorRes
|
||||
public int getDeselectAnimRes() {
|
||||
return deselectAnimRes;
|
||||
}
|
||||
|
||||
public boolean isFlat() {
|
||||
return flat;
|
||||
}
|
||||
|
||||
public void setTiltValue(float tilt) {
|
||||
tiltValue = tilt;
|
||||
}
|
||||
|
||||
public float getTiltValue() {
|
||||
return tiltValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder for composing LatLngBounds objects.
|
||||
*/
|
||||
public static final class Builder {
|
||||
|
||||
private PointF centerOffset;
|
||||
private Point infoWindowOffset;
|
||||
private boolean flat;
|
||||
|
||||
private int animSelectRes;
|
||||
private int animDeselectRes;
|
||||
|
||||
public Builder() {
|
||||
centerOffset = new PointF();
|
||||
infoWindowOffset = new Point();
|
||||
}
|
||||
|
||||
public Builder centerOffset(float dx, float dy) {
|
||||
centerOffset.offset(dx, dy);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder infoWindowOffset(int dx, int dy) {
|
||||
infoWindowOffset.offset(dx, -dy);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder flat(boolean isFlat) {
|
||||
flat = isFlat;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder animSelectRes(@AnimatorRes int animatorRes) {
|
||||
animSelectRes = animatorRes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder animDeselectRes(@AnimatorRes int animatorRes) {
|
||||
animDeselectRes = animatorRes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MarkerViewSettings build() {
|
||||
return new MarkerViewSettings(centerOffset, infoWindowOffset, flat, animSelectRes, animDeselectRes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,6 +69,7 @@ import com.mapbox.mapboxsdk.annotations.Icon;
|
||||
import com.mapbox.mapboxsdk.annotations.IconFactory;
|
||||
import com.mapbox.mapboxsdk.annotations.InfoWindow;
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerView;
|
||||
import com.mapbox.mapboxsdk.annotations.Polygon;
|
||||
import com.mapbox.mapboxsdk.annotations.Polyline;
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
@@ -1109,6 +1110,33 @@ public class MapView extends FrameLayout {
|
||||
return new ArrayList<>(annotations);
|
||||
}
|
||||
|
||||
List<MarkerView> getMarkerViewsInBounds(@NonNull LatLngBounds bbox) {
|
||||
if (mDestroyed || bbox == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// TODO: filter in JNI using C++ parameter to getAnnotationsInBounds
|
||||
long[] ids = mNativeMapView.getAnnotationsInBounds(bbox);
|
||||
|
||||
List<Long> idsList = new ArrayList<>(ids.length);
|
||||
for (int i = 0; i < ids.length; i++) {
|
||||
idsList.add(ids[i]);
|
||||
}
|
||||
|
||||
List<MarkerView> annotations = new ArrayList<>(ids.length);
|
||||
List<Annotation> annotationList = mMapboxMap.getAnnotations();
|
||||
int count = annotationList.size();
|
||||
for (int i = 0; i < count; i++) {
|
||||
Annotation annotation = annotationList.get(i);
|
||||
if (annotation instanceof MarkerView && idsList.contains(annotation.getId())) {
|
||||
annotations.add((MarkerView) annotation);
|
||||
}
|
||||
}
|
||||
|
||||
return new ArrayList<>(annotations);
|
||||
}
|
||||
|
||||
|
||||
int getTopOffsetPixelsForIcon(Icon icon) {
|
||||
if (mDestroyed) {
|
||||
return 0;
|
||||
@@ -1350,7 +1378,7 @@ public class MapView extends FrameLayout {
|
||||
mCompassView.update(getDirection());
|
||||
mMyLocationView.update();
|
||||
|
||||
Map<Marker, View> viewMarkers = mMapboxMap.getMarkerViewMap();
|
||||
Map<MarkerView, View> viewMarkers = mMapboxMap.getMarkerViewMap();
|
||||
for (Marker marker : viewMarkers.keySet()) {
|
||||
mViewHolder = viewMarkers.get(marker);
|
||||
if (mViewHolder != null) {
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.content.Context;
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorInflater;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Point;
|
||||
import android.location.Location;
|
||||
@@ -26,12 +25,13 @@ import android.view.ViewGroup;
|
||||
|
||||
import com.mapbox.mapboxsdk.annotations.Annotation;
|
||||
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
|
||||
import com.mapbox.mapboxsdk.annotations.BaseMarkerViewOptions;
|
||||
import com.mapbox.mapboxsdk.annotations.Icon;
|
||||
import com.mapbox.mapboxsdk.annotations.IconFactory;
|
||||
import com.mapbox.mapboxsdk.annotations.InfoWindow;
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerViewSettings;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerView;
|
||||
import com.mapbox.mapboxsdk.annotations.Polygon;
|
||||
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
|
||||
import com.mapbox.mapboxsdk.annotations.Polyline;
|
||||
@@ -77,8 +77,7 @@ public class MapboxMap {
|
||||
private LongSparseArray<Annotation> mAnnotations;
|
||||
|
||||
private List<Marker> mSelectedMarkers;
|
||||
private Map<Marker, View> mMarkerViewMap;
|
||||
private LongSparseArray<MarkerViewSettings> mMarkerViewSettingsMap;
|
||||
private Map<MarkerView, View> mMarkerViewMap;
|
||||
|
||||
private List<InfoWindow> mInfoWindows;
|
||||
private MapboxMap.InfoWindowAdapter mInfoWindowAdapter;
|
||||
@@ -118,7 +117,6 @@ public class MapboxMap {
|
||||
mSelectedMarkers = new ArrayList<>();
|
||||
mInfoWindows = new ArrayList<>();
|
||||
mMarkerViewMap = new HashMap<>();
|
||||
mMarkerViewSettingsMap = new LongSparseArray<>();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -619,6 +617,7 @@ public class MapboxMap {
|
||||
* <p>
|
||||
* Sets the current Mapbox access token used to load map styles and tiles.
|
||||
* </p>
|
||||
*
|
||||
* @param accessToken Your public Mapbox access token.
|
||||
* @see MapView#setAccessToken(String)
|
||||
* @deprecated As of release 4.1.0, replaced by {@link com.mapbox.mapboxsdk.MapboxAccountManager#start(Context, String)}
|
||||
@@ -652,18 +651,17 @@ public class MapboxMap {
|
||||
//
|
||||
|
||||
void invalidateViewMarkersInBounds() {
|
||||
List<Marker> markers = mMapView.getMarkersInBounds(mProjection.getVisibleRegion().latLngBounds);
|
||||
List<MarkerView> markers = mMapView.getMarkerViewsInBounds(mProjection.getVisibleRegion().latLngBounds);
|
||||
View convertView;
|
||||
|
||||
// remove old markers
|
||||
Iterator<Marker> iterator = mMarkerViewMap.keySet().iterator();
|
||||
Iterator<MarkerView> iterator = mMarkerViewMap.keySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Marker m = iterator.next();
|
||||
MarkerView m = iterator.next();
|
||||
if (!markers.contains(m)) {
|
||||
// remove marker
|
||||
convertView = mMarkerViewMap.get(m);
|
||||
MarkerViewSettings settings = mMarkerViewSettingsMap.get(m.getId());
|
||||
int deselectAnimRes = settings.getDeselectAnimRes();
|
||||
int deselectAnimRes = m.getDeselectAnimRes();
|
||||
if (deselectAnimRes != 0) {
|
||||
Animator animator = AnimatorInflater.loadAnimator(mMapView.getContext(), deselectAnimRes);
|
||||
animator.setDuration(0);
|
||||
@@ -676,34 +674,27 @@ public class MapboxMap {
|
||||
}
|
||||
|
||||
// introduce new markers
|
||||
for (final Marker marker : markers) {
|
||||
if (marker.isViewMarker() && !mMarkerViewMap.containsKey(marker)) {
|
||||
for (final MarkerView marker : markers) {
|
||||
if (!mMarkerViewMap.containsKey(marker)) {
|
||||
for (final MarkerViewAdapter adapter : mMarkerViewAdapters) {
|
||||
if (adapter.getMarkerClass() == marker.getClass()) {
|
||||
|
||||
MarkerViewSettings settings = mMarkerViewSettingsMap.get(marker.getId());
|
||||
if (settings == null) {
|
||||
settings = adapter.getMarkerViewSettings(marker);
|
||||
mMarkerViewSettingsMap.put(marker.getId(), settings);
|
||||
}
|
||||
|
||||
convertView = (View) adapter.getViewReusePool().acquire();
|
||||
View adaptedView = adapter.getView(marker, convertView, mMapView);
|
||||
|
||||
// infowindow offset
|
||||
Point infoWindowOffset = settings.getInfoWindowOffset();
|
||||
marker.setTopOffsetPixels(infoWindowOffset.y);
|
||||
// InfoWindow offset
|
||||
Point infoWindowOffset = marker.getInfoWindowOffset();
|
||||
marker.setTopOffsetPixels(-infoWindowOffset.y);
|
||||
marker.setRightOffsetPixels(infoWindowOffset.x);
|
||||
|
||||
if (adaptedView != null) {
|
||||
|
||||
// tilt
|
||||
adaptedView.setRotationX(settings.getTiltValue());
|
||||
adaptedView.setRotationX(marker.getTiltValue());
|
||||
|
||||
if (mSelectedMarkers.contains(marker)) {
|
||||
// if a marker to be shown was selected
|
||||
// replay that animation with duration 0
|
||||
int selectAnimRes = settings.getSelectAnimRes();
|
||||
int selectAnimRes = marker.getSelectAnimRes();
|
||||
if (selectAnimRes != 0) {
|
||||
Animator animator = AnimatorInflater.loadAnimator(mMapView.getContext(), selectAnimRes);
|
||||
animator.setDuration(0);
|
||||
@@ -712,7 +703,7 @@ public class MapboxMap {
|
||||
}
|
||||
}
|
||||
|
||||
final int animSelectRes = settings.getSelectAnimRes();
|
||||
final int animSelectRes = marker.getSelectAnimRes();
|
||||
adaptedView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@@ -752,11 +743,10 @@ public class MapboxMap {
|
||||
}
|
||||
|
||||
void setTilt(double tilt) {
|
||||
for (Map.Entry<Marker, View> entry : mMarkerViewMap.entrySet()) {
|
||||
MarkerViewSettings settings = mMarkerViewSettingsMap.get(entry.getKey().getId());
|
||||
if (settings.isFlat()) {
|
||||
settings.setTiltValue((float) tilt);
|
||||
entry.getValue().setRotationX((float) tilt);
|
||||
for (MarkerView markerView : mMarkerViewMap.keySet()) {
|
||||
if (markerView.isFlat()) {
|
||||
markerView.setTiltValue((float) tilt);
|
||||
mMarkerViewMap.get(markerView).setRotationX((float) tilt);
|
||||
}
|
||||
}
|
||||
mMapView.setTilt(tilt);
|
||||
@@ -800,6 +790,29 @@ public class MapboxMap {
|
||||
return marker;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Adds a marker to this map.
|
||||
* </p>
|
||||
* The marker's icon is rendered on the map at the location {@code Marker.position}.
|
||||
* If {@code Marker.title} is defined, the map shows an info box with the marker's title and snippet.
|
||||
*
|
||||
* @param markerOptions A marker options object that defines how to render the marker.
|
||||
* @return The {@code Marker} that was added to the map.
|
||||
*/
|
||||
@UiThread
|
||||
@NonNull
|
||||
public Marker addMarker(@NonNull BaseMarkerViewOptions markerOptions) {
|
||||
Marker marker = markerOptions.getMarker();
|
||||
Icon icon = IconFactory.recreate("markerViewSettings", mViewMarkerBitmap);
|
||||
marker.setIcon(icon);
|
||||
long id = mMapView.addMarker(marker);
|
||||
marker.setMapboxMap(this);
|
||||
marker.setId(id);
|
||||
mAnnotations.put(id, marker);
|
||||
return marker;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Adds multiple markers to this map.
|
||||
@@ -1284,13 +1297,15 @@ public class MapboxMap {
|
||||
marker.hideInfoWindow();
|
||||
}
|
||||
|
||||
View viewMarker = mMarkerViewMap.get(marker);
|
||||
if (viewMarker != null) {
|
||||
int deselectAnimatorRes = mMarkerViewSettingsMap.get(marker.getId()).getDeselectAnimRes();
|
||||
if (deselectAnimatorRes != 0) {
|
||||
Animator animator = AnimatorInflater.loadAnimator(mMapView.getContext(), deselectAnimatorRes);
|
||||
animator.setTarget(viewMarker);
|
||||
animator.start();
|
||||
if (marker instanceof MarkerView) {
|
||||
View viewMarker = mMarkerViewMap.get(marker);
|
||||
if (viewMarker != null) {
|
||||
int deselectAnimatorRes = ((MarkerView) marker).getDeselectAnimRes();
|
||||
if (deselectAnimatorRes != 0) {
|
||||
Animator animator = AnimatorInflater.loadAnimator(mMapView.getContext(), deselectAnimatorRes);
|
||||
animator.setTarget(viewMarker);
|
||||
animator.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1327,7 +1342,7 @@ public class MapboxMap {
|
||||
|
||||
private Marker prepareMarker(BaseMarkerOptions markerOptions) {
|
||||
Marker marker = markerOptions.getMarker();
|
||||
if (markerOptions.isViewMarker()) {
|
||||
if (marker instanceof MarkerView) {
|
||||
Icon icon = IconFactory.recreate("markerViewSettings", mViewMarkerBitmap);
|
||||
marker.setIcon(icon);
|
||||
} else {
|
||||
@@ -1407,7 +1422,7 @@ public class MapboxMap {
|
||||
return mInfoWindows;
|
||||
}
|
||||
|
||||
Map<Marker, View> getMarkerViewMap() {
|
||||
Map<MarkerView, View> getMarkerViewMap() {
|
||||
return mMarkerViewMap;
|
||||
}
|
||||
|
||||
@@ -1939,7 +1954,7 @@ public class MapboxMap {
|
||||
View getInfoWindow(@NonNull Marker marker);
|
||||
}
|
||||
|
||||
public static abstract class MarkerViewAdapter<U extends Marker> {
|
||||
public static abstract class MarkerViewAdapter<U extends MarkerView> {
|
||||
|
||||
private Context context;
|
||||
private final Class<U> persistentClass;
|
||||
@@ -1966,10 +1981,6 @@ public class MapboxMap {
|
||||
public Context getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
public MarkerViewSettings getMarkerViewSettings(Marker marker) {
|
||||
return new MarkerViewSettings.Builder().build();
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnMarkerViewClickListener {
|
||||
|
||||
Reference in New Issue
Block a user