I want to call a javascript function when a feature's popup is clicked.
Tried hardcoding it because I couldn't make much out of the API
documentation on events, but the map was capturing the clicks and I
couldn't get around it (it worked but only after a second click_. So now
I'm trying to do it via events.register.
Here is what I have:
var vector = new OpenLayers.Layer.Vector("Points",{
eventListeners:{
'featureselected':function(evt){
var feature = evt.feature;
popup = new OpenLayers.Popup.Anchored("popup",
OpenLayers.LonLat.fromString(feature.geometry.toShortString()),
new OpenLayers.Size(275,71),
'<div id="pincontent" onclick=""><h3>' +
feature.attributes.title +'</h3><div style="display: none;"
id="pindescription">'+ feature.attributes.content +'</div></div>',
null,
false
);
popup.imageSrc = 'img/popup.png';
popup.autoSize = false;
popup.backgroundColor = 'transparent';
var offset = {'size':new OpenLayers.Size(0,0),'offset':new
OpenLayers.Pixel(-74,-10)};
popup.anchor = offset;
popup.panMapIfOutOfView = true;
popup.imageSize = new OpenLayers.Size(275,71);
popup.relativePosition = "br";
popup.calculateRelativePosition = function () {
return 'tr';
};
feature.popup = popup;
map.addPopup(popup);
var popcontent = document.getElementById('pincontent');
map.events.register('mousedown', popcontent,
function(evt){alert('help')}, false);
},
'featureunselected':function(evt){
var feature = evt.feature;
map.removePopup(feature.popup);
feature.popup.destroy();
feature.popup = null;
}
}
});
vector.addFeatures(features);
// create the select feature control
var selector = new OpenLayers.Control.SelectFeature(vector,{
click:true,
autoActivate:true
});
map.addLayers([osm, vector]);
event.register in a few different places with no luck.. I feel like inside
featureselected makes sense because elsewhere the popup will not actually
exist. Any advice on getting this to work would be amazing
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users