[OpenLayers-Users] Styling a GeoJson vector layer with a stylemap by value

John Cole jcole at solidearth.com
Wed Jan 18 13:44:54 EST 2012


Arnd and Eric,

  Thanks for the quick help.  I was thinking that it was looking for the
properties off of the vector feature object, and was hoping passing in a
different context would allow me to keep the fields on the same level as
the coordinates.

  The current json document indeed does draw, but not not with the
addUniqueValueRules set.  Perhaps the formatter is creating a vector
feature good enough to draw, but not filter.

  The source is from a C# web service call to a MongoDB collection (table
in mongo parlance).  And performance is impressive, the 3 points was a
sample from the original 1800 points (hence a W status thrown in there),
which draw faster than the OSM basemap.  In fact performance doesn't start
to drop off until 30K points, far more than I expected.

  Converting the source from a GeometryCollection to a FeatureCollection
ins't a problem, but I have to figure out how to create an object from the
MongoDB document that has the properties object inside the feature object.
 Like I said, I was hoping the context would allow me to fake that :-)

Let me see what I can come up with.

On Wed, Jan 18, 2012 at 12:14 PM, Eric Lemoine
<eric.lemoine at camptocamp.com>wrote:

>
>
> On Wednesday, January 18, 2012, John Cole <jcole at solidearth.com> wrote:
> > Hey guys,
> >   I'm trying to use a stylemap on a GeoJson datasource, and want to
> change the color of the symbol based off of a field in the data.
> > My data looks like:
> > {
> > "type" : "GeometryCollection",
> > "geometries" : [{
> > "type" : "Point",
> > "_id" : {
> > "code" : "123",
> > "version" : 0
> > },
> > "coordinates" : [-86.586502, 34.731189],
> > "Status" : "W"
> > }, {
> > "type" : "Point",
> > "_id" : {
> > "code" : "234",
> > "version" : 0
> > },
> > "coordinates" : [-86.57294326, 34.73563314],
> > "Status" : "W"
> > }, {
> > "type" : "Point",
> > "_id" : {
> > "code" : "456",
> > "version" : 0
> > },
> > "coordinates" : [-86.45717254, 34.82754903],
> > "Status" : "A"
> > }
> > ]
> > }
>
> I don't think OpenLayers's GeoJSON format can produce
> OpenLayers.Feature.Vector objects from such a JSON doc. To produce features
> the GeoJSON format should receive a doc whose root object is of type
> FeatureCollection.
>
> >
> > and my style stylemap:
> >         var styleMap = new OpenLayers.StyleMap({
> >             "default": new OpenLayers.Style({
> >                 fillOpacity: 0.5,
> >                 pointRadius: 5,
> >                 fillColor: "#ee9900"
> >             })
> >         });
> >
> >         var lookup = {
> >             "S": {fillColor: "red"},
> >             "A": {fillColor: "green"},
> >             "X": {fillColor: "blue"}
> >         };
> >         styleMap.addUniqueValueRules("default", "Status", lookup);
> > However, when I apply the addUniqueValueRules, no features are drawn.
>  Tracing through the draw cycle,
> > line 117 of Comparison.js which is getting the value of "Status" from
> the context returns undefined.  What do I need to do to get the "Status"
> into the correct context?
>
>
> For your rules to work "Status" must be a property of the "properties"
> object in each "feature" object of the GeoJSON doc.
>
> So make sure you have correctly formed feature objects in your layer. Each
> feature object should a "Status" property in its "attributes" object.
>
> Hope this helps.
>
> --
> Eric Lemoine
>
> Camptocamp France SAS
> Savoie Technolac, BP 352
> 73377 Le Bourget du Lac, Cedex
>
> Tel : 00 33 4 79 44 44 96
> Mail : eric.lemoine at camptocamp.com
> http://www.camptocamp.com
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20120118/994aff33/attachment-0001.html


More information about the Users mailing list