[OpenLayers-Users] Difficulty setting up an event on a popup.
Damon Muma
damuma at gmail.com
Wed Feb 6 11:54:30 PST 2013
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20130206/89dd1fc5/attachment.html>
More information about the Users
mailing list