[android] #5276 - icon should be optional for MarkerView

This commit is contained in:
Tobrun Van Nuland
2016-06-13 12:46:38 +02:00
committed by Tobrun
parent 7942ce9455
commit 8e9fde6608
7 changed files with 15 additions and 1 deletions

View File

@@ -33,6 +33,7 @@ public final class IconFactory {
private Context mContext;
private static IconFactory sInstance;
private Icon mDefaultMarker;
private Icon mDefaultMarkerView;
private BitmapFactory.Options mOptions;
private int mNextId = 0;
@@ -121,6 +122,13 @@ public final class IconFactory {
return mDefaultMarker;
}
public Icon defaultMarkerView() {
if (mDefaultMarkerView == null) {
mDefaultMarkerView = fromResource(R.drawable.default_markerview);
}
return mDefaultMarkerView;
}
private Icon fromInputStream(@NonNull InputStream is) {
Bitmap bitmap = BitmapFactory.decodeStream(is, null, mOptions);
return fromBitmap(bitmap);

View File

@@ -20,6 +20,7 @@ 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;
@@ -1208,7 +1209,12 @@ public class MapboxMap {
private MarkerView prepareViewMarker(BaseMarkerViewOptions markerViewOptions) {
MarkerView marker = markerViewOptions.getMarker();
marker.setIcon(markerViewOptions.getIcon());
Icon icon = markerViewOptions.getIcon();
if (icon == null) {
icon = IconFactory.getInstance(mMapView.getContext()).defaultMarkerView();
}
marker.setIcon(icon);
return marker;
}