How to activate the function + pop-up when clicking outside the map in Openlayers?

I reassemble the KML that is already loaded on a map similar to the example here: http://openlayers.org/dev/examples/sundials.html and turn it into a clickable list that will center the map on the click of a dot and display a popup for her.

It was very easy to do in Google Maps, but I can not find similar examples of Openlayers. Is there an easier way to do this? Is there something inbuilt that I am 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; } } } 
+6
javascript openstreetmap openlayers
source share
1 answer

I think you should remove the call to "selected.clickFeature" and instead create an event listener for the "featureelected" event in your functional level:

OpenLayers.Layer.Vector

If you pop up a window in this case, you only need to find it and select it using the existing code and delete the selected.clickFeature();

Sidenote: can your feature server provide data in other formats? For example, WFS? KML data analysis is not required.

+1
source share

All Articles