简体   繁体   English

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

[英]How do I activate a feature + popup when clicking outside of a map in Openlayers?

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

This was really easy to do in Google Maps, but I can't find any similar Openlayers examples. 这在Google地图中很容易实现,但我找不到任何类似的Openlayers示例。 Is there any easier way to do this? 有没有更简单的方法来做到这一点? Something built-in that I'm missing? 内置的东西我不见了?

HTML : HTML

<ul id="locationTable">
</ul>

JS: 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: 然后为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 think you should remove the "selected.clickFeature" call, and instead create an event listener for the "featureselected" event in your feature layer: 我认为您应该删除“selected.clickFeature”调用,而是为要素图层中的“featureselected”事件创建一个事件侦听器:

OpenLayers.Layer.Vector 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(); 如果您在该事件中显示弹出窗口,则只需找到它并使用现有代码选择它,然后删除selected.clickFeature();

Sidenote: Can your feature server deliver data in other formats? 旁注:您的功能服务器能否以其他格式提供数据? WFS for instance? 例如WFS? Parsing KML data shouldn't be needed. 不需要解析KML数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM