<br><br>On Wednesday, January 18, 2012, John Cole <<a href="mailto:jcole@solidearth.com">jcole@solidearth.com</a>> wrote:<br>> Hey guys,<br>> 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.<br>
> My data looks like:<br>> {<br>> "type" : "GeometryCollection",<br>> "geometries" : [{<br>> "type" : "Point",<br>> "_id" : {<br>> "code" : "123",<br>
> "version" : 0<br>> },<br>> "coordinates" : [-86.586502, 34.731189],<br>> "Status" : "W"<br>> }, {<br>> "type" : "Point",<br>> "_id" : {<br>
> "code" : "234",<br>> "version" : 0<br>> },<br>> "coordinates" : [-86.57294326, 34.73563314],<br>> "Status" : "W"<br>> }, {<br>> "type" : "Point",<br>
> "_id" : {<br>> "code" : "456",<br>> "version" : 0<br>> },<br>> "coordinates" : [-86.45717254, 34.82754903],<br>> "Status" : "A"<br>
> }<br>> ]<br>> }<br><br>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. <br>
<br>><br>> and my style stylemap:<br>> var styleMap = new OpenLayers.StyleMap({<br>> "default": new OpenLayers.Style({<br>> fillOpacity: 0.5,<br>> pointRadius: 5,<br>
> fillColor: "#ee9900"<br>> })<br>> });<br>> <br>> var lookup = {<br>> "S": {fillColor: "red"},<br>> "A": {fillColor: "green"},<br>
> "X": {fillColor: "blue"}<br>> };<br>> styleMap.addUniqueValueRules("default", "Status", lookup);<br>> However, when I apply the addUniqueValueRules, no features are drawn. Tracing through the draw cycle,<br>
> 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? <br><br><br>For your rules to work "Status" must be a property of the "properties" object in each "feature" object of the GeoJSON doc.<br>
<br>So make sure you have correctly formed feature objects in your layer. Each feature object should a "Status" property in its "attributes" object.<br><br>Hope this helps.<br><br>-- <br>Eric Lemoine<br>
<br>Camptocamp France SAS<br>Savoie Technolac, BP 352<br>73377 Le Bourget du Lac, Cedex<br><br>Tel : 00 33 4 79 44 44 96<br>Mail : <a href="mailto:eric.lemoine@camptocamp.com">eric.lemoine@camptocamp.com</a><br><a href="http://www.camptocamp.com">http://www.camptocamp.com</a><br>
<br>