[GIS] ny way to configure MapFish config.yaml from Javascript

geoservermapfishopenlayers-2printingweb-mapping

I am using the mapfish print module in my webmapping application.In that I need to have various mapfish print layouts with different background pdf options. For that, am I need to create each config.yaml? or can we configure it from client side (from javascript)?

System: Windows XP / Tomcat7 / Geoserver 2.4.0/printing-2.1-SNAPSHOT.jar

For Example:

 #===========================================================================
 A4 portrait:
#===========================================================================
mainPage:
  pageSize: A4
  landscape: false
  rotation: true
  backgroundPdf: '${configDir}/MyCompany.pdf' #Here I need to change as per the client template

  items:    
   - !columns          
      absoluteX: 50
      absoluteY: 690
      width: 502
      config:
        borderWidth: 0.3
        cells:
          - padding: 2
      items:
        - !map
          width: 500
          height: 600

and my javascript code for layers:

    var printurl = 'http://xxx.xxx.x.xx:8080/geoserver/pdf/print.pdf?spec={' +
'"layout":"A4 portrait",' +
'"srs":"EPSG:404000",' +
'"units":"m",' +
'"dpi":300,' +
'"outputFilename": "mapPrint",' +
'"layers":[{"baseURL":"http://xxx.xxx.x.xx:8080/geoserver/cite/wms",' +
            '"opacity":1,' +
            '"singleTile":false,' +
            '"customParams":{},' +
            '"type":"WMS",' +
            '"layers":["Oxford_Map"],' +
            '"format":"image/png",' +
            '"styles":[],' +
            '"overview":true' +
          '}],' +
  '"pages":[{' +
            '"center":[' + osMap.getCenter().lon + ',' + osMap.getCenter().lat + '],' +
            '"mapTitle":"Sample Title",' +
            '"comment":"This is the map comment",' +
            '"scale":200000,' +
            '"rotation":0}' +
           ']}';

          window.open(printurl);  

Kindly suggest me the solution to achieve this. Thanks in advance

Best Answer

You can pass variable in your spec document that will be used in your configuratoin block:

http://www.mapfish.org/doc/print/configuration.html#id1

In your case, you will use the following config:

mainPage:
  pageSize: A4
  landscape: false
  rotation: true
  backgroundPdf: '${configDir}/${company}.pdf' #company is a value in the spec

Your JavaScript will simply add the company element in your spec:

      '"pages":[{' +
        '"center":[' + osMap.getCenter().lon + ',' + osMap.getCenter().lat + '],' +
        '"mapTitle":"Sample Title",' +
        '"company":"MyCompany",'+
        '"comment":"This is the map comment",' +
        '"scale":200000,' +
        '"rotation":0}' +
       ']}';
Related Question