Skip to content
Permalink
Browse files

Support fill-opacity/stroke-opacity for map features (#1859)

  • Loading branch information
rgangela99 authored and SusanRatiLane committed Nov 4, 2019
1 parent a321f90 commit fca2c244331c7f9cfc270d11937a039bba361fd5
@@ -358,8 +358,16 @@ private static void upgradeComponentProperties(Map<String, JSONValue> componentP
srcCompVersion = upgradePedometerProperties(componentProperties, srcCompVersion);
} else if (componentType.equals("Map")) {
srcCompVersion = upgradeMapProperties(componentProperties, srcCompVersion);
} else if (componentType.equals("Circle")) {
srcCompVersion = upgradeCircleProperties(componentProperties, srcCompVersion);
} else if (componentType.equals("LineString")) {
srcCompVersion = upgradeLineStringProperties(componentProperties, srcCompVersion);
} else if (componentType.equals("Marker")) {
srcCompVersion = upgradeMarkerProperties(componentProperties, srcCompVersion);
} else if (componentType.equals("Polygon")) {
srcCompVersion = upgradePolygonProperties(componentProperties, srcCompVersion);
} else if (componentType.equals("Rectangle")) {
srcCompVersion = upgradeRectangleProperties(componentProperties, srcCompVersion);
} else if (componentType.equals("FeatureCollection")) {
srcCompVersion = upgradeFeatureCollection(componentProperties, srcCompVersion);
}
@@ -1635,14 +1643,56 @@ private static int upgradeMapProperties(Map<String, JSONValue> componentProperti
}
return srcCompVersion;
}

private static int upgradeCircleProperties(Map<String, JSONValue> componentProperties,
int srcCompVersion) {
if (srcCompVersion < 2) {
// Verison 2
// The FillOpacity and StrokeOpacity properties were added
srcCompVersion = 2;
}
return srcCompVersion;
}

