1

我的问题很简单——我正在使用 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);

            }
4

1 回答 1

0

似乎诀窍是从图层中删除要素并在图层添加到地图后重新添加它们:

this.observationLayer.removeFeatures(this.observationLayer.features);
this.observationLayer.addFeatures(features);

这使得集群神奇地工作。

于 2012-12-20T16:59:58.433 回答