OSM - 单击标记时弹出窗口不可见

时间:2013-06-28 06:09:12

标签: javascript popup openlayers openstreetmap

点击标记时,OSM弹出窗口没有出现。 我已尝试在标记上单击事件。它有效吗? 建议我如何在点击标记时显示弹出窗口。

JS我试过的代码

var newlonLat = new OpenLayers.LonLat( 78.447876 ,17.371610 )
.transform( new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
    map.getProjectionObject() // to Spherical Mercator Projection
    );
var zoom=9;
var newmarkers = new OpenLayers.Layer.Markers( "Markers" );
map.addLayer(newmarkers);
newmarkers.addMarker(new OpenLayers.Marker(newlonLat));
map.setCenter (newlonLat, zoom);

newmarkers = new OpenLayers.Layer.Markers( "Markers" );

newmarkers.events.register('mouseover', newmarkers, function(evt) {
    popup = new OpenLayers.Popup("chicken",
    newlonLat,
    new OpenLayers.Size(200,50),
    "Location", 
    true);
    map.addPopup(popup);
});

newmarkers.events.register('mouseout', newmarkers, function(evt) {
    popup.hide();
});

map.addLayer(newmarkers);
newmarkers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(Tlon,Tlat).transform( fromProjection, toProjection),icon));

1 个答案:

答案 0 :(得分:0)

正如OpenLayers API中所述,Marker layer本身没有任何特征选择处理。 But Vector Layers does。但是,标记本身也可以处理鼠标事件。

您的代码不起作用,因为您尝试在图层上注册“鼠标悬停”事件而不是标记。

因此,您可以将事件处理程序直接添加到标记中:

myMarker.events.register('mousedown', myMarker, function(evt) { alert("this is Sparta! " + this.icon.url); OpenLayers.Event.stop(evt); });

或者为您的标记使用矢量图层as seen in this example

或使用Layer.Text(Layer.Text sample