Quantcast

Order/Priority of Control.GetFeature and Control.WMSGetFeatureInfo on click?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Order/Priority of Control.GetFeature and Control.WMSGetFeatureInfo on click?

anwa
Hello,

I am unsure if OpenLayers provides any way to control the order in which controls handle events.

---Situation:
I have a WMS layer with multiple features very close together.
I use Control.WMSGetFeatureInfo to get general information about all the features within the search radius around a  click.
I also use Control.GetFeature to get specific information for a single feature when it is selected.

Both controls do those jobs like they're supposed to do.

Now, I only need the WMSGetFeatureInfo if no actual feature was clicked (i.e. selected by GetFeature). If GetFeature doesn't hit a feature (clickout), the WMSGetFeatureInfo should work as usual.


---Problem:
WMSGetFeatureInfo is always called before GetFeature, so it is always performed regardless of GetFeature selected a feature or not, and I cannot figure out a way to make it go last (so it could change its behaviour according to GetFeature's results).


---What I've tried:
* Switching around the order in which those two Controls were created, added to the map, activated. Didn't manage to make GetFeature go before WMSGetFeatureInfo. (Maybe I missed the correct order?)

* Setting GetFeature's click handler's stopSingle option to true, but then WMSGetFeatureInfo obviously won't be called when no feature was hit, either.

* Deactivating WMSGetFeatureInfo when GetFeature was active, and activating WMSGetFeatureInfo when GetFeature registered a clickout. But then the click event that triggered GetFeature in the first place doesn't get handed to WMSGetFeatureInfo.


Any thoughts/tips what else I can try to get my desired behaviour?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Order/Priority of Control.GetFeature and Control.WMSGetFeatureInfo on click?

Alexandre Dubé
Hello,

   I'd try your solution proposed below, and manually call the
WMSGetFeatureInfo getInfoForClick or request method.  They need an
OpenLayers.Pixel object, so that'd be what you need to track down from
the GetFeature control.  You might need to override one of its method
for that, as such (untested) :

     OpenLayers.Control.GetFeature.prototype.selectClick = function(evt) {
         // override
         this.lastXY = evt.xy;

         var bounds = this.pixelToBounds(evt.xy);

         this.setModifiers(evt);
         this.request(bounds, {single: this.single});
     };

   and then, in your 'clickout' callback method, you could access what
the last pixel was.  How does that sound ?

HTH,

Alexandre


On 12-08-23 05:35 AM, nica wrote:
> * Deactivating WMSGetFeatureInfo when GetFeature was active, and activating
> WMSGetFeatureInfo when GetFeature registered a clickout. But then the click
> event that triggered GetFeature in the first place doesn't get handed to
> WMSGetFeatureInfo.


--
Alexandre Dubé
Mapgears
www.mapgears.com

_______________________________________________
Users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Order/Priority of Control.GetFeature and Control.WMSGetFeatureInfo on click?

anwa
This post was updated on .
Hello Alexandre,

sorry for taking so long to answer, I was away from work for a while and just now got around to trying your solution!

The only thing that needed to be changed was that WMSGetFeatureInfo getInfoForClick needs the click event, not just the event's xy. Now it works just the way I intended to:

----
//Overriding the selectClick method
        OpenLayers.Control.GetFeature.prototype.selectClick = function(evt) {
        this.lastClick = evt; //We need the click event, not the xy coordinates
                var bounds = this.pixelToBounds(evt.xy);
                this.setModifiers(evt);
                this.request(bounds, {single: this.single});
        };

//After overriding the method, create the GetFeature control
        getFeatureControl = new OpenLayers.Control.GetFeature ( { ... } );
        map.addControl( getFeatureControl );
        getFeatureControl.activate();

//Deactivate the (existing) WMSGetFeatureInfo control until we need it
        wmsGFIControl.deactivate();

//On GetFeature clickout, activate the WMSGetFeatureInfo control, let it run for the last click, and deactivate it again
        getFeatureControl.events.register("clickout", this, function(e) {
                wmsGFIControl.activate();
                wmsGFIControl.getInfoForClick( getFeatureControl.lastClick ); //or: e.object.lastClick
                wmsGFIControl.deactivate();
        });
----

Thanks a lot for your help, overriding the selectClick method to remember the last clicked coordinates never even occurred to me! :)

Anne
Loading...