AW: [OpenLayers-Users] Styling a GeoJson vector layer with a stylemapby value

Arnd Wippermann arnd.wippermann at web.de
Wed Jan 18 13:11:57 EST 2012


it's nothing wrong with your code. But your GeoJSON object describes a
MultiPoint instead of three single points. 
And the properties should not attached to the geometry.
 
Try something like this to create single points: 
 
{
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "properties": {
                "_id" :
                {
                "code" : "123",
                "version" : 0
                },
                "Status" : "W"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -86.586502,
                     34.731189
                ]
            }
        },
        {
            "type": "Feature",
 
...
 
by the way Status="W" is not declared in your styleMap.
 
Arnd
 
 
  _____  

Von: openlayers-users-bounces at lists.osgeo.org
[mailto:openlayers-users-bounces at lists.osgeo.org] Im Auftrag von John Cole
Gesendet: Mittwoch, 18. Januar 2012 17:36
An: openlayers-users at lists.osgeo.org
Betreff: [OpenLayers-Users] Styling a GeoJson vector layer with a stylemapby
value


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"
}
]
}


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?  

Thanks,

John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20120118/8d6a5f2c/attachment.html


More information about the Users mailing list