@Test public void testCreatePointSymbolizerExternalGraphic() throws Exception { JSONObject style = new JSONObject(); style.put("externalGraphic", "mark.png"); PointSymbolizer symbolizer = helper.createPointSymbolizer(new PJsonObject(style, null)); assertNotNull(symbolizer); transformer.transform(symbolizer); final Graphic graphic = symbolizer.getGraphic(); assertNotNull(graphic); final List<GraphicalSymbol> graphicalSymbols = graphic.graphicalSymbols(); assertEquals(1, graphicalSymbols.size()); ExternalGraphic externalGraphic = (ExternalGraphic) graphicalSymbols.get(0); assertEquals("image/png", externalGraphic.getFormat()); assertEquals(getFile("mark.png"), new File(externalGraphic.getLocation().toURI())); }
@Nullable public PointSymbolizer createPointSymbolizer(final PJsonObject styleJson) { if (this.allowNullSymbolizer && !( styleJson.has(JSON_EXTERNAL_GRAPHIC) || styleJson.has(JSON_GRAPHIC_NAME) || styleJson.has(JSON_POINT_RADIUS))) { return null; } Graphic graphic = this.styleBuilder.createGraphic(); graphic.graphicalSymbols().clear(); if (styleJson.has(JSON_EXTERNAL_GRAPHIC)) { String externalGraphicUrl = validateURL(styleJson.getString(JSON_EXTERNAL_GRAPHIC)); try { final URI uri = URI.create(externalGraphicUrl); if (uri.getScheme().startsWith("http")) { final ClientHttpRequest request = this.requestFactory.createRequest(uri, HttpMethod.GET); externalGraphicUrl = request.getURI().toString(); } } catch (IOException ignored) { } final String graphicFormat = getGraphicFormat(externalGraphicUrl, styleJson); ExternalGraphic externalGraphic = null; if (externalGraphicUrl.startsWith("data:")) { try { externalGraphic = this.styleBuilder.createExternalGraphic( new URL(null, externalGraphicUrl, new Handler()), graphicFormat ); } catch (MalformedURLException e) { } } else { externalGraphic = this.styleBuilder.createExternalGraphic(externalGraphicUrl, graphicFormat); } if (externalGraphic != null) { graphic.graphicalSymbols().add(externalGraphic); } } if (styleJson.has(JSON_GRAPHIC_NAME)) { Expression graphicName = parseProperty(styleJson.getString(JSON_GRAPHIC_NAME), input -> input); Fill fill = createFill(styleJson); Stroke stroke = createStroke(styleJson, false); final Mark mark = this.styleBuilder.createMark(graphicName, fill, stroke); graphic.graphicalSymbols().add(mark); } if (graphic.graphicalSymbols().isEmpty()) { Fill fill = createFill(styleJson); Stroke stroke = createStroke(styleJson, false); final Mark mark = this.styleBuilder.createMark(DEFAULT_POINT_MARK, fill, stroke); graphic.graphicalSymbols().add(mark); } graphic.setOpacity( parseExpression(null, styleJson, JSON_GRAPHIC_OPACITY, Double::parseDouble)); if (!StringUtils.isEmpty(styleJson.optString(JSON_POINT_RADIUS))) { Expression size = parseExpression(null, styleJson, JSON_POINT_RADIUS, (final String input) -> Double.parseDouble(input) * 2); graphic.setSize(size); } else if (!StringUtils.isEmpty(styleJson.optString(JSON_GRAPHIC_WIDTH))) { Expression size = parseExpression(null, styleJson, JSON_GRAPHIC_WIDTH, Double::parseDouble); graphic.setSize(size); } if (!StringUtils.isEmpty(styleJson.optString(JSON_GRAPHIC_Y_OFFSET)) && !StringUtils.isEmpty(styleJson.optString(JSON_GRAPHIC_X_OFFSET))) { Expression dy = parseExpression(null, styleJson, JSON_GRAPHIC_Y_OFFSET, Double::parseDouble); Expression dx = parseExpression(null, styleJson, JSON_GRAPHIC_X_OFFSET, Double::parseDouble); Displacement offset = this.styleBuilder.createDisplacement(dx, dy); graphic.setDisplacement(offset); } if (!StringUtils.isEmpty(styleJson.optString(JSON_ROTATION))) { final Expression rotation = parseExpression(null, styleJson, JSON_ROTATION, Double::parseDouble); graphic.setRotation(rotation); } return this.styleBuilder.createPointSymbolizer(graphic); }
JsonStyleParserHelper { @Nullable public PointSymbolizer createPointSymbolizer(final PJsonObject styleJson) { if (this.allowNullSymbolizer && !( styleJson.has(JSON_EXTERNAL_GRAPHIC) || styleJson.has(JSON_GRAPHIC_NAME) || styleJson.has(JSON_POINT_RADIUS))) { return null; } Graphic graphic = this.styleBuilder.createGraphic(); graphic.graphicalSymbols().clear(); if (styleJson.has(JSON_EXTERNAL_GRAPHIC)) { String externalGraphicUrl = validateURL(styleJson.getString(JSON_EXTERNAL_GRAPHIC)); try { final URI uri = URI.create(externalGraphicUrl); if (uri.getScheme().startsWith("http")) { final ClientHttpRequest request = this.requestFactory.createRequest(uri, HttpMethod.GET); externalGraphicUrl = request.getURI().toString(); } } catch (IOException ignored) { } final String graphicFormat = getGraphicFormat(externalGraphicUrl, styleJson); ExternalGraphic externalGraphic = null; if (externalGraphicUrl.startsWith("data:")) { try { externalGraphic = this.styleBuilder.createExternalGraphic( new URL(null, externalGraphicUrl, new Handler()), graphicFormat ); } catch (MalformedURLException e) { } } else { externalGraphic = this.styleBuilder.createExternalGraphic(externalGraphicUrl, graphicFormat); } if (externalGraphic != null) { graphic.graphicalSymbols().add(externalGraphic); } } if (styleJson.has(JSON_GRAPHIC_NAME)) { Expression graphicName = parseProperty(styleJson.getString(JSON_GRAPHIC_NAME), input -> input); Fill fill = createFill(styleJson); Stroke stroke = createStroke(styleJson, false); final Mark mark = this.styleBuilder.createMark(graphicName, fill, stroke); graphic.graphicalSymbols().add(mark); } if (graphic.graphicalSymbols().isEmpty()) { Fill fill = createFill(styleJson); Stroke stroke = createStroke(styleJson, false); final Mark mark = this.styleBuilder.createMark(DEFAULT_POINT_MARK, fill, stroke); graphic.graphicalSymbols().add(mark); } graphic.setOpacity( parseExpression(null, styleJson, JSON_GRAPHIC_OPACITY, Double::parseDouble)); if (!StringUtils.isEmpty(styleJson.optString(JSON_POINT_RADIUS))) { Expression size = parseExpression(null, styleJson, JSON_POINT_RADIUS, (final String input) -> Double.parseDouble(input) * 2); graphic.setSize(size); } else if (!StringUtils.isEmpty(styleJson.optString(JSON_GRAPHIC_WIDTH))) { Expression size = parseExpression(null, styleJson, JSON_GRAPHIC_WIDTH, Double::parseDouble); graphic.setSize(size); } if (!StringUtils.isEmpty(styleJson.optString(JSON_GRAPHIC_Y_OFFSET)) && !StringUtils.isEmpty(styleJson.optString(JSON_GRAPHIC_X_OFFSET))) { Expression dy = parseExpression(null, styleJson, JSON_GRAPHIC_Y_OFFSET, Double::parseDouble); Expression dx = parseExpression(null, styleJson, JSON_GRAPHIC_X_OFFSET, Double::parseDouble); Displacement offset = this.styleBuilder.createDisplacement(dx, dy); graphic.setDisplacement(offset); } if (!StringUtils.isEmpty(styleJson.optString(JSON_ROTATION))) { final Expression rotation = parseExpression(null, styleJson, JSON_ROTATION, Double::parseDouble); graphic.setRotation(rotation); } return this.styleBuilder.createPointSymbolizer(graphic); } }
JsonStyleParserHelper { @Nullable public PointSymbolizer createPointSymbolizer(final PJsonObject styleJson) { if (this.allowNullSymbolizer && !( styleJson.has(JSON_EXTERNAL_GRAPHIC) || styleJson.has(JSON_GRAPHIC_NAME) || styleJson.has(JSON_POINT_RADIUS))) { return null; } Graphic graphic = this.styleBuilder.createGraphic(); graphic.graphicalSymbols().clear(); if (styleJson.has(JSON_EXTERNAL_GRAPHIC)) { String externalGraphicUrl = validateURL(styleJson.getString(JSON_EXTERNAL_GRAPHIC)); try { final URI uri = URI.create(externalGraphicUrl); if (uri.getScheme().startsWith("http")) { final ClientHttpRequest request = this.requestFactory.createRequest(uri, HttpMethod.GET); externalGraphicUrl = request.getURI().toString(); } } catch (IOException ignored) { } final String graphicFormat = getGraphicFormat(externalGraphicUrl, styleJson); ExternalGraphic externalGraphic = null; if (externalGraphicUrl.startsWith("data:")) { try { externalGraphic = this.styleBuilder.createExternalGraphic( new URL(null, externalGraphicUrl, new Handler()), graphicFormat ); } catch (MalformedURLException e) { } } else { externalGraphic = this.styleBuilder.createExternalGraphic(externalGraphicUrl, graphicFormat); } if (externalGraphic != null) { graphic.graphicalSymbols().add(externalGraphic); } } if (styleJson.has(JSON_GRAPHIC_NAME)) { Expression graphicName = parseProperty(styleJson.getString(JSON_GRAPHIC_NAME), input -> input); Fill fill = createFill(styleJson); Stroke stroke = createStroke(styleJson, false); final Mark mark = this.styleBuilder.createMark(graphicName, fill, stroke); graphic.graphicalSymbols().add(mark); } if (graphic.graphicalSymbols().isEmpty()) { Fill fill = createFill(styleJson); Stroke stroke = createStroke(styleJson, false); final Mark mark = this.styleBuilder.createMark(DEFAULT_POINT_MARK, fill, stroke); graphic.graphicalSymbols().add(mark); } graphic.setOpacity( parseExpression(null, styleJson, JSON_GRAPHIC_OPACITY, Double::parseDouble)); if (!StringUtils.isEmpty(styleJson.optString(JSON_POINT_RADIUS))) { Expression size = parseExpression(null, styleJson, JSON_POINT_RADIUS, (final String input) -> Double.parseDouble(input) * 2); graphic.setSize(size); } else if (!StringUtils.isEmpty(styleJson.optString(JSON_GRAPHIC_WIDTH))) { Expression size = parseExpression(null, styleJson, JSON_GRAPHIC_WIDTH, Double::parseDouble); graphic.setSize(size); } if (!StringUtils.isEmpty(styleJson.optString(JSON_GRAPHIC_Y_OFFSET)) && !StringUtils.isEmpty(styleJson.optString(JSON_GRAPHIC_X_OFFSET))) { Expression dy = parseExpression(null, styleJson, JSON_GRAPHIC_Y_OFFSET, Double::parseDouble); Expression dx = parseExpression(null, styleJson, JSON_GRAPHIC_X_OFFSET, Double::parseDouble); Displacement offset = this.styleBuilder.createDisplacement(dx, dy); graphic.setDisplacement(offset); } if (!StringUtils.isEmpty(styleJson.optString(JSON_ROTATION))) { final Expression rotation = parseExpression(null, styleJson, JSON_ROTATION, Double::parseDouble); graphic.setRotation(rotation); } return this.styleBuilder.createPointSymbolizer(graphic); } JsonStyleParserHelper(
            @Nullable final Configuration configuration,
            @Nonnull final ClientHttpRequestFactory requestFactory,
            @Nonnull final StyleBuilder styleBuilder,
            final boolean allowNullSymbolizer); }
JsonStyleParserHelper { @Nullable public PointSymbolizer createPointSymbolizer(final PJsonObject styleJson) { if (this.allowNullSymbolizer && !( styleJson.has(JSON_EXTERNAL_GRAPHIC) || styleJson.has(JSON_GRAPHIC_NAME) || styleJson.has(JSON_POINT_RADIUS))) { return null; } Graphic graphic = this.styleBuilder.createGraphic(); graphic.graphicalSymbols().clear(); if (styleJson.has(JSON_EXTERNAL_GRAPHIC)) { String externalGraphicUrl = validateURL(styleJson.getString(JSON_EXTERNAL_GRAPHIC)); try { final URI uri = URI.create(externalGraphicUrl); if (uri.getScheme().startsWith("http")) { final ClientHttpRequest request = this.requestFactory.createRequest(uri, HttpMethod.GET); externalGraphicUrl = request.getURI().toString(); } } catch (IOException ignored) { } final String graphicFormat = getGraphicFormat(externalGraphicUrl, styleJson); ExternalGraphic externalGraphic = null; if (externalGraphicUrl.startsWith("data:")) { try { externalGraphic = this.styleBuilder.createExternalGraphic( new URL(null, externalGraphicUrl, new Handler()), graphicFormat ); } catch (MalformedURLException e) { } } else { externalGraphic = this.styleBuilder.createExternalGraphic(externalGraphicUrl, graphicFormat); } if (externalGraphic != null) { graphic.graphicalSymbols().add(externalGraphic); } } if (styleJson.has(JSON_GRAPHIC_NAME)) { Expression graphicName = parseProperty(styleJson.getString(JSON_GRAPHIC_NAME), input -> input); Fill fill = createFill(styleJson); Stroke stroke = createStroke(styleJson, false); final Mark mark = this.styleBuilder.createMark(graphicName, fill, stroke); graphic.graphicalSymbols().add(mark); } if (graphic.graphicalSymbols().isEmpty()) { Fill fill = createFill(styleJson); Stroke stroke = createStroke(styleJson, false); final Mark mark = this.styleBuilder.createMark(DEFAULT_POINT_MARK, fill, stroke); graphic.graphicalSymbols().add(mark); } graphic.setOpacity( parseExpression(null, styleJson, JSON_GRAPHIC_OPACITY, Double::parseDouble)); if (!StringUtils.isEmpty(styleJson.optString(JSON_POINT_RADIUS))) { Expression size = parseExpression(null, styleJson, JSON_POINT_RADIUS, (final String input) -> Double.parseDouble(input) * 2); graphic.setSize(size); } else if (!StringUtils.isEmpty(styleJson.optString(JSON_GRAPHIC_WIDTH))) { Expression size = parseExpression(null, styleJson, JSON_GRAPHIC_WIDTH, Double::parseDouble); graphic.setSize(size); } if (!StringUtils.isEmpty(styleJson.optString(JSON_GRAPHIC_Y_OFFSET)) && !StringUtils.isEmpty(styleJson.optString(JSON_GRAPHIC_X_OFFSET))) { Expression dy = parseExpression(null, styleJson, JSON_GRAPHIC_Y_OFFSET, Double::parseDouble); Expression dx = parseExpression(null, styleJson, JSON_GRAPHIC_X_OFFSET, Double::parseDouble); Displacement offset = this.styleBuilder.createDisplacement(dx, dy); graphic.setDisplacement(offset); } if (!StringUtils.isEmpty(styleJson.optString(JSON_ROTATION))) { final Expression rotation = parseExpression(null, styleJson, JSON_ROTATION, Double::parseDouble); graphic.setRotation(rotation); } return this.styleBuilder.createPointSymbolizer(graphic); } 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 { @Nullable public PointSymbolizer createPointSymbolizer(final PJsonObject styleJson) { if (this.allowNullSymbolizer && !( styleJson.has(JSON_EXTERNAL_GRAPHIC) || styleJson.has(JSON_GRAPHIC_NAME) || styleJson.has(JSON_POINT_RADIUS))) { return null; } Graphic graphic = this.styleBuilder.createGraphic(); graphic.graphicalSymbols().clear(); if (styleJson.has(JSON_EXTERNAL_GRAPHIC)) { String externalGraphicUrl = validateURL(styleJson.getString(JSON_EXTERNAL_GRAPHIC)); try { final URI uri = URI.create(externalGraphicUrl); if (uri.getScheme().startsWith("http")) { final ClientHttpRequest request = this.requestFactory.createRequest(uri, HttpMethod.GET); externalGraphicUrl = request.getURI().toString(); } } catch (IOException ignored) { } final String graphicFormat = getGraphicFormat(externalGraphicUrl, styleJson); ExternalGraphic externalGraphic = null; if (externalGraphicUrl.startsWith("data:")) { try { externalGraphic = this.styleBuilder.createExternalGraphic( new URL(null, externalGraphicUrl, new Handler()), graphicFormat ); } catch (MalformedURLException e) { } } else { externalGraphic = this.styleBuilder.createExternalGraphic(externalGraphicUrl, graphicFormat); } if (externalGraphic != null) { graphic.graphicalSymbols().add(externalGraphic); } } if (styleJson.has(JSON_GRAPHIC_NAME)) { Expression graphicName = parseProperty(styleJson.getString(JSON_GRAPHIC_NAME), input -> input); Fill fill = createFill(styleJson); Stroke stroke = createStroke(styleJson, false); final Mark mark = this.styleBuilder.createMark(graphicName, fill, stroke); graphic.graphicalSymbols().add(mark); } if (graphic.graphicalSymbols().isEmpty()) { Fill fill = createFill(styleJson); Stroke stroke = createStroke(styleJson, false); final Mark mark = this.styleBuilder.createMark(DEFAULT_POINT_MARK, fill, stroke); graphic.graphicalSymbols().add(mark); } graphic.setOpacity( parseExpression(null, styleJson, JSON_GRAPHIC_OPACITY, Double::parseDouble)); if (!StringUtils.isEmpty(styleJson.optString(JSON_POINT_RADIUS))) { Expression size = parseExpression(null, styleJson, JSON_POINT_RADIUS, (final String input) -> Double.parseDouble(input) * 2); graphic.setSize(size); } else if (!StringUtils.isEmpty(styleJson.optString(JSON_GRAPHIC_WIDTH))) { Expression size = parseExpression(null, styleJson, JSON_GRAPHIC_WIDTH, Double::parseDouble); graphic.setSize(size); } if (!StringUtils.isEmpty(styleJson.optString(JSON_GRAPHIC_Y_OFFSET)) && !StringUtils.isEmpty(styleJson.optString(JSON_GRAPHIC_X_OFFSET))) { Expression dy = parseExpression(null, styleJson, JSON_GRAPHIC_Y_OFFSET, Double::parseDouble); Expression dx = parseExpression(null, styleJson, JSON_GRAPHIC_X_OFFSET, Double::parseDouble); Displacement offset = this.styleBuilder.createDisplacement(dx, dy); graphic.setDisplacement(offset); } if (!StringUtils.isEmpty(styleJson.optString(JSON_ROTATION))) { final Expression rotation = parseExpression(null, styleJson, JSON_ROTATION, Double::parseDouble); graphic.setRotation(rotation); } return this.styleBuilder.createPointSymbolizer(graphic); } 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);  }