[OpenLayers-Users] problem using pointRadius computed in context

Heidt, Christopher M. CHRISTOPHER.M.HEIDT at saic.com
Mon Mar 16 08:57:56 EDT 2009


I don't see what you had before but this wont work because
pointRadius has to be a number, not a function.
You can use a function to create the number:

//Styles
	var clusterStyle = new OpenLayers.Style({
            pointRadius: "${radius}",
            fillColor: '#ee9900',
            fillOpacity: 0.8,
            strokeColor: '#ee9900',
            strokeWidth: 1,
            strokeOpacity: 0.8,
		cursor: 'pointer'
        }, {
            context: {
                radius: function(feature) {
	
if(typeof(feature.attributes.count) != 'undefined')
					{
						return
Math.min(feature.attributes.count, 7) + 3;
					}
					return 4;
                }
            }
        }); 

-----Original Message-----
From: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org]
On Behalf Of Didrik Pinte
Sent: Monday, March 16, 2009 6:52 AM
To: sylvie fiat
Cc: users at openlayers.org
Subject: Re: [OpenLayers-Users] problem using pointRadius computed in
context

On Sun, 2009-03-08 at 23:12 -0700, sylvie fiat wrote:
> Hi,
> 
> I have the same problem and it's taking me hours, did you figure out 
> what was the problem ?
> I have tried : 
> styleMap: new OpenLayers.StyleMap(OpenLayers.Util.applyDefaults(
> 		        	        {	pointRadius:
function(feature){return
> Math.min(feature.attributes.count, 7) + 3;},
> 		        	        	fillColor: "blue", 
> 		        	        	fillOpacity: 0.5, 
> 		        	        	strokeColor: "black"},
>
OpenLayers.Feature.Vector.style["default"]))
> 
> But I got the error:
> unexpected value function (feature) { return 
> Math.min(feature.attributes.count, 7) + 3; } parsing r attribute.
> 
> Thanks for any help.
> Sylvie

Hi Sylvie,

I guess it was related to some errors in my javascript file. I would
suggest you to use online javascriptlint to check your syntax and
identify potential errors. 

Didrik



More information about the Users mailing list