Question

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;             
                         }
            }

        }
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top