OpenLayers打印地图

时间:2012-09-27 12:32:18

标签: printing map openlayers geoserver

如何从OpenLayers打印地图?我想在我的OpenLayers页面中添加打印按钮=)我的geoserver有MapFish扩展,但不知道如何向它发出请求。欢迎任何其他想法)请帮助。

2 个答案:

答案 0 :(得分:3)

我在使用反向代理时遇到了类似的问题,因为我发现了info.json的答案,包括本地ip引用而不是公共网址

粗暴地解决我用ajax请求中的公共URL替换ip referenze(参见下面的代码。我希望它对其他人有用...

this.capabilities.createURL = this.capabilities.createURL.replaceAll("192.168.0.0:8080", "mypublicurl");
this.capabilities.printURL= this.capabilities.printURL.replaceAll("192.168.0.0:8080", "mypublicurl");


Ext.Ajax.request({
    url:this.capabilities.createURL,
    jsonData:jsonData,
    success:function(response){
        response.responseText = response.responseText.replaceAll("192.168.0.0:8080", "mypublicurl");
        window.open(Ext.decode(response.responseText).getURL);
  }
});

答案 1 :(得分:1)

最简单的方法是使用GeoExt.PrintMapPanel(geoext example)。请务必阅读GeoServer Printing Module

UPD GET请求示例。您必须修改网址,“baseURL”,“图层”。如果指定现有图层,则此请求必须返回pdf文件。

http://demo.opengeo.org/geoserver/pdf/print.pdf?spec={"units":"degrees","srs":"EPSG:4326","layout":"A4","dpi":75,"mapTitle":"Printing Demo","comment":"This is a simple map printed from GeoExt.","layers":[{"baseURL":"http://demo.opengeo.org/geoserver/wms","opacity":1,"singleTile":true,"type":"WMS","layers":["topp:tasmania_state_boundaries"],"format":"image/jpeg","styles":[""]}],"pages":[{"center":[146.56000000001,-41.56],"scale":8192000,"rotation":0}]}