arcgis server api for flex 笔记
发布时间:2020-12-15 03:44:55 所属栏目:百科 来源:网络整理
导读:转自:http://www.voidcn.com/article/p-wdyzobiz-nh.html 从arcgis for flex 在线sample中摘抄,供参考用。 一、API中的相关属性 1.esri:map 的?wrapAround180属性 esri:Map ?wrapAround180="true"如果是世界地图将此属性设置为true时,一直往西(或往东)
转自:http://www.voidcn.com/article/p-wdyzobiz-nh.html 从arcgis for flex 在线sample中摘抄,供参考用。
一、API中的相关属性1.esri:map 的?wrapAround180属性 <esri:Map ?wrapAround180="true">如果是世界地图将此属性设置为true时,一直往西(或往东)拖动地图时,当拖到地图边界时会接上世界的另一端显示,就像平铺图片一样。
2.设置esri:map的初始地图显示范围和空间参考定义<fx:Declarations> <esri:Extent id="initialExtent" xmin="-13635000" ymin="4541000" xmax="-13625000" ymax="4547000"> <esri:SpatialReference wkid="102100"/> </esri:Extent> </fx:Declarations> <esri:Map extent="{initialExtent}" wrapAround180="true"> <esri:ArcGISTiledMapServiceLayer url="http://10.19.1.50/arcgis/rest/services/baseMap/MapServer"/> </esri:Map> 3.设置esri:map中鼠标样式 (1)<esri:Map openHandCursorVisible="false" 设置是否显示小手样式。
4.调用arcIMS地图服务<esri:Map> <esri:ArcIMSMapServiceLayer serviceHost="http://www.geographynetwork.com" serviceName="Census_TIGER2000"/> </esri:Map> 二、实用代码整理加载地图相关代码1.加载维基地图<esri:Map? <esri:OpenStreetMapLayer /> ?? </esri:Map> 这个openStreetMapLayer指的就是维基地图,内置了。具体详细的信息应该是看这个网址里的文档http://www.openstreetmap.org/,比如加载指定的图层等等。 2.给地图添加一个版权示例在线帮助中打开维基地图的版权示例挺不错的,简洁。 3.调用wms地图服务,控制图层显示<fx:Script> <![CDATA[ import com.esri.ags.Units; ]]> </fx:Script> <esri:Map units="{Units.MILLIMETERS}"> <esri:WMSLayer url="http://10.19.1.50/arcgis/rest/services/Geometry/GeometryServer"> <esri:visibleLayers> <!--Order matters--> <s:ArrayList> <!--States--> <fx:String>0</fx:String> <!--Cities--> <fx:String>2</fx:String> </s:ArrayList> </esri:visibleLayers> </esri:WMSLayer> </esri:Map> 4.控制显示切片地图图层及初始显示等级<fx:Script> <![CDATA[ import com.esri.ags.geometry.MapPoint; import com.esri.ags.layers.TiledMapServiceLayer; import mx.events.FlexEvent; private function layerShowHandler(event:FlexEvent):void { // update the LODs/zoomslider to use/show the levels for the selected base map var tiledLayer:TiledMapServiceLayer = event.target as TiledMapServiceLayer; //myMap.lods = tiledLayer.tileInfo.lods; } ]]> </fx:Script> <esri:Map id="myMap" ?level="1" ?load="myMap.centerAt(new MapPoint(-11713000,4822000))"> <esri:ArcGISTiledMapServiceLayer show="layerShowHandler(event)" url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" visible="{bb.selectedIndex == 0}"/> <esri:ArcGISTiledMapServiceLayer show="layerShowHandler(event)" url="http://server.arcgisonline.com/ArcGIS/rest/services/USA_Topo_Maps/MapServer" visible="{bb.selectedIndex == 1}"/> <esri:ArcGISTiledMapServiceLayer show="layerShowHandler(event)" url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer" visible="{bb.selectedIndex == 2}"/> </esri:Map> <s:ButtonBar id="bb" right="5" top="5" requireSelection="true"> <s:dataProvider> <s:ArrayList> <fx:String>Streets</fx:String> <fx:String>U.S. Topo</fx:String> <fx:String>Imagery</fx:String> </s:ArrayList> </s:dataProvider> </s:ButtonBar> 获取地图的显示范围,经纬度坐标,比例尺,显示等级信息<fx:Script> <![CDATA[ import com.esri.ags.events.ExtentEvent; import com.esri.ags.geometry.Extent; import com.esri.ags.geometry.MapPoint; import com.esri.ags.utils.WebMercatorUtil; // when mouse (cursor) is on the map ... private function loadHandler():void { myMap.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler); } // ... show coordinates of current (mouse) location private function mouseMoveHandler(event:MouseEvent):void { const mapPoint:MapPoint = myMap.toMapFromStage(event.stageX,event.stageY); const latlong:MapPoint = WebMercatorUtil.webMercatorToGeographic(mapPoint) as MapPoint; mousecoords.text = "x,y is " + mapPoint.x.toFixed(0) + "," + mapPoint.y.toFixed(0) + " and Lat/Long is: " + latlong.y.toFixed(6) + " / " + latlong.x.toFixed(6); } // convert current projected extent to geographic and show as such protected function showExtentInGeographic(extent:Extent):String { const geoExtent:Extent = WebMercatorUtil.webMercatorToGeographic(myMap.extent) as Extent; // return geoExtent.toString() + ".." ; return " " + geoExtent.xmin.toFixed(6) + "," + geoExtent.ymin.toFixed(6) + "," + geoExtent.xmax.toFixed(6) + "," + geoExtent.ymax.toFixed(6) + " ? (wkid: " + geoExtent.spatialReference.wkid + ")"; } ]]> </fx:Script> <s:layout> <s:VerticalLayout paddingTop="6"/> </s:layout> <s:HGroup> <s:Label fontWeight="bold" text="Current map extent:"/> <s:RichEditableText editable="false" text='xmin="{myMap.extent.xmin.toFixed(0)}" ymin="{myMap.extent.ymin.toFixed(0)}" xmax="{myMap.extent.xmax.toFixed(0)}" ymax="{myMap.extent.ymax.toFixed(0)}" ? (wkid="{myMap.spatialReference.wkid}")'/> </s:HGroup> <s:HGroup> <s:Label fontWeight="bold" text="Current map extent (in geographic):"/> <s:RichEditableText editable="false" text="{showExtentInGeographic(myMap.extent)}"/> </s:HGroup> <s:HGroup> <s:Label fontWeight="bold" text="Current Mouse Coordinates:"/> <s:RichEditableText id="mousecoords" editable="false" text="Move the mouse over the map to see its current coordinates..."/> </s:HGroup> <s:HGroup> <s:Label fontWeight="bold" text="Current map scale is"/> <s:RichEditableText editable="false" text="1:{myMap.scale.toFixed(0)} (level {myMap.level})"/> </s:HGroup> <esri:Map id="myMap" load="loadHandler()"> <esri:extent> <esri:Extent xmin="3035000" ymin="4305000" xmax="3475000" ymax="10125000"> <esri:SpatialReference wkid="102100"/> <!-- same as tiled map service below --> </esri:Extent> </esri:extent> <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/> </esri:Map> 自定义地图的显示级别<esri:Map> <esri:lods> <esri:LOD resolution="0.0439453125" scale="18468599.9106772"/> <esri:LOD resolution="0.02197265625" scale="9234299.95533859"/> <esri:LOD resolution="0.010986328125" scale="4617149.97766929"/> <esri:LOD resolution="0.0054931640625" scale="2308574.98883465"/> <esri:LOD resolution="0.00274658203125" scale="1154287.49441732"/> </esri:lods> <esri:extent> <esri:Extent xmin="-124.629" ymin="18.826" xmax="-68.027" ymax="56.311"> <esri:SpatialReference wkid="4269"/> </esri:Extent> </esri:extent> <esri:ArcGISDynamicMapServiceLayer url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer"/> </esri:Map> 动态添加图层的显示级别: <fx:Script> <![CDATA[ import com.esri.ags.layers.supportClasses.LOD; private function addLODs():void { // make sure the resolution makes sense for tile schema of the base layer // both resolution and scale are required fields // About NaN: The lods are automatically sorted based on scale,so setting level isn't necessary. var lods:Array = myMap.lods; lods.push(new LOD(NaN,0.6,3000)); lods.push(new LOD(NaN,0.3,1500)); lods.push(new LOD(NaN,0.1,500)); myMap.lods = lods; } ]]> </fx:Script> <esri:Map id="myMap" load="addLODs()"> 一种解决方案当对地图进行查询后,查询结果显示不全时控制地图自动缩小一级,确保完全显示查询结果。<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; 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.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"/> </fx:Declarations> <s:layout> <s:VerticalLayout horizontalAlign="center"/> </s:layout> <s:Label paddingTop="8" text="Click on a state to select or unselect it. ?The map will zoom to current selection."/> <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:GraphicsLayer id="myGraphicsLayer"/> </esri:Map> 加载CSVlayer加载的是一种文本格式的数据。rul指向数据地址,然后指定经纬度坐标 <esri:CSVLayer id="csvLayer" ? fault="csvLayer_faultHandler(event)" ? latitudeFieldName="Lat" ? loadError="csvLayer_loadErrorHandler(event)" ? longitudeFieldName="Lon" ? renderer="{magnitudeRenderer}" ? url="http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-M2.5.txt"> <esri:sourceFields> <esri:Field name="Magnitude"/> <esri:Field name="Depth"/> <esri:Field name="Region" alias="Location"/> <esri:Field name="Datetime"/> </esri:sourceFields> 一个控制二维地图旋转的方向盘arcgis server api for flex的3.1的版本里的sample里有一个这样的例子,方向盘是皮肤组件写的,鼠标旋转方向盘然后地图也按相同的北方向旋转,效果很好。 路径:解压后的API中arcgis_api_for_flex_3_1ArcGIS_FlexsamplessrcMapRotation.mxml, This sample also uses the following files: com/esri/ags/samples/components/RotationWheel.as com/esri/ags/samples/skins/RotationWheelSkin.mxml FeatureLayer相关通过字段属性值动态设置地图符号样式,还有添加tooltip的代码注:对featureLayer中的图形元素设置不同的显示风格时,针对 点线面都用不同的类 点esri:SimpleMarkerSymbol 如:示例中是点 线? esri:SimpleLineSymbol 面 esri:SimpleFillSymbol<fx:Script> <![CDATA[ import com.esri.ags.events.GraphicEvent; protected function featurelayer1_graphicAddHandler(event:GraphicEvent):void { event.graphic.toolTip = event.graphic.attributes.FIPS; } ]]> </fx:Script> <fx:Declarations> <esri:SimpleMarkerSymbol id="symbol1" alpha="0.7" color="0xFF0000" size="6" style="triangle"/> <esri:SimpleMarkerSymbol id="symbol2" alpha="0.7" color="0xFF0000" size="10" style="triangle"/> <esri:SimpleMarkerSymbol id="symbol3" alpha="0.7" color="0xFF0000" size="16" style="triangle"/> <esri:SimpleMarkerSymbol id="symbol4" alpha="0.7" color="0xFF0000" size="22" style="triangle"/> <esri:SimpleMarkerSymbol id="symbol5" alpha="0.7" color="green" size="26" style="circle"/> </fx:Declarations> <s:Label width="100%" text="This map combines a tiled street map with a FeatureLayer service showing census block points rendered using a class break renderer."/> <esri:Map ?openHandCursorVisible="false"> <esri:extent> <esri:Extent id="lowerManhattan" xmin="-8239000" ymin="4968000" xmax="-8235000" ymax="4971000"> <esri:SpatialReference wkid="102100"/> </esri:Extent> </esri:extent> <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/> <esri:FeatureLayer graphicAdd="featurelayer1_graphicAddHandler(event)" ? outFields="[FIPS,POP2000]" ? url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/0"> <esri:renderer> <esri:ClassBreaksRenderer attribute="POP2000"> <esri:ClassBreakInfo maxValue="61" symbol="{symbol1}"/> <esri:ClassBreakInfo maxValue="264" minValue="62" symbol="{symbol2}"/> <esri:ClassBreakInfo maxValue="759" minValue="265" symbol="{symbol3}"/> <esri:ClassBreakInfo maxValue="1900" minValue="760" symbol="{symbol4}"/> <esri:ClassBreakInfo minValue="1901" symbol="{symbol5}"/> </esri:ClassBreaksRenderer> </esri:renderer> </esri:FeatureLayer> </esri:Map> 地图符号样式(二)--多个不同形状的simpleMakerSymbol组合成新的符号图形<esri:renderer> <esri:UniqueValueRenderer attribute="CAPITAL"> <esri:defaultSymbol> <esri:SimpleMarkerSymbol color="0xCCCCCC" size="12" style="x"/> </esri:defaultSymbol> <esri:UniqueValueInfo value="Y"> <esri:symbol> <esri:CompositeSymbol> <!-- Star in circle --> <esri:SimpleMarkerSymbol color="0xFF0000" size="22" style="circle"/> <esri:SimpleMarkerSymbol color="0xFFFFFF" size="20" style="triangle"/> <esri:SimpleMarkerSymbol angle="180" color="0xFFFFFF" size="20" style="triangle"/> </esri:CompositeSymbol> </esri:symbol> </esri:UniqueValueInfo> <esri:UniqueValueInfo value="N"> <esri:symbol> <esri:SimpleMarkerSymbol color="0xFF0000" size="18" style="diamond"/> </esri:symbol> </esri:UniqueValueInfo> </esri:UniqueValueRenderer> </esri:renderer> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |