Java Code Examples for mil.nga.geopackage.extension.style.StyleRow#getColorOrDefault()

The following examples show how to use mil.nga.geopackage.extension.style.StyleRow#getColorOrDefault() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StyleUtils.java    From geopackage-android-map with MIT License 6 votes vote down vote up
/**
 * Set the style into the polygon options
 *
 * @param polygonOptions polygon options
 * @param style          style row
 * @param density        display density: {@link android.util.DisplayMetrics#density}
 * @return true if style was set into the polygon options
 */
public static boolean setStyle(PolygonOptions polygonOptions, StyleRow style, float density) {

    if (style != null) {

        Color color = style.getColorOrDefault();
        polygonOptions.strokeColor(color.getColorWithAlpha());

        double width = style.getWidthOrDefault();
        polygonOptions.strokeWidth((float) width * density);

        Color fillColor = style.getFillColor();
        if (fillColor != null) {
            polygonOptions.fillColor(fillColor.getColorWithAlpha());
        }
    }

    return style != null;
}
 
Example 2
Source File: StyleUtils.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Set the style into the marker options
 *
 * @param markerOptions marker options
 * @param style         style row
 * @return true if style was set into the marker options
 */
public static boolean setStyle(MarkerOptions markerOptions, StyleRow style) {

    boolean styleSet = false;

    if (style != null) {
        Color color = style.getColorOrDefault();
        float hue = color.getHue();
        markerOptions.icon(BitmapDescriptorFactory.defaultMarker(hue));
        styleSet = true;
    }

    return styleSet;
}
 
Example 3
Source File: FeatureTiles.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Get the style paint from cache, or create and cache it
 *
 * @param style    style row
 * @param drawType draw type
 * @return paint
 */
private Paint getStylePaint(StyleRow style, FeatureDrawType drawType) {

    Paint paint = featurePaintCache.getPaint(style, drawType);

    if (paint == null) {

        Color color = null;
        Style paintStyle = null;
        Float strokeWidth = null;

        switch (drawType) {
            case CIRCLE:
                color = style.getColorOrDefault();
                paintStyle = Style.FILL;
                break;
            case STROKE:
                color = style.getColorOrDefault();
                paintStyle = Style.STROKE;
                strokeWidth = this.density * (float) style.getWidthOrDefault();
                break;
            case FILL:
                color = style.getFillColor();
                paintStyle = Style.FILL;
                strokeWidth = this.density * (float) style.getWidthOrDefault();
                break;
            default:
                throw new GeoPackageException("Unsupported Draw Type: " + drawType);
        }

        Paint stylePaint = new Paint();
        stylePaint.setAntiAlias(true);
        stylePaint.setStyle(paintStyle);
        stylePaint.setColor(color.getColorWithAlpha());
        if (strokeWidth != null) {
            stylePaint.setStrokeWidth(strokeWidth);
        }

        synchronized (featurePaintCache) {

            paint = featurePaintCache.getPaint(style, drawType);

            if (paint == null) {
                featurePaintCache.setPaint(style, drawType, stylePaint);
                paint = stylePaint;
            }

        }
    }

    return paint;
}
 
Example 4
Source File: GeoPackageUtils.java    From geopackage-mapcache-android with MIT License 4 votes vote down vote up
/**
 * Prepare the feature draw limits and defaults
 *
 * @param context
 * @param geoPackage
 * @param featureTable
 * @param pointAlpha
 * @param lineAlpha
 * @param polygonAlpha
 * @param polygonFillAlpha
 * @param pointColor
 * @param lineColor
 * @param pointRadius
 * @param lineStroke
 * @param polygonColor
 * @param polygonStroke
 * @param polygonFill
 * @param polygonFillColor
 */
