6

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

这在谷歌地图中很容易做到,但我找不到任何类似的 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;             
                         }
            }

        }
4

1 回答 1

1

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

OpenLayers.Layer.Vector

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

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

于 2010-12-20T17:50:54.973 回答