Add low zoom level icons
This commit is contained in:
parent
dcdca35a4f
commit
fe14dcee91
1 changed files with 39 additions and 19 deletions
|
@ -31,6 +31,7 @@ import net.osmand.plus.views.ContextMenuLayer.ApplyMovedObjectCallback;
|
|||
import net.osmand.plus.views.MapTextLayer.MapTextProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider,
|
||||
|
@ -39,22 +40,19 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
|||
protected int startZoom = 6;
|
||||
|
||||
protected OsmandMapTileView view;
|
||||
private Paint paint;
|
||||
private FavouritesDbHelper favorites;
|
||||
private MapMarkersHelper mapMarkersHelper;
|
||||
protected List<FavouritePoint> cache = new ArrayList<>();
|
||||
private MapTextLayer textLayer;
|
||||
private Paint paintIcon;
|
||||
private HashMap<String, Bitmap> smallIconCache = new HashMap<>();
|
||||
private Bitmap pointSmall;
|
||||
@ColorInt
|
||||
private int defaultColor;
|
||||
@ColorInt
|
||||
private int grayColor;
|
||||
|
||||
private OsmandSettings settings;
|
||||
|
||||
private ContextMenuLayer contextMenuLayer;
|
||||
|
||||
protected String getObjName() {
|
||||
return view.getContext().getString(R.string.favorite);
|
||||
}
|
||||
|
@ -62,21 +60,27 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
|||
@Override
|
||||
public void initLayer(OsmandMapTileView view) {
|
||||
this.view = view;
|
||||
paint = new Paint();
|
||||
paint.setAntiAlias(true);
|
||||
paint.setFilterBitmap(true);
|
||||
paint.setDither(true);
|
||||
settings = view.getApplication().getSettings();
|
||||
favorites = view.getApplication().getFavorites();
|
||||
mapMarkersHelper = view.getApplication().getMapMarkersHelper();
|
||||
textLayer = view.getLayerByClass(MapTextLayer.class);
|
||||
paintIcon = new Paint();
|
||||
for (FavouritePoint.BackType backType : FavouritePoint.BackType.values()) {
|
||||
putBitmap(backType, "top");
|
||||
putBitmap(backType, "center");
|
||||
putBitmap(backType, "bottom");
|
||||
}
|
||||
pointSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_white_shield_small);
|
||||
defaultColor = ContextCompat.getColor(view.getContext(), R.color.color_favorite);
|
||||
grayColor = ContextCompat.getColor(view.getContext(), R.color.color_favorite_gray);
|
||||
contextMenuLayer = view.getLayerByClass(ContextMenuLayer.class);
|
||||
}
|
||||
|
||||
|
||||
private void putBitmap(FavouritePoint.BackType backType, String bottom) {
|
||||
smallIconCache.put(backType.name() + bottom, BitmapFactory.decodeResource(view.getResources(),
|
||||
getSmallIconID(bottom, backType.getIconId())));
|
||||
}
|
||||
|
||||
private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) {
|
||||
return (Math.abs(objx - ex) <= radius * 1.5 && Math.abs(objy - ey) <= radius * 1.5) ;
|
||||
// return Math.abs(objx - ex) <= radius && (ey - objy) <= radius / 2 && (objy - ey) <= 3 * radius ;
|
||||
|
@ -87,14 +91,12 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
|||
public void destroyLayer() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean drawInScreenPixels() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
|
||||
if (contextMenuLayer.getMoveableObject() instanceof FavouritePoint) {
|
||||
|
@ -104,7 +106,7 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
|||
drawBigPoint(canvas, objectInMotion, pf.x, pf.y, mapMarker);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
|
||||
cache.clear();
|
||||
|
@ -145,8 +147,15 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
|||
} else {
|
||||
color = o.getColor() == 0 || o.getColor() == Color.BLACK ? defaultColor : o.getColor();
|
||||
}
|
||||
paintIcon.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
|
||||
canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon);
|
||||
paintIcon.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN));
|
||||
Bitmap pointSmallTop = getBitmap(o, "top");
|
||||
Bitmap pointSmallCenter = getBitmap(o, "center");
|
||||
Bitmap pointSmallBottom = getBitmap(o, "bottom");
|
||||
float left = x - (pointSmallTop.getWidth() >> 1);
|
||||
float top = y - (pointSmallTop.getHeight() >> 1);
|
||||
canvas.drawBitmap(pointSmallBottom, left, top, null);
|
||||
canvas.drawBitmap(pointSmallCenter, left, top, paintIcon);
|
||||
canvas.drawBitmap(pointSmallTop, left, top, null);
|
||||
smallObjectsLatLon.add(new LatLon(lat, lon));
|
||||
} else {
|
||||
fullObjects.add(new Pair<>(o, marker));
|
||||
|
@ -171,6 +180,14 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
|||
|
||||
}
|
||||
|
||||
private Bitmap getBitmap(FavouritePoint o, String layer) {
|
||||
Bitmap pointSmall = smallIconCache.get(o.getBackType().name() + layer);
|
||||
if (pointSmall == null) {
|
||||
pointSmall = this.pointSmall;
|
||||
}
|
||||
return pointSmall;
|
||||
}
|
||||
|
||||
private void drawBigPoint(Canvas canvas, FavouritePoint o, float x, float y, @Nullable MapMarker marker) {
|
||||
FavoriteImageDrawable fid;
|
||||
boolean history = false;
|
||||
|
@ -182,14 +199,19 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
|||
}
|
||||
fid.drawBitmapInCenter(canvas, x, y, history);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private int getSmallIconID(String layer, int iconId) {
|
||||
String iconName = view.getResources().getResourceEntryName(iconId);
|
||||
return view.getResources().getIdentifier("map_" + iconName + "_" + layer + "_small"
|
||||
, "drawable", view.getContext().getPackageName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongPressEvent(PointF point, RotatedTileBox tileBox) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void getFavoriteFromPoint(RotatedTileBox tb, PointF point, List<? super FavouritePoint> res) {
|
||||
private void getFavoriteFromPoint(RotatedTileBox tb, PointF point, List<? super FavouritePoint> res) {
|
||||
int r = getDefaultRadiusPoi(tb);
|
||||
int ex = (int) point.x;
|
||||
int ey = (int) point.y;
|
||||
|
@ -209,7 +231,6 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PointDescription getObjectName(Object o) {
|
||||
if(o instanceof FavouritePoint){
|
||||
|
@ -278,7 +299,6 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isObjectMovable(Object o) {
|
||||
return o instanceof FavouritePoint;
|
||||
|
|
Loading…
Reference in a new issue