public static void prepareFeatureDraw(Context context, GeoPackage geoPackage, String featureTable, EditText pointAlpha, EditText lineAlpha, EditText polygonAlpha, EditText polygonFillAlpha,
                                      EditText pointColor, EditText lineColor, EditText pointRadius, EditText lineStroke,
                                      EditText polygonColor, EditText polygonStroke, CheckBox polygonFill, EditText polygonFillColor) {

    FeatureTableStyles featureTableStyles = new FeatureTableStyles(geoPackage, featureTable);

    // Set feature limits
    pointAlpha.setFilters(new InputFilter[]{new InputFilterMinMax(
            0, 255)});
    lineAlpha.setFilters(new InputFilter[]{new InputFilterMinMax(
            0, 255)});
    polygonAlpha.setFilters(new InputFilter[]{new InputFilterMinMax(
            0, 255)});
    polygonFillAlpha.setFilters(new InputFilter[]{new InputFilterMinMax(
            0, 255)});

    // Set default feature attributes
    FeatureTiles featureTiles = new DefaultFeatureTiles(context);
    String defaultColor = "#000000";

    StyleRow pointStyle = featureTableStyles.getTableStyle(GeometryType.POINT);
    if(pointStyle != null){
        mil.nga.geopackage.style.Color pointStyleColor = pointStyle.getColorOrDefault();
        pointColor.setText(pointStyleColor.getColorHex());
        pointAlpha.setText(String.valueOf(pointStyleColor.getAlpha()));
        pointRadius.setText(new DecimalFormat("0.0#").format(pointStyle.getWidthOrDefault() / 2.0));
    }else{
        Paint pointPaint = featureTiles.getPointPaint();
        pointColor.setText(defaultColor);
        pointAlpha.setText(String.valueOf(pointPaint.getAlpha()));
        pointRadius.setText(String.valueOf(featureTiles.getPointRadius()));
    }

    StyleRow lineStyle = featureTableStyles.getTableStyle(GeometryType.LINESTRING);
    if(lineStyle != null){
        mil.nga.geopackage.style.Color lineStyleColor = lineStyle.getColorOrDefault();
        lineColor.setText(lineStyleColor.getColorHex());
        lineAlpha.setText(String.valueOf(lineStyleColor.getAlpha()));
        lineStroke.setText(new DecimalFormat("0.0#").format(lineStyle.getWidthOrDefault()));
    }else{
        Paint linePaint = featureTiles.getLinePaintCopy();
        lineColor.setText(defaultColor);
        lineAlpha.setText(String.valueOf(linePaint.getAlpha()));
        lineStroke.setText(String.valueOf(linePaint.getStrokeWidth()));
    }

    StyleRow polygonStyle = featureTableStyles.getTableStyle(GeometryType.POLYGON);
    if(polygonStyle != null){
        mil.nga.geopackage.style.Color polygonStyleColor = polygonStyle.getColorOrDefault();
        polygonColor.setText(polygonStyleColor.getColorHex());
        polygonAlpha.setText(String.valueOf(polygonStyleColor.getAlpha()));
        polygonStroke.setText(new DecimalFormat("0.0#").format(polygonStyle.getWidthOrDefault()));
        mil.nga.geopackage.style.Color polygonStyleFillColor = polygonStyle.getFillColor();
        polygonFill.setChecked(polygonStyleFillColor != null);
        if(polygonStyleFillColor != null){
            polygonFillColor.setText(polygonStyleFillColor.getColorHex());
            polygonFillAlpha.setText(String.valueOf(polygonStyleFillColor.getAlpha()));
        }else{
            polygonFillColor.setText(defaultColor);
            polygonFillAlpha.setText(String.valueOf(255));
        }
    }else{
        Paint polygonPaint = featureTiles.getPolygonPaintCopy();
        polygonColor.setText(defaultColor);
        polygonAlpha.setText(String.valueOf(polygonPaint.getAlpha()));
        polygonStroke.setText(String.valueOf(polygonPaint.getStrokeWidth()));

        polygonFill.setChecked(featureTiles.isFillPolygon());
        Paint polygonFillPaint = featureTiles.getPolygonFillPaintCopy();
        polygonFillColor.setText(defaultColor);
        polygonFillAlpha.setText(String.valueOf(polygonFillPaint.getAlpha()));
    }

}
 
Example 5
Source File: FeatureTiles.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Get the style paint from cache, or create and cache it
 *
 * @param style
 *            style row
 * @param drawType
 *            draw type
 * @return paint
 */
private Paint getStylePaint(StyleRow style, FeatureDrawType drawType) {

	Paint paint = featurePaintCache.getPaint(style, drawType);

	if (paint == null) {

		mil.nga.geopackage.style.Color color = null;
		Float strokeWidth = null;

		switch (drawType) {
		case CIRCLE:
			color = style.getColorOrDefault();
			break;
		case STROKE:
			color = style.getColorOrDefault();
			strokeWidth = this.scale * (float) style.getWidthOrDefault();
			break;
		case FILL:
			color = style.getFillColor();
			strokeWidth = this.scale * (float) style.getWidthOrDefault();
			break;
		default:
			throw new GeoPackageException(
					"Unsupported Draw Type: " + drawType);
		}

		Paint stylePaint = new Paint();
		stylePaint.setColor(new Color(color.getColorWithAlpha(), true));
		if (strokeWidth != null) {
			stylePaint.setStrokeWidth(strokeWidth);
		}

		synchronized (featurePaintCache) {

			paint = featurePaintCache.getPaint(style, drawType);

			if (paint == null) {
				featurePaintCache.setPaint(style, drawType, stylePaint);
				paint = stylePaint;
			}

		}
	}

	return paint;
}
 
Example 6
Source File: StyleUtils.java    From geopackage-android-map with MIT License 3 votes vote down vote up
/**
 * Set the style into the polyline options
 *
 * @param polylineOptions polyline options
 * @param style           style row
 * @param density         display density: {@link android.util.DisplayMetrics#density}
 * @return true if style was set into the polyline options
 */
public static boolean setStyle(PolylineOptions polylineOptions, StyleRow style, float density) {

    if (style != null) {

        Color color = style.getColorOrDefault();
        polylineOptions.color(color.getColorWithAlpha());

        double width = style.getWidthOrDefault();
        polylineOptions.width((float) width * density);

    }

    return style != null;
}