Allow modification of color for overlays.

This commit is contained in:
Mikael Capelle
2018-03-05 18:35:01 +01:00
parent 98aba8dd06
commit b77a39e01b
8 changed files with 124 additions and 54 deletions

View File

@@ -14,28 +14,39 @@ import org.mapsforge.map.layer.overlay.Marker;
public class MarkerAutoScaling extends Marker {
// Original image.
private final Image originalImage;
private Image image;
public MarkerAutoScaling(LatLong latLong, Image image) {
super(latLong, null, 0, 0);
this.originalImage = image;
this.image = image;
}
/**
* @return
* Set a new image for this marker overlay
*
* @param image New image to set.
*/
public void setImage(Image image) {
this.image = image;
}
/**
* @return Current image (marker) of this overlay.
*/
public Image getImage() {
return originalImage;
return image;
}
@Override
public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) {
public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas,
Point topLeftPoint) {
int width = (int) PaintUtils.getStrokeWidth(8, zoomLevel),
height = (int) PaintUtils.getStrokeWidth(16, zoomLevel);
BufferedImage bfd = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D g = bfd.createGraphics();
g.drawImage(this.originalImage.getScaledInstance(bfd.getWidth(), bfd.getHeight(), Image.SCALE_SMOOTH), 0, 0,
null);
g.drawImage(
this.image.getScaledInstance(bfd.getWidth(), bfd.getHeight(), Image.SCALE_SMOOTH),
0, 0, null);
setBitmap(new AwtBitmap(bfd));
setVerticalOffset(-height / 2);

View File

@@ -1,16 +1,9 @@
package org.insa.graphics.drawing.overlays;
import java.awt.Color;
import org.insa.graph.Point;
public interface MarkerOverlay extends Overlay {
/**
* @return Color associated with this marker.
*/
public Color getColor();
/**
* @return The point associated with this marker.
*/

View File

@@ -1,7 +1,21 @@
package org.insa.graphics.drawing.overlays;
import java.awt.Color;
public interface Overlay {
/**
* Set the color of this overlay.
*
* @param color New color for the overlay.
*/
public void setColor(Color color);
/**
* @return The current color of this overlay.
*/
public Color getColor();
/**
* Show or hide this marker - A marker should be visible when created.
*

View File

@@ -11,11 +11,24 @@ public class PaintUtils {
private static final GraphicFactory GRAPHIC_FACTORY = AwtGraphicFactory.INSTANCE;
/**
* Convert the given AWT color to a mapsforge compatible color.
*
* @param color
* @return
*/
public static int convertColor(Color color) {
return GRAPHIC_FACTORY.createColor(color.getAlpha(), color.getRed(), color.getGreen(), color.getBlue());
return GRAPHIC_FACTORY.createColor(color.getAlpha(), color.getRed(), color.getGreen(),
color.getBlue());
}
/**
* Convert the given mapsforge color to an AWT Color.
*
* @param color
* @return
*/
public static Color convertColor(int color) {
return new Color(color, true);
}
/**
@@ -38,4 +51,5 @@ public class PaintUtils {
}
return width * mul;
}
}

View File

@@ -6,13 +6,6 @@ import org.insa.graph.Point;
public interface PointSetOverlay extends Overlay {
/**
* Set the color of this overlay for future addPoint().
*
* @param color
*/
public void setColor(Color color);
/**
* Set the width of this overlay for future addPoint().
*

View File

@@ -31,6 +31,22 @@ public class PolylineAutoScaling extends Polyline {
this.width = width;
}
/**
* Set the color for this polyline.
*
* @param color New color for this polyline.
*/
public void setColor(Color color) {
getPaintStroke().setColor(PaintUtils.convertColor(color));
}
/**
* @return Color of this polyline.
*/
public Color getColor() {
return PaintUtils.convertColor(getPaintStroke().getColor());
}
/**
* @param point
*/