当前位置: 动力学知识库 > 问答 > 编程问答 >

printing - OpenLayers print map

问题描述:

How can I print a map from the OpenLayers? I want to add print button in my OpenLayers page =) I have MapFish extension for my geoserver, but don`t know how to make request to it. Any other ideas are welcome) Help please.

网友答案:

The simplest way is to use GeoExt.PrintMapPanel (geoext example). And be sure to read GeoServer Printing Module.

UPD GET request example. You must modify url, "baseURL", "layers". If you specify an existing layer, this request must return pdf file.

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}]}
网友答案:

I had a similar problem using a reverse proxy, because I discovered the answer from info.json contais local ip reference instead of the public url

to solve brutally i replaced the ip referenze with the public url in the ajax request (see the following code. I hope it can be usefull for others...

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);
  }
});
分享给朋友:
您可能感兴趣的文章:
随机阅读: