Javascript 只有一个弹出窗口
问题是我只显示了地图上的一个弹出窗口。 我可以看到所有的点,但弹出窗口只能看到列表的最后一点 我从周日就开始处理rhis问题,在互联网上找不到任何可以解决我问题的信息:(Javascript 只有一个弹出窗口,javascript,jquery,popup,popupwindow,Javascript,Jquery,Popup,Popupwindow,问题是我只显示了地图上的一个弹出窗口。 我可以看到所有的点,但弹出窗口只能看到列表的最后一点 我从周日就开始处理rhis问题,在互联网上找不到任何可以解决我问题的信息:( //创建图层 var vectorLayer=新的OpenLayers.Layer.Vector(“场馆”); //将标记定义为矢量图层的“特征”: var特征=[]; 对于(变量i=0;i
//创建图层
var vectorLayer=新的OpenLayers.Layer.Vector(“场馆”);
//将标记定义为矢量图层的“特征”:
var特征=[];
对于(变量i=0;i<10;i++){
feature[i]=新的OpenLayers.feature.Vector(
新OpenLayers.Geometry.Point(value.location.lng,value.location.lat).transform('EPSG:4326','EPSG:3857'){
描述:“名称:“+Name+”
地址:“+value.location.Address+”
喜欢:“+value.Likes.count+”
此时此地:“+value.hereNow.count”
}, {
填充颜色:'#008040',
填充不透明度:0.8,
strokeColor:#ee9900“,
频闪不透明度:1,
冲程宽度:1,
点半径:8
}
);
矢量图层。添加特征(特征);
map.addLayer(矢量层);
//使用弹出功能向矢量层添加选择器控件
变量控制={
选择器:新建OpenLayers.Control.SelectFeature(矢量层{
onSelect:createPopup,
ononselect:销毁弹出窗口
})
};
函数createPopup(功能){
feature.popup=新建OpenLayers.popup.FramedCloud(“pop”,
feature.geometry.getBounds().getCenterLonLat(),
无效的
''+feature.attributes.description+'',
无效的
符合事实的
函数(){
控件['selector']。取消选择全部();
});
//feature.popup.closeOnMove=true;
map.addPopup(feature.popup);
}
功能(特性){
feature.popup.destroy();
feature.popup=null;
}
addControl(控件['selector']);
控件['selector']。激活();
}
当我在中运行代码时,我发现
- 谷歌浏览器-我可以看到所有的点,但只有一个弹出窗口
- Firefox-一点不弹出
- IE-可以查看所有点和所有弹出窗口
// create the layer
var vectorLayer = new OpenLayers.Layer.Vector("Venues");
// Define markers as "features" of the vector layer:
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();
}