Fix poi layer icons

This commit is contained in:
max-klaus 2020-04-30 16:31:03 +03:00
parent 208727a78f
commit d5366368b7
2 changed files with 33 additions and 11 deletions

View file

@ -148,6 +148,26 @@ public class RenderingIcons {
return iconsBmp.get(s); return iconsBmp.get(s);
} }
public static Drawable getDrawableIcon(Context ctx, String s, boolean includeShader) {
if (s == null) {
return null;
}
if (includeShader && shaderIcons.containsKey(s)) {
s = "h_" + s;
}
Integer drawableId = s.startsWith("h_") ? shaderIcons.get(s.substring(2)) : smallIcons.get(s);
if (drawableId != null) {
Drawable drawable = ContextCompat.getDrawable(ctx, drawableId);
if (drawable != null) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
drawable = (DrawableCompat.wrap(drawable)).mutate();
}
}
return drawable;
}
return null;
}
public static Integer getResId(String id) { public static Integer getResId(String id) {
return id.startsWith("h_") ? shaderIcons.get(id.substring(2)) : smallIcons.get(id); return id.startsWith("h_") ? shaderIcons.get(id.substring(2)) : smallIcons.get(id);
} }

View file

@ -61,11 +61,11 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
public static final org.apache.commons.logging.Log log = PlatformUtil.getLog(POIMapLayer.class); public static final org.apache.commons.logging.Log log = PlatformUtil.getLog(POIMapLayer.class);
private Paint paintIcon;
private Paint paintIconBackground; private Paint paintIconBackground;
private Bitmap poiBackground; private Bitmap poiBackground;
private Bitmap poiBackgroundSmall; private Bitmap poiBackgroundSmall;
private PorterDuffColorFilter poiColorFilter;
private int poiSize;
private OsmandMapTileView view; private OsmandMapTileView view;
@ -176,11 +176,8 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
public void initLayer(OsmandMapTileView view) { public void initLayer(OsmandMapTileView view) {
this.view = view; this.view = view;
paintIcon = new Paint(); poiSize = dpToPx(view.getContext(), 16f);
//paintIcon.setStrokeWidth(1); poiColorFilter = new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN);
//paintIcon.setStyle(Style.STROKE);
//paintIcon.setColor(Color.BLUE);
paintIcon.setColorFilter(new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN));
paintIconBackground = new Paint(); paintIconBackground = new Paint();
poiBackground = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_white_orange_poi_shield); poiBackground = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_white_orange_poi_shield);
poiBackgroundSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_white_orange_poi_shield_small); poiBackgroundSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_white_orange_poi_shield_small);
@ -263,9 +260,14 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
} }
} }
if (id != null) { if (id != null) {
Bitmap bmp = RenderingIcons.getIcon(view.getContext(), id, false); Drawable img = RenderingIcons.getDrawableIcon(view.getContext(), id, false);
if (bmp != null) { if (img != null) {
canvas.drawBitmap(bmp, x - bmp.getWidth() / 2, y - bmp.getHeight() / 2, paintIcon); canvas.save();
canvas.translate(x - poiSize / 2f, y - poiSize / 2f);
img.setBounds(0, 0, poiSize, poiSize);
img.setColorFilter(poiColorFilter);
img.draw(canvas);
canvas.restore();
} }
} }
} }