[OpenLayers-Users] Clustering strategy not applying to feature layer

Leon D'mello leondmello at gmail.com
Mon Mar 5 09:25:39 EST 2012


Hello All,

I'm trying to apply clustering strategy to a feature layer which i
construct from lat/long points returned in JSON by a web service. When the
map loads, all i can see is the string 'undefined' at each and every point.
I think there is some problem with the activation of the cluster strategy.
I debugged the functions and found out that there is a problem with the
code line which uses " feature.attributes.count". Any one knows how do i
get the clustering strategy to work?
I have included the code which I have written below. Any help will be
appreciated.


        resultObject = $.parseJSON(jsonResponse.d);
        var point;
        var feature_point;
        var proj = new OpenLayers.Projection("EPSG:4326");

        var vector_layer = new OpenLayers.Layer.Vector('Customer Points
Layer', { strategies: [new OpenLayers.Strategy.Cluster()]});

        //Add data points to the feature layer by converting to the
appropriate projection
        for (var customerCount = 0; customerCount < resultObject.length;
customerCount += 1) {
            point = new
OpenLayers.Geometry.Point(resultObject[customerCount].Longitude,
resultObject[customerCount].Latitude);
            point.transform(proj, map.getProjectionObject());
            feature_point = new OpenLayers.Feature.Vector(point);
            vector_layer.addFeatures([feature_point]);
        }

        var vector_style = new OpenLayers.Style({
            fillColor: '#669933',
            fillOpacity: .8,
            fontColor: '#f0f0f0',
            fontFamily: 'arial, sans-serif',
            fontSize: '.9em',
            fontWeight: 'bold',
            label: '${num_points}',
            pointRadius: '${point_radius}',
            strokeColor: '#aaee77',
            strokeWidth: 3
        },
           {
            context: {
                num_points: function (feature) { return
feature.attributes.count; },
                point_radius: function (feature) {
                    return 9 + (feature.attributes.count)
                }
            }
        });

         var vector_style_map = new OpenLayers.StyleMap({
            'default': vector_style
        });

        vector_layer.styleMap = vector_style_map;

        map.addLayer(vector_layer);

-- 
Thanks,
Leon Dmello.
(+91) 779 832 8248
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20120305/1b27bf78/attachment.html


More information about the Users mailing list