ArcGIS For Flex学习之Mapping---Select and zoom
2014-10-21 16:13
429 查看
Tips:这个例子说明如何在图层中选择或反选几何对象,当点击地图时,触发mapClick事件,激活QueryTask,这里的Query中的query.geometry = event.mapPoint;利用鼠标点击的点来查找包括该选择点的Polygon,然后将查询到的几何要素添加到GraphicsLayer中并放大一个级别;同时,再次点击选择的要素时,触发unselectGraphic事件,并从GraphicsLayer中移除该要素。具体效果图及代码如下:
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:esri="http://www.esri.com/2008/ags" pageTitle="Select and Zoom"> <fx:Script> <![CDATA[ import com.esri.ags.Graphic; import com.esri.ags.events.MapMouseEvent; import com.esri.ags.events.QueryEvent; import com.esri.ags.geometry.Extent; import com.esri.ags.utils.GraphicUtil; import mx.collections.ArrayCollection; import mx.collections.ArrayList; private var mapClickToggler:Boolean = true; private function mapClickHandler(event:MapMouseEvent):void { if (mapClickToggler) { query.geometry = event.mapPoint; queryTask.execute(query); } } private function executeCompleteHandler(event:QueryEvent):void { for each (var myGraphic:Graphic in event.featureSet.features) { myGraphic.symbol = mySymbol; myGraphic.addEventListener(MouseEvent.CLICK, unselectGraphic); // myGraphic.addEventListener(MouseEvent.ROLL_OVER, toggleMapClick); // myGraphic.addEventListener(MouseEvent.ROLL_OUT, toggleMapClick); myGraphicsLayer.add(myGraphic); } zoomToGraphics(); } private function zoomToGraphics():void { var graphicProvider:ArrayCollection = myGraphicsLayer.graphicProvider as ArrayCollection; var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(graphicProvider.toArray()); if (graphicsExtent) { myMap.extent = graphicsExtent; // make sure the whole extent is visible if (!myMap.extent.contains(graphicsExtent)) { myMap.level--; } } } private function unselectGraphic(event:MouseEvent):void { myGraphicsLayer.remove(event.currentTarget as Graphic); zoomToGraphics(); } private function toggleMapClick(event:MouseEvent):void { mapClickToggler = !mapClickToggler; } ]]> </fx:Script> <fx:Declarations> <esri:QueryTask id="queryTask" executeComplete="executeCompleteHandler(event)" url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5" useAMF="false"/> <esri:Query id="query" outSpatialReference="{myMap.spatialReference}" returnGeometry="true"/> <esri:SimpleFillSymbol id="mySymbol" alpha="0.7" color="#D3D1D1" > </esri:SimpleFillSymbol> </fx:Declarations> <s:controlBarContent> <s:RichText width="100%"> This sample demonstrates how to select or deselect a graphic in a graphics layer. This is accomplished by using a QueryTask to add features to a graphics layer, or remove graphics from the graphics layer by clicking on that graphic. The GraphicUtil class is also used in this sample to get the extent of all the graphics in the graphics layer and adjust the map extent and scale based upon if the features are contained within the current extent. Click on a state to select or unselect it. The map will zoom to current selection. </s:RichText> </s:controlBarContent> <esri:Map id="myMap" mapClick="mapClickHandler(event)"> <esri:extent> <esri:Extent xmin="-13901000" ymin="3292000" xmax="-8812000" ymax="6154000"> <esri:SpatialReference wkid="102100"/> </esri:Extent> </esri:extent> <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/> <esri:ArcGISDynamicMapServiceLayer url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer" visibleLayers="{new ArrayList([5])}"/> <esri:GraphicsLayer id="myGraphicsLayer"/> </esri:Map> </s:Application>
相关文章推荐
- ArcGIS For Flex学习之Mapping---Map Extent and Mouse Coordinates
- ArcGIS For Flex学习之Mapping---Add LODs for extra zooming
- ArcGIS API for Flex入门 - 7.API学习路线
- ArcGIS API For Flex对ImageServer发布的服务进行渲染及RasterFunction支持函数(学习笔记)
- arcgis api for flex 学习笔记
- 【论文学习记录】PTAM:Parallel Tracking and Mapping for Small AR Workspaces
- ArcGIS for Java_Flex入门学习_数据绑定功能
- [Esri官方声明]ArcGIS APIs / Viewers for Flex and Silverlight的产品周期
- arcgis for flex 学习笔记(一)
- ArcGIS Server API For Flex 学习收集1
- ArcGIS API for Flex制作程序发布后出现错误:"访问 URL 时遇到安全性错误" 解决办法尝试(学习笔记)
- [Esri官方声明]ArcGIS APIs / Viewers for Flex and Silverlight的产品周期
- ArcGIS API For Flex对ImageServer发布的服务进行渲染及RasterFunction支持函数(学习笔记)
- arcgis api for flex学习
- ArcGIS API for Flex and ArcGIS Viewer for Flex 2.2 发布
- Some Useful resources for ArcGIS and Flex
- (转)ArcGIS API for Flex入门 - 7.API学习路线
- 转载的arcgis for flex api version3.7 教程,多学习啊!!!
- Flex 3 Cookbook: Code-Recipes, Tips, and Tricks for RIA Developers
- Flex for ArcGIS实现数据库地图查询