@Test public void testCreateTextSymbolizer() throws Exception { final String fontColor = "#333333"; final String fontStyle = "normal"; final String fontFamily = "Liberation Sans, sans-serif"; final String fontWeight = "bold"; final String labelXOffset = "-25.0"; final String labelYOffset = "-35.0"; final String haloColor = "#123456"; final String haloRadius = "3.0"; JSONObject style = new JSONObject(); style.put("label", "name"); style.put("fontColor", fontColor); style.put("fontStyle", fontStyle); style.put("fontFamily", fontFamily); style.put("fontWeight", fontWeight); style.put("fontSize", "12"); style.put("labelXOffset", labelXOffset); style.put("labelYOffset", labelYOffset); style.put("labelRotation", "45"); style.put("labelAlign", "cm"); style.put("haloColor", haloColor); style.put("haloOpacity", "0.7"); style.put("haloRadius", haloRadius); style.put("conflictResolution", "false"); style.put("goodnessOfFit", "0.6"); style.put("spaceAround", "10"); final PJsonObject pStyle = new PJsonObject(style, null); TextSymbolizer symbolizer = helper.createTextSymbolizer(pStyle); assertNotNull(symbolizer); transformer.transform(symbolizer); assertFill(1.0, fontColor, symbolizer.getFill()); assertEquals("name", valueOf(symbolizer.getLabel())); final Font font = symbolizer.getFont(); final List<Expression> family = font.getFamily(); assertEquals(2, family.size()); assertEquals("Liberation Sans", valueOf(family.get(0))); assertEquals("SansSerif", valueOf(family.get(1))); assertEquals(12.0, valueOf(font.getSize())); assertEquals(fontStyle, valueOf(font.getStyle())); assertEquals(fontWeight, valueOf(font.getWeight())); PointPlacement placement = (PointPlacement) symbolizer.getLabelPlacement(); assertEquals(45.0, valueOf(placement.getRotation())); assertEquals(0.5, valueOf(placement.getAnchorPoint().getAnchorPointX())); assertEquals(0.5, valueOf(placement.getAnchorPoint().getAnchorPointY())); assertEquals(labelXOffset, valueOf(placement.getDisplacement().getDisplacementX()).toString()); assertEquals(labelYOffset, valueOf(placement.getDisplacement().getDisplacementY()).toString()); Halo halo = symbolizer.getHalo(); assertFill(0.7, haloColor, halo.getFill()); assertEquals(haloRadius, valueOf(halo.getRadius()).toString()); style.put("label", "label"); style.put("fontSize", "15"); symbolizer = helper.createTextSymbolizer(pStyle); assertEquals("label", valueOf(symbolizer.getLabel())); assertEquals(15.0, valueOf(symbolizer.getFont().getSize())); assertEquals("false", symbolizer.getOptions().get("conflictResolution")); assertEquals("0.6", symbolizer.getOptions().get("goodnessOfFit")); assertEquals("10", symbolizer.getOptions().get("spaceAround")); }
@VisibleForTesting protected TextSymbolizer createTextSymbolizer(final PJsonObject styleJson) { final TextSymbolizer textSymbolizer = this.styleBuilder.createTextSymbolizer(); textSymbolizer.getOptions().put("partials", "true"); if (styleJson.has(JSON_LABEL)) { final Expression label = parseExpression(null, styleJson, JSON_LABEL, (final String labelValue) -> labelValue.replace("${", "") .replace("}", "")); textSymbolizer.setLabel(label); } else { return null; } textSymbolizer.setFont(createFont(textSymbolizer.getFont(), styleJson)); if (styleJson.has(JSON_LABEL_ANCHOR_POINT_X) || styleJson.has(JSON_LABEL_ANCHOR_POINT_Y) || styleJson.has(JSON_LABEL_ALIGN) || styleJson.has(JSON_LABEL_X_OFFSET) || styleJson.has(JSON_LABEL_Y_OFFSET) || styleJson.has(JSON_LABEL_ROTATION) || styleJson.has(JSON_LABEL_PERPENDICULAR_OFFSET)) { textSymbolizer.setLabelPlacement(createLabelPlacement(styleJson)); } if (!StringUtils.isEmpty(styleJson.optString(JSON_HALO_RADIUS)) || !StringUtils.isEmpty(styleJson.optString(JSON_HALO_COLOR)) || !StringUtils.isEmpty(styleJson.optString(JSON_HALO_OPACITY)) || !StringUtils.isEmpty(styleJson.optString(JSON_LABEL_OUTLINE_WIDTH)) || !StringUtils.isEmpty(styleJson.optString(JSON_LABEL_OUTLINE_COLOR))) { textSymbolizer.setHalo(createHalo(styleJson)); } if (!StringUtils.isEmpty(styleJson.optString(JSON_FONT_COLOR)) || !StringUtils.isEmpty(styleJson.optString(JSON_FONT_OPACITY))) { textSymbolizer.setFill(addFill( styleJson.optString(JSON_FONT_COLOR, "black"), styleJson.optString(JSON_FONT_OPACITY, "1.0"))); } this.addVendorOptions(JSON_LABEL_ALLOW_OVERRUNS, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_AUTO_WRAP, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_CONFLICT_RESOLUTION, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_FOLLOW_LINE, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_GOODNESS_OF_FIT, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_GROUP, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_MAX_DISPLACEMENT, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_SPACE_AROUND, styleJson, textSymbolizer); return textSymbolizer; }
JsonStyleParserHelper { @VisibleForTesting protected TextSymbolizer createTextSymbolizer(final PJsonObject styleJson) { final TextSymbolizer textSymbolizer = this.styleBuilder.createTextSymbolizer(); textSymbolizer.getOptions().put("partials", "true"); if (styleJson.has(JSON_LABEL)) { final Expression label = parseExpression(null, styleJson, JSON_LABEL, (final String labelValue) -> labelValue.replace("${", "") .replace("}", "")); textSymbolizer.setLabel(label); } else { return null; } textSymbolizer.setFont(createFont(textSymbolizer.getFont(), styleJson)); if (styleJson.has(JSON_LABEL_ANCHOR_POINT_X) || styleJson.has(JSON_LABEL_ANCHOR_POINT_Y) || styleJson.has(JSON_LABEL_ALIGN) || styleJson.has(JSON_LABEL_X_OFFSET) || styleJson.has(JSON_LABEL_Y_OFFSET) || styleJson.has(JSON_LABEL_ROTATION) || styleJson.has(JSON_LABEL_PERPENDICULAR_OFFSET)) { textSymbolizer.setLabelPlacement(createLabelPlacement(styleJson)); } if (!StringUtils.isEmpty(styleJson.optString(JSON_HALO_RADIUS)) || !StringUtils.isEmpty(styleJson.optString(JSON_HALO_COLOR)) || !StringUtils.isEmpty(styleJson.optString(JSON_HALO_OPACITY)) || !StringUtils.isEmpty(styleJson.optString(JSON_LABEL_OUTLINE_WIDTH)) || !StringUtils.isEmpty(styleJson.optString(JSON_LABEL_OUTLINE_COLOR))) { textSymbolizer.setHalo(createHalo(styleJson)); } if (!StringUtils.isEmpty(styleJson.optString(JSON_FONT_COLOR)) || !StringUtils.isEmpty(styleJson.optString(JSON_FONT_OPACITY))) { textSymbolizer.setFill(addFill( styleJson.optString(JSON_FONT_COLOR, "black"), styleJson.optString(JSON_FONT_OPACITY, "1.0"))); } this.addVendorOptions(JSON_LABEL_ALLOW_OVERRUNS, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_AUTO_WRAP, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_CONFLICT_RESOLUTION, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_FOLLOW_LINE, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_GOODNESS_OF_FIT, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_GROUP, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_MAX_DISPLACEMENT, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_SPACE_AROUND, styleJson, textSymbolizer); return textSymbolizer; } }
JsonStyleParserHelper { @VisibleForTesting protected TextSymbolizer createTextSymbolizer(final PJsonObject styleJson) { final TextSymbolizer textSymbolizer = this.styleBuilder.createTextSymbolizer(); textSymbolizer.getOptions().put("partials", "true"); if (styleJson.has(JSON_LABEL)) { final Expression label = parseExpression(null, styleJson, JSON_LABEL, (final String labelValue) -> labelValue.replace("${", "") .replace("}", "")); textSymbolizer.setLabel(label); } else { return null; } textSymbolizer.setFont(createFont(textSymbolizer.getFont(), styleJson)); if (styleJson.has(JSON_LABEL_ANCHOR_POINT_X) || styleJson.has(JSON_LABEL_ANCHOR_POINT_Y) || styleJson.has(JSON_LABEL_ALIGN) || styleJson.has(JSON_LABEL_X_OFFSET) || styleJson.has(JSON_LABEL_Y_OFFSET) || styleJson.has(JSON_LABEL_ROTATION) || styleJson.has(JSON_LABEL_PERPENDICULAR_OFFSET)) { textSymbolizer.setLabelPlacement(createLabelPlacement(styleJson)); } if (!StringUtils.isEmpty(styleJson.optString(JSON_HALO_RADIUS)) || !StringUtils.isEmpty(styleJson.optString(JSON_HALO_COLOR)) || !StringUtils.isEmpty(styleJson.optString(JSON_HALO_OPACITY)) || !StringUtils.isEmpty(styleJson.optString(JSON_LABEL_OUTLINE_WIDTH)) || !StringUtils.isEmpty(styleJson.optString(JSON_LABEL_OUTLINE_COLOR))) { textSymbolizer.setHalo(createHalo(styleJson)); } if (!StringUtils.isEmpty(styleJson.optString(JSON_FONT_COLOR)) || !StringUtils.isEmpty(styleJson.optString(JSON_FONT_OPACITY))) { textSymbolizer.setFill(addFill( styleJson.optString(JSON_FONT_COLOR, "black"), styleJson.optString(JSON_FONT_OPACITY, "1.0"))); } this.addVendorOptions(JSON_LABEL_ALLOW_OVERRUNS, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_AUTO_WRAP, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_CONFLICT_RESOLUTION, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_FOLLOW_LINE, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_GOODNESS_OF_FIT, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_GROUP, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_MAX_DISPLACEMENT, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_SPACE_AROUND, styleJson, textSymbolizer); return textSymbolizer; } JsonStyleParserHelper(
            @Nullable final Configuration configuration,
            @Nonnull final ClientHttpRequestFactory requestFactory,
            @Nonnull final StyleBuilder styleBuilder,
            final boolean allowNullSymbolizer); }
