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

发布于 2024-10-06 19:12:42 字数 1368 浏览 4 评论 0原文

我正在重新解析已加载到地图上的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Saygoodbye 2024-10-13 19:12:42

我认为您应该删除“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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文