mapfish-print icon indicating copy to clipboard operation
mapfish-print copied to clipboard

Style: External graphic in project folder fails for SLD

Open tsauerwein opened this issue 11 years ago • 1 comments

I have a point symbolizer with an external graphic, which is inside the project folder:

"layers": [
    {
      "type": "geojson",
      "geoJson": "file://resources/geojson.json",
      "style": {
        "version": "2",
        "graphicWidth": 32,
        "graphicHeight": 32,
        "*": {
          "symbolizers": [
            {
              "externalGraphic": "file://resources/marker-24.svg",
              "type": "point"
            }
          ]
        }
      }
    },

When I try to render, the style is not applied and I see the following in the logs:

16:33:16.744 [ForkJoinPool-1-worker-1] DEBUG o.m.p.h.ConfigFileResolvingHttpRequestFactory - Executing http request: file:/home/tsauerwein/projects/mapfish-printV3/examples/%7B%22graphicWidth%22:32,%22*%22:%7B%22symbolizers%22:%5B%7B%22externalGraphic%22:%22file:/resources/marker-24.svg%22,%22type%22:%22point%22%7D%5D%7D,%22graphicHeight%22:32,%22version%22:%222%22%7D
16:33:16.786 [ForkJoinPool-1-worker-1] DEBUG o.m.print.map.style.StyleParser - Loaded style from: 

 '{"graphicWidth":32,"*":{"symbolizers":[{"externalGraphic":"file://resources/marker-24.svg","type":"point"}]},"graphicHeight":32,"version":"2"}': 

<?xml version="1.0" encoding="UTF-8"?><sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" version="1.0.0"><sld:UserLayer><sld:LayerFeatureConstraints><sld:FeatureTypeConstraint/></sld:LayerFeatureConstraints><sld:UserStyle><sld:Name>Default Styler</sld:Name><sld:FeatureTypeStyle><sld:Name>name</sld:Name><sld:Rule><sld:MinScaleDenominator>4.9E-324</sld:MinScaleDenominator><sld:MaxScaleDenominator>1.7976931348623157E308</sld:MaxScaleDenominator><sld:PointSymbolizer><sld:Graphic><sld:ExternalGraphic><sld:OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="file://resources/marker-24.svg"/><sld:Format>image/svg</sld:Format></sld:ExternalGraphic><sld:Size>32.0</sld:Size></sld:Graphic></sld:PointSymbolizer></sld:Rule></sld:FeatureTypeStyle></sld:UserStyle></sld:UserLayer></sld:StyledLayerDescriptor>

The URL for the HTTP request to fetch the file is completely wrong.

(Using an absolute URL works fine.)

tsauerwein avatar Oct 17 '14 14:10 tsauerwein

For the JSON style definition the file path has to be given without the file://:

{
  "version": "2",
  "*": {
    "symbolizers": [
      {
        "externalGraphic": "marker.png",
        "graphicWidth": 32,
        "graphicOpacity" : 1.0,
        "graphicFormat" : "image/png",
        "type": "point"
      }
    ]
  }
}

But when the style is given as SLD it does not work neither with file:// nor without. The problem is that the ConfigFileResolvingHttpRequestFactory is not used from GeoTools to request the graphic. A possible solution would be to create a StyleVisitor which visits ExternalGraphic (similar to the OpacitySettingStyleVisitor) and replaces relative paths with absolute paths (while checking that the given file is inside the config folder).

tsauerwein avatar Feb 25 '15 13:02 tsauerwein