如何在Openlayers中单击地图外部时激活功能+弹出窗口?

Chr*_*ris 6 javascript openlayers openstreetmap

我正在重新解析已加载到地图上的KML,类似于此处的示例:http: //openlayers.org/dev/examples/sundials.html并将其转换为可点击列表,将地图置于中心点击,然后显示它的弹出窗口.

这在Google地图中很容易实现,但我找不到任何类似的Openlayers示例.有没有更简单的方法来做到这一点?内置的东西我不见了?

HTML:

<ul id="locationTable">
</ul>
Run Code Online (Sandbox Code Playgroud)

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);
Run Code Online (Sandbox Code Playgroud)

然后为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;             
                         }
            }

        }
Run Code Online (Sandbox Code Playgroud)

Nik*_*lff 1

我认为您应该删除“selected.clickFeature”调用,而是为要素图层中的“featureselected”事件创建一个事件侦听器:

OpenLayers.Layers.Vector

如果您在该事件中显示弹出窗口,您只需找到它并使用现有代码选择它,然后删除该行 selected.clickFeature();

旁注:您的功能服务器可以提供其他格式的数据吗?例如WFS?不需要解析 KML 数据。