[android] #5081 - added rotation to View Marker
This commit is contained in:
@@ -27,6 +27,7 @@ public abstract class BaseMarkerViewOptions<U extends MarkerView, T extends Base
|
||||
protected Point infoWindowOffset;
|
||||
protected int selectAnimRes;
|
||||
protected int deselectAnimRes;
|
||||
protected int rotation;
|
||||
|
||||
public BaseMarkerViewOptions() {
|
||||
centerOffset = new PointF();
|
||||
@@ -78,6 +79,11 @@ public abstract class BaseMarkerViewOptions<U extends MarkerView, T extends Base
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public T rotation(int rotation){
|
||||
this.rotation = rotation;
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public LatLng getPosition() {
|
||||
return position;
|
||||
}
|
||||
@@ -114,6 +120,10 @@ public abstract class BaseMarkerViewOptions<U extends MarkerView, T extends Base
|
||||
return deselectAnimRes;
|
||||
}
|
||||
|
||||
public int getRotation() {
|
||||
return rotation;
|
||||
}
|
||||
|
||||
public abstract T getThis();
|
||||
|
||||
public abstract U getMarker();
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.mapbox.mapboxsdk.annotations;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.PointF;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
|
||||
public class MarkerView extends Marker {
|
||||
|
||||
private PointF centerOffset;
|
||||
@@ -13,8 +15,9 @@ public class MarkerView extends Marker {
|
||||
private int deselectAnimRes;
|
||||
|
||||
private float tiltValue;
|
||||
private float rotation;
|
||||
|
||||
MarkerView(){
|
||||
MarkerView() {
|
||||
centerOffset = new PointF();
|
||||
infoWindowOffset = new Point();
|
||||
}
|
||||
@@ -75,4 +78,17 @@ public class MarkerView extends Marker {
|
||||
public void setTiltValue(float tiltValue) {
|
||||
this.tiltValue = tiltValue;
|
||||
}
|
||||
|
||||
public void setRotation(float rotation) {
|
||||
this.rotation = rotation;
|
||||
|
||||
MapboxMap mapboxMap = getMapboxMap();
|
||||
if (mapboxMap != null) {
|
||||
mapboxMap.setMarkerViewRotation(this, rotation);
|
||||
}
|
||||
}
|
||||
|
||||
public float getRotation() {
|
||||
return rotation;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ public class MarkerViewOptions extends BaseMarkerViewOptions<MarkerView, MarkerV
|
||||
infoWindowOffset((Point) in.readParcelable(Point.class.getClassLoader()));
|
||||
selectAnimatorResource(in.readInt());
|
||||
deselectAnimatorResource(in.readInt());
|
||||
rotation(in.readInt());
|
||||
if (in.readByte() != 0) {
|
||||
// this means we have an icon
|
||||
String iconId = in.readString();
|
||||
@@ -55,6 +56,7 @@ public class MarkerViewOptions extends BaseMarkerViewOptions<MarkerView, MarkerV
|
||||
out.writeParcelable(getInfoWindowOffset(),flags);
|
||||
out.writeInt(getSelectAnimRes());
|
||||
out.writeInt(getDeselectAnimRes());
|
||||
out.writeInt(getRotation());
|
||||
Icon icon = getIcon();
|
||||
out.writeByte((byte) (icon != null ? 1 : 0));
|
||||
if (icon != null) {
|
||||
@@ -74,45 +76,10 @@ public class MarkerViewOptions extends BaseMarkerViewOptions<MarkerView, MarkerV
|
||||
marker.setInfoWindowOffset(infoWindowOffset);
|
||||
marker.setSelectAnimRes(selectAnimRes);
|
||||
marker.setDeselectAnimRes(deselectAnimRes);
|
||||
marker.setRotation(rotation);
|
||||
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) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.content.Context;
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorInflater;
|
||||
@@ -691,6 +692,9 @@ public class MapboxMap {
|
||||
// tilt
|
||||
adaptedView.setRotationX(marker.getTiltValue());
|
||||
|
||||
// rotation
|
||||
adaptedView.setRotation(marker.getRotation());
|
||||
|
||||
if (mSelectedMarkers.contains(marker)) {
|
||||
// if a marker to be shown was selected
|
||||
// replay that animation with duration 0
|
||||
@@ -804,8 +808,8 @@ public class MapboxMap {
|
||||
*/
|
||||
@UiThread
|
||||
@NonNull
|
||||
public Marker addMarkerView(@NonNull BaseMarkerViewOptions markerOptions) {
|
||||
Marker marker = prepareViewMarker(markerOptions);
|
||||
public MarkerView addMarkerView(@NonNull BaseMarkerViewOptions markerOptions) {
|
||||
MarkerView marker = prepareViewMarker(markerOptions);
|
||||
long id = mMapView.addMarker(marker);
|
||||
marker.setMapboxMap(this);
|
||||
marker.setId(id);
|
||||
@@ -1407,8 +1411,8 @@ public class MapboxMap {
|
||||
return marker;
|
||||
}
|
||||
|
||||
private Marker prepareViewMarker(BaseMarkerViewOptions markerViewOptions) {
|
||||
Marker marker = markerViewOptions.getMarker();
|
||||
private MarkerView prepareViewMarker(BaseMarkerViewOptions markerViewOptions) {
|
||||
MarkerView marker = markerViewOptions.getMarker();
|
||||
Icon icon = IconFactory.recreate("markerViewSettings", mViewMarkerBitmap);
|
||||
marker.setIcon(icon);
|
||||
return marker;
|
||||
@@ -1425,6 +1429,22 @@ public class MapboxMap {
|
||||
return mMarkerViewAdapters;
|
||||
}
|
||||
|
||||
public void setMarkerViewRotation(@NonNull MarkerView markerView, float rotation) {
|
||||
final View convertView = mMarkerViewMap.get(markerView);
|
||||
if (convertView != null) {
|
||||
convertView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
||||
ObjectAnimator rotateAnimator = ObjectAnimator.ofFloat(convertView, View.ROTATION, convertView.getRotation(), rotation);
|
||||
rotateAnimator.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
super.onAnimationEnd(animation);
|
||||
convertView.setLayerType(View.LAYER_TYPE_NONE, null);
|
||||
}
|
||||
});
|
||||
rotateAnimator.start();
|
||||
}
|
||||
}
|
||||
|
||||
public void setOnMarkerViewClickListener(@Nullable OnMarkerViewClickListener listener) {
|
||||
mOnMarkerViewClickListener = listener;
|
||||
}
|
||||
|
||||
@@ -145,7 +145,6 @@ public class ViewMarkerAdapterActivity extends AppCompatActivity {
|
||||
} else {
|
||||
viewHolder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
Log.v(MapboxConstants.TAG, "SSSSST");
|
||||
viewHolder.title.setText(marker.getTitle());
|
||||
return convertView;
|
||||
}
|
||||
@@ -177,7 +176,6 @@ public class ViewMarkerAdapterActivity extends AppCompatActivity {
|
||||
} else {
|
||||
viewHolder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
Log.v(MapboxConstants.TAG, "TESTSSSSS");
|
||||
viewHolder.flag.setImageResource(marker.getFlagRes());
|
||||
viewHolder.abbrev.setText(marker.getAbbrevName());
|
||||
return convertView;
|
||||
|
||||
Reference in New Issue
Block a user