OpenLayers群集--群集数据不';t出现在event.feature对象中
我的问题很简单——我正在使用Dojo(但不是DojoxOpenLayers模块)创建一个映射项目。我已经在网络上引用了一些例子,为元数据和集群创建了一些悬停气泡。我目前正试图绘制一组由传感器记录的100多个观测值(传感器从不移动,因此每个观测值具有相同的纬度/经度)。选择对象时,激发的事件不包含feature.cluster对象。在任何缩放级别,仅显示顶部功能,我无法访问任何其他数据。我做错了什么OpenLayers群集--群集数据不';t出现在event.feature对象中,openlayers,Openlayers,我的问题很简单——我正在使用Dojo(但不是DojoxOpenLayers模块)创建一个映射项目。我已经在网络上引用了一些例子,为元数据和集群创建了一些悬停气泡。我目前正试图绘制一组由传感器记录的100多个观测值(传感器从不移动,因此每个观测值具有相同的纬度/经度)。选择对象时,激发的事件不包含feature.cluster对象。在任何缩放级别,仅显示顶部功能,我无法访问任何其他数据。我做错了什么 drawObservations: function(data){
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);
}
drawObservations:函数(数据){
控制台信息(“图纸观测”,数据);
if(this.observationLayer!==null){
this.map.removeLayer(this.observationLayer);
}
控制台信息(“建筑特征”);
var特征=[];
用于(数据观察中的var i){
//console.info(“处理观察:”,data.observations[i]);
var point=new OpenLayers.Geometry.point(data.observations[i].经度,data.observations[i].纬度);
//控制台信息(“点:”,点);
features[i]=新的OpenLayers.Feature.Vector(点{
id:data.observations[i].id,
startTime:data.observations[i].startTime,
endTime:data.observations[i].endTime
}, {
填充颜色:'#008040',
填充不透明度:0.8,
strokeColor:#ee9900“,
频闪不透明度:1,
冲程宽度:1,
点半径:8
});
}
控制台信息(“特征尺寸:”,特征长度);
控制台信息(“建筑向量”);
this.observationLayer=新的OpenLayers.Layer.Vector(“观测”{
投影:“EPSG:4326”,
策略:[
新的OpenLayers.Strategy.Cluster()
],
eventListeners:{
“featureselected”:函数(evt){
控制台信息(“所选功能:”,evt);
console.info(“this:,this”);
var特征=evt特征;
var popup=new OpenLayers.popup.FramedCloud(“popup”,
OpenLayers.LonLat.fromString(feature.geometry.toShortString()),
无效的
“观察-”+feature.attributes.id+”
开始时间:“+feature.attributes.startTime+”
结束时间:“+feature.attributes.endTime+”,
无效的
真的
);
feature.popup=弹出窗口;
this.map.addPopup(弹出窗口);
},
“featureunselected”:函数(evt){
控制台信息(“未选择的功能:”,evt);
var特征=evt特征;
this.map.removePopup(feature.popup);
feature.popup.destroy();
feature.popup=null;
}
}
});
console.info(“向向量添加特性”,this.observationLayer);
this.observationLayer.addFeatures(features);
this.map.addLayer(this.observationLayer);
var选择器=新建OpenLayers.Control.SelectFeature(this.observationLayer{
哈弗:没错,
自动激活:真
});
this.observationLayer.events.on({
“featureselected”:此选项显示
});
this.map.addControl(选择器);
},
显示:功能(事件){
控制台信息(“事件:”,事件);
}
将图层添加到地图后,似乎要从图层中删除要素并重新添加:
this.observationLayer.removeFeatures(this.observationLayer.features);
this.observationLayer.addFeatures(features);
这使得集群神奇地工作