Mapfish打印矢量图层GeoJSON的例子?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mapfish打印矢量图层GeoJSON的例子?相关的知识,希望对你有一定的参考价值。

我正在使用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中的每个特征都使用一种样式。

答案

问题是(未记录的),您必须在矢量图层中定义一组样式和一个样式属性,并确保geoJSON中的每个特征都使用一种样式。

样式本身是SVG样式,虽然许多标签被重命名,因此它们不是填充颜色,而是fillColor。

有关详细信息,请参阅此处:http://www.mapfish.org/doc/print/protocol.html#layers-params

另一答案

需要定义的SVG样式采用OpenLayers.Feature.Vector.style的形式

以上是关于Mapfish打印矢量图层GeoJSON的例子?的主要内容,如果未能解决你的问题,请参考以下文章

ArcGIS风暴如何将矢量数据(点线面)折点坐标转为GeoJSON格式?

ArcGIS风暴如何将矢量数据(点线面)折点坐标转为GeoJSON格式?

QGIS入门实战精品教程004:如何将矢量数据转为GeoJSON格式?

QGIS入门实战精品教程4.7:QGIS如何将矢量数据转为GeoJSON格式?

leaflet入门使用GeoJSON创建矢量图形

Openlayers 4 矢量图