@Test public void testLabelAttributes() { JSONObject json = new JSONObject(); PJsonObject pJson = new PJsonObject(json, "symbolizers"); json.put(JsonStyleParserHelper.JSON_LABEL, "att"); TextSymbolizer textSymbolizer = this.helper.createTextSymbolizer(pJson); assertTrue(textSymbolizer.getLabel() instanceof Literal); json.put(JsonStyleParserHelper.JSON_LABEL, "[att]"); textSymbolizer = this.helper.createTextSymbolizer(pJson); assertTrue(textSymbolizer.getLabel() instanceof PropertyName); json.put(JsonStyleParserHelper.JSON_LABEL, "['att']"); textSymbolizer = this.helper.createTextSymbolizer(pJson); assertTrue(textSymbolizer.getLabel() instanceof Literal); json.put(JsonStyleParserHelper.JSON_LABEL, "[env('java.home')]"); textSymbolizer = this.helper.createTextSymbolizer(pJson); assertTrue(textSymbolizer.getLabel() instanceof Function); json.put(JsonStyleParserHelper.JSON_LABEL, "[centroid(geomAtt)]"); textSymbolizer = this.helper.createTextSymbolizer(pJson); assertTrue(textSymbolizer.getLabel() instanceof Function); }
@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);  }