Openlayer 2.x 聚类
Openlayer 2.x clustering
我正在尝试使用 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" 属性 添加到您的 StyleMap 中,因为聚类会绘制点而不是多边形要素。
我正在尝试使用 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" 属性 添加到您的 StyleMap 中,因为聚类会绘制点而不是多边形要素。