如何激活功能 +在 Openlayers 中单击地图外部时会弹出窗口吗?
我正在重新解析已加载到地图上的 KML,类似于此处的示例: http://openlayers.org/dev/examples/sundials.html 并将其变成一个可单击的列表,它将地图集中在单击的点上,并显示它的弹出窗口。
这在 Google 地图中确实很容易做到,但我找不到任何类似的 Openlayers 示例。有没有更简单的方法来做到这一点?我缺少一些内置的东西?
HTML:
<ul id="locationTable">
</ul>
JS:
htmlRows = "";
for(var feat in features) {
// Build details table
featId = features[feat].id; // determine the feature ID
title = jQuery(f).filter('[name=TITLE]').text();
htmlRow = "<li><a href="javascript:selectFeature('"+featId+"');\">"+title+"</a></li>";
htmlRows = htmlRows + htmlRow;
}
jQuery('#locationTable').append(htmlRows);
然后对于 selectFeature 函数:
function selectFeature(fid) {
for(var i = 0; i<kml.features.length;++i) {
if (kml.features[i].id == fid)
{
selected = new OpenLayers.Control.SelectFeature(kml.features[i]);
selected.clickFeature(); // make call to simulate Click event of feature
break;
}
}
}
I'm re-parsing the KML that's already been loaded onto the map similar to the example here:
http://openlayers.org/dev/examples/sundials.html and turning it into a clickable list that will center the map on the point clicked, and display the popup window for it.
This was really easy to do in Google Maps, but I can't find any similar Openlayers examples. Is there any easier way to do this? Something built-in that I'm missing?
HTML:
<ul id="locationTable">
</ul>
JS:
htmlRows = "";
for(var feat in features) {
// Build details table
featId = features[feat].id; // determine the feature ID
title = jQuery(f).filter('[name=TITLE]').text();
htmlRow = "<li><a href="javascript:selectFeature('"+featId+"');\">"+title+"</a></li>";
htmlRows = htmlRows + htmlRow;
}
jQuery('#locationTable').append(htmlRows);
And then for the selectFeature function:
function selectFeature(fid) {
for(var i = 0; i<kml.features.length;++i) {
if (kml.features[i].id == fid)
{
selected = new OpenLayers.Control.SelectFeature(kml.features[i]);
selected.clickFeature(); // make call to simulate Click event of feature
break;
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您应该删除“selected.clickFeature”调用,而是为要素图层中的“featureselected”事件创建一个事件侦听器:
OpenLayers.Layer.Vector
如果您在该事件中显示弹出窗口,则只需找到它并选择与您现有的代码一起使用,然后删除该行
selected.clickFeature();
旁注:您的要素服务器可以提供其他格式的数据吗?例如WFS?不需要解析 KML 数据。
I think you should remove the "selected.clickFeature" call, and instead create an event listener for the "featureselected" event in your feature layer:
OpenLayers.Layer.Vector
If you display the popup in that event, you will only have to find it and select it with your existing code, and remove the line
selected.clickFeature();
Sidenote: Can your feature server deliver data in other formats? WFS for instance? Parsing KML data shouldn't be needed.