private static int upgradeMarkerProperties(Map<String, JSONValue> componentProperties,
private static int upgradeLineStringProperties(Map<String, JSONValue> componentProperties,
int srcCompVersion) {
if (srcCompVersion < 2) {
// Verison 2
// The StrokeOpacity property was added
srcCompVersion = 2;
}
return srcCompVersion;
}

private static int upgradeMarkerProperties(Map<String, JSONValue> componentProperties,
int srcCompVersion) {
if (srcCompVersion < 3) {
// The ShowShadow property was removed.
if (componentProperties.containsKey("ShowShadow")) {
componentProperties.remove("ShowShadow");
}
// Verison 3
// The FillOpacity and StrokeOpacity properties were added
srcCompVersion = 3;
}
return srcCompVersion;
}

private static int upgradePolygonProperties(Map<String, JSONValue> componentProperties,
int srcCompVersion) {
if (srcCompVersion < 2) {
// Verison 2
// The FillOpacity and StrokeOpacity properties were added
srcCompVersion = 2;
}
return srcCompVersion;
}

private static int upgradeRectangleProperties(Map<String, JSONValue> componentProperties,
int srcCompVersion) {
if (srcCompVersion < 2) {
// Verison 2
// The FillOpacity and StrokeOpacity properties were added
srcCompVersion = 2;
}
return srcCompVersion;
@@ -1897,11 +1897,39 @@ Blockly.Versioning.AllUpgradeMaps =

}, // End Map upgraders

"Circle": {
// AI2:
// - The FillOpacity and StrokeOpacity properties were added
2: "noUpgrade"
}, // End Circle upgraders

"LineString": {
// AI2:
// - The StrokeOpacity property was added
2: "noUpgrade"
}, // End LineString upgraders

"Marker": {
// AI2:
// - The ShowShadow property was removed
2: "noUpgrade"
2: "noUpgrade",

// AI2:
// - The FillOpacity and StrokeOpacity properties were added
3: "noUpgrade"
}, // End Marker upgraders

"Polygon": {
// AI2:
// - The FillOpacity and StrokeOpacity properties were added
2: "noUpgrade"
}, // End Polygon upgraders

"Rectangle": {
// AI2:
// - The FillOpacity and StrokeOpacity properties were added
2: "noUpgrade"
}, // End Rectangle upgraders

"NearField": {

@@ -714,7 +714,9 @@ private YaVersion() {

// For CIRCLE_COMPONENT_VERSION 1:
// - Initial implementation of Circle for Maps
public static final int CIRCLE_COMPONENT_VERSION = 1;
// For CIRCLE_COMPONENT_VERSION 2:
// - Added fill and stroke opacity properties
public static final int CIRCLE_COMPONENT_VERSION = 2;

// For CLOCK_COMPONENT_VERSION 2:
// - The pattern parameter was added to the FormatDate and FormatDateTime.
@@ -896,7 +898,9 @@ private YaVersion() {

// For LINESTRING_COMPONENT_VERSION 1:
// - Initial LineString implementation for Maps
public static final int LINESTRING_COMPONENT_VERSION = 1;
// For LINESTRING_COMPONENT_VERSION 2:
// - Added fill and stroke opacity properties
public static final int LINESTRING_COMPONENT_VERSION = 2;

// For LISTPICKER_COMPONENT_VERSION 2:
// - The Alignment property was renamed to TextAlignment.
@@ -956,7 +960,9 @@ private YaVersion() {
// - Initial Marker implementation using OpenStreetMap
// For MARKER_COMPONENT_VERSION 2:
// - The ShowShadow property was removed
public static final int MARKER_COMPONENT_VERSION = 2;
// For MARKER_COMPONENT_VERSION 3:
// - Added fill and stroke opacity properties
public static final int MARKER_COMPONENT_VERSION = 3;

// For NEARFIELD_COMPONENT_VERSION 1:
public static final int NEARFIELD_COMPONENT_VERSION = 1;
@@ -1059,11 +1065,15 @@ private YaVersion() {

// For POLYGON_COMPONENT_VERSION 1:
// - Initial Polygon implementation for Maps
public static final int POLYGON_COMPONENT_VERSION = 1;
// For POLYGON_COMPONENT_VERSION 2:
// - Added fill and stroke opacity properties
public static final int POLYGON_COMPONENT_VERSION = 2;

// For RECTANGLE_COMPONENT_VERSION 1:
// - Initial Rectangle implementation for Maps
public static final int RECTANGLE_COMPONENT_VERSION = 1;
// For RECTANGLE_COMPONENT_VERSION 2:
// - Added fill and stroke opacity properties
public static final int RECTANGLE_COMPONENT_VERSION = 2;

public static final int SHARING_COMPONENT_VERSION = 1;

@@ -33,6 +33,7 @@
protected Map map = null;
private boolean visible = true;
private int strokeColor = COLOR_BLACK;
private float strokeOpacity = 1;
private int strokeWidth = 1;
private String title = "";
private String description = "";
@@ -99,6 +100,7 @@ protected MapFeatureBase(MapFeatureContainer container,
Draggable(false);
EnableInfobox(false);
StrokeColor(COLOR_BLACK);
StrokeOpacity(1);
StrokeWidth(1);
Title("");
Visible(true);
@@ -153,6 +155,23 @@ public int StrokeColor() {
return strokeColor;
}

@Override
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_FLOAT,
defaultValue = "1.0")
@SimpleProperty
public void StrokeOpacity(float opacity) {
strokeOpacity = opacity;
strokeColor = (strokeColor & 0x00FFFFFF) | (Math.round(0xFF * opacity) << 24);
map.getController().updateFeatureStroke(this);
}

@Override
@SimpleProperty(category = PropertyCategory.APPEARANCE,
description = "The opacity of the stroke used to outline the map feature.")
public float StrokeOpacity() {
return strokeOpacity;
}

@Override
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_INTEGER,
defaultValue = "1")
@@ -18,11 +18,13 @@
@SimpleObject
public abstract class MapFeatureBaseWithFill extends MapFeatureBase implements HasFill {
private int fillColor = COLOR_RED;
private float fillOpacity = 1;

public MapFeatureBaseWithFill(MapFactory.MapFeatureContainer container,
MapFeatureVisitor<Double> distanceComputation) {
super(container, distanceComputation);
FillColor(Color.RED);
FillOpacity(1);
}

@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_COLOR,
@@ -40,4 +42,21 @@ public void FillColor(int argb) {
public int FillColor() {
return fillColor;
}

@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_FLOAT,
defaultValue = "1.0")
@SimpleProperty
@Override
public void FillOpacity(float opacity) {
fillOpacity = opacity;
fillColor = (fillColor & 0x00FFFFFF) | (Math.round(0xFF * opacity) << 24);
map.getController().updateFeatureFill(this);
}

@SimpleProperty(category = PropertyCategory.APPEARANCE,
description = "The opacity of the interior of the map feature.")
@Override
public float FillOpacity() {
return fillOpacity;
}
}
@@ -201,8 +201,10 @@ public void run() {
* draggable becomes Draggable;
* infobox becomes EnableInfobox;
* fill becomes FillColor;
* fill-opacity becomes FillOpacity;
* image becomes ImageAsset;
* stroke becomes StrokeColor;
* stroke-opacity becomes StrokeOpacity;
* stroke-width becomes StrokeWidth;
* title becomes Title;
* visible becomes Visible
@@ -53,10 +53,12 @@
private static final String PROPERTY_DESCRIPTION = "description";
private static final String PROPERTY_DRAGGABLE = "draggable";
private static final String PROPERTY_FILL = "fill";
private static final String PROPERTY_FILL_OPACITY = "fill-opacity";
private static final String PROPERTY_HEIGHT = "height";
private static final String PROPERTY_IMAGE = "image";
private static final String PROPERTY_INFOBOX = "infobox";
private static final String PROPERTY_STROKE = "stroke";
private static final String PROPERTY_STROKE_OPACITY = "stroke-opacity";
private static final String PROPERTY_STROKE_WIDTH = "stroke-width";
private static final String PROPERTY_TITLE = "title";
private static final String PROPERTY_WIDTH = "width";
@@ -126,6 +128,14 @@ public void apply(MapFeature feature, Object value) {
}
}
});
SUPPORTED_PROPERTIES.put(PROPERTY_FILL_OPACITY, new PropertyApplication() {
@Override
public void apply(MapFeature feature, Object value) {
if (feature instanceof HasFill) {
((HasFill) feature).FillOpacity(parseFloatOrString(value));
}
}
});
SUPPORTED_PROPERTIES.put(PROPERTY_HEIGHT, new PropertyApplication() {
@Override
public void apply(MapFeature feature, Object value) {
@@ -157,6 +167,14 @@ public void apply(MapFeature feature, Object value) {
}
}
});
SUPPORTED_PROPERTIES.put(PROPERTY_STROKE_OPACITY, new PropertyApplication() {
@Override
public void apply(MapFeature feature, Object value) {
if (feature instanceof HasStroke) {
((HasStroke) feature).StrokeOpacity(parseFloatOrString(value));
}
}
});
SUPPORTED_PROPERTIES.put(PROPERTY_STROKE_WIDTH, new PropertyApplication() {
@Override
public void apply(MapFeature feature, Object value) {
@@ -411,6 +429,19 @@ static int parseIntegerOrString(Object value) {
}
}

@VisibleForTesting
static float parseFloatOrString(Object value) {
if (value instanceof Number) {
return ((Number) value).floatValue();
} else if (value instanceof String) {
return Float.parseFloat((String) value);
} else if (value instanceof FString) {
return Float.parseFloat(value.toString());
} else {
throw new IllegalArgumentException();
}
}

private static final class FeatureWriter implements MapFactory.MapFeatureVisitor<Void> {

private final PrintStream out;
@@ -483,11 +514,13 @@ private void writeProperties(MapFeature feature) {

private void writeProperties(HasStroke feature) {
writeColorProperty(PROPERTY_STROKE, feature.StrokeColor());
writeProperty(PROPERTY_STROKE_OPACITY, feature.StrokeOpacity());
writeProperty(PROPERTY_STROKE_WIDTH, feature.StrokeWidth());
}

private void writeProperties(HasFill feature) {
writeColorProperty(PROPERTY_FILL, feature.FillColor());
writeProperty(PROPERTY_FILL_OPACITY, feature.FillOpacity());
}

private void writePoints(List<GeoPoint> points) {
@@ -897,6 +897,18 @@
* @return the fill paint color
*/
int FillColor();

/**
* Sets the opacity of the interior of the feature
* @param opacity the fill opacity
*/
void FillOpacity(float opacity);

/**
* Gets the opacity of the interior of the feature
* @return the fill opacity
*/
float FillOpacity();
}

/**
@@ -917,6 +929,18 @@
*/
int StrokeColor();

/**
* Sets the opacity of the outline of the feature
* @param opacity the stroke opacity
*/
void StrokeOpacity(float opacity);

/**
* Gets the opacity of the outline of the feature
* @return the stroke opacity
*/
float StrokeOpacity();

/**
* Sets the width of the outline of the feature
* @param width the outline width
@@ -1000,6 +1000,7 @@ public void onFailure(String message) {

@Override
public void onSuccess(BitmapDrawable result) {
result.setAlpha((int) Math.round(aiMarker.FillOpacity() * 255.0f));
callback.onSuccess(result);
}
});
@@ -1052,6 +1053,7 @@ private Drawable rasterizeSVG(MapMarker aiMarker, SVG markerSvg) {
path.baseStyle.stroke = new SVG.Colour(strokePaint.getColor());
path.baseStyle.strokeOpacity = strokePaint.getAlpha()/255.0f;
path.baseStyle.strokeWidth = strokeWidth;
path.baseStyle.specifiedFlags = 0x3d;
if (path.style != null) {
if ((path.style.specifiedFlags & SPECIFIED_FILL) == 0) {
path.style.fill = new SVG.Colour(fillPaint.getColor());

0 comments on commit fca2c24

Please sign in to comment.
You can’t perform that action at this time.