[OpenLayers-Users] Difficulty setting up an event on a popup.
Xavier Mamano (jorix)
xavier.mamano at gmail.com
Wed Feb 6 14:11:42 PST 2013
Hi,
Try: OpenLayers.Event.observe(popcontent,
'mousedown',function(evt){alert('help')});
Regards,
Xavier Mamano
thedamon wrote
> 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="">
> ' +
> feature.attributes.title +'
> <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
> Users at .osgeo
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
--
View this message in context: http://osgeo-org.1560.n6.nabble.com/Difficulty-setting-up-an-event-on-a-popup-tp5032584p5032609.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
More information about the Users
mailing list