2012-09-27 150 views
3

如何從OpenLayers打印地圖?我想在我的OpenLayers頁面中添加打印按鈕=)我的地圖服務器有MapFish擴展,但不知道如何向它發出請求。歡迎任何其他想法)請幫助。OpenLayers打印地圖

+0

http://openlayers.org/en/latest/examples/export-pdf.html –

回答

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}]} 
+0

我做但是並不是所有的東西都可以工作,Geoserver和與他合作的網站使用不同的服務VERS。代理已配置,但不返回到create.json pdf文件。可能是什麼問題? – iGriffer

+0

Geoserver打印模塊安裝是否正確?試試'http:// {geoserver_url}:8080/geoserver/pdf/info.json'; – winsent

+0

是的,它完美的工作。但是http:// {geoserver_url}:8080/geoserver/pdf/create.json返回:「生成PDF時出錯: 未知方法:/create.json」 – iGriffer

3

我不得不使用反向代理類似的問題,因爲我發現答案從info.json contais本地IP參考,而不是公共URL

殘忍地解決我更換了IP referenze與公衆網址在Ajax請求(見下面的代碼。我希望它可以是有用的人......

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); 
    } 
});