[OpenLayers-Dev] feature events
michael at mulholland.hu
Fri Nov 27 05:36:47 EST 2009
I tried your "FeatureAgent"...
"featureclick" works fine.
"featureover" and "featureout" do not fire.
In your modified (sandbox) Vector.js file, I could find "featureclick", but
not the other 2 events, listed at line 99. "EVENT_TYPES"
Is it possible this could be a reason for the events not firing, or should I
be looking at my own code?
ps. I add my vote for this to be included as an OpenLayers feature.
Ivan Grcic-2 wrote:
> On Sat, Oct 17, 2009 at 1:46 AM, Tim Schaub <tschaub at opengeo.org> wrote:
>> We've wrestled for some time with browser events being blocked by
>> svg/vml elements. This originally meant that you could only use a
>> select feature control with one layer at a time. Andreas contributed a
>> nice solution for selecting features on multiple layers for the last
>> I got a number of things wrong in the select feature control (layer gets
>> selectedFeatures array [ack] and control maintains it [ug], control has
>> select method but layer doesn't, you can't easily deal with
>> feature/mouse interaction without getting all the select feature control
>> behavior, etc.) I've long wanted to just have vector layers trigger
>> feature related events.
>> I put together what seems like a potential solution:
>> This introduces a "FeatureAgent" constructor. If a map has the
>> "featureEvents" property set to true, it gets a feature agent that
>> manages feature related events (from click and mousemove). This gives
>> us featureclick, nofeatureclick, featureover, and featureout event on
>> vector layers.
>> As described in the example, these events are fired for visible vector
>> layers. The over/out events are similar to mouseover/mouseout for other
>> doc elements - except that all features on all layers are essentially
>> treated as if they share the same z-index. This means you get over/out
>> for every feature on every layer as you pass over and out. Similarly,
>> the featureclick event "drills" through all features on all layers. You
>> get the event once for each of multiple overlapping features on a single
>> layer or the same on multiple layers. Listeners are triggered for
>> features in reverse draw order (top first). Any listener can return
>> false to stop remaining listeners from getting called.
>> The whole thing relies on document.elementFromPoint . This is a
>> handy method that accounts for the currently computed style of all
>> elements. The trick is to set the display style to none for each target
>> and call the method again, until all targets on all layers have been
>> accounted for. All this happens in a single browser event listener
>> sequence. Since style display is getting set and reset for all targets
>> during the same sequence, we don't trigger a reflow with each display
>> change. It appears that there also isn't a reflow at the end of the
>> listener sequence either (though I need some heavier examples to test
>> I've played with the example on Firefox 3.5 and IE 6. Haven't tested
>> other browsers yet.
>> There are a number of ways this could be implemented:
>> a) As a control. Traditional, but we don't need the dom element or
>> events object - and this may be a more awkward way in practice.
>> b) As it is now. The agent is added/activated if a map property is set.
>> Could also be added/activated after map construction.
>> c) Crammed into Map.js. I'd rather not do this.
>> d) Other (handler, plugin, more).
>> Thanks for any feedback.
>>  https://developer.mozilla.org/en/DOM/document.elementFromPoint
>> Tim Schaub
>> OpenGeo - http://opengeo.org
>> Expert service straight from the developers.
>> Dev mailing list
>> Dev at openlayers.org
View this message in context: http://n2.nabble.com/feature-events-tp3839189p4075103.html
Sent from the OpenLayers Dev mailing list archive at Nabble.com.
More information about the Dev