[OpenLayers-Users] GetFeatureInfo on Single Click, Zoom In on Double Click

jvanulde jvanulde at NRCAN.GC.CA
Wed Aug 20 15:37:20 EDT 2008


I managed to get it to work with the OpenLayers.Handler.Click as follows:

// create a new event handler for single click query
var clickEventHandler = new OpenLayers.Handler.Click({ 'map': map }, {
'click': function(e) { doQuery(e); } }); 

clickEventHandler.activate();

function doQuery(evt)
        {

            // get the active layerName from the custom layerSwitcher
property
            // which is set when a user clicks on the nameLabel

            var layerName = layerSwitcher.activeLayer;
            
            if(evt)
            {
                var activeLayer = map.getLayersBy("name", layerName); 
                
                if(activeLayer)
                {        
                    var url =   activeLayer.getFullRequestString({
                                REQUEST: "GetFeatureInfo",
                                EXCEPTIONS: "application/vnd.ogc.se_xml",
                                BBOX: activeLayer.map.getExtent().toBBOX(),
                                X: evt.xy.x,
                                Y: evt.xy.y,
                                INFO_FORMAT: 'text/html',
                                QUERY_LAYERS: activeLayer.params.LAYERS,
                                WIDTH: activeLayer.map.size.w,
                                HEIGHT: activeLayer.map.size.h});
                                
                    var popupWindow = window.open(url, "GetFeatureInfo",
"width=550,height=350,status=yes,scrollbars=yes,resizable=yes");
                    popupWindow.focus();
                    OpenLayers.Event.stop(evt);
                }
            }
        }

Note that I still have some issues with getting the layerName from the
layerSwitcher, so if you have any suggestions on how this can be improved
please let me know. 

Cheers,

Joost



Eric Lemoine-3 wrote:
> 
> You can look at the click-handler.html example. We should change the
> GetFeatureInfo example and use the click handler. A patch would be
> welcome :) Eric
> 
> 2008/8/20, jvanulde <jvanulde at nrcan.gc.ca>:
>>
>> Hi Eric,
>>
>> I am following the demo so I am using the following:
>>
>> map.events.register('click', map, function (e) { ... }
>>
>> Is there an example of using the OpenLayers.Handler.Click that does more
>> or
>> less the same thing that I can look at?
>>
>> Thank you for your help.
>>
>> Joost
>>
>>
>> Eric Lemoine-3 wrote:
>>>
>>> On Wed, Aug 20, 2008 at 4:45 AM, jvanulde <jvanulde at nrcan.gc.ca> wrote:
>>>>
>>>> Hi all,
>>>>
>>>> Currently I have a singleclick handler that does a getFeatureInfo
>>>> request
>>>> on
>>>> an active layer (as per the demo).  Of course everytime I double click
>>>> to
>>>> zoom and recenter the map a getFeatureInfo request is made.  Is there
>>>> an
>>>> elegant way to deal with this?  Ideally, I don't want a getFeatureInfo
>>>> request to be made everytime a user double clicks the map to zoom in
>>>> and
>>>> recenter.  Any suggestions would be helpful.
>>>
>>> Hi
>>>
>>> Do you use OpenLayers.Handler.Click for registering the getFeatureInfo
>>> handler? If you use that I guess double-clicking for zooming shouldn't
>>> trigger getFeatureInfo. Unless I'm missing something; in that case,
>>> some code would help me.
>>>
>>> Regards,
>>> --
>>> Eric
>>> _______________________________________________
>>> Users mailing list
>>> Users at openlayers.org
>>> http://openlayers.org/mailman/listinfo/users
>>>
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/GetFeatureInfo-on-Single-Click%2C-Zoom-In-on-Double-Click-tp19062128p19069989.html
>> Sent from the OpenLayers Users mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> Users mailing list
>> Users at openlayers.org
>> http://openlayers.org/mailman/listinfo/users
>>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
> 
> 

-- 
View this message in context: http://www.nabble.com/GetFeatureInfo-on-Single-Click%2C-Zoom-In-on-Double-Click-tp19062128p19076587.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.




More information about the Users mailing list