[OpenLayers-Users] Event "featureunhighlighted" not triggered

Olivier THIERRY olivier.thierry at gmail.com
Thu Mar 18 06:08:22 EDT 2010


2010/3/17 Eric Lemoine <eric.lemoine at camptocamp.com>:
> On Wed, Mar 17, 2010 at 5:14 PM, Olivier THIERRY
> <olivier.thierry at gmail.com> wrote:
>> Hi,
>>
>> I have a vector layer with two SelectFeature controls : one is used
>> for selection, the other is used to show a popup.
>> It works well except for one case : if I select an element in the
>> vector, then I move the mouse to this element, the
>> "featurehighlighted" event is fired, but on mouse out the
>> "featureunhighlighted" event is not fired !
>
> This is expected, although it's not clear to me whether this the
> wished behavior.
>
> 1. mouse click on the feature -> control 1 selects the feature
> 2. mouse over the feature -> control 2 highlights the feature ->
> "featurehighlighted" triggers
> 3. mouse out of feature -> control 2 detects that another control
> (control 1) had highlighted the feature before it highlighted it
> itself, so it uses that control to highlight the feature the way it
> was highlighted before it highlighted it itself ->
> "featureunhighlighted" does not trigger
>
> Do you (or others) think we should trigger "featureunhighlighted"
> after the call to theOtherControl.highlight()?
>
> See attached patch (untested).
>
> --
> Eric Lemoine
>
> Camptocamp France SAS
> Savoie Technolac, BP 352
> 73377 Le Bourget du Lac, Cedex
>
> Tel : 00 33 4 79 44 44 96
> Mail : eric.lemoine at camptocamp.com
> http://www.camptocamp.com
>

Thanks for your response.
I think "featureunhighlighted" event sould be triggered in my case,
but I don't know for other cases.

Anyway I found a way to workaround the problem by writing my own
control for highlighting. I started from an example found on the web.
Here it is :

OpenLayers.Control.OverRejet = OpenLayers.Class(OpenLayers.Control,
		{
		    layer: null,
	            defaultHandlerOptions: {
		    'delay': 2000,
		    'pixelTolerance': 1,
		    'stopMove': false
	    },
	    initialize: function(layer, options)
			{
			this.layer = layer;
			this.handlerOptions = OpenLayers.Util.extend(
				{}, this.defaultHandlerOptions);
				OpenLayers.Control.prototype.initialize.apply(
					this, arguments
				);

			this.handlers = {
				feature: new OpenLayers.Handler.Feature(
					this,
					this.layer,
					{
						'over': this.over,
						'out' : this.out
					},
			        	{}
				)};
			},

			draw: function() {
				return false;
			},

			activate: function() {
				this.handlers.feature.activate();
			},

			deactivate: function() {
				this.handlers.feature.deactivate();
			},

			over: function(feature) {
				var rejet = feature.rejet;
				if (rejet != null) {
					rejet.showTooltip();
				}
			},

			out: function(feature) {
				var rejet = feature.rejet;
				if (rejet != null) {
					rejet.hideTooltip();
				}
			}); 	

Then I configure this control for my layer :

var highlightControl = new OpenLayers.Control.OverRejet(layer);
map.addControl(highlightControl);
highlightControl.activate();

This does what I needed so no more problem for me ;)

Regards,

Olivier



More information about the Users mailing list