Vector layer cluster count Label not showing

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Vector layer cluster count Label not showing

umair.abbas
This post has NOT been accepted by the mailing list yet.
Hi, I,m trying to implement animated cluster strategy on vector layer .Cluster strategy is implemented but unable to show cluster feature count in label of cluster, My code is below please help me on this issue. /......................... // set up cluster strategy and vector layer var dx = 3; var dy = 3; var px, py; var proj1 = new OpenLayers.Projection("EPSG:4326"); var proj2 = new OpenLayers.Projection("EPSG:900913"); var colors = { low: "rgb(181, 226, 140)", middle: "rgb(241, 211, 87)", high: "rgb(253, 156, 115)" }; // Define three rules to style the cluster features. var lowRule = new OpenLayers.Rule({ filter: new OpenLayers.Filter.Comparison({ type: OpenLayers.Filter.Comparison.LESS_THAN, property: "count", value: 15 }), symbolizer: { fillColor: colors.low, fillOpacity: 0.9, strokeColor: colors.low, strokeOpacity: 0.5, strokeWidth: 12, pointRadius: 10, label: "${count}", labelOutlineWidth: 1, fontColor: "#000000", fontOpacity: 0.8, fontSize: "12px" } }); var middleRule = new OpenLayers.Rule({ filter: new OpenLayers.Filter.Comparison({ type: OpenLayers.Filter.Comparison.BETWEEN, property: "count", lowerBoundary: 15, upperBoundary: 50 }), symbolizer: { fillColor: colors.middle, fillOpacity: 0.9, strokeColor: colors.middle, strokeOpacity: 0.5, strokeWidth: 12, pointRadius: 15, label: "${count}", labelOutlineWidth: 1, fontColor: "#000000", fontOpacity: 0.8, fontSize: "12px" } }); var highRule = new OpenLayers.Rule({ filter: new OpenLayers.Filter.Comparison({ type: OpenLayers.Filter.Comparison.GREATER_THAN, property: "count", value: 50 }), symbolizer: { fillColor: colors.high, fillOpacity: 0.9, strokeColor: colors.high, strokeOpacity: 0.5, strokeWidth: 12, pointRadius: 20, label: "${count}", labelOutlineWidth: 1, fontColor: "#000000", fontOpacity: 0.8, fontSize: "12px" } }); // Create a Style that uses the three previous rules var style = new OpenLayers.Style("default", { rules: [lowRule, middleRule, highRule] } ); var styleMap = new OpenLayers.StyleMap({ 'default': style, }); vector2 = new OpenLayers.Layer.Vector("Features", { renderers: ['Canvas','SVG'], strategies: [ new OpenLayers.Strategy.AnimatedCluster({ distance: 45, animationMethod: OpenLayers.Easing.Expo.easeOut, animationDuration: 20 }) ], styleMap: new OpenLayers.StyleMap(style) }); map.addLayer(vector2); for(var i=0; i< 50000; i++) { var lon = Math.random() * 2 + -4; var lat = Math.random() * 2 + 40; var lonlat = new OpenLayers.LonLat(lon, lat); lonlat.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913")); var f = new OpenLayers.Feature.Vector( new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat)); features.push(f); } vector2.addFeatures(features); }
Reply | Threaded
Open this post in threaded view
|

Re: Vector layer cluster count Label not showing

Fixi
This post has NOT been accepted by the mailing list yet.
This post was updated on .
Hi.

Test:

...
...
...
var highRule = new OpenLayers.Rule({
    filter: new OpenLayers.Filter.Comparison({
        type: OpenLayers.Filter.Comparison.GREATER_THAN,
        property: "count",
        value: 50
    }),
    symbolizer: {
        fillColor: colors.high,
        fillOpacity: 0.9,
        strokeColor: colors.high,
        strokeOpacity: 0.5,
        strokeWidth: 12,
        pointRadius: 20,
        label: "${count}", // this!!!!!
        labelOutlineWidth: 1,
        fontColor: "#000000",
        fontOpacity: 0.8,
        fontSize: "12px"
    }
});

var styleMap = new OpenLayers.StyleMap({
    'default': style,
});

styleMap.styles["default"].context ={
        count: function(feature) {   //count is field "label" defined in OpenLayers.Rule-->symbolizer
                return feature.attributes.count;
        }
};