问题描述
我正在重新解析已加载到地图上的KML,类似于此处的示例:
并将其转换为可点击的列表,该列表将地图置于点击的点上,并显示该窗口的弹出窗口。
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.
这在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函数:
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;
}
}
}
推荐答案
我认为你应该删除selected.clickFeature调用,而是为你的要素图层中的featureselected事件创建一个事件监听器:
I think you should remove the "selected.clickFeature" call, and instead create an event listener for the "featureselected" event in your feature layer:
如果您在该事件中显示弹出窗口,则只需找到它并使用现有代码选择它,然后删除行
selected.clickFeature();
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 lineselected.clickFeature();
旁注:您的功能服务器能否以其他格式提供数据?例如WFS?不需要解析KML数据。
Sidenote: Can your feature server deliver data in other formats? WFS for instance? Parsing KML data shouldn't be needed.
这篇关于如何在Openlayers中单击地图外部时激活功能+弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!