OpenLayers 弹出窗口未切换
当我创建静态标记并附加静态弹出窗口时,一切似乎工作正常。我正在尝试构建动态标记,虽然标记和弹出窗口已正确创建,但它们不再因事件而切换。
我已将代码精简到足以显示地图并绘制一个构造的标记/弹出窗口二人组。也许你能看到我缺少的东西?
<html>
<head>
<style type="text/css">html,body,#basicMap{width:69%;height:60%;}</style>
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
<script>
/**/var oldProjection=new OpenLayers.Projection("EPSG:4326");//Used to scale the GPS coordinates
/**/var newProjection=new OpenLayers.Projection("EPSG:900913");//To the map
/**/var marks=new OpenLayers.Layer.Markers("Debug Site");
/**/var mapnik=new OpenLayers.Layer.OSM("World Map");//Layer containing the map tiles
/**/var size=new OpenLayers.Size(21,25);//Icon height and width
/**/var offset=new OpenLayers.Pixel(-(size.w/2),-size.h);//Icon offset
/**/var mapCenter=new OpenLayers.LonLat(-125.2,54.8).transform(oldProjection,newProjection);
function init()
{
var map=new OpenLayers.Map($("BasicMap"),{controls:[]});
map.addLayer(mapnik);
map.setCenter(mapCenter,3);
map.addLayer(marks);
var TestSite=new site(-131,57.2,"TestSite","DE","Hello World");
map.addPopup(TestSite.popup);
}
function site(lon,lat,siteID,layer,content)
{
this.content=content;
this.layer=layer;
this.lon=lon;this.lat=lat;this.siteID=siteID;
this.lonlat=new OpenLayers.LonLat(lon,lat).transform(oldProjection,newProjection);
this.popup=new OpenLayers.Popup.Anchored(this.siteID,this.lonlat,new OpenLayers.Size(150,375),this.content);
this.marker=new OpenLayers.Marker(this.lonlat);
this.popup.border='1px solid black';this.popup.autoSize=true;
this.marker.events.register("click",this.marker,function(e){this.popup.toggle()});
marks.addMarker(this.marker);
}
</script>
</head>
<body onload="init();"><div id="basicMap"></div></body>
When I create a static marker and attach a static popup, things seem to work fine. I am trying to build dynamic markers, and while the marker's and popup's are being created correctly, they are no longer toggling due to events.
I've stripped the code down to just enough to bring the map up and draw one constructed marker/popup duo. Maybe you can see something I'm missing?
<html>
<head>
<style type="text/css">html,body,#basicMap{width:69%;height:60%;}</style>
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
<script>
/**/var oldProjection=new OpenLayers.Projection("EPSG:4326");//Used to scale the GPS coordinates
/**/var newProjection=new OpenLayers.Projection("EPSG:900913");//To the map
/**/var marks=new OpenLayers.Layer.Markers("Debug Site");
/**/var mapnik=new OpenLayers.Layer.OSM("World Map");//Layer containing the map tiles
/**/var size=new OpenLayers.Size(21,25);//Icon height and width
/**/var offset=new OpenLayers.Pixel(-(size.w/2),-size.h);//Icon offset
/**/var mapCenter=new OpenLayers.LonLat(-125.2,54.8).transform(oldProjection,newProjection);
function init()
{
var map=new OpenLayers.Map($("BasicMap"),{controls:[]});
map.addLayer(mapnik);
map.setCenter(mapCenter,3);
map.addLayer(marks);
var TestSite=new site(-131,57.2,"TestSite","DE","Hello World");
map.addPopup(TestSite.popup);
}
function site(lon,lat,siteID,layer,content)
{
this.content=content;
this.layer=layer;
this.lon=lon;this.lat=lat;this.siteID=siteID;
this.lonlat=new OpenLayers.LonLat(lon,lat).transform(oldProjection,newProjection);
this.popup=new OpenLayers.Popup.Anchored(this.siteID,this.lonlat,new OpenLayers.Size(150,375),this.content);
this.marker=new OpenLayers.Marker(this.lonlat);
this.popup.border='1px solid black';this.popup.autoSize=true;
this.marker.events.register("click",this.marker,function(e){this.popup.toggle()});
marks.addMarker(this.marker);
}
</script>
</head>
<body onload="init();"><div id="basicMap"></div></body>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论