1

I'm trying to configure printing from the map view in GeoNetwork 3.0.x. This seems to use MapFish version 2.1.1 (if Maven is to be believed). I have a REST WMTS layer that (after I've modified PrintMapService.js to pass the encoding correctly) seems to produce a reasonable config.json header:

{"layout":"A4 landscape","srs":"EPSG:27700","units":"m","rotation":0,"lang":"en","dpi":"190",
   "layers":[{
      "layer":"os_background_bng_colour",
      "opacity":1,
      "type":"WMTS",
      "baseURL":"https://xxx.xxxx.co.uk/services/xxxxxxx/wmts/os_background_bng_colour/{style}/{TileMatrixSet}/{TileMatrix}/{TileCol}/{TileRow}.png",
      "version":"1.0.0",
      "requestEncoding":"REST",
      "format":"image/png",
      "customParams":{},
      "style":"default",
      "matrixSet":"scotland_bng",
      "matrixIds":[{"identifier":"00","resolution":1000,"tileSize":[256,256],"topLeftCorner":[0,1300000],"matrixSize":[156.54303392804096,156.54303392804096]},....],
      "enableLegends":true,
      "pages":[{"center":[301200,743200],
      "scale":"500000.0",
      "dataOwner":"© ",
      "rotation":0,
      "comment":"",
      "title":"",
      "langen":true}
     ]
}

This gives me an error in the response:

org.mapfish.print.InvalidJsonValueException: spec.layers[0].baseURL has an invalid value: https://xxxx.xxxx.co.uk/services/xxxxxxx/wmts/os_background_bng_colour/{style}/{TileMatrixSet}/{TileMatrix}/{TileCol}/{TileRow}.png (Illegal character in path at index 98: https://xxxx.xxxxx.co.uk/services/xxxxxxx/wmts/os_background_bng_colour/{style}/{TileMatrixSet}/{TileMatrix}/{TileCol}/{TileRow}.png)
    at org.mapfish.print.map.readers.HTTPMapReader.<init>(HTTPMapReader.java:73)
    at org.mapfish.print.map.readers.TileableMapReader.<init>(TileableMapReader.java:42)
    at org.mapfish.print.map.readers.WMTSMapReader.<init>(WMTSMapReader.java:90)
    at org.mapfish.print.map.readers.WMTSMapReader.<init>(WMTSMapReader.java:40)
    at org.mapfish.print.map.readers.WMTSMapReader$Factory.create(WMTSMapReader.java:68)
    at org.mapfish.print.map.readers.MapReaderFactoryFinder.create(MapReaderFactoryFinder.java:36)
    at org.mapfish.print.map.MapChunkDrawer.renderImpl(MapChunkDrawer.java:129)
    at org.mapfish.print.ChunkDrawer.render(ChunkDrawer.java:55)
    at org.mapfish.print.config.layout.MapBlock$1.render(MapBlock.java:77)
    at org.mapfish.print.PDFCustomBlocks.addAbsoluteDrawer(PDFCustomBlocks.java:183)
    at org.mapfish.print.config.layout.MapBlock.render(MapBlock.java:73)
    at org.mapfish.print.config.layout.Page.render(Page.java:73)
    at org.mapfish.print.config.layout.MainPage.render(MainPage.java:63)
    at org.mapfish.print.config.layout.Layout.render(Layout.java:59)
    at org.mapfish.print.output.AbstractOutputFormat.doPrint(AbstractOutputFormat.java:30)
    at org.mapfish.print.output.PdfOutputFactory.print(PdfOutputFactory.java:58)
    at org.mapfish.print.MapPrinter.print(MapPrinter.java:173)
    at org.mapfish.print.servlet.MapPrinterServlet.doCreatePDFFile(MapPrinterServlet.java:367)
    at org.mapfish.print.servlet.MapPrinterServlet.createPDF(MapPrinterServlet.java:184)
    at org.mapfish.print.servlet.MapPrinterServlet.doPost(MapPrinterServlet.java:112)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.fao.geonet.monitor.webapp.WebappMetricsFilter.doFilter(WebappMetricsFilter.java:96)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.fao.geonet.monitor.webapp.MetricsRegistryInitializerFilter.doFilter(MetricsRegistryInitializerFilter.java:31)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)
    at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
    at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
    at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:381)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:186)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)
    at jeeves.config.springutil.JeevesDelegatingFilterProxy.doFilter(JeevesDelegatingFilterProxy.java:64)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:610)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

This seems to be because { is not a valid character in an URI - but if I leave these elements off the end of the base URL I get a PDF back which has a scale bar but a note saying "Null Pointer Exception" in it.

The docs are a little vague on what should go in the baseURL.

has anyone managed to print a WMTS layer in MapFish v2?

1

After some time with the debugger and the mapfish code base I have managed to print a WMTS baselayer using the REST protocol.

First I had to modify components/common/map/print/PrintMapService.js to include the required optional parameters that MapFish wanted, (around line 300) - I added dimensions and customParams (I left them empty) and changed requestEncoding to look up the required encoding.

    angular.extend(enc, {
        type: 'WMTS',
        baseURL: url,
        layer: source.getLayer(),
        version: source.getVersion(),
        requestEncoding: source.getRequestEncoding() || 'KVP',
        format: source.getFormat(),
        customParams: {},
        style: source.getStyle(),
        dimensions: [],
        matrixSet: matrixSet,
        matrixIds: matrixIds
      });

I also had to fake out the baseURL in the config.js file as MapFish needs it to be URLEncoded (so { becomes %7B and } becomes %7D) but OpenLayers3 seems unable to handle this when it tries to draw the map on screen (sigh!). So I added a new URL field to the ol.layer.tile which was encoded and left the url in the ol.source.WMTS unencoded. To handle this in MapFish I modified line 289 of components/common/map/print/PrintMapService.js to be

      /*var url = layer instanceof ol.source.WMTS ?
          layer.getSource().getUrl() :
          layer.getSource().getUrls()[0];*/
      var url = layer.get('url');

so it picks up the urlencoded version.

The next step is to stop MapFish trying to fetch the Capabilities document from the tile URL (my WMTS server doesn't seem to support a getcapabilities request - I suspect it's broken). All that is needed is to set the (undocumented) ignoreCapabilities variable to true in the print-config.yaml file, just add the following line:

ignoreCapabilities: true

The final issue I ran into is that my map tiles are served over https and MapFish was having an issue with security certificate lookups. I solved this by switching the the "printing" url to use http while the OpenLayers tiles continued to get the tiles via https.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.