0

我想使用底图(ex OSM)在指定的中心和比例打印我的地图,我分别测试了这个打印并且它可以工作,但是当我重新组合我的图层+ OpenStreetMap baselayer时,我生成的PDF中没有任何内容,这是我的打印链接:

我的代码:

var printurl = 'http://' + host + ':' + port + '/geoserver/pdf/print.pdf?spec={"units":"degrees","srs":"EPSG:4326","layout":"A4 portrait","dpi":"300","mapTitle":"' + maptitle + '","comment":"' + mapcomment + '","resourcesUrl": "http://' + host + ':' + port + '/img","layers":[{"baseURL":"http://' + host + ':' + port + '/geoserver/' + workspace + '/wms","opacity":1,"singleTile":true,"type":"WMS","layers":["' + layers + '"],"format":"image/jpeg","styles":[""]}, {"baseURL": "http://a.tile.openstreetmap.org", "singleTile": false, "type": "OSM", "tileSize": [256, 256], "extension": "png",  "maxExtent":' + map.getView().calculateExtent() + ', "resolutions":' + map.getView().getResolution() + ' }],"pages":[{"center":[' + map.getView().getCenter()[0] + ',' + map.getView().getCenter()[1] + '],"scale":' + mapScale(300) + ',"rotation":0}]}';

计算我使用的mapScale:

function mapScale(dpi) {
        var unit = map.getView().getProjection().getUnits();
        var resolution = map.getView().getResolution();
        var inchesPerMetre = 39.37;

        return resolution * ol.proj.METERS_PER_UNIT[unit] * inchesPerMetre * dpi;
    }

那么生成的 URL 是:

{
"units":"degrees",
"srs":"EPSG:4326",
"layout":"A4%20portrait",
"dpi":"300",
"mapTitle":"This%20is%20the%20map%20title",
"comment":"This%20is%20the%20map%20comment",
"resourcesUrl":%20"http://localhost:1xx5/img",
"layers":[ {
    "baseURL": "http://localhost:1xx5/geoserver/Espace1/wms", "opacity": 1, "singleTile": true, "type": "WMS", "layers": ["STATIONS"], "format": "image/jpeg", "styles": [""]
}
,
{
    "baseURL": "http://a.tile.openstreetmap.org", "singleTile": false, "type": "OSM", "tileSize": [256, 256], "extension": "png",  "maxExtent":[-20037508.3392,-20037508.3392,20037508.3392,20037508.3392], "resolutions":[156543.03390625,78271.516953125,39135.758475, 19567.8792375, 9783.93961875, 4891.969809375, 2445.9849046875, 1222.99245256282, 611.496226171875, 305.7481130859375, 152.87405654296876, 76.43702827148438, 38.21851413574219, 19.109257067871095, 9.554628533935547, 4.777314266967774, 2.388657133483887, 1.1943285667419434, 0.5971642833709717,0.41999977320012255, 0.2799998488000817,0.13999992440004086, 0.08399995464002451, 0.05599996976001634, 0.02799998488000817] 
}
],
"pages":[ {
    "center": [-5.64422607421875, 35.33203125], "scale": 1803574.209836933, "rotation": 0
}
]
}
4

1 回答 1

1

Mapfish 打印对其参数非常敏感,验证您的所有参数作为单块 OSM 是否需要?

我没有尝试使用 OSM,而是我的层配置的一个旧示例:

layers: [
    { type: 'xyz', baseURL: layer_basemap, extension: 'png', maxExtent: [-20037508.34, -20037508.34, 20037508.34, 20037508.34], tileSize: [256, 256], resolutions: [156543.03392800014, 78271.51696399994, 39135.75848200009, 19567.87924099992, 9783.93962049996, 4891.96981024998, 2445.98490512499, 1222.992452562495, 611.4962262813797, 305.74811314055756, 152.87405657041106, 76.43702828507324, 38.21851414253662, 19.10925707126831, 9.554628535634155, 4.77731426794937, 2.388657133974685, 1.1943285668550503, 0.5971642835598172, 0.29858214164761665], tileOriginCorner: 'bl', path_format: '${z}/${y}/${x}' },
    { baseURL: mapserver_url, type: 'WMS', format: 'image/png', layers: layer_list },
    { type: 'xyz', baseURL: 'https://server.arcgisonline.com/ArcGIS/rest/services/Reference/World_Transportation/MapServer/tile/', extension: 'png', maxExtent: [-20037508.34, -20037508.34, 20037508.34, 20037508.34], tileSize: [256, 256], resolutions: [156543.03392800014, 78271.51696399994, 39135.75848200009, 19567.87924099992, 9783.93962049996, 4891.96981024998, 2445.98490512499, 1222.992452562495, 611.4962262813797, 305.74811314055756, 152.87405657041106, 76.43702828507324, 38.21851414253662, 19.10925707126831, 9.554628535634155, 4.77731426794937, 2.388657133974685, 1.1943285668550503, 0.5971642835598172, 0.29858214164761665], tileOriginCorner: 'bl', path_format: '${z}/${y}/${x}' },
    { type: 'xyz', baseURL: 'https://server.arcgisonline.com/ArcGIS/rest/services/Reference/World_Boundaries_and_Places/MapServer/tile/', extension: 'png', maxExtent: [-20037508.34, -20037508.34, 20037508.34, 20037508.34], tileSize: [256, 256], resolutions: [156543.03392800014, 78271.51696399994, 39135.75848200009, 19567.87924099992, 9783.93962049996, 4891.96981024998, 2445.98490512499, 1222.992452562495, 611.4962262813797, 305.74811314055756, 152.87405657041106, 76.43702828507324, 38.21851414253662, 19.10925707126831, 9.554628535634155, 4.77731426794937, 2.388657133974685, 1.1943285668550503, 0.5971642835598172, 0.29858214164761665], tileOriginCorner: 'bl', path_format: '${z}/${y}/${x}' }
],
于 2018-04-03T13:13:26.167 回答