Ticket #2577 (closed feature: duplicate)

Opened 3 years ago

Last modified 3 years ago

OpenLayers.Event: new transversal method addListener and new events "mapmouse..."

Reported by: jorix Owned by: jorix
Priority: minor Milestone: 2.10 Release
Component: Events Version: SVN
Keywords: Cc:
State:

Description

Advantages of the addListener method:

  • This ensures the call of "un" method and the destruction of events
  • The developer will forget to call "un" or "unregister" methods
  • No are required properties to store: Events instances or functions for call "un" method
  • The code is shorter (and better)

Advantages of new events "mapmouse...":

  • The listener who heard these methods has fewer entries
  • Allows some div on the map that they behave as if they were outside (see below Popup.js)
  • Allows automatic deactivation for Control.KeyboardDefaults

see in:

 http://perso.wanadoo.es/xavier.mamano/sandbox/addlistener/examples/addlistener.html

I opened this ticket to discuss my approach, I would appreciate any comments.

SVN revision: 10198

Attachments

addlistener.html Download (14.0 KB) - added by jorix 3 years ago.
Example of use
addlistener.2.html Download (16.8 KB) - added by jorix 3 years ago.
more tests
toolbar-icons.gif Download (5.2 KB) - added by jorix 3 years ago.
The icons
addListener-2577-map.patch Download (9.5 KB) - added by jorix 3 years ago.
small change in usage of "movestart" event
addListener-2577-the-rest.patch Download (50.2 KB) - added by jorix 3 years ago.
sorted by impact and exclude MeasureToolbar control
MeasureToolbar-2577.patch Download (26.0 KB) - added by jorix 3 years ago.
MeasureToolbar panel control
addlistener.3.html Download (17.2 KB) - added by jorix 3 years ago.
more uses of panel
addListener-2577-events.patch Download (9.8 KB) - added by jorix 3 years ago.
fix a bug
addListener-2577-the-rest.2.patch Download (53.4 KB) - added by jorix 3 years ago.
new type of control implemented in panel, see also 2507
addListener-2577-tests-compatibility.patch Download (10.5 KB) - added by jorix 3 years ago.
for tests compatibility
addListener-2577-tests-compatibility.2.patch Download (10.5 KB) - added by jorix 3 years ago.
for tests compatibility
addListener-2577-tests-compatibility.txt Download (10.5 KB) - added by jorix 3 years ago.
I have trouble uploading patches are empty. Why? Now I test it in txt

Change History

Changed 3 years ago by jorix

Example of use

Changed 3 years ago by jorix

more tests

Changed 3 years ago by jorix

The icons

Changed 3 years ago by jorix

small change in usage of "movestart" event

Changed 3 years ago by jorix

sorted by impact and exclude MeasureToolbar control

Changed 3 years ago by jorix

MeasureToolbar panel control

  Changed 3 years ago by jorix

  • keywords review added
  • state set to Review

