Using OpenLayers 2.12, I’m retrieving KML map data, containing map point locations from a remote server. The data is successfully received by my Javascript, features are created, and I can see the location markers on my map.
What I try to do then is create a popup when each location is clicked. Here’s my ‘feature selected’ event handler:
function site_selected(event) {
var feature = event.feature;
feature.closeBox = true;
feature.popupClass = OpenLayers.Class(OpenLayers.Popup.FramedCloud, {
'autoSize': true
});
feature.data.popupContentHTML = '<div>hello</div>';
feature.data.overflow = "auto";
feature.lonlat = new OpenLayers.LonLat(feature.geometry.x, feature.geometry.y);
var popup = feature.createPopup(true);
popup.show();
}
However, the call to feature.createPopup(true) returns null.
I’ve looked at the popup example, but that doesn’t involve loading KML data.
I set the lonlat property, however I’m still getting null returned. Question is, why?
I’ve found that using the following code creates a popup and displays it on the map: