3

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

4

2 回答 2

3

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

为了残酷地解决,我用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);
  }
});
于 2012-11-09T08:30:36.847 回答
1

最简单的方法是使用 GeoExt.PrintMapPanel(geoext 示例)。并且一定要阅读GeoServer Printing Module

UPD GET 请求示例。您必须修改 url、“baseURL”、“layers”。如果您指定现有层,则此请求必须返回 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}]}
于 2012-10-04T08:14:02.487 回答