首页 文章

OL3和geoserver打印模块,OSM作为背景图层

提问于
浏览
1

我有一个在OL3和geoserver中构建的应用程序 . 我在我的应用程序中使用bootstrap和jQuery .

我正在尝试以pdf格式打印 Map . 我在我的应用程序中将OSM作为基础层,其他层来自我的本地地理服务器 .

现在我有一种情况需要在pdf中打印我的 Map (包含所有可见图层和OSM图层) .

我已经在我的地理服务器中安装了打印插件并且工作正常我已经使用以下代码测试了我的打印模块:

http://localhost:8080/geoserver/pdf/print.pdf?spec={
    "layout":"A4 portrait",
    "srs":"EPSG:4326",
    "units":"degrees",
    "dpi":300,
    "outputFilename": "map",
    "mapTitle":"This is the map title",
    "layers":[
    {
        "baseURL":"http://localhost:8080/geoserver/genesis/wms",
        "opacity":0.5,
        "singleTile":false,
        "type":"WMS",
        "layers":["District_Boundary", "DevelopmentRegions"],
        "format":"image/png",
        "styles":[]
    } 
    ],
    "pages":[
    {
        "center":[84.25,28.1],
        "mapTitle":"",
        "comment":"",
        "scale":4000000,
        "rotation":0
    }
    ] }

但问题是如何打印我的OSM层?我没有在我的应用程序中使用Extjs所以我不想仅仅用于我的打印功能 .

任何人都可以建议我应该如何处理jQuery和bootstrap以及没有Extjs的普通javascript?

谢谢 .

2 回答

  • 1

    您只需要将osm作为另一层添加到您的请求有效负载中

    http://localhost:8080/geoserver/pdf/print.pdf?spec={
        "layout":"A4 portrait",
        "srs":"EPSG:4326",
        "units":"degrees",
        "dpi":300,
        "outputFilename": "map",
        "mapTitle":"This is the map title",
        "layers":[
           {  
             "baseURL":"http://a.tile.openstreetmap.org",
             "maxExtent":[  
                //your extent of map in the correct projection
             ],
             "tileSize":[  
                256,
                256
             ],
             "extension":"png",
             "type":"OSM",
             "opacity":1
          },{
            "baseURL":"http://localhost:8080/geoserver/genesis/wms",
            "opacity":0.5,
            "singleTile":false,
            "type":"WMS",
            "layers":["District_Boundary", "DevelopmentRegions"],
            "format":"image/png",
            "styles":[]
        }
        ],
        "pages":[
        {
            "center":[84.25,28.1],
            "mapTitle":"",
            "comment":"",
            "scale":4000000,
            "rotation":0
        }
        ] }
    

    您需要根据需要更改范围

    一旦发送请求,Geoserver将填充osm磁贴并将其放在 Map 上

    请注意,您应该将osm图层放在json字符串中的其他图层之前,否则它将被放置在打印 Map 中的其他图层之上 .

  • 0

    Geoserver Print插件仅适用于地理服务器数据 . 在您的情况下,您应该将OSM数据作为地理服务器实例中的图层来处理 . 通过地理服务器不可能只有"proxy" OSM切片,您必须将OSM数据导入数据库 . 请查看这篇文章:http://blog.geoserver.org/2009/01/30/geoserver-and-openstreetmap/

    当您使用OL3(画布支持)时,您可以考虑浏览器端打印 . 从画布获取图像非常简单:https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL

    您还可以使用以下命令在JavaScript中生成PDF:https://github.com/MrRio/jsPDF

相关问题