[OpenLayers-Users] Properties of Vector Features to be printed Using MapFish Print

Jerome A. Wendell jawendell at suddenlink.net
Fri Feb 14 14:07:30 PST 2014


I basically have the spec to print my map with the desired layers, except
for one property that I have not been able to include in the geojson string
for the features.  I am using OpenLayers Version 2.12.  The spec is as
follows:

 

http://mydomain:8080/print/pdf/print.pdf?spec={
<http://mydomain:8080/print/pdf/print.pdf?spec=%7b%22layout%22:%22Letter>
"layout":"Letter
portrait","srs":"EPSG:3857","units":"ft","dpi":300,"mapTitle":"Printed from
mydomain.com","layers":[{"baseURL":"http://a.tile.openstreetmap.org/","opaci
ty":1,"singleTile":false,"type":"OSM","maxExtent":[-20037508.3392,
-20037508.3392, 20037508.3392, 20037508.3392],"tileSize":[256,
256],"extension":"png","resolutions":[156543.03390625, 78271.516953125,
39135.7584765625, 19567.87923828125, 9783.939619140625, 4891.9698095703125,
2445.9849047851562, 1222.9924523925781, 611.4962261962891,
305.74811309814453, 152.87405654907226, 76.43702827453613,
38.218514137268066, 19.109257068634033, 9.554628534317017,
4.777314267158508, 2.388657133579254, 1.194328566789627,
0.5971642833948135]},{"baseURL":"http://mydomain:8080/geoserver/wv_data/wms"
,"opacity":1,"singleTile":true,"customParams":{},"type":"WMS","layers":["wv_
data:wv_tax_districts","wv_data:wv_county","wv_data:wv_state"],"format":"ima
ge/png","styles":[],"transparent":true},{"type":"Vector","styles":{"1":{"str
okeColor":"#000000","strokeOpacity":0.5,"fillColor":"#99FF00","fillOpacity":
0.3}},"styleProperty":"_gx_style","geoJson":{"type":"FeatureCollection","fea
tures":[{"type":"Feature","properties":{"_gx_style":1, "rootid":"03-04-
22-0009-0000-0000"},"geometry":{"type":"MultiPolygon","coordinates":[[[[-909
6521.031054683,4598298.723518376],[-9096508.058329634,4598338.853603111],[-9
096046.00308546,4598028.754632352],[-9096054.460792316,4598022.619581236],[-
9096067.676031547,4598007.215465028],[-9096095.49339352,4597959.168712229],[
-9096122.568241857,4597918.154104033],[-9096160.503799679,4597875.767949502]
,[-9096180.603656983,4597852.659764481],[-9096203.843161233,4597823.77633773
],[-9096209.261893097,4597816.083499497],[-9096211.57365225,4597811.60256099
8],[-9096216.243212458,4597804.553092468],[-9096220.114133514,4597799.894358
914],[-9096224.773759445,4597794.285915068],[-9096235.60818699,4597783.98821
5557],[-9096257.2638415,4597768.519091412],[-9096269.681709073,4597763.96016
8759],[-9096296.739037376,4597752.274799273],[-9096323.073627673,4597750.158
696852],[-9096348.661872733,4597743.58521329],[-9096357.126164695,4597741.09
7003529],[-9096368.756827036,4597737.691704096],[-9096381.859516736,4597735.
040114307],[-9096402.03263128,4597729.783522871],[-9096420.59772951,4597725.
1641588705],[-9096450.813370682,4597721.1049796855],[-9096486.408399766,4597
713.816178738],[-9096517.384951781,4597706.563017243],[-9096552.962476604,45
97702.4620325295],[-9096570.043988377,4597701.054553932],[-9096614.952565616
,4597696.8810641905],[-9096628.171333157,4597695.720208254],[-9096894.676004
061,4598085.73112343],[-9096732.521829559,4598160.354191241],[-9096521.03105
4683,4598298.723518376]]]]},"id":"mineral.2217","crs":{"type":"name","proper
ties":{"name":"urn:ogc:def:crs:OGC:1.3:CRS84"}}},{"type":"Feature","properti
es":{"_gx_style":1, "rootid":"03-04-
24-0013-0000-0000"},"geometry":{"type":"MultiPolygon","coordinates":[[[[-910
0885.931437397,4595830.641061093],[-9100618.955667052,4595813.922834314],[-9
100544.320274929,4595809.239025285],[-9100219.47980554,4595780.614032372],[-
9100227.273714347,4595722.363540661],[-9100240.120513162,4595604.891296111],
[-9100465.568072638,4595705.5650386475],[-9100553.996820783,4595730.16615384
2],[-9100619.003285743,4595747.167447766],[-9100660.777464475,4595758.084937
326],[-9100824.032890169,4595685.371798294],[-9100840.055007722,4595682.9334
84964],[-9100849.432155106,4595708.18948892],[-9100863.225394715,4595714.986
957449],[-9100867.942023106,4595731.076151991],[-9100887.97905841,4595729.17
8693363],[-9100888.634211006,4595738.964712751],[-9100881.922785217,4595759.
736949781],[-9100879.965270448,4595801.200690653],[-9100885.931437397,459583
0.641061093]]]]},"id":"mineral.2237","crs":{"type":"name","properties":{"nam
e":"urn:ogc:def:crs:OGC:1.3:CRS84"}}}]},"opacity":1,"name":"Selected Mineral
Tracts"}],"pages":[{"center":[-9098467.3186875,4596971.8698045],"scale":1200
0,"rotation":0}]}

 

I have highlighted the property that I need to include in the spec.  I have
tried to add it to the geoJson representing the feature by using the
following code:

 

                var featureFormat = new OpenLayers.Format.GeoJSON();

                var featureGeoJson = featureFormat.write.call(

                                featureFormat, feature);

                featureGeoJson.properties = OpenLayers.Util.extend({

                                _gx_style: 1

                                },featureGeoJson.properties);

 

The problem seems to be that featureGeoJson.properties is not defined.  I
know that featureGeoJson is correct because it contains all of the feature
information.  My problem is trying to insert _gx_style: 1 as a property into
the GeoJson.  Without it MapFish gives the following error:

 

2014-02-14 16:52:29,158 ERROR [org.mapfish.print.servlet.BaseMapServlet] -
Error while generating PDF

DocumentException: 

org.mapfish.print.JsonMissingException: attribute [spec.layers[2].styles.]
missing

                at
org.mapfish.print.utils.PJsonObject.getJSONObject(PJsonObject.java:134)

                at
org.mapfish.print.map.renderers.vector.StyledMfGeoFactory.createFeature(Styl
edMfGeoFactory.java:52)

                at
org.mapfish.geo.MfGeoJSONReader.decodeFeature(MfGeoJSONReader.java:84)

                at
org.mapfish.geo.MfGeoJSONReader.decodeFeatureCollection(MfGeoJSONReader.java
:75)

                at
org.mapfish.geo.MfGeoJSONReader.decode(MfGeoJSONReader.java:63)

                at
org.mapfish.print.map.readers.VectorMapReader.<init>(VectorMapReader.java:75
)

                at
org.mapfish.print.map.readers.VectorMapReader$Factory.create(VectorMapReader
.java:57)

                at
org.mapfish.print.map.readers.MapReaderFactoryFinder.create(MapReaderFactory
Finder.java:39)

                ...

 

Any suggestions that you may have are greatly appreciated.

 

Thanks,

 

Jerome Wendell

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20140214/b9deacd9/attachment.html>


More information about the Users mailing list