JsonStyleParserHelper { @VisibleForTesting protected TextSymbolizer createTextSymbolizer(final PJsonObject styleJson) { final TextSymbolizer textSymbolizer = this.styleBuilder.createTextSymbolizer(); textSymbolizer.getOptions().put("partials", "true"); if (styleJson.has(JSON_LABEL)) { final Expression label = parseExpression(null, styleJson, JSON_LABEL, (final String labelValue) -> labelValue.replace("${", "") .replace("}", "")); textSymbolizer.setLabel(label); } else { return null; } textSymbolizer.setFont(createFont(textSymbolizer.getFont(), styleJson)); if (styleJson.has(JSON_LABEL_ANCHOR_POINT_X) || styleJson.has(JSON_LABEL_ANCHOR_POINT_Y) || styleJson.has(JSON_LABEL_ALIGN) || styleJson.has(JSON_LABEL_X_OFFSET) || styleJson.has(JSON_LABEL_Y_OFFSET) || styleJson.has(JSON_LABEL_ROTATION) || styleJson.has(JSON_LABEL_PERPENDICULAR_OFFSET)) { textSymbolizer.setLabelPlacement(createLabelPlacement(styleJson)); } if (!StringUtils.isEmpty(styleJson.optString(JSON_HALO_RADIUS)) || !StringUtils.isEmpty(styleJson.optString(JSON_HALO_COLOR)) || !StringUtils.isEmpty(styleJson.optString(JSON_HALO_OPACITY)) || !StringUtils.isEmpty(styleJson.optString(JSON_LABEL_OUTLINE_WIDTH)) || !StringUtils.isEmpty(styleJson.optString(JSON_LABEL_OUTLINE_COLOR))) { textSymbolizer.setHalo(createHalo(styleJson)); } if (!StringUtils.isEmpty(styleJson.optString(JSON_FONT_COLOR)) || !StringUtils.isEmpty(styleJson.optString(JSON_FONT_OPACITY))) { textSymbolizer.setFill(addFill( styleJson.optString(JSON_FONT_COLOR, "black"), styleJson.optString(JSON_FONT_OPACITY, "1.0"))); } this.addVendorOptions(JSON_LABEL_ALLOW_OVERRUNS, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_AUTO_WRAP, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_CONFLICT_RESOLUTION, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_FOLLOW_LINE, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_GOODNESS_OF_FIT, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_GROUP, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_MAX_DISPLACEMENT, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_SPACE_AROUND, styleJson, textSymbolizer); return textSymbolizer; } JsonStyleParserHelper(
            @Nullable final Configuration configuration,
            @Nonnull final ClientHttpRequestFactory requestFactory,
            @Nonnull final StyleBuilder styleBuilder,
            final boolean allowNullSymbolizer); Style createStyle(final List<Rule> styleRules); @Nullable PointSymbolizer createPointSymbolizer(final PJsonObject styleJson); }
JsonStyleParserHelper { @VisibleForTesting protected TextSymbolizer createTextSymbolizer(final PJsonObject styleJson) { final TextSymbolizer textSymbolizer = this.styleBuilder.createTextSymbolizer(); textSymbolizer.getOptions().put("partials", "true"); if (styleJson.has(JSON_LABEL)) { final Expression label = parseExpression(null, styleJson, JSON_LABEL, (final String labelValue) -> labelValue.replace("${", "") .replace("}", "")); textSymbolizer.setLabel(label); } else { return null; } textSymbolizer.setFont(createFont(textSymbolizer.getFont(), styleJson)); if (styleJson.has(JSON_LABEL_ANCHOR_POINT_X) || styleJson.has(JSON_LABEL_ANCHOR_POINT_Y) || styleJson.has(JSON_LABEL_ALIGN) || styleJson.has(JSON_LABEL_X_OFFSET) || styleJson.has(JSON_LABEL_Y_OFFSET) || styleJson.has(JSON_LABEL_ROTATION) || styleJson.has(JSON_LABEL_PERPENDICULAR_OFFSET)) { textSymbolizer.setLabelPlacement(createLabelPlacement(styleJson)); } if (!StringUtils.isEmpty(styleJson.optString(JSON_HALO_RADIUS)) || !StringUtils.isEmpty(styleJson.optString(JSON_HALO_COLOR)) || !StringUtils.isEmpty(styleJson.optString(JSON_HALO_OPACITY)) || !StringUtils.isEmpty(styleJson.optString(JSON_LABEL_OUTLINE_WIDTH)) || !StringUtils.isEmpty(styleJson.optString(JSON_LABEL_OUTLINE_COLOR))) { textSymbolizer.setHalo(createHalo(styleJson)); } if (!StringUtils.isEmpty(styleJson.optString(JSON_FONT_COLOR)) || !StringUtils.isEmpty(styleJson.optString(JSON_FONT_OPACITY))) { textSymbolizer.setFill(addFill( styleJson.optString(JSON_FONT_COLOR, "black"), styleJson.optString(JSON_FONT_OPACITY, "1.0"))); } this.addVendorOptions(JSON_LABEL_ALLOW_OVERRUNS, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_AUTO_WRAP, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_CONFLICT_RESOLUTION, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_FOLLOW_LINE, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_GOODNESS_OF_FIT, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_GROUP, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_MAX_DISPLACEMENT, styleJson, textSymbolizer); this.addVendorOptions(JSON_LABEL_SPACE_AROUND, styleJson, textSymbolizer); return textSymbolizer; } JsonStyleParserHelper(
            @Nullable final Configuration configuration,
            @Nonnull final ClientHttpRequestFactory requestFactory,
            @Nonnull final StyleBuilder styleBuilder,
            final boolean allowNullSymbolizer); Style createStyle(final List<Rule> styleRules); @Nullable PointSymbolizer createPointSymbolizer(final PJsonObject styleJson);  }