[OpenLayers-Users] attribute based styles

Mr. Puneet Kishor punk.kish at gmail.com
Sat Sep 24 08:31:45 EDT 2011


On Sep 23, 2011, at 5:25 PM, <christopher.schmidt at nokia.com> <christopher.schmidt at nokia.com> wrote:

> 
> On Sep 23, 2011, at 6:15 PM, ext Puneet Kishor wrote:
>> 
>> and the layer definition is 
>> 
>>   var lyr = new OpenLayers.Layer.Vector(
>>       "a layer", {
>>           style: {
>>               "strokeWidth": 1, 
>>               "strokeColor": "#ff0000", 
>>               "fillColor": "#ff0000", 
>>               "fillOpacity": "${opacity}", 
>>               "pointRadius": "${radius}"
>>           }
>>       }
>>   );
>> 
>> I was expecting the points to be rendered with the radius and opacity values for each feature. But not so. What am I doing wrong?
> 
> s/style:/styleMap: new OpenLayers.StyleMap({'strokWidth':, etc.})/
> 


Thanks, that works. Perhaps the following should be corrected at [http://docs.openlayers.org/library/feature_styling.html]

> The most common way of accessing attributes of the feature when creating a style is through the attribute replacement syntax. By using style values like ${varname} in your style, OpenLayers can replace these strings with attributes of your feature. For example, if you had a GeoJSON file where each feature had a thumbnail property describing an image to use, you might use something like:
> 
> var s = new OpenLayers.Style({
>   'pointRadius': 10,
>   'externalGraphic': '${thumbnail}'
> });
> 


More information about the Users mailing list