arcgis api for flex 编辑功能

<?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:mx="library://ns.adobe.com/flex/mx"
               xmlns:esri="http://www.esri.com/2008/ags"
               pageTitle="Edit graphics with the EditTool">
    <!--
    Description:
    This sample demonstrates how to use the EditTool in your workflows.
    The DrawTool and EditTool are both part of an editing experience.
    The DrawTool allows you to draw new graphics,
    while the EditTool allows you to edit geometries of existing graphics.
    In this sample, click on the toolbar first, then draw a graphic on the map.
    Next, click the graphic that you just created; this will activate the EditTool for that feature.
    You can then move the selected feature by click (mouse down) and drag (move) it somewhere else.
    To edit individual vertices of a line or polygon, simply move any existing
    vertices or add new ones by clicking on a "ghost" vertice and dragging it to anywhere.
    Reshaping features (ellipses, circles, extent, and polygons): click once to select the graphic,
    click again (to activate scaling and rotate mode) you will be able to re-shape the feature.
    Be sure to read to the documentation for full editing behaviors.


    Documentation:
    For more information, see the API documentation.
    http://resources.arcgis.com/en/help/flex-api/apiref/com/esri/ags/events/DrawEvent.html
    http://resources.arcgis.com/en/help/flex-api/apiref/com/esri/ags/events/DrawEvent.html#graphic
    http://resources.arcgis.com/en/help/flex-api/apiref/com/esri/ags/layers/GraphicsLayer.html
    http://resources.arcgis.com/en/help/flex-api/apiref/com/esri/ags/tools/DrawTool.html
    http://resources.arcgis.com/en/help/flex-api/apiref/com/esri/ags/tools/DrawTool.html#graphicsLayer
    http://resources.arcgis.com/en/help/flex-api/apiref/com/esri/ags/tools/DrawTool.html#map
    http://resources.arcgis.com/en/help/flex-api/apiref/com/esri/ags/tools/DrawTool.html#activate()
    http://resources.arcgis.com/en/help/flex-api/apiref/com/esri/ags/tools/DrawTool.html#deactivate()
    http://resources.arcgis.com/en/help/flex-api/apiref/com/esri/ags/tools/DrawTool.html#event:drawStart
    http://resources.arcgis.com/en/help/flex-api/apiref/com/esri/ags/tools/DrawTool.html#event:drawEnd
    http://resources.arcgis.com/en/help/flex-api/apiref/com/esri/ags/tools/EditTool.html


    ArcGIS REST API documentation:
    http://resources.arcgis.com/en/help/rest/apiref/featureserver.html
    http://resources.arcgis.com/en/help/rest/apiref/fslayer.html


    ArcGIS for Server documentation:
    http://resources.arcgis.com/en/help/main/10.1/#/What_is_a_feature_service/0154000002w8000000/
    http://resources.arcgis.com/en/help/main/10.1/#/Using_feature_services_in_a_client_application/0154000005sq000000/
    -->


    <fx:Script>
        <![CDATA[
            import com.esri.ags.Graphic;
            import com.esri.ags.events.DrawEvent;
            import com.esri.ags.events.MapMouseEvent;
            import com.esri.ags.geometry.Extent;
            import com.esri.ags.geometry.Polygon;
            import com.esri.ags.geometry.Polyline;
            import com.esri.ags.symbols.SimpleFillSymbol;
            import com.esri.ags.symbols.SimpleLineSymbol;
            import com.esri.ags.symbols.SimpleMarkerSymbol;


            import mx.events.FlexEvent;
            import mx.events.ItemClickEvent;


            import spark.events.IndexChangeEvent;


            private var graphic:Graphic;
            private var lastEditGraphic:Graphic;
            private var lastActiveEditTypes:String;


            protected function tbb_itemClickHandler(event:ItemClickEvent):void
            {
                if (tbb.selectedIndex < 0)
                {
                    // when toggling a tool off, deactivate it
                    myDrawTool.deactivate();
                }
                else
                {
                    switch (event.item.label)
                    {
                        case "MAPPOINT":
                        {
                            myDrawTool.activate(DrawTool.MAPPOINT);
                            break;
                        }
                        case "POLYLINE":
                        {
                            myDrawTool.activate(DrawTool.POLYLINE);
                            break;
                        }
                        case "FREEHAND_POLYLINE":
                        {
                            myDrawTool.activate(DrawTool.FREEHAND_POLYLINE);
                            break;
                        }
                        case "POLYGON":
                        {
                            myDrawTool.activate(DrawTool.POLYGON);
                            break;
                        }
                        case "FREEHAND_POLYGON":
                        {
                            myDrawTool.activate(DrawTool.FREEHAND_POLYGON);
                            break;
                        }
                        case "EXTENT":
                        {
                            myDrawTool.activate(DrawTool.EXTENT);
                            break;
                        }
                        case "CIRCLE":
                        {
                            myDrawTool.activate(DrawTool.CIRCLE);
                            break;
                        }
                        case "ELLIPSE":
                        {
                            myDrawTool.activate(DrawTool.ELLIPSE);
                            break;
                        }
                    }
                }
            }


            protected function drawTool_drawEndHandler(event:DrawEvent):void
            {
                // reset after finished drawing a feature
                myDrawTool.deactivate();
                tbb.selectedIndex = -1;
            }


            private function myMap_mapMouseDownHandler(event:MapMouseEvent):void
            {
                event.currentTarget.addEventListener(MouseEvent.MOUSE_MOVE, map_mouseMoveHandler);
                event.currentTarget.addEventListener(MouseEvent.MOUSE_UP, map_mouseUpHandler);
            }


            private function map_mouseMoveHandler(event:MouseEvent):void
            {
                event.currentTarget.removeEventListener(MouseEvent.MOUSE_MOVE, map_mouseMoveHandler);
                event.currentTarget.removeEventListener(MouseEvent.MOUSE_UP, map_mouseUpHandler);
            }


            private function map_mouseUpHandler(event:MouseEvent):void
            {
                event.currentTarget.removeEventListener(MouseEvent.MOUSE_MOVE, map_mouseMoveHandler);
                event.currentTarget.removeEventListener(MouseEvent.MOUSE_UP, map_mouseUpHandler);


                if (event.target is Graphic || event.target.parent is Graphic)
                {
                    if (event.target is Graphic)
                    {
                        graphic = Graphic(event.target);
                    }
                    else if (event.target.parent is Graphic) //check for PictureMarkerSymbol
                    {
                        graphic = Graphic(event.target.parent);
                    }


                    if (lastEditGraphic !== graphic)
                    {
                        lastEditGraphic = graphic;
                        lastActiveEditTypes = "moveRotateScale"; // make sure move and edit vertices is the 1st mode
                    }
                    if (graphic.geometry is Polyline || graphic.geometry is Polygon)
                    {
                        if (lastActiveEditTypes == "moveEditVertices")
                        {
                            lastActiveEditTypes = "moveRotateScale";
                            myEditTool.activate(EditTool.MOVE | EditTool.SCALE | EditTool.ROTATE, [ graphic ]);
                        }
                        else
                        {
                            lastActiveEditTypes = "moveEditVertices";
                            myEditTool.activate(EditTool.MOVE | EditTool.EDIT_VERTICES, [ graphic ]);
                        }
                    }
                    else if (graphic.geometry is Extent)
                    {
                        myEditTool.activate(EditTool.MOVE | EditTool.SCALE, [ graphic ]);
                    }
                    else if (graphic.graphicsLayer == myGraphicsLayer)
                    {
                        myEditTool.activate(EditTool.MOVE | EditTool.EDIT_VERTICES, [ graphic ]);
                    }
                }
                else
                {
                    myEditTool.deactivate();
                    lastActiveEditTypes = "moveRotateScale"; // make sure move and edit vertices is the 1st mode
                }
            }
        ]]>
    </fx:Script>


    <fx:Declarations>
        <!-- Symbol for all point shapes -->
        <esri:SimpleMarkerSymbol id="sms"
                                 color="0x00FF00"
                                 size="12"
                                 style="square"/>


        <!-- Symbol for all line shapes -->
        <esri:SimpleLineSymbol id="sls"
                               width="3"
                               color="0x00FF00"/>


        <!-- Symbol for all polygon shapes -->
        <esri:SimpleFillSymbol id="sfs"
                               color="0xFFFFFF"
                               style="diagonalcross">
            <esri:outline>
                <esri:SimpleLineSymbol width="2" color="0x00FF00"/>
            </esri:outline>
        </esri:SimpleFillSymbol>


        <esri:DrawTool id="myDrawTool"
                       drawEnd="drawTool_drawEndHandler(event)"
                       fillSymbol="{sfs}"
                       graphicsLayer="{myGraphicsLayer}"
                       lineSymbol="{sls}"
                       map="{myMap}"
                       markerSymbol="{sms}"/>


        <esri:EditTool id="myEditTool" map="{myMap}"/>
    </fx:Declarations>


    <s:controlBarLayout>
        <s:VerticalLayout gap="10"
                          paddingBottom="7"
                          paddingLeft="10"
                          paddingRight="10"
                          paddingTop="7"/>
    </s:controlBarLayout>
    <s:controlBarContent>
        <s:RichText width="100%">
            The DrawTool and EditTool are both part of an editing experience.  The DrawTool allows you to draw new graphics,
            while the EditTool allows you to edit geometries of existing graphics.
            In this sample, click on the toolbar first, then draw a graphic on the map.
            Next, click the graphic that you just created; this will activate the EditTool for that feature.
            You can then move the selected feature by click (mouse down) and drag (move) it somewhere else.
            To edit individual vertices of a line or polygon, simply move any existing
            vertices or add new ones by clicking on a "ghost" vertice and dragging it to anywhere.
            Reshaping features (ellipses, circles, extent, and polygons): click once to select the graphic,
            click again (to activate scaling and rotate mode) you will be able to re-shape the feature.
            Be sure to read to the documentation for full editing behaviors.
        </s:RichText>
        <mx:ToggleButtonBar id="tbb"
                            itemClick="tbb_itemClickHandler(event)"
                            labelField="null"
                            selectedIndex="-1"
                            toggleOnClick="true">
            <fx:Object icon="@Embed(source='assets/i_draw_point.png')"
                       label="MAPPOINT"
                       toolTip="MapPoint"/>
            <fx:Object icon="@Embed(source='assets/i_draw_line.png')"
                       label="POLYLINE"
                       toolTip="Polyline"/>
            <fx:Object icon="@Embed(source='assets/i_draw_freeline.png')"
                       label="FREEHAND_POLYLINE"
                       toolTip="Freehand Polyline"/>
            <fx:Object icon="@Embed(source='assets/i_draw_poly.png')"
                       label="POLYGON"
                       toolTip="Polygon"/>
            <fx:Object icon="@Embed(source='assets/i_draw_freepoly.png')"
                       label="FREEHAND_POLYGON"
                       toolTip="Freehand Polygon"/>
            <fx:Object icon="@Embed(source='assets/i_draw_rect.png')"
                       label="EXTENT"
                       toolTip="Extent"/>
            <fx:Object icon="@Embed(source='assets/i_draw_circle.png')"
                       label="CIRCLE"
                       toolTip="Circle"/>
            <fx:Object icon="@Embed(source='assets/i_draw_ellipse.png')"
                       label="ELLIPSE"
                       toolTip="Ellipse"/>
        </mx:ToggleButtonBar>
    </s:controlBarContent>


    <esri:Map id="myMap"
              level="3"
              mapMouseDown="myMap_mapMouseDownHandler(event)"
              wrapAround180="true">
        <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"/>
        <esri:GraphicsLayer id="myGraphicsLayer"/>
    </esri:Map>


</s:Application>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ArcGIS API for Flex实现在Flex程序中浏览自己的ArcGIS.Server.9.3中发布的地图,一个最基本的入门例子。 目錄 一、ArcGIS.Server.9.3和ArcGIS API for Flex实现基本的地图浏览(一)........................................................................ 3 二、ArcGIS.Server.9.3和ArcGIS API for Flex实现动态图层和瓦片图层叠加显示(二)...................................................................... 5 三、ArcGIS.Server.9.3和ArcGIS API for Flex实现自己的Toc控件(三) .............................................................................. 8 四、ArcGIS.Server.9.3和ArcGIS API for Flex实现Toolbar功能(四)........................................................................ 16 五、ArcGIS.Server.9.3和ArcGIS API for Flex实现GraphicsLayer上画点、线、面(五) ..................................................................... 20 六、ArcGIS.Server.9.3和ArcGIS API for Flex实现Identify的功能图查属性(六)........................................................................ 24 七、ArcGIS.Server.9.3和ArcGIS API for Flex实现Query查询定位中心功能(七)........................................................................ 30 八、ArcGIS.Server.9.3和ArcGIS API for Flex实现MapTips(八)........................................................................ 37 九、ArcGIS.Server.9.3和ArcGIS API for Flex在MapTips显示饼图数据统计(九) ............................................................................. 41 十、ArcGIS.Server.9.3和ArcGIS API for Flex的GeometryService和buffer分析(十)...................................................................... 48 十一、ArcGIS.Server.9.3和ArcGIS API for Flex的GeometryService和量算距离面积(十一)............................................................................54 十二、ArcGis的SanFrancisco网络数据集制作(网络分析数据篇)............59 十三、ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)......................................................... 67十四、ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和最短路径分析(十三)............................. ..................... ........... ........ . 72

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值