Hi James, yeah after I hit "Send" I thought just use the function name directly since there are no extra parameters necessary anymore. So option 1 is the way to go.
No they are not equivalent, since the second option loses the scope down the line, and the scope becomes the window object. The only way to keep the scope would be to use an OpenLayers.Function.bind in between. Best regards, Bart James Leveille wrote: > Hi Bart, > > First, thanks for the answer. > > Just to let you know that using "i" as my scope works fine with : > > OpenLayers.loadURL ( url, '', i, setHTML ); > > but not with : > > OpenLayers.loadURL ( url, '', i, function ( response ) { setHTML ( > response ); }); > > where I get "[object Window]" instead of the actual value if "i" printed out > (as I get with the first declaration). > > Aren't those two declarations equivalent ? > Again, thanks for your help. > > James > > > > > -----Message d'origine----- > De : Bart van den Eijnden (OSGIS) [mailto:bart...@osgis.nl] > Envoyé : 22 avril 2009 14:25 > À : James Leveille > Cc : users@openlayers.org > Objet : Re: [OpenLayers-Users] GetFeatureInfo with loadURL > > Hi, > > one way is to use i as your scope: > > OpenLayers.loadURL ( url, '', i, function ( response ) { setHTML ( > response); }); > > function setHTML ( response) > > { > > alert ( this ); > > Best regards, > Bart > > James Leveille wrote: > >> Hi, >> >> I'm trying to send a getFeatureInfo to all queryable layers. >> >> In the "onComplete" function, I would like to be able to "know", for >> each response, the index of the corresponding layer (the layer index >> for which the request was sent). >> >> But the "index" value in the "onComplete" function is always wrong >> (seems to be equal to "map.layers.length" value). >> >> How can I make sure the index is correctly passed ? >> >> Thanks a lot. >> >> function findLayerClick ( event ) >> >> { >> >> var url; >> >> var mouseLoc = map.getLonLatFromPixel ( event.xy ); >> >> for ( var i = 0; i < map.layers.length; i++ ) >> >> { >> >> if ( map.layers[i].queryable ) >> >> { >> >> url = map.layers[i].getFullRequestString >> >> ({ >> >> REQUEST: "GetFeatureInfo", >> >> EXCEPTIONS: "application/vnd.ogc.se_xml", >> >> BBOX: map.getExtent().toBBOX(), >> >> X: event.xy.x, >> >> Y: event.xy.y, >> >> SRS: "EPSG:32187", >> >> INFO_FORMAT: "text/html; charset=ISO-8859-1", >> >> QUERY_LAYERS: map.layers[i].params.LAYERS, >> >> FEATURE_COUNT: 5, >> >> VERSION: "1.1.1", >> >> WIDTH: map.size.w, >> >> HEIGHT: map.size.h >> >> }, map.layers[i].url ); >> >> OpenLayers.loadURL ( url, '', this, function ( response ) { setHTML ( >> response, i ); }); >> >> } >> >> } >> >> OpenLayers.Event.stop(event); >> >> } >> >> function setHTML ( response, index ) >> >> { >> >> alert ( index ); >> >> ... ... ... // manipulate the result >> >> } >> >> James >> >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> Users mailing list >> Users@openlayers.org >> http://openlayers.org/mailman/listinfo/users >> >> > > > -- Bart van den Eijnden OSGIS, Open Source GIS bart...@osgis.nl http://www.osgis.nl _______________________________________________ Users mailing list Users@openlayers.org http://openlayers.org/mailman/listinfo/users