我正在使用MapFish Print生成地图的PDF,当我仅使用WMS图层作为基础图块时,在pdf中创建地图图像是完全没问题的。按预期工作。
但是,当我在其中添加矢量图层和geoJSON对象时,mapfish print会抛出以下错误:
Exception in thread "tilesReader3" java.lang.NullPointerException
at org.mapfish.print.map.renderers.vector.PointRenderer.renderImpl(PointRenderer.java:113)
at org.mapfish.print.map.renderers.vector.PointRenderer.renderImpl(PointRenderer.java:49)
at org.mapfish.print.map.renderers.vector.GeometriesRenderer.render(GeometriesRenderer.java:69)
at org.mapfish.print.map.renderers.vector.FeaturesRenderer$FeatureRenderer.renderImpl(FeaturesRenderer.java:62)
at org.mapfish.print.map.renderers.vector.FeaturesRenderer$FeatureRenderer.renderImpl(FeaturesRenderer.java:58)
at org.mapfish.print.map.renderers.vector.FeaturesRenderer.render(FeaturesRenderer.java:53)
at org.mapfish.print.map.renderers.vector.FeaturesRenderer$FeatureCollectionRenderer.renderImpl(FeaturesRenderer.java:70)
at org.mapfish.print.map.renderers.vector.FeaturesRenderer$FeatureCollectionRenderer.renderImpl(FeaturesRenderer.java:67)
at org.mapfish.print.map.renderers.vector.FeaturesRenderer.render(FeaturesRenderer.java:53)
at org.mapfish.print.map.readers.VectorMapReader$1.renderOnPdf(VectorMapReader.java:85)
at org.mapfish.print.map.ParallelMapTileLoader.handle(ParallelMapTileLoader.java:97)
at org.mapfish.print.map.ParallelMapTileLoader.handle(ParallelMapTileLoader.java:41)
at org.pvalsecc.concurrent.OrderedResultsExecutor.addOutput(OrderedResultsExecutor.java:148)
at org.pvalsecc.concurrent.OrderedResultsExecutor.access$600(OrderedResultsExecutor.java:23)
at org.pvalsecc.concurrent.OrderedResultsExecutor$Runner.run(OrderedResultsExecutor.java:181)
at java.lang.Thread.run(Unknown Source)
我发送给Mapfish打印的查询是默认样本的略微修改版本(使用不同的WMS作为示例的默认值为down),添加了Vector层,如下所示:
{
layout: 'A4 portrait',
title: 'A simple example',
srs: 'EPSG:4326',
units: 'dd',
outputFilename: 'mapfish-print',
outputFormat: 'pdf',
layers: [
{
type: 'WMS',
format: 'image/png',
layers: ['OSM-GB:__all__'],
baseURL: 'http://www.osmgb.org.uk/ogc/wms'
},
{
type: 'Vector',
geoJson: {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-0.0996621,
51.5059247
]
},
"properties": {
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-0.099332,
51.5072000
]
},
"properties": {
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-0.0945508,
51.50240484
]
},
"properties": {
}
}
]
}
}
],
pages: [
{
center: [0.09, 51.50],
scale: 4000000,
dpi: 190,
mapTitle: "First map",
comment: "The \"routes\" layer is not shown (the scale is too small)",
data: [
{id:1, name: 'blah', icon: 'icon_pan'},
{id:2, name: 'blip', icon: 'icon_zoomin'}
]
},
{
center: [0.09, 51.50],
scale: 500000,
dpi: 190,
mapTitle: "Second map",
comment: "This is a zoomed in version of the first map. Since the scale is more appropriate, we show the \"routes\" layer.",
data: [
{id:1, name: 'blah', icon: 'icon_pan'},
{id:2, name: 'blip', icon: 'icon_zoomin'}
]
}
]
}
GeoJSON验证并在geojsonlint.com上显示,很好。浏览了mapfish打印源后,我无法弄清楚为什么会发生这种情况。虽然它似乎与样式有关,但我没有运气在解决此问题的请求中添加一个。
- 更新:
如果有其他人遇到过这个问题,问题是(未记录),您必须在矢量图层中定义一组样式,并确保geoJSON中的每个功能都使用样式。
答案 0 :(得分:0)
问题在于(未记录),您必须在矢量图层中定义一组样式和一个样式属性,并确保geoJSON中的每个要素都使用样式。
样式本身是SVG样式,虽然许多标签都被重命名,因此它们不是填充颜色,而是填充颜色。
请点击此处了解更多详情:http://www.mapfish.org/doc/print/protocol.html#layers-params
答案 1 :(得分:0)
需要定义的SVG样式采用OpenLayers.Feature.Vector.style
的形式