[Mapeasy] what is listenersupport?
-Written by prodigal son @ cnblogs.com (07-03-30)
Abstract:
Yesterday, in the description of cresposhi about the problems that occurred in the mapeasy QQ Group yesterday afternoon, I saw some friends who had doubts about listenersupport. Yesterday I just climbed through it.CodeTake a look at the mapeasy UML class diagram of cresposhi before going to bed.Source codeI hope more people can understand and join the mapeasy team. I personally think that the future of GIS is limitless.
1. What is listenersupport?
I personally think the name of this class is a bit invalid. This class is used to set all listener objects and differentiate them by different event types, such as drap and click. Therefore, you can intuitively understand that this is a listenerlist.
Object collection involves addlistener and addfirstlistener, and removelistener. However, only these operations do not make much sense. Therefore, listenersupport also has its own behavior: triggers the propertychange event (firepropertychange) of the listener set ).
In this case, listenersupport should be understood as the event publishing and subscription center of map, which is in charge of all the dynamic changes of map.
2. How does listenersupport work with mapeasy )?
First, understand the storage format of listenersupport for listener.
This. Listeners is an array. Each member array stores all listener objects of the same type. For example:
This. Listeners ["drap"] collects all listener objects related to drap.
So what is the purpose of collecting these objects? It is used to notify all listening objects after a specified event so that they can make corresponding dynamic changes.
Here is a specific example:
1. Understand that commond is a proxy class of listenersupport and calls the fire event of listenersupport through the exce method.
2. view the dragaction instance.
| FunctionDragaction (mapmodel ){ |
|
| Baseaction. Apply (This,New Array(Mapmodel )); |
|
| //~ Method |
| /** |
| * Constructor |
| */ |
| { |
| // Register the listener of the command object |
| Command. addlistener ("Drag",This); |
| } |
|
| This. Propertychange =Function(Param, newvalue ){ |
| If(Newvalue! =Null& Newvalue [0] =This. Model. GETID ()){ |
| If(Param ="Drag"){ |
| VaROffset = newvalue [1]; |
| If(Offset. X! = 0 & offset. y! = 0 ){ |
| VaRCentercoord =This. Model. getviewercentercoord (); |
| Newx = centercoord. X-offset. x * mapmodel. Bound. getwidth ()/(This. Model. getzoom (). getbordertilesnum () * mapmodel. tilesize ); |
| Newy = centercoord. Y + offset. y * mapmodel. Bound. getheight ()/(This. Model. getzoom (). getbordertilesnum () * mapmodel. tilesize ); |
| VaRNewcoord =NewCoordinate (newx, newy ); |
| If(! Newcoord. Same (centercoord )){ |
| This. Model. setviewercentercoord (newcoord ); |
| } |
| } |
| } |
| } |
| } |
| } |
|
In the constructor, add the listening object to the drag category of the listening set (command. addlistener ("drag", this);). In this case, as long as map triggers the drap event, listenersupport will trigger listeners whose rates in the set belong to the drag category, this triggers their propertchange event and allows them to perform the drag action based on the newvalue parameter (the action in the above Code ).
3. langziyu
In fact, I don't think there is anything to discuss about this issue. I only need to look at the code and understand its intention. However, I am confused when I see some friends who are within my reach, so Let's explain it at random.