OpenLayers Marker Popups没有消失

时间:2015-08-10 15:14:07

标签: javascript openlayers

问题是我可以看到带标记的所有点,但是当我想获得弹出信息时,我只能看到列表最后一个点的弹出窗口。 我正在使用openlayers 2.1。

这是我的代码:

// create the layer
var vectorLayer = new OpenLayers.Layer.Vector();
var feature = [];
for(var i = 0; i < 10; i++){
  feature[i] = new OpenLayers.Feature.Vector(
  new OpenLayers.Geometry.Point(value.location.lng, value.location.lat).transform('EPSG:4326', 'EPSG:3857'), {
      description: "Name: " + Name + "<br>Address:" + value.location.address + "<br>Likes: " + value.likes.count + "<br>Here now: " + value.hereNow.count
      }, {
      fillColor: '#008040',
      fillOpacity: 0.8,
      strokeColor: "#ee9900",
      strokeOpacity: 1,
      strokeWidth: 1,
      pointRadius: 8
      }

  );

  vectorLayer.addFeatures(feature);map.addLayer(vectorLayer); //Add a selector control to the vectorLayer with popup functions
  var controls = {
      selector: new OpenLayers.Control.SelectFeature(vectorLayer, {
      onSelect: createPopup,
      onUnselect: destroyPopup
      })
  };

  function createPopup(feature) {
      feature.popup = new OpenLayers.Popup.FramedCloud("pop",
      feature.geometry.getBounds().getCenterLonLat(),
      null,
      '<div class="markerContent">' + feature.attributes.description + '</div>',
      null,
      true,

      function() {
      controls['selector'].unselectAll();
      });
      //feature.popup.closeOnMove = true;
      map.addPopup(feature.popup);
  }

  function destroyPopup(feature) {
      feature.popup.destroy();
      feature.popup = null;
  }

  map.addControl(controls['selector']);
  controls['selector'].activate(); 
}

0 个答案:

没有答案