Further to my email last night I now have a public facing example I can share - see e.g. <a href="http://www.catchingtherain.com/bikestats/station.php?id=191">http://www.catchingtherain.com/bikestats/station.php?id=191</a><br>
<br>If you click on either of the 'popular' or 'longest' tabs to the left you'll see the links that display the representative popup on the map. These are the ones that won't close, whereas if you click on a feature on the map they do.<br>
<br>The rest of the site is undeveloped as yet so I'd appreciate it if this isn't shared more widely, but thought a live demonstration of the problem might help.<br><br>Thanks, James<br><br><br><br><div class="gmail_quote">
On Sun, Nov 18, 2012 at 9:18 PM, James Morley <span dir="ltr"><<a href="mailto:james@jamesmorley.net" target="_blank">james@jamesmorley.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi, I have written a basic function to allow me to display a popup from a link outside the map. The basic functionality to open the popup is working fine, but I can't then close it.<br><br>Here's a bit more detail ...<br>

<br>A typical map has about 300 features on a vector layer 'stations' loaded from kml. These are activated onload using<br><br>            select = new OpenLayers.Control.SelectFeature(stations);            <br>            stations.events.on({<br>

                "featureselected": onFeatureSelect,<br>                "featureunselected": onFeatureUnselect<br>                });<br>            map.addLayer(stations);<br>            map.addControl(select);<br>

            select.activate();<br><br>which works fine - I can open and close popups.<br><br>With my off-map links I am calling<span><span> <span>onclick</span>="<span>showMyPopup([x]) with [x] being an ID attribute loaded in from the kml</span></span></span>. The showMyPopup function is<br>

<br>function showMyPopup(myID){<br>    for(var a = 0; a < stations.features.length; a++){                             //loop through all the features in stations <br>    var feature = stations.features[a];<br>    if (feature.attributes.ID.value == myID) {                                        //until it finds the one with the matching ID attribute<br>

       var content = "<h4>" + <a href="http://feature.attributes.name" target="_blank">feature.attributes.name</a> + "</h4>" + feature.attributes.description;<br>       popup = new OpenLayers.Popup.FramedCloud("chicken", <br>

                                     feature.geometry.getBounds().getCenterLonLat(),<br>                                     new OpenLayers.Size(200,200),<br>                                     content,<br>                                     null, true, onPopupClose);<br>

       feature.popup = popup;<br>       map.addPopup(popup);<br>       }<br>    }<br>}<br clear="all"><br>This opens the correct popup from the stations layer as expected, and I can see the popup using the DOM inspector on the stations layer just as it would appear if loaded by clicking on the map feature, but there's then seemingly no way of closing it. The original features on the stations layer are working fine though (opening and closing). And the final clue is that if I open a popup from on the map but click the 'x' on a popup still being displayed from off-map link it closes the other popup. So the bottom line is that when it calls onFeatureUnselect it doesn't seem to connect with the popup loaded from the off-map link, if that makes sense!<br>

<br>Any help would be much appreciated (maybe there's a simpler way of tackling this?)<br><br>Thanks, James<br><br>PS and just in case, here's the onFeatureUnselect function ...<br><br>function onFeatureUnselect(event) {<br>

            var feature = event.feature;<br>            if(feature.popup) {<br>                map.removePopup(feature.popup);<br>                feature.popup.destroy();<br>                delete feature.popup;<br>            }<br>

         }<br><br>Maybe I should just make that generic so it kills any and all pop-ups?<br><br>
</blockquote></div><br><br clear="all"><br>-- <br>---<br>James Morley<br><a href="http://www.jamesmorley.net" target="_blank">www.jamesmorley.net</a> / @jamesinealing<br><a href="http://www.whatsthatpicture.com" target="_blank">www.whatsthatpicture.com</a> / @PhotosOfThePast<br>
<a href="http://www.apennypermile.com" target="_blank">www.apennypermile.com</a><br>