[OpenLayers-Dev] Vector layer - Hover and click at same time

palewire ben.welsh at gmail.com
Tue Feb 3 15:15:36 EST 2009


I was trying to acheive some similar functionality, so I downloaded the trunk
and took a look at SelectFeature.js.  It looks like there is a strict
either/or enforced that doesn't anticipate my -- perhaps crazy -- desire to
allow for both hovering and clicking action.

My desired outcome is for hovers to trigger their own on and off functions
-- and then the click function to act as a sort of hyperlink, pushing the
user to a new "drill down page" about the selected feature.

Would it be possible to either modify the trunk -- or pass in some
modifications to the callback options -- that would allow both hovering and
clicking. I'm imagine an initialize function that looks something mor e
like:

initialize: function(layer, options):

        if (this.hover) {
            callbacks.over = this.overFeature;
            callbacks.out = this.outFeature;
            callbacks.click = this.hoverClickFeature;
        }

And then defined it below as:

    hoverClickFeature: function(feature) {
        if(this.hover) {
            this.onHoverClick(feature);
        }
    },

And, theoretically, my map select code could change to:

var select = new OpenLayers.Control.SelectFeature(feature_vector, {
        hover: true,
        onSelect: show_feature,
        onUnselect: hide_feature,
        onHoverClick: click_feature
}); 

How many stupid decisions have I made here? I'm guessing many. Just an idea.
I see you discussing here the possibility of creating a second independent
control that handles the click. How would that work?

I gave this method above a try and it worked great in FF, but, again,
crashed in IE6. What happens is that it throws a "Failed" error as you jump
from the first page to the next. Again, working the first time, but screwing
up the page if you hit the back button and return or otherwise reload it.

I ran the routine while in Visual Web Developers JavaScript debugging mode
-- and it seems the exception happens in a destroy geometry function that is
passed in my selected feature for some reason.

Not knowing anything about how OL properly closes when it leaves a page, I'm
not sure exactly what's up, but I wonder if there might be a tidy way to
prevent this type of error. Can anyone clue me in? 
-- 
View this message in context: http://n2.nabble.com/Vector-layer---Hover-and-click-at-same-time-tp1835567p2265415.html
Sent from the OpenLayers Dev mailing list archive at Nabble.com.




More information about the Dev mailing list