flex中的bufer

    技术2022-05-20  51

    昨日改了一个buffer,buffer出来了但是跟随着一个问题,那就是identifytask出不来了。重新修改,发现一开始的问题就出来没有给地图指出extent,和wkid。这个必须制定,否则就会出现buffer做不出来的我难题。以下是buffer的正确代码

    <?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  xmlns:esri="http://www.esri.com/2008/ags" layout="absolute" backgroundColor="#FFFFFF"><mx:Script> <![CDATA[    import com.esri.ags.events.DrawEvent;    import com.esri.ags.events.*;    import com.esri.ags.geometry.Geometry;    import com.esri.ags.Graphic;    import com.esri.ags.tasks.*;    import com.esri.ags.SpatialReference;    import com.esri.ags.toolbars.Navigation;        import  mx.events.ItemClickEvent;    import mx.controls.Alert;   [Bindable]       [Embed(source="assets/measure-point.png")]        public var point:Class;

            [Bindable]       [Embed(source="assets/measure-line.png")]        public var polyline:Class;                [Bindable]       [Embed(source="assets/measure-line.png")]        public var polygon:Class;                 [Bindable]        [Embed(source="assets/measure-line.png")]        public var ext:Class;                        private function itemClickHandler(event:ItemClickEvent):void             {                 switch(event.index)                 {                     case 0:                     {                         drawToolbar.activate(Draw.MAPPOINT);                         break;                     }                    case 1:                    {                        drawToolbar.activate(Draw.POLYLINE);                        break;                    }                    case 2:                    {                        drawToolbar.activate(Draw.POLYGON);                        break;                    }                     case 3:                    {                        drawToolbar.activate(Draw.EXTENT);                        break;                    }                }            }

    private function drawEndHandler(event:DrawEvent):void            {                var myGraphic:Graphic=event.graphic;                //设置buffer参数                var bufferParameters : BufferParameters = new BufferParameters();                                   bufferParameters.features=[myGraphic];                //buffer距离半径 这里的具体单位由下面的单位设置决定                bufferParameters.distances = [1000];                //buffer单位 KILOMETER,METER                bufferParameters.unit = BufferParameters.UNIT_METER;                //buffer空间参照系,样例的空间参考系Id,WKID为102113的id,4326,对应于中国的wkid为102100,                //只要使用了Geometry Service,则必须有与map控件中的wkid对应的wkid                                bufferParameters.bufferSpatialReference = new SpatialReference(102113);                                          //添加BUFFER_COMPLETE监听                myGeometryService.addEventListener(GeometryServiceEvent.BUFFER_COMPLETE, bufferCompleteHandler);                  //进行buffer分析                myGeometryService.buffer( bufferParameters );                 Alert.show(myGraphic.geometry.type.toString());                 }                          //buffer完成后调用方法            private function bufferCompleteHandler( event : GeometryServiceEvent ) : void            {                             myGraphicsLayer.clear();                //移除BUFFER_COMPLETE监听                myGeometryService.removeEventListener(GeometryServiceEvent.BUFFER_COMPLETE,bufferCompleteHandler);                //获取buffer结果Graphic                for each (var graphic : Graphic in event.graphics )                {                    //设置显示样式                    graphic.symbol = sfs;                    //添加到GraphicsLayer进行显示                    myGraphicsLayer.add( graphic );                               var identifyParams:IdentifyParameters=new IdentifyParameters();                    //查询结果需要返回Geometry                    identifyParams.returnGeometry=true;                    //查询冗余范围                    identifyParams.tolerance=2;                    //宽                    identifyParams.width = myMap.width;                    //高                    identifyParams.height = myMap.height;                    //设置查询的Geometry                    identifyParams.geometry=graphic.geometry;                    //从ComboBox获取选择的图层index设置要查询的图层                    //查询图层id为2的图层,就是States层                    identifyParams.layerIds=[0];                    //查询可见图层                    //identifyParams.layerOption=IdentifyParameters.LAYER_OPTION_VISIBLE;                    identifyParams.mapExtent=myMap.extent;                    //进行查询                   identifyTask.execute(identifyParams);                }            }                            //查询完成后执行的事件             private function identifyCompleteHandler(event:IdentifyEvent):void             {                   var datas:Array=new Array();                // myGraphicsLayer.clear();                 //遍历查询结果把查询到的feature添加到GraphicsLayer进行高亮显示                 //同时把查询到的元素的名称添加到datas对象数组用来DataGrid显示用                 for each (var result:IdentifyResult in event.identifyResults)                {                    myGraphicsLayer.add(result.feature);                /*     datas.push(result.feature.attributes);                    //Alert.show(result.feature.attributes.toString());     */                    datas.push({"value":result.value});                }                //设置mx:DataGrid的数据源                datalist.dataProvider=datas;            }          ]]></mx:Script> <mx:Canvas width="700" height="600" borderStyle="solid" borderThickness="3" verticalCenter="16" left="10">     <esri:Map id="myMap" crosshairVisible="false" logoVisible="false"  scaleBarVisible="true"  >  <esri:extent>     <esri:Extent xmin="71" ymin="8" xmax="137" ymax="56">                          <esri:SpatialReference wkid="4326"/>                  </esri:Extent>        </esri:extent>        <esri:ArcGISDynamicMapServiceLayer  id="testlayer" url="http://localhost/ArcGIS/rest/services/ggg/MapServer" />        <esri:GraphicsLayer id="myGraphicsLayer"  />    </esri:Map>    </mx:Canvas>    <mx:DataGrid id="datalist" height="398" verticalCenter="14" borderStyle="solid" borderThickness="3" left="708">    </mx:DataGrid> <esri:GeometryService id="myGeometryService" url="http://localhost/ArcGIS/rest/services/Geometry/GeometryServer"/>

    <esri:SimpleFillSymbol id="sfs" color="0x00FF00" alpha="0.6"/>

             <esri:Draw id="drawToolbar" map="{myMap}" graphicsLayer="{myGraphicsLayer}" drawEnd="drawEndHandler(event)" />

         <mx:ToggleButtonBar verticalCenter="-300"  itemClick="itemClickHandler(event)" toggleOnClick="true" left="11">         <mx:dataProvider>         <mx:Array>         <mx:Object icon="{point}" />         <mx:Object icon="{polyline}" />         <mx:Object icon="{polygon}" />         <mx:Object icon="{ext}" />        </mx:Array>        </mx:dataProvider>    </mx:ToggleButtonBar>     <esri:IdentifyTask id="identifyTask" identifyComplete="identifyCompleteHandler(event)" url="http://localhost/ArcGIS/rest/services/ggg/MapServer"/></mx:Application>


    最新回复(0)