/** * Creates a simple line with default widt. * * @param color The color to use * @param isAreaEdge If this is an edge for an area. Edges are drawn at lower Z-Index. * @return The line style. */ public static LineElement createSimpleLineStyle(Color color, boolean isAreaEdge) { MultiCascade mc = new MultiCascade(); Cascade c = mc.getOrCreateCascade("default"); c.put(WIDTH, Keyword.DEFAULT); c.put(COLOR, color != null ? color : PaintColors.UNTAGGED.get()); c.put(OPACITY, 1f); if (isAreaEdge) { c.put(Z_INDEX, -3f); } Way w = new Way(); return createLine(new Environment(w, mc, "default", null)); }
private static LineElement createImpl(Environment env, LineType type) { Cascade c = env.mc.getCascade(env.layer); Cascade cDef = env.mc.getCascade("default"); Float width = computeWidth(type, c, cDef); if (width == null) return null; float realWidth = computeRealWidth(env, type, c); Float offset = computeOffset(type, c, cDef, width); int alpha = 255; Color color = c.get(type.prefix + COLOR, null, Color.class); if (color != null) { alpha = color.getAlpha(); } if (type == LineType.NORMAL && color == null) { color = c.get(FILL_COLOR, null, Color.class); } if (color == null) { color = PaintColors.UNTAGGED.get(); } Integer pAlpha = Utils.colorFloat2int(c.get(type.prefix + OPACITY, null, Float.class)); if (pAlpha != null) { alpha = pAlpha; } color = new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha); float[] dashes = c.get(type.prefix + DASHES, null, float[].class, true); if (dashes != null) { boolean hasPositive = false; for (float f : dashes) { if (f > 0) { hasPositive = true; } if (f < 0) { dashes = null; break; } } if (!hasPositive || (dashes != null && dashes.length == 0)) { dashes = null; } } float dashesOffset = c.get(type.prefix + DASHES_OFFSET, 0f, Float.class); Color dashesBackground = c.get(type.prefix + DASHES_BACKGROUND_COLOR, null, Color.class); if (dashesBackground != null) { pAlpha = Utils.colorFloat2int(c.get(type.prefix + DASHES_BACKGROUND_OPACITY, null, Float.class)); if (pAlpha != null) { alpha = pAlpha; } dashesBackground = new Color( dashesBackground.getRed(), dashesBackground.getGreen(), dashesBackground.getBlue(), alpha); } Integer cap = null; Keyword capKW = c.get(type.prefix + LINECAP, null, Keyword.class); if (capKW != null) { if ("none".equals(capKW.val)) { cap = BasicStroke.CAP_BUTT; } else if ("round".equals(capKW.val)) { cap = BasicStroke.CAP_ROUND; } else if ("square".equals(capKW.val)) { cap = BasicStroke.CAP_SQUARE; } } if (cap == null) { cap = dashes != null ? BasicStroke.CAP_BUTT : BasicStroke.CAP_ROUND; } Integer join = null; Keyword joinKW = c.get(type.prefix + LINEJOIN, null, Keyword.class); if (joinKW != null) { if ("round".equals(joinKW.val)) { join = BasicStroke.JOIN_ROUND; } else if ("miter".equals(joinKW.val)) { join = BasicStroke.JOIN_MITER; } else if ("bevel".equals(joinKW.val)) { join = BasicStroke.JOIN_BEVEL; } } if (join == null) { join = BasicStroke.JOIN_ROUND; } float miterlimit = c.get(type.prefix + MITERLIMIT, 10f, Float.class); if (miterlimit < 1f) { miterlimit = 10f; } BasicStroke line = new BasicStroke(width, cap, join, miterlimit, dashes, dashesOffset); BasicStroke dashesLine = null; if (dashes != null && dashesBackground != null) { float[] dashes2 = new float[dashes.length]; System.arraycopy(dashes, 0, dashes2, 1, dashes.length - 1); dashes2[0] = dashes[dashes.length - 1]; dashesLine = new BasicStroke(width, cap, join, miterlimit, dashes2, dashes2[0] + dashesOffset); } boolean wayDirectionArrows = c.get(type.prefix + WAY_DIRECTION_ARROWS, env.osm.isSelected(), Boolean.class); return new LineElement( c, type.defaultMajorZIndex, line, color, dashesLine, dashesBackground, offset, realWidth, wayDirectionArrows); }