我正在尝试使用描述的属性聚类 here 。我已复制 OpenLayers.Strategy.AttributeCluster =...
片段。这是我的代码:
styleMap = new OpenLayers.StyleMap({
label: "${labelText}",
fontColor: "blue",
fontSize: "12px",
fontFamily: "Courier New, monospace",
fontWeight: "bold",
labelAlign: "lc",
labelXOffset: "14",
labelYOffset: "0",
labelOutlineColor: "white",
labelOutlineWidth: 3,
//fillColor: "#ee9900",
fillColor: "${fillColor}",
fillOpacity: 0.3,
stroke: false
});
strategies.push(new OpenLayers.Strategy.AttributeCluster({
attribute: 'obs'
}));
var vectorLayer = new OpenLayers.Layer.Vector("Overlay", {
styleMap: styleMap,
strategies: strategies
});
map.addLayer(vectorLayer);
我通过以下方式创建功能:
var circle = new OpenLayers.Geometry.Polygon.createRegularPolygon(
new OpenLayers.Geometry.Point( dataArr[i][2],dataArr[i][1]).transform(epsg4326, projectTo), 100, 20, 0);
var feature = new OpenLayers.Feature.Vector(circle, {labelText: dataArr[i][0], all: dataArr[i][5],ami: dataArr[i][6],obs: dataArr[i][3], fillColor: areaColors[dataArr[i][3]]});
然后我向图层添加功能:
vectorLayer.addFeatures(features);
当我运行页面时,只有标签可见(没有圆圈),但在放大和缩小时,没有任何功能聚集。我的代码中缺少什么?
最佳答案
您应该将“pointRadius”属性添加到您的样式图中,因为聚类绘制点而不是多边形特征。
关于javascript - Openlayer 2.x 集群,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35721597/