我想使用底图(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
}
]
}