The previous article has been completed from the database to query the work of tourist attractions, the following is to show the results of these queries on the map, but also to achieve the query list and map linkage. That is, by clicking on an item in the list, the map can be positioned to that location and pop up Infowindow.
The development itself is not too difficult, but I think it adds a bit of a hurdle because I don't really like the infowindow that comes with the ArcGIS API, I need to do it myself, and this section starts with this DIY Infowindow. First of all to design this form, in order to show no plagiarism, this infowindow renamed Popupwindow.
Popupwindow.mxml
<?XML version= "1.0" encoding= "Utf-8"?><S:groupXmlns:fx= "http://ns.adobe.com/mxml/2009"xmlns:s= "Library://ns.adobe.com/flex/spark"xmlns:mx= "Library://ns.adobe.com/flex/mx"width= "280"Height= "+"Xmlns:esri= "Http://www.esri.com/2008/ags"> <Fx:script> <! [Cdata[import com.esri.ags.Graphic; Import Flash.net.navigateToURL; [Bindable] public var graphic:graphic; protected function Image_close_clickhandler (event:mouseevent): void {this.parent.removeChild (thi s); } ]]> </Fx:script> <!--Bubble shape outer frame - <S:pathData= "M 1 1 L 278 1 L 278 l 175 L 118 L 1"Winding= "Nonzero"> <S:stroke> <S:solidcolorstrokecaps= "None"Color= "#696969"Joints= "Miter"Miterlimit= "4"Weight= "1"/> </S:stroke> <S:fill> <S:solidcolorColor= "#FFFFFF"/> </S:fill> </S:path> <!--Main content - <S:bordercontainer Left= "1" Right= "1"Top= "1"Height= "+"BackgroundColor= "#EAEAEA"dropshadowvisible= "false"> <S:imageID= "Image_close" Right= "5"Click= "Image_close_clickhandler (event)"Source= "Image/close.png"Verticalcenter= "0"/> <S:labelID= "Label_title" Left= "Ten"Color= "#1D2DC6"fontFamily= "Song Body"fontSize= "+"FontWeight= "Bold"text= "{Graphic.attributes.NAME}"Verticalcenter= "0"/> </S:bordercontainer> <S:labelID= "Label_address" Left= "Ten"Top= "$"Color= "#6B6B6B"text= "{Graphic.attributes.REGION}"/> <!--skip to the link to the data when viewing details - <S:label Right= "Ten"Top= "$"Color= "#0000FF"text= "View Details"textdecoration= "Underline"Buttonmode= "true"Click= "Navigatetourl (new URLRequest (Graphic.attributes.URL.toString ()), ' _blank ')"/></S:group>
This component has only two special tricks, one is to use path to draw the bubble shape outside the box, and the other is the closing button click on the processing, also is not difficult to understand things. Here is the core question, how to put this thing on the map? Use the Addchild () method inherited by the map control to remove the RemoveChild () method. Also use the map control's own geographic coordinates and screen coordinate conversion methods to calculate the screen coordinates of the form's placement in the application. This is not complete, we also have to consider when the map in the pan, zoom, the form should be smooth along with the map, which requires simultaneous monitoring of map Extent_change, Pan_update, zoom_update three events, These three events represent any situation where map has changed in extent, ensuring that the form can follow the map completely. The main idea of these, the work behind the previous article has been done in the Leftresultpage.mxml, the following is the revised page of the entire code.
Leftresultpage.mxml
<?XML version= "1.0" encoding= "Utf-8"?><S:vgroupXmlns:fx= "http://ns.adobe.com/mxml/2009"xmlns:s= "Library://ns.adobe.com/flex/spark"xmlns:mx= "Library://ns.adobe.com/flex/mx"width= "+"Gap= "0"> <!--Register event for click Back button back home - <Fx:metadata>[Event (name= "Backtofront", type= "tool. Customevent ")]</Fx:metadata> <Fx:script> <! [Cdata[ Import com.esri.ags.Graphic; Import Com.esri.ags.Map; Import com.esri.ags.events.ExtentEvent; Import com.esri.ags.events.PanEvent; Import com.esri.ags.events.ZoomEvent; Import Com.esri.ags.geometry.MapPoint; Import Com.esri.ags.layers.GraphicsLayer; Import Com.esri.ags.symbols.PictureMarkerSymbol; Import Com.esri.ags.symbols.SimpleMarkerSymbol; Import Com.esri.ags.utils.GeometryUtil; Import Com.esri.ags.utils.GraphicUtil; Import mx.collections.ArrayCollection; Import spark.events.IndexChangeEvent; Import Tool. Customevent; When binding map is used to display features, control Popupwindow//assignment map, three listeners are registered [Bindable] private var _map:map; Public function set Map (VALUE:MAP): void {_map = value; _map.addeventlistener (Extentevent.extenT_change,mapextentchanger); _map.addeventlistener (Panevent.pan_update,panhandler); _map.addeventlistener (Zoomevent.zoom_update,zoomhandler); } Public function Get Map (): map {return _map; }//Change the result to a set function, the binding in the component is to be resultarray//used to assign a map, and then to assign result, then result will add features to map [Bindable] private var resultarray:arraycollection; Public function set Result (value:arraycollection): void {resultarray = value; if (map) {var glayer:graphicslayer = Addgraphiclayer ("query"); For each (Var graphic:graphic in resultarray) {glayer.add (graphic); } map.zoomto (Graphicutil.getgraphicsextent (Resultarray.toarray ())); }} public function get result (): ARRaycollection {return resultarray; }//Return button added remove features and Popwindow private function Back_clickhandler (event:mouseevent): void {Removegraphiclayer ("query"); Removepopup (); Dispatchevent (New Customevent (Customevent.backtofront)); } Private Function Removegraphiclayer (layerid:string): void {if (Map.getlayer (Layerid) !=null) {Map.removelayer (Map.getlayer (Layerid)); }} Private Function Removepopup (): void {if (map.getchildb Yname ("popup")) {Map.removechild (Map.getchildbyname ("popup")); }}//This is a common add Graphicslayer function Private Function Addgraphiclayer (layerid:string): graphicslayer {VAR Glayer:graphicslayer; if (Map.getlayer (Layerid)!=null) {Glayer = Map.getlayer (Layerid) as Graphicslayer; } else {glayer = new Graphicslayer (); Glayer.id = Layerid; Map.addlayer (Glayer); } return Glayer; } Private Function List_result_changehandler (event:indexchangeevent): void {var graph Ic:graphic = List_result.selecteditem as Graphic; var mappoint:mappoint = graphic.geometry as MapPoint; Navigate to the selected feature while controlling the level Map.zoomto (MapPoint); if (Map.level <) Map.level = 12; var Popupwindow:popupwindow; If the map already has Popupwindow, move the Popupwindow to the current position if (Map.getchildbyname ("popup")) { Popupwindow = Map.getchildbyname ("pOpup ") as Popupwindow; popupwindow.graphic = graphic; The popup x, Y is positioned in the upper left corner, to calculate the positioning point to move to the bottom of the bubble, and the symbol to match popupwindow.x = Map.toscreenx (mappoint.x)-130; Popupwindow.y = Map.toscreeny (MAPPOINT.Y)-148; }//If map does not have Popupwindow, create a new one and place it in the corresponding location else {Popupwindow = n EW Popupwindow (); popupwindow.graphic = graphic; Popupwindow.name = "Popup"; popupwindow.x = Map.toscreenx (mappoint.x)-130; Popupwindow.y = Map.toscreeny (MAPPOINT.Y)-148; Map.addchild (Popupwindow); }} Private Function Panhandler (event:panevent): void {popupmove (); } Private Function Zoomhandler (event:zoomevent): void {popupmove (); } Private Function Mapextentchanger (event:extentevent): void {popupmove (); //move is actually recalculating the screen coordinates of the anchor point, moving the Popupwindow private Function popupmove (): void { if (Map.getchildbyname ("popup")) {var Popupwindow:popupwindow = Map.getchildb Yname ("popup") as Popupwindow; var mappoint:mappoint = popupWindow.graphic.geometry as MapPoint; popupwindow.x = Map.toscreenx (mappoint.x)-130; Popupwindow.y = Map.toscreeny (MAPPOINT.Y)-148; } }]]> </Fx:script> <fx:declarations> <!--Place non-visual elements (such as services, value objects) here - </fx:declarations> <S:groupwidth= "100%"Height= "+"> <S:label Left= "0"text= "{' has found ' +resultarray.length+ ' results '}"Verticalcenter= "0"/> <Mx:linkbutton Right= "0"label= "Back"Click= "Back_clickhandler (event)"Verticalcenter= "0"/> </S:group> <s:listID= "List_result"width= "100%"Height= "100%"Itemrenderer= "Renderer.listrenderer"Dataprovider= "{resultarray}" Change= "List_result_changehandler (event)"></s:list></S:vgroup>
So all the design functions are implemented, as a result of the usual effect:
Here, the main function of the project design is completed. Of course, the current project of this kind of delivery is not very appropriate, after the project to do a series of interface adjustment and beautification, which will open our art section.
Arcgis APIs for Flex Project Instance-development article (6): Your own Infowindow