protocol.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. .. _print_protocol:
  2. Protocol
  3. ********
  4. Four commands are available and are documented in the next sections.
  5. Every command uses the HTTP status code to notify errors.
  6. .. note:: Warranty disclaimer and license
  7. The authors provide these documents "AS-IS", without warranty of any kind
  8. either expressed or implied.
  9. Document under `Creative Common License Attribution-Share Alike 2.5 Generic
  10. <http://creativecommons.org/licenses/by-sa/2.5/>`_.
  11. Authors: MapFish developers.
  12. info.json
  13. ---------
  14. HTTP command::
  15. GET {PRINT_URL}/info.json?url={PRINT_URL}%2Finfo.json&var=printConfig
  16. Returns a JSON structure as such:
  17. .. code-block:: javascript
  18. var printConfig = {
  19. "scales":[
  20. {"name":"25000"},
  21. {"name":"50000"},
  22. {"name":"100000"}
  23. ],
  24. "dpis":[
  25. {"name":"190"},
  26. {"name":"254"}
  27. ],
  28. "outputFormats":[
  29. {"name":"pdf"},
  30. {"name":"png"}
  31. ],
  32. "layouts":[
  33. {
  34. "name":"A4 portrait",
  35. "map":{
  36. "width":440,
  37. "height":483
  38. }
  39. }
  40. ],
  41. "printURL":"http:\/\/localhost:5000\/print\/print.pdf",
  42. "createURL":"http:\/\/localhost:5000\/print\/create.json"
  43. }
  44. This can be loaded through an HTML script tag like that::
  45. <script type="text/javascript"
  46. src="http://localhost:5000/print/info.json?var=printConfig"></script>
  47. or through an AJAX request, in this case the ``var`` query parameter will be
  48. omitted.
  49. The "url" query parameter is here to help the print servlet to know what URL is used by the browser to access the servlet. This parameter is here because the servlet can be behind a proxy, hiding the real URL.
  50. print.pdf
  51. ---------
  52. HTTP command::
  53. GET {PRINT_URL}/print.pdf?spec={SPEC}
  54. or
  55. POST {PRINT_URL}/print.pdf with {SPEC} in the request body
  56. The "SPEC" parameter is a JSON structure like that:
  57. .. code-block:: javascript
  58. {
  59. layout: 'A4 portrait',
  60. ...CUSTOM_PARAMS...
  61. srs: 'EPSG:4326',
  62. units: 'degrees',
  63. geodetic: false,
  64. outputFilename: 'political-boundaries',
  65. outputFormat: 'pdf',
  66. mergeableParams: {
  67. cql_filter: {
  68. defaultValue: 'INCLUDE',
  69. separator: ';',
  70. context: 'http://labs.metacarta.com/wms/vmap0'
  71. }
  72. },
  73. layers: [
  74. {
  75. type: 'WMS',
  76. layers: ['basic'],
  77. baseURL: 'http://labs.metacarta.com/wms/vmap0',
  78. format: 'image/jpeg'
  79. }
  80. ],
  81. pages: [
  82. {
  83. center: [6, 45.5],
  84. scale: 4000000,
  85. dpi: 190,
  86. geodetic: false,
  87. strictEpsg4326: false,
  88. ...CUSTOM_PARAMS...
  89. }
  90. ],
  91. legends: [
  92. {
  93. classes: [
  94. {
  95. icons: [
  96. 'full url to the image'
  97. ],
  98. name: 'an icon name',
  99. iconBeforeName: true
  100. }
  101. ],
  102. name: 'a class name'
  103. }
  104. ]
  105. }
  106. The location to show on the map can be specified with a **center** and a **scale** as show or with a **bbox** like that::
  107. bbox: [5, 45, 6, 46]
  108. The print module will use the nearest scale and will make sure the aspect ratio stays correct.
  109. The geodetic parameter can be set to true so the scale of geodetic layers can correctly be calculated. Certain projections (Google and Latlong for example) are based on a spheroid and therefore require **geodetic: true** in order to correctly calculate the scale. If the geodetic parameter is not present it will be assumed to be false.
  110. The **optional** strictEpsg4326 parameter can be set to true to control how EPSG:4326 is interpreted. This needs to be true for WMS version 1.3.0 GetMap requests. See https://www.google.ch/search?q=epsg+4326+latitude+longitude+order&oq=epsg+4326+&aqs=chrome.3.69i57j0l5.5996j0j4&sourceid=chrome&espv=210&es_sm=93&ie=UTF-8 for some links to the history and mess that is EPSG:4326.
  111. The outputFilename parameter is optional and if omitted the values used in the server's configuration will be used instead. If it is present it will be the name of the downloaded file. The suffix will be added if not left off in the parameter. The date can be substituted into the filename as well if desired. See configuration's outputFilename for more information and examples
  112. The outputFormat parameter is optional and if omitted the value 'pdf' will be used. Only the formats returned in the info are permitted.
  113. There are two locations where custom parameters can be added. Those will be ignored by the web service but, will be accessible from the layout templates.
  114. Some layer types support merging more layers request into one, when the server is the same (for example WMS). For those, a mergeableParams section can be used to define merging strategies for some custom parameters.
  115. The default rule is to merge layers with identical custom parameters. Using mergeableParams, defined parameters values can be joined using a given separator and a default value if some of the layers miss the parameter.
  116. Mergeable parameters can have a context, that is the baseURL they can be used for (if not defined they will be used for every layer).
  117. For the format of the **layers** section, please look at the implementations pointed by mapfish.PrintProtocol.SUPPORTED_TYPES.
  118. This command returns the PDF file directly.
  119. create.json
  120. -----------
  121. HTTP command::
  122. POST {PRINT_URL}/create.json?url={PRINT_URL}%2Fcreate.json
  123. The spec defined in the "print.pdf" command must be included in the POST body.
  124. Returns a JSON structure like that:
  125. .. code-block:: javascript
  126. {
  127. getURL: 'http:\/\/localhost:5000\/print\/56723.pdf'
  128. }
  129. The URL returned can be used to retrieve the PDF file. See the next section.
  130. {ID}.pdf
  131. --------
  132. This command's URL is returned by the "create.json" command.
  133. HTTP command::
  134. GET {PRINT_URL}/{ID}.pdf
  135. Returns the PDF. Can be called only during a limited time since the server side temporary file is deleted afterwards.
  136. Multiple maps on a single page
  137. ******************************
  138. To print more than one map on a single page you need to:
  139. * specify several map blocks in a page of the yaml file, each with a distinct name property value
  140. * use a particular syntax in the spec to bind different rendering properties to each map block
  141. This is possible specifying a **maps** object in spec root object with a distinct key - object pair for each map. The
  142. key will refer the map block name as defined in yaml file. The object will contain layers and srs for the named map.
  143. Another **maps** object has to be specified inside the page object to describe positioning, scale and so on.
  144. .. code-block:: javascript
  145. {
  146. ...
  147. maps: {
  148. "main": {
  149. layers: [
  150. ...
  151. ],
  152. srs: 'EPSG:4326'
  153. },
  154. "other": {
  155. layers: [
  156. ...
  157. ],
  158. srs: 'EPSG:4326'
  159. }
  160. },
  161. ...
  162. pages: [
  163. {
  164. maps: {
  165. "main": {
  166. center: [6, 45.5],
  167. scale: 4000000,
  168. dpi: 190,
  169. geodetic: false,
  170. strictEpsg4326: false,
  171. ...CUSTOM_PARAMS...
  172. },
  173. "other": {
  174. center: [7.2, 38.6],
  175. scale: 1000000,
  176. dpi: 300,
  177. geodetic: false,
  178. strictEpsg4326: false,
  179. ...CUSTOM_PARAMS...
  180. }
  181. }
  182. }
  183. ],
  184. ...
  185. }
  186. Other config blocks have been enabled to multiple maps usage.
  187. The scalebar block can be bound to a specific map, specifying a name property that matches the map
  188. name.
  189. Also, in text blocks you can use the ${scale.<mapname>} placeholder to print the scale of the map
  190. whose name is <mapname>.
  191. Layers Params
  192. *************
  193. Vector
  194. ------
  195. Type: vector
  196. Render vector layers. The geometries and the styling comes directly from the spec JSON.
  197. * opacity (Defaults to ``1.0``)
  198. * geoJson (Required) the geoJson to render
  199. * styleProperty (Defaults to '_style') Name of the property within the features to use as style name. The given property may contain a style object directly.
  200. * styles (Optional) dictionary of styles. One style is defined as in OpenLayers.Feature.Vector.style.
  201. * name (Defaults to ``vector``) the layer name. (deprecated: use pdfLayerName instead)
  202. * pdfLayerName (Defaults to ``vector``) PDF layer name.
  203. WMS
  204. ---
  205. Type: wms
  206. Support for the WMS protocol with possibilities to go through a WMS-C service (TileCache).
  207. * opacity (Defaults to ``1.0``)
  208. * baseURL (Required) Service URL
  209. * customParams (Optional) Map, additional URL arguments
  210. * layers (Required)
  211. * styles (Optional)
  212. * format (Required)
  213. * version (Defaults to ``1.1.1``)
  214. * useNativeAngle (Defaults to false) it true transform the map angle to customParams.angle for GeoServer, and customParams.map_angle for MapServer.
  215. * pdfLayerName (Defaults to stringify layers field comma separated) PDF layer name.
  216. WMTS
  217. ----
  218. Type: wmts
  219. Support for the protocol using directly the content of a WMTS tiled layer, support REST or KVP.
  220. Two possible mode, standard or simple, the simple mode imply that all the topLeftCorner are identical.
  221. Standard mode:
  222. * opacity (Defaults to 1.0)
  223. * baseURL the 'ResourceURL' available in the WMTS capabilities.
  224. * customParams (Optional) Map, additional URL arguments
  225. * layer (Required) the layer name
  226. * version (Defaults to ``1.0.0``) WMTS protocol version
  227. * requestEncoding (Defaults to ``REST``) ``REST`` or ``KVP``
  228. * style (Optional) the style name
  229. * dimensions (Optional) list of dimensions names
  230. * params (Optional) dictionary of dimensions name (capital) => value
  231. * matrixSet (Required) the name of the matrix set
  232. * matrixIds (Required) array of matrix ids e.g.:
  233. .. code-block:: javascript
  234. [{
  235. "identifier": "0",
  236. "matrixSize": [1, 1],
  237. "resolution": 4000,
  238. "tileSize": [256, 256],
  239. "topLeftCorner": [420000, 350000]
  240. }, ...]
  241. * format (Optional, Required id requestEncoding is ``KVP``)
  242. * pdfLayerName (Defaults to layer field) PDF layer name.
  243. Simple mode:
  244. * baseURL base URL without the version.
  245. * layer (Required)
  246. * version (Required)
  247. * requestEncoding (Required) ``REST``
  248. * tileOrigin (Required)
  249. * tileSize (Required)
  250. * extension (Required)
  251. * resolutions (Required)
  252. * style (Required)
  253. * tileFullExtent (Required)
  254. * zoomOffset (Required)
  255. * dimensions (Optional)
  256. * params (Optional)
  257. * formatSuffix (Required)
  258. Tms
  259. ---
  260. Type: tms
  261. Support the TMS tile layout.
  262. * opacity (Defaults to 1.0)
  263. * baseURL (Required) Service URL
  264. * customParams (Optional) Map, additional URL arguments
  265. * maxExtent (Required) Array, extent coordinates ``[420000, 30000, 900000, 350000]``
  266. * tileSize (Required) Array, tile size e.g. ``[256, 256]``
  267. * format (Required)
  268. * layer (Required)
  269. * resolutions (Required) Array of resolutions
  270. * tileOrigin (Optional) Object, tile origin. Defaults to ``0,0``
  271. * pdfLayerName (Defaults to layer field) PDF layer name.
  272. Resources:
  273. * Quick intro to TMS requests: http://geowebcache.org/docs/current/services/tms.html
  274. * TMS Spec (Not an Official Standard): http://wiki.osgeo.org/wiki/Tile_Map_Service_Specification
  275. Xyz
  276. ---
  277. Type: xyz
  278. Support the tile layout z/x/y.<extension>.
  279. * opacity (Defaults to 1.0)
  280. * baseURL (Required) Service URL
  281. * customParams (Optional) Map, additional URL arguments
  282. * maxExtent (Required) Array, extent coordinates ``[420000, 30000, 900000, 350000]``
  283. * tileSize (Required) Array, tile size e.g. ``[256, 256]``
  284. * resolutions (Required) Array of resolutions (Required) Array of resolutions
  285. * extension (Required) file extension (Required) file extension
  286. * tileOrigin (Optional) Array, tile origin e.g. ``[420000, 350000]``
  287. * tileOriginCorner ``tl`` or ``bl`` (Defaults to ``bl``)
  288. * path_format (Optional) url fragment used to construct the tile location. Can support variable replacement of ``${x}``, ``${y}``, ``${z}`` and ``${extension}``. Defaults to zz/x/y.extension format. You can use multiple "letters" to indicate a replaceable pattern (aka, ``${zzzz}`` will ensure the z variable is 0 padded to have a length of AT LEAST 4 characters).
  289. * pdfLayerName (Defaults to "t") PDF layer name.
  290. Osm
  291. ---
  292. Type: osm
  293. Support the OSM tile layout.
  294. * opacity (Defaults to ``1.0``)
  295. * baseURL (Required) Service URL
  296. * customParams (Optional) Map, additional URL arguments
  297. * maxExtent (Required) Array, extent coordinates ``[420000, 30000, 900000, 350000]``
  298. * tileSize (Required) Array, tile size e.g. ``[256, 256]``
  299. * resolutions (Required) Array of resolutions
  300. * extension (Required) file extension
  301. * pdfLayerName (Defaults to "t") PDF layer name.
  302. TileCache
  303. ---------
  304. Type: tileCache
  305. Support for the protocol using directly the content of a TileCache directory.
  306. * opacity (Defaults to ``1.0``)
  307. * baseURL (Required) Service URL
  308. * customParams (Optional) Map, additional URL arguments
  309. * layer (Required)
  310. * maxExtent (Required) Array, extent coordinates ``[420000, 30000, 900000, 350000]``
  311. * tileSize (Required) Array, tile size e.g. ``[256, 256]``
  312. * resolutions (Required) Array of resolutions
  313. * extension (Required) file extension
  314. * pdfLayerName (Defaults to layer field) PDF layer name.
  315. Image
  316. -----
  317. Type: image
  318. * opacity (Defaults to ``1.0``)
  319. * name (Required)
  320. * baseURL (Required) Service URL
  321. * extent (Required)
  322. * pdfLayerName (Defaults to name field) PDF layer name.
  323. MapServer
  324. ---------
  325. Type: mapServer
  326. Support mapserver WMS server.
  327. * opacity (Defaults to ``1.0``)
  328. * baseURL (Required) Service URL
  329. * customParams (Optional) Map, additional URL arguments
  330. * layers (Required)
  331. * format (Required)
  332. * pdfLayerName (Defaults to stringify layers field comma separated) PDF layer name.
  333. KaMap
  334. -----
  335. Type: kaMap
  336. Support for the protocol using the KaMap tiling method
  337. * opacity (Defaults to ``1.0``)
  338. * baseURL (Required) Service URL
  339. * customParams (Optional) Map, additional URL arguments
  340. * map
  341. * group
  342. * maxExtent (Required) Array, extent coordinates ``[420000, 30000, 900000, 350000]``
  343. * tileSize (Required) Array, tile size e.g. ``[256, 256]``
  344. * resolutions (Required) Array of resolutions
  345. * extension (Required) file extension
  346. * pdfLayerName (Defaults to map field) PDF layer name.
  347. KaMapCache
  348. ----------
  349. Type: kaMapCache
  350. Support for the protocol talking directly to a web-accessible ka-Map cache generated by the precache2.php script.
  351. * opacity (Defaults to ``1.0``)
  352. * baseURL (Required) Service URL
  353. * customParams (Optional) Map, additional URL arguments
  354. * map (Required)
  355. * group (Required)
  356. * metaTileWidth (Required)
  357. * metaTileHeight (Required)
  358. * units (Required)
  359. * maxExtent (Required) Array, extent coordinates ``[420000, 30000, 900000, 350000]``
  360. * tileSize (Required) Array, tile size e.g. ``[256, 256]``
  361. * resolutions (Required) Array of resolutions
  362. * extension (Required) file extension
  363. * pdfLayerName (Defaults to map field) PDF layer name.
  364. Google
  365. ------
  366. Type: google or tiledGoogle
  367. They used the Google Map Static API, tiledGoogle will create tiles and google only one image.
  368. The google map reader has several custom parameters that can be added to the request they are:
  369. * opacity (Optional, Defaults to ``1.0``)
  370. * baseURL (Required, should be 'http://maps.google.com/maps/api/staticmap')
  371. * customParams (Optional) Map, additional URL arguments
  372. * maxExtent (Required, should be ``[-20037508.34, -20037508.34, 20037508.34, 20037508.34]``)
  373. * resolutions (Required, should be ``[156543.03390625, 78271.516953125, 39135.7584765625, 19567.87923828125, 9783.939619140625, 4891.9698095703125, 2445.9849047851562, 1222.9924523925781, 611.4962261962891, 305.74811309814453, 152.87405654907226, 76.43702827453613, 38.218514137268066, 19.109257068634033, 9.554628534317017, 4.777314267158508, 2.388657133579254, 1.194328566789627, 0.5971642833948135, 0.29858214169740677, 0.14929107084870338, 0.07464553542435169]``)
  374. * extension (Required, should be ``png``)
  375. * client (Optional)
  376. * format (Optional)
  377. * maptype (Required) - type of map to display: http://code.google.com/apis/maps/documentation/staticmaps/#MapTypes
  378. * sensor (Optional) - specifies whether the application requesting the static map is using a sensor to determine the user's location
  379. * language (Optional) - language of labels.
  380. * pdfLayerName (Defaults to "t") PDF layer name.
  381. * markers (Optional) - add markers to the map: http://code.google.com/apis/maps/documentation/staticmaps/#Markers
  382. .. code-block:: javascript
  383. markers: ['color:blue|label:S|46.5195933305192,6.566684726913701']
  384. * path (Optional) - add a path to the map: http://code.google.com/apis/maps/documentation/staticmaps/#Paths
  385. .. code-block:: javascript
  386. path: 'color:0x0000ff|weight:5|46.5095933305192,6.506684726913701|46.5195933305192,6.526684726913701|46.5395933305192,6.536684726913701|46.5695933305192,6.576684726913701',
  387. Warranty disclaimer and license
  388. -------------------------------
  389. The authors provide these documents "AS-IS", without warranty of any kind
  390. either expressed or implied.
  391. Document under `Creative Common License Attribution-Share Alike 2.5 Generic
  392. <http://creativecommons.org/licenses/by-sa/2.5/>`_.
  393. Authors: MapFish developers.