[OpenLayers-Users] OpenLayers.Feature.Vector hover + click event

_greg_ gstopar at gmail.com
Thu Dec 10 09:24:41 EST 2009



I think the "problem" is in this method inside OpenLayers.Handler.Feature:

triggerCallback: function(type, mode, args) {
        var key = this.EVENTMAP[type][mode];
        if(key) {
            if(type == 'click' && this.up && this.down) {
                // for click/clickout, only trigger callback if tolerance is
met
                var dpx = Math.sqrt(
                    Math.pow(this.up.x - this.down.x, 2) +
                    Math.pow(this.up.y - this.down.y, 2)
                );
                if(dpx <= this.clickTolerance) {
                    this.callback(key, args);
                }
            } else {
                this.callback(key, args);
            }
        }
    }


First time click on draggable feature I have this.down = null, so bottom
this.callback gets executed.
At second click this.down is not null - dpx is calculated and it is always
larger than this.clickTolerance (default value = 4). So, I set it up to some
large value and seems ok - don't know for side effects.
I guess the problem is in this.down value.



Ivan Grcic-2 wrote:
> 
> BTW you might also investigate this a little bit:
> http://dev.openlayers.org/sandbox/tschaub/select/examples/feature-events.html
> 
> On Thu, Dec 10, 2009 at 2:41 PM, Ivan Grcic <igrcic at gmail.com> wrote:
>> Hi, so your first feature is allready selected when you click on it
>> second time?
>>
>> On Thu, Dec 10, 2009 at 1:30 PM, _greg_ <gstopar at gmail.com> wrote:
>>>
>>> Hi,
>>> Thanks for your answer.
>>> Yes. I've tried this and here is what happens:
>>> 1. I click first on draggable feature => click event occurs => cool
>>> 2. Click on second not draggable feature => click event occurs => cool
>>> 3. Click again on first feature => click event is not dispatched.
>>>
>>> Any ideas ?
>>>
>>>
>>>
>>>
>>> Ivan Grcic-2 wrote:
>>>>
>>>> Hi,
>>>> selectFeature doesnt have click event:
>>>> http://dev.openlayers.org/releases/OpenLayers-2.8/doc/apidocs/files/OpenLayers/Control/SelectFeature-js.html#OpenLayers.Control.SelectFeature.EVENT_TYPES
>>>>
>>>> Defining callback for click should work though
>>>>
>>>>
>>>> OpenLayers.Control.SelectFeature([vector1,vector2],{
>>>>            hover : true,
>>>>            highlightOnly : false,
>>>>             callbacks: {
>>>>                 click : function (feat){
>>>>                      // do what you want here
>>>>                 }
>>>>             }
>>>>        });
>>>>     );
>>>>
>>>> Cheers
>>>>
>>>> On Thu, Dec 10, 2009 at 12:34 PM, _greg_ <gstopar at gmail.com> wrote:
>>>>>
>>>>> Hi all
>>>>>
>>>>> Is possible to recive click events and have hover turned on with
>>>>> OpenLayers.Control.SelectFeature ?
>>>>> I have two vector layers. One for draggable features and another for
>>>>> not
>>>>> draggable.
>>>>> I want to be able to select features from both layers (I'm using
>>>>> OL-2.8).
>>>>> Feature hover works fine and  also featureselected events are ok. But
>>>>> I
>>>>> do
>>>>> not get click events.
>>>>>
>>>>> My code is :
>>>>> ...
>>>>> var vector1 = new OpenLayers.Layer.Vector("NotDraggableMarkers",{
>>>>>            isBaseLayer : false,
>>>>>            rendererOptions : {
>>>>>                yOrdering : true
>>>>>            },
>>>>>            styleMap : this.getMarkerStyleMap()
>>>>>
>>>>>
>>>>>        });
>>>>>        var vector2 = new OpenLayers.Layer.Vector("DraggableMarkers",{
>>>>>            isBaseLayer : false,
>>>>>            rendererOptions : {
>>>>>                yOrdering : true
>>>>>            },
>>>>>            styleMap : this.getMarkerStyleMap()
>>>>>
>>>>>        });
>>>>>
>>>>>        this.map.addLayers([vector1,vector2]);
>>>>>
>>>>>
>>>>>        var dragFeature = new OpenLayers.Control.DragFeature(vector2);
>>>>>        this.map.addControl(dragFeature);
>>>>>        dragFeature.activate();
>>>>>
>>>>>
>>>>>        var select = new
>>>>> OpenLayers.Control.SelectFeature([vector1,vector2],{
>>>>>            hover : true,
>>>>>            highlightOnly : false
>>>>>
>>>>>        });
>>>>>
>>>>>        this.map.addControl(select);
>>>>>        select.events.on({
>>>>>            "featurehighlighted" : this.high,
>>>>>            "click" : this.click
>>>>>        });
>>>>> ...
>>>>>
>>>>> Is there any way to do this ? Any ideas ?
>>>>> Thanks.
>>>>> --
>>>>> View this message in context:
>>>>> http://n2.nabble.com/OpenLayers-Feature-Vector-hover-click-event-tp4144872p4144872.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
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Ivan Grcic
>>>> _______________________________________________
>>>> Users mailing list
>>>> Users at openlayers.org
>>>> http://openlayers.org/mailman/listinfo/users
>>>>
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://n2.nabble.com/OpenLayers-Feature-Vector-hover-click-event-tp4144872p4145073.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
>>>
>>
>>
>>
>> --
>> Ivan Grcic
>>
> 
> 
> 
> -- 
> Ivan Grcic
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
> 
> 

-- 
View this message in context: http://n2.nabble.com/OpenLayers-Feature-Vector-hover-click-event-tp4144872p4145602.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.



More information about the Users mailing list