I’ve had a couple of other posts (1 and 2 and 3 and) on simple clients for MapFish. I like the client server infrastructure for MapFish– with the client end of things built up in GeoExt, it makes for a really elegant combo. But I’d like articulate my vision for simple clients for MapFish a little further. One thing that seems quite feasible is to embed the JSON for the MapFish requests in a PostgreSQL table. Why there and not just within our client? Well, we can use PostGIS to construct really clever multi-page prints if we want to, build into PostGIS the logic to decide the orientation, number of pages, scale, and other information needed to decide how best to print this object, and we can access that JSON through a GetFeatureInfo Request through any WMS compliant server (e.g. GeoServer). In this way, we can use the GetFeatureInfo bubble as a place where we have links (enhanced with a little javascript) to post the JSON to our MapFish service and return a PDF.
Any object we want exposed through our interface could have a link associated with it that generates a pdf map of that object. Let’s start with the functionality we want in our PostgreSQL function and figure out what it needs to generate the JSON we want. Here’s what we want our JSON to look like, at least for a very simple example:
{ "units" : "ft", "srs" : "EPSG:3734", "layout" : "1) LETTER 8.5x11 Portrait", "dpi" : 300, "serviceParams" : { "locale" : "en_US" }, "resourcesUrl" : "http://maps/geoserver/www/printing", "layersMerging" : true, "preferredIntervalFractions" : [0.1, 0.2, 0.4], "metaTitle" : "Title Here Please! GIS Print", "metaAuthor" : "Title Here Please!", "metaSubject" : "Title Here Please! GIS Print", "metaKeywords" : "", "outputFilename" : "cm_gis", "legends" : [], "layers" : [{ "baseURL" : "http://maps/geoserver/wms?", "opacity" : 1, "singleTile" : false, "type" : "WMS", "layers" : ["cuy_bridge_decks", "planet_osm_line_outside_cuy_map", "cuy_roads_poly", "cuy_street_centerlines", "reservation_bounds_solid"], "format" : "image/png", "styles" : [""], "customParams" : { "TILED" : "false", "TRANSPARENT" : true } } ], "pages" : [{ "center" : [2160649.7795275, 597547.8687664], "scale" : 6000, "rotation" : 0, "mapTitle" : "Title Here Please!" } ] }
As a starting point, we can split this into two sections, the global parameters, i.e. everything except “pages” (pages is what we want postgis to calculate for us). In the most generic sense, we would want to pass all of the parameters in the global section to the function, plus the geometry of the object over which we want to print the extent, plus the actual print size of the printable area for the desired layout have it return the json, with a population of pages section done by a little PostGIS magic. PL/pgSQL to come… .