Author: Flyingis
Flex is inherently capable of asynchronous calling, so that Flex can well adapt to common functions in webgis applications. In ArcGIS Flex API, the most typical is dynamic display of geographical element information, for example, if you move the cursor over a geographical element to display the basic information of the element, the "Show InfoWindow on mouse hover" section of ArcGIS Flex API Demo is used as an example.
Code
<! [CDATA [
Import com. esri. ags. geometry. MapPoint;
Import com. esri. ags. Graphic;
Private const m_content: infowindowrolovercontent = new infowindowrolovercontent ();
Override protected function createChildren (): void
{
Super. createChildren ();
Map. infoWindow. content = m_content;
Map. infoWindow. labelVisible = false;
Map. infoWindow. closeButtonVisible = false;
}
Private function roloverhandler (event: MouseEvent): void
{
Const graphic: Graphic = Graphic (event.tar get );
Const mapPoint: MapPoint = MapPoint (graphic. geometry );
M_content.lat = mapPoint. y. toFixed (3 );
M_content.lon = mapPoint. x. toFixed (3 );
Map. infoWindow. show (mapPoint );
}
Private function rollOutHandler (event: MouseEvent): void
{
Map. infoWindow. hide ();
}
]>
When you move the cursor over a geographical element (point, line, and surface), The roloverhandler method is called to display the x/y coordinates of the geographical element, and then the result is cleared by rollOutHandler, all maps are not refreshed synchronously throughout the process. The features of the Flex asynchronous call and the single-thread mechanism make it common to use the callback function method in Flex, such as the previously written event listening:
Code
<? Xml version = "1.0"?>
<! -- Events/SimpleEventHandler. mxml -->
<Mx: Application xmlns: mx = "http://www.adobe.com/2006/mxml" creationComplete = "initApp ();">
<Mx: Script> <! [CDATA [
Import mx. controls. Alert;
Private function initApp (): void {
B1.addEventListener (MouseEvent. CLICK, myEventHandler );
}
Private function myEventHandler (event: Event): void {
Alert. show ("An event occurred .");
}
]> </Mx: Script>
<Mx: Button id = "b1" label = "Click Me"/>
</Mx: Application>
If you want to implement synchronization in Flex, you can consider WebService Components. asynchronous calling is initially a performance-based design. Now, changing to WebService seems to go to another extreme, the design is as follows: "When Using RemoteObject for data interaction, the invoke event is triggered, the screen is locked, and the result is unlocked. "
However, this only means that the RemoteObject is synchronized in data interaction, and the action on the screen still exists asynchronously. For map interaction, the asynchronous design is closer to the actual application.