title: OpenLayers: Unable to close popup when added using call from outside map
body: <p>I have written a basic function to allow me to display a popup from a link outside the map. The functionality to open the popup is working fine, but I can't then close it.</p>
  
  <p>Demo link: <a href="http://www.catchingtherain.com/bikestats/stations.php" rel="nofollow">http://www.catchingtherain.com/bikestats/stations.php</a> - click on links in left-hand tabbed panels.</p>
  
  <p>Here's a bit more detail ...</p>
  
  <p>A typical map has about 300 features on a vector layer 'stations' loaded from kml. These are activated onload using</p>
  
  <pre><code>select = new OpenLayers.Control.SelectFeature(stations);           
  stations.events.on({
                  "featureselected": onFeatureSelect,
                  "featureunselected": onFeatureUnselect
                  });
  map.addLayer(stations);
  map.addControl(select);
  select.activate();
  </code></pre>
  
  <p>which works fine - I can open and close popups.</p>
  
  <p>With my off-map links I am calling onclick="showMyPopup([x]) with [x] being an ID attribute loaded in from the kml. The showMyPopup function is</p>
  
  <pre><code>function showMyPopup(myID){
      for(var a = 0; a &lt; stations.features.length; a++){    //loop through all the features
      var feature = stations.features[a];
      if (feature.attributes.ID.value == myID) {            //until it finds the one with the matching ID attribute
         var content = "&lt;h4&gt;" + feature.attributes.name + "&lt;/h4&gt;" + feature.attributes.description;
         popup = new OpenLayers.Popup.FramedCloud("chicken",
                                       feature.geometry.getBounds().getCenterLonLat(),
                                       new OpenLayers.Size(200,200),
                                       content,
                                       null, true, onPopupClose);
         feature.popup = popup;
         map.addPopup(popup);
         }
      }
  }
  </code></pre>
  
  <p>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).</p>
  
  <p>Any help would be much appreciated (maybe there's a simpler way of tackling this?)</p>
  
  <p>Thanks, James</p>
  
  <p>PS and just in case, here's the onFeatureUnselect function ...</p>
  
  <pre><code>function onFeatureUnselect(event) {
          var feature = event.feature;
          if(feature.popup) {
              map.removePopup(feature.popup);
              feature.popup.destroy();
              delete feature.popup;
          }
       }
  </code></pre>