Search in sources :

Example 1 with TextStyleRenderer

use of com.revolsys.swing.map.layer.record.renderer.TextStyleRenderer in project com.revolsys.open by revolsys.

the class ArcGisRestServerRecordLayer method addTextRenderer.

private void addTextRenderer(final AbstractMultipleRenderer renderers, final MapEx labelProperties) {
    final TextStyle textStyle = new TextStyle();
    final String alignment = labelProperties.getString("labelPlacement");
    if (alignment.endsWith("Left")) {
        textStyle.setTextHorizontalAlignment("right");
    } else if (alignment.endsWith("Right")) {
        textStyle.setTextHorizontalAlignment("left");
    } else if (alignment.endsWith("Before")) {
        textStyle.setTextHorizontalAlignment("right");
        textStyle.setTextPlacementType("vertex(0)");
    } else if (alignment.endsWith("Start")) {
        textStyle.setTextHorizontalAlignment("left");
        textStyle.setTextPlacementType("vertex(0)");
    } else if (alignment.endsWith("After")) {
        textStyle.setTextHorizontalAlignment("left");
        textStyle.setTextPlacementType("vertex(n)");
    } else if (alignment.endsWith("End")) {
        textStyle.setTextHorizontalAlignment("right");
        textStyle.setTextPlacementType("vertex(n)");
    } else if (alignment.endsWith("Along")) {
        textStyle.setTextHorizontalAlignment("center");
        textStyle.setTextPlacementType("auto");
    } else {
        textStyle.setTextHorizontalAlignment("center");
    }
    if (alignment.contains("Above")) {
        textStyle.setTextVerticalAlignment("bottom");
    } else if (alignment.endsWith("Below")) {
        textStyle.setTextVerticalAlignment("top");
    } else {
        textStyle.setTextVerticalAlignment("center");
    }
    String textName = labelProperties.getString("labelExpression");
    textName = textName.replace(" CONCAT ", "");
    textName = textName.replaceAll("\"([^\"]+)\"", "$1");
    textStyle.setTextName(textName);
    final MapEx symbol = labelProperties.getValue("symbol");
    if ("esriTS".equals(symbol.getString("type"))) {
        final Color textFill = getColor(symbol);
        textStyle.setTextFill(textFill);
        final Color backgroundColor = getColor(symbol, "backgroundColor");
        textStyle.setTextBoxColor(backgroundColor);
        // "useCodedValues": false,
        // "borderLineColor": null,
        // "verticalAlignment": "bottom",
        // "horizontalAlignment": "left",
        // "rightToLeft": false,
        // "kerning": true,
        final double angle = symbol.getDouble("angle", 0);
        textStyle.setTextOrientation(angle);
        final Quantity<Length> textDx = Quantities.getQuantity(symbol.getDouble("xoffset", 0), CustomUnits.PIXEL);
        textStyle.setTextDx(textDx);
        final Quantity<Length> textDy = Quantities.getQuantity(symbol.getDouble("yoffset", 0), CustomUnits.PIXEL);
        textStyle.setTextDx(textDy);
        final MapEx font = symbol.getValue("font");
        if (font != null) {
            final String faceName = font.getString("family", "Arial");
            textStyle.setTextFaceName(faceName);
            final Quantity<Length> size = Quantities.getQuantity(font.getDouble("size", 10), CustomUnits.PIXEL);
            textStyle.setTextSize(size);
        }
    // "font": {
    // "style": "normal",
    // "weight": "bold",
    // "decoration": "none"
    }
    final TextStyleRenderer textRenderer = new TextStyleRenderer(this, textStyle);
    textRenderer.setName(textName.replace("[", "").replace("]", ""));
    long minimumScale = labelProperties.getLong("minScale", Long.MAX_VALUE);
    if (minimumScale == 0) {
        minimumScale = Long.MAX_VALUE;
    }
    textRenderer.setMinimumScale(minimumScale);
    final long maximumScale = labelProperties.getLong("maxScale", 0);
    textRenderer.setMaximumScale(maximumScale);
    final String where = labelProperties.getString("where");
    textRenderer.setQueryFilter(where);
    renderers.addRenderer(textRenderer);
}
Also used : TextStyle(com.revolsys.swing.map.layer.record.style.TextStyle) MapEx(com.revolsys.collection.map.MapEx) Length(javax.measure.quantity.Length) Color(java.awt.Color) TextStyleRenderer(com.revolsys.swing.map.layer.record.renderer.TextStyleRenderer)

Aggregations

MapEx (com.revolsys.collection.map.MapEx)1 TextStyleRenderer (com.revolsys.swing.map.layer.record.renderer.TextStyleRenderer)1 TextStyle (com.revolsys.swing.map.layer.record.style.TextStyle)1 Color (java.awt.Color)1 Length (javax.measure.quantity.Length)1