我正在重新解析已加载到地图上的 KML,类似于此处的示例:http://openlayers.org/dev/examples/sundials.html 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;
}
}
}
我认为您应该删除“selected.clickFeature”调用,而是为要素图层中的“featureselected”事件创建一个事件侦听器:
OpenLayers.Layers.Vector http://dev.openlayers.org/apidocs/files/OpenLayers/Layer/Vector-js.html#OpenLayers.Layer.Vector.EVENT_TYPES
如果您在该事件中显示弹出窗口,您只需找到它并使用现有代码选择它,然后删除该行selected.clickFeature();
旁注:您的功能服务器可以提供其他格式的数据吗?例如WFS?不需要解析 KML 数据。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)