In what order to read attachments?

  • "addlistener.2.html" It is an example of using the proposals in this ticket, see everything running on  http://perso.wanadoo.es/xavier.mamano/sandbox/addlistener/examples/addlistener.html, highlights:
    • addListener method.
    • events "mapmouse..."
    • allowSelectTextToObjectDiv method and KeyboardDefaults usage.
    • Improvements on CSS and controls array into Panel usage.
  • "addListener-2577-events.patch" new addListener method usage.
  • "addListener-2577-map.patch" new events "mapmouse..." and more.
  • "addListener-2577-the-rest.patch" includes tickets (#2518, #2507 and #2508) use improvements in "addListener-2577-events.patch" and "addListener-2577-map.patch" and others tickets unchanged (#2567, #2501 (only js), #2519 and #2520).
  • "MeasureToolbar-2577.patch" example of using a panel inside another panel. Contains ticket #2509 adapted to use improvements in this ticket.

Detail of "addListener-2577-the-rest.patch" (some tickets mine adapted to better show the possibilities of addListener):

I opened this ticket to discuss my approach, I would appreciate any comments. Please review.

Changed 3 years ago by jorix

more uses of panel

Changed 3 years ago by jorix

fix a bug

Changed 3 years ago by jorix

new type of control implemented in panel, see also 2507

Changed 3 years ago by jorix

for tests compatibility

Changed 3 years ago by jorix

for tests compatibility

Changed 3 years ago by jorix

I have trouble uploading patches are empty. Why? Now I test it in txt

  Changed 3 years ago by jorix

Have trouble uploading patches, are empty (see "addListener-2577-tests-compatibility.txt"). Why?

I still have things to upload :-(

This has not affected the important patches of the ticket:

I would appreciate any comments. Please review.

follow-ups: ↓ 4 ↓ 6   Changed 3 years ago by elemoine

I must say that I don't exactly know what to review. Twelve files are attached to this ticket. What file does actually correspond to the ticket description? MeasureToolbar-2577.patch, for example, looks unrelated to this ticket. I'd love to see one single patch, which makes it clear that your code is "shorter and better".

in reply to: ↑ 3   Changed 3 years ago by jorix

Replying to elemoine:

I must say that I don't exactly know what to review. Twelve files are attached to this ticket. What file does actually correspond to the ticket description? MeasureToolbar-2577.patch, for example, looks unrelated to this ticket. I'd love to see one single patch, which makes it clear that your code is "shorter and better".

Yes, yes. It is difficult to follow the thread. It is best to start at the end.

What I propose is that objects derived from Map, Layer Control, Popup, Marker and Tile have the addListener method. To record events addListener used the method events.on and save the couple of events+eventsListener in a array. This array is used in destruction to unregister de eventsListener and, if necessary, to destroy events. As this is in the base class, all derivatives can only worry about addListener and they can forget unregister.

An example in Control:

  • Listeners by Events.on method:
    • At draw :
          this.myFunction1 = function() {// need a property to use in destroy
              // ... my code    
          };
          this.map.events.on({
            mouseover: this.myFunction1, 
            scope: this
          });

(need this.myFunction1 to use in destroy)

  • and...
    • At destroy:
          this.map.events.un({mouseover: this.myFunction1, scope: this});
          this.myFunction1 = null;

  • Listeners by addListeners:
    • At draw:

this.AddListener(this.map.events,{
            mouseover: this.myFunction1, 
            scope: this
        });

This vision is an evolution of what I raised in #2518, which allows implementations such as #2819, #2520 and #2567. Where whenActive option of addListener is used to unregister events automatically when the control is deactivated.

It also allows you to record events in another object that "this". This can be useful for example in OpenLayers.Control.Panel to record events on the controls instead of panel.

And we at the beginning...

To use cross addListener I thought to implement the code in OpenLayers.Event for reuse in other base classes. Thus, So the beginning is  http://trac.openlayers.org/attachment/ticket/2577/addListener-2577-events.patch in this ticket.


But this is only half, I was worried about the unintended impact of KeyboardDefaults when writes a text and use the arrows. This led me to open the #2508, but was not satisfied.

I mixed part of the solution #2508 with registerEvents Popup and put it on OpenLayers.Event as allowSelectTextToObjectDiv method. With this method indicate that a div into the map to ignore the events of the map and not act KeyboardDefaults.

This is useful for popups and other text to select by mouse or kb. Finally, to have an efficient management of events "mouseover" and "moseout" used in KeyboardDefaults I created the "mapmouseover" and "mapmoseout" and outMapEventsAddDiv method in OpenLayers.Map by  http://trac.openlayers.org/attachment/ticket/2577/addListener-2577-map.patch

These two are the patch in this ticket.


The rest is to mount the usage example:

 http://perso.wanadoo.es/xavier.mamano/sandbox/addlistener/examples/addlistener.html (the code is compressed by a problem with my hosting)

It has been difficult to explain and not too extensive, uuuuf! I hope I've made.

Thanks for reading.

  Changed 3 years ago by jorix

  • owner changed from tschaub to jorix

in reply to: ↑ 3   Changed 3 years ago by jorix

Replying to elemoine:

I must say that I don't exactly know what to review. Twelve files are attached to this ticket. What file does actually correspond to the ticket description? MeasureToolbar-2577.patch, for example, looks unrelated to this ticket. I'd love to see one single patch, which makes it clear that your code is "shorter and better".

I think with the above explanation was not enough, the thing is still unclear. I have opened a new ticket for reading #2629 focused only on addListener. Please, send me some feedback, thanks.

  Changed 3 years ago by jorix

  • keywords review removed
  • state changed from Review to Needs More Work

I am working to split it into multiple tickets, uuuuuf! (see #2629 for addListener)

  Changed 3 years ago by jorix

  • status changed from new to closed
  • state Needs More Work deleted
  • resolution set to duplicate

I close as duplicate, see #2629 and #2647

Note: See TracTickets for help on using tickets.