我的问题很简单 - 我正在使用Dojo(但不是Dojox openlayers模块)来创建一个映射项目。我已经在网上跟踪了一些示例,为元数据和群集创建了小悬停气泡。我正在尝试绘制一组由传感器记录的100多个观测值(从不移动,因此每个观测值具有相同的纬度/经度)。选择对象后,触发的事件不包含feature.cluster对象。在任何缩放级别,只显示顶部功能,我无法访问任何其他数据。我做错了什么?
drawObservations: function(data){
console.info("drawing observatoins", data);
if (this.observationLayer !== null){
this.map.removeLayer(this.observationLayer);
}
console.info("building features");
var features = [];
for (var i in data.observations){
//console.info("working on observation: ", data.observations[i]);
var point = new OpenLayers.Geometry.Point(data.observations[i].longitude, data.observations[i].latitude);
//console.info("point: ", point);
features[i] = new OpenLayers.Feature.Vector(point, {
id : data.observations[i].id,
startTime: data.observations[i].startTime,
endTime: data.observations[i].endTime
}, {
fillColor : '#008040',
fillOpacity : 0.8,
strokeColor : "#ee9900",
strokeOpacity : 1,
strokeWidth : 1,
pointRadius : 8
});
}
console.info("features size: ", features.length);
console.info("building vectors");
this.observationLayer = new OpenLayers.Layer.Vector("Observations", {
projection: "EPSG:4326",
strategies: [
new OpenLayers.Strategy.Cluster()
],
eventListeners:{
'featureselected':function(evt){
console.info("feature selected: ", evt);
console.info("this: ", this);
var feature = evt.feature;
var popup = new OpenLayers.Popup.FramedCloud("popup",
OpenLayers.LonLat.fromString(feature.geometry.toShortString()),
null,
"<div style='font-size:.8em'><h3>Observation - " + feature.attributes.id + "</h3><hr/><b>Start Time: </b>" + feature.attributes.startTime + "<br/><b>End Time: </b>" + feature.attributes.endTime + "</div>",
null,
true
);
feature.popup = popup;
this.map.addPopup(popup);
},
'featureunselected':function(evt){
console.info("feature unselected: ", evt);
var feature = evt.feature;
this.map.removePopup(feature.popup);
feature.popup.destroy();
feature.popup = null;
}
}
});
console.info("adding features to vector", this.observationLayer);
this.observationLayer.addFeatures(features);
this.map.addLayer(this.observationLayer);
var selector = new OpenLayers.Control.SelectFeature(this.observationLayer,{
hover:true,
autoActivate:true
});
this.observationLayer.events.on({
"featureselected": this.display
});
this.map.addControl(selector);
},
display: function(event){
console.info("event: ", event);
}
答案 0 :(得分:0)
似乎诀窍是从图层中删除要素并在图层添加到地图后重新添加它们:
this.observationLayer.removeFeatures(this.observationLayer.features);
this.observationLayer.addFeatures(features);
这使得聚类神奇地起作用。