Implement clustering statistics display based on openlayers and openlayers Clustering
Overview:
In the previous blog, we talked about how to implement clustering statistics display based on Arcgis for js and how to implement clustering statistics based on openlayers. The address of the blog post on Arcgis for js clustering statistics is:
Http://blog.csdn.net/gisshixisheng/article/details/40867989
Effect:
Key points:
Implementation Code:
1. Data Format
2. Set the display style
var style = new OpenLayers.Style({ fillColor: "#ffcc66", strokeColor: "#ff9933", strokeWidth: 2, label: "${count}", fontColor: "#333333", fontFamily: "sans-serif", fontWeight: "bold" }, { rules: [ new OpenLayers.Rule({ minScaleDenominator: 100000000, symbolizer: { pointRadius: 7, fontSize: "9px" } }), new OpenLayers.Rule({ maxScaleDenominator: 100000000, minScaleDenominator: 50000000, symbolizer: { pointRadius: 10, fontSize: "11px" } }), new OpenLayers.Rule({ maxScaleDenominator: 50000000, symbolizer: { pointRadius: 13, fontSize: "13px" } }) ] });
3. Add a vector Layer
var features = new Array(); for (var i=0; i<data.length; i++) { features[i] = new OpenLayers.Feature.Vector( new OpenLayers.Geometry.Point(data[i].x, data[i].y), { count:data[i].count, name:data[i].name } ); } var clusterLayer = new OpenLayers.Layer.Vector("Points", { styleMap: new OpenLayers.StyleMap(style) }); clusterLayer.addFeatures(features); map1.addLayer(clusterLayer);
Complete program code;
<! DOCTYPE html>