• 2010年8月20日周五_UsingGraphic_6.5


    /*****************************************************************************************/

    //2010年8月20日_周五

    //Using Graphic

    /****************************************************************************************/

    Tutorial overview

    NOTE: Thefollowing discussion assumes that you are familiar with the basic concepts ofFlex.

    Working withGraphics

    The GraphicsLayerenables overlaying(覆盖,重复占位)graphics on top of the map. The graphicscan be drawn by the user as markup or input to a task, or they can be drawn bythe application in response to a task. For example, the application might addthe results of a query to the map as graphics.

    教程向导

    注意:下面的讨论假设你已经熟悉了Flex的基本概念。

    使用图像

    GraphicLayer图层能够让Graphics覆盖在地图的上面。 Graphics可以被用户绘制为标记或者输入的任务,或者被应用程序对任务的响应中绘制。

    比如:应用程序可能会将查询的结果以Graphic的形式展示在地图上

    A graphic iscomprised(包含、包括) of:

    Geometry - Thegeometry determines where the graphic is located and can be point, multipoint, polyline, polygon or extent.

    Symbol - Thesymbol determines how the graphic looks and can be a marker symbol (for pointand multipoint geometries), a line symbol (for polylines), or a fill symbol(for polygons).

    Attributes - Theseare name-value pairs that describe the graphic. If you create the graphic, youneed to assign the attributes. If the graphic is created in response to a taskperformed on a layer, the graphic automatically includes the field attributesof the layer. Some tasks allow you to limit the attributes that are returned tothe result graphic. Query.outFieldsis an example of a property that limits the returned attributes of atask.

    Graphics are notrequired to have all of the above items, and no one item is required. Forexample, many task results are returned as graphic objects in a FeatureSet. These graphics only have geometry andattributes when they are returned. If you want to add the graphics to a map,you must define a symbol for them.

    一个Graphic包含:

    Geometry:Geometry决定了Graphic定位在什么位置,什么位置可以单击,multipoint, polyline, polygon or extent.

    Symbol:symbol决定Graphic显示的样式,她可以是一个marker样式,一个线样式,或者填充样式

    Attributes:他们是描述Graphic的名称值对。 如果你创建了graphic,你需要关联Attribute。 如果Graphic是由在一个图层中task的响应常见,那么Graphi 就自动的包含图层的字段属性。

    一些属性能够让你限制返回的结果Graphic中的属性。Query.outFields 是一个属性,它能偶限制一个task返回的属性。

    Graphic没有要求要含有上面的所有项,并且没有一个项是必须包含的。比如:很多任务的结果以Graphic对象返回在FeatureSet。这些Graphic仅仅含有GEOMETRY属性和Attribute属性,当他们返回的时候。如果你想添加一个Graphic到地图,你必须为他们定义一个symbol

    If you're writingcode that allows users to draw graphics on the map, the Draw toolbar can make your work easier. The Draw toolbar isa class that can help you capture the geometry that a user draws on the screen.You can then define a symbol and apply it to the geometry in a new graphicobject. The drawing toolbar sample demonstrates(示范, 演示,证明) this workflow.(工作流程)

    The way that youadd task results to the map as graphics varies by task type. If your taskreturns a FeatureSet, you get an array of graphics (FeatureSet.features) that you can assign to the graphicProvider of the GraphicsLayer. The code below showshow you might do this with results from QueryTask. Note that the code defines a symbol to theGraphicLayer that is assigned to all the graphics added to that layer.

    如果你正在写代码使之能够让用户在地图上绘制Graphic,那么DrawToolbar可能让你的工作更加容易一些。DrawToolbar控件是一个类,她可以帮助你计算在屏幕上绘制的Geometry。然后你可以定义一个mark样式,然后应用到新Graphic对象的Geometry。drawing toolbar sample说明了他的工作流程。将任务结果以graphics的形式添加到Map上面根据任务类型的不同而分为多种方式。如果任务返回一个FeatureSet,你就获取了一个GRAPHIC(FetureSet.features)数组,它可以指定给GraphicLayer的graphicProvider属性。下面的代码向展示了你可能如何使用来自queryTask的返回结果去做这些操作。

    private functiondoQuery():void

        {

            queryTask.execute(query, newAsyncResponder(onResult, onFault));

            functiononResult(featureSet:FeatureSet, token:Object = null):void

            {

                myGraphicsLayer.graphicProvider =featureSet.features;

            }

            function onFault(info:Object,token:Object = null):void

            {

                Alert.show( info.toString() );

            }

        }

    <esri:SimpleMarkerSymbolid="sms" size="10" color="0xFF0000"style="circle" />

    <esri:GraphicsLayerid="myGraphicsLayer" symbol="{sms}"/>

    Other tasks do notprovide a feature set as a result but do provide the geometry, which you canuse to create a graphic. For example, a Locator task finds an AddressCandidate, whose location property is a MapPoint geometry. You can use this geometry to create agraphic showing the address location, as in the code below:

    for each (varcandidate:AddressCandidate in candidates)

    {

        if (candidate.score > 80) {

            var myGraphic:Graphic = new Graphic();

            myGraphic.geometry =candidate.location;

            myGraphic.symbol = mySymbol;

            myGraphic.attributes = { address:candidate.address,score: candidate.score, locatorName:candidate.attributes.Loc_name };

            myGraphicsLayer.add(myGraphic);

        }

    }

    See the Samplesfor more ideas of how to create graphics from the results of differenttasks.

    查看Samples获取更多的的如何从不同任务返回的结果中创建Graphics。

    Working withSymbols

    Symbols that are available to render the graphic areSimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol, PictureMarkerSymbol, PictureMarkerSymbol,InfoSymbol, CartographicLineSymbol and CompositeSymbol.Refer to the samples to learn how to use the different symbols.

    Infosymbol andinfoRenderer

    与符号一起工作

    Symbols能够render Graphic为SimpleMarkerSymbol,SimpleLineSymbol,SimpleFillSymbol,PictureMarkerSymbol,PictureMarkerSymbol,InfoSymbol,CartograhicLineSymbol和CompositeSymbol

    参照例子学习如何使用不同的Symbols.

    InfoSymbols aresmall windows containing user interface (UI) controls and data that provideinformation about a point feature on a map. Unlike InfoWindows, multipleInfoSymbols can be displayed on a map at one time.

    InfoSymbol has two properties infoPlacementand infoRenderer. The property infoPlacement determinesthe orientation(n.方向,目标;熟悉,适应,情况介绍) of the symbol. Refer to the InfoPlacement class for the list of possible values.

    The propertyinfoRenderer is of type IFactory and can be defined as either inlineor external.The infoRenderer contains the definition of UI controls to add to theInfoSymbol and the data that determines its appearance. Once the InfoSymbol has been created, it can be assigned as agraphic symbol, similar to a MarkerSymbol.

    Defining inlineinfoRenderer

    You can defineinfoRenderers as inline, i.e. defined in the same file as InfoSymbol.

    To define aninline infoRenderer:

    Insert InfoSymboland infoRenderer tags.

    Define UI controlswithin the <mx:Component> tag. These will be the contents of InfoSymbol.

    If necessary, useouterDocument to include variables and methods outside <mx:Component>.

    InfoSymbols是一个小的窗口,包含着用户界面控件和数据,这些数据提供了地图上point Feature的相关信息, 和infoWindows不一样的是,多infoSymbols可以在同一事件展示在地图上面。

    InfoSymbol包含有两个属性:infoPlacement和infoRenderer。infoPlacement属性决定了symbol的方向。

    单击链接InfoPlacement 类获取可能值的列表。

    infoRenderer属性是一个Ifactory类型,它可以在内部定义也可以在外部定义。infoRenderer包含了添加到InfoSymbol中UI控件的定义以及决定他们表现样式的数据。一旦InfoSymbol被创建,她就可以以一个Graphic Symbol分配,这个和MarkerSymbol类似。

    <esri:InfoSymbolid="infoSymbol1">

        <esri:infoRenderer>

            <mx:Component>

                <mx:VBox>

                    <mx:Panelid="myPanel" height="100%"

                        width="100%"backgroundAlpha="0"

                       initialize="{outerDocument.initPanel(event)}"/>

                    <mx:Buttonid="myButton" height="100%"

                        width="100%"backgroundAlpha="0"

                       click="{outerDocument.showResults()}"/>

                </mx:VBox>

            </mx:Component>

        </esri:infoRenderer>

    </esri:InfoSymbol>

    //

    Defining external infoRenderer

    Defined in aseparate file from InfoSymbol, external infoRenderers are preferred because oftheir modular, reusable design. The external infoRenderer isdefined by taking all the content that would be contained between the<mx:Component> tags and placing it in a discrete(分离的、毫无关联的) MXML or ActionScript file. An example of aninfoRenderer in a separate MXML file called MyInfoRenderer.mxml will look like below.

    定义外部infoRenderer

    定义一个来自的infoSymbol的单独的文件,我们更喜欢外部的infoRenderers,因为他们的modular、可重复使用的设计。 外部的infoRenderer将所有的将被包包含的内容包含在<mx:Component>标签之间,然后将他们放置在分离的MXML或者脚本文件中。一个infoRenderer包含在一个单独的MXML文件中的例子,例子的名称为:MyInfoRenderer.mxml将会和下面的代码相似。

    <?xmlversion="1.0" encoding="utf-8"?>

    <mx:VBoxxmlns:mx="http://www.adobe.com/2006/mxml"

        label="{data.STATE_NAME}"

        backgroundColor="0xEEEEEE">

        <mx:Label text="State Fips:{data.STATE_FIPS}"/>

        <mx:Label text="Abbreviation:{data.STATE_ABBR}"/>

        <mx:Label text="Area:{data.AREA}"/>

    </mx:VBox>

    Once defined, theinfoRenderer can be used by any InfoSymbol inActionScript or MXML.To set the infoRenderer inActionScript, construct your code similar to the following:

    varmySymbol:InfoSymbol = new InfoSymbol();

    mySymbol.infoRenderer= new ClassFactory(MyInfoRenderer);

    myGraphic.symbol =mySymbol;

    To set the infoRenderer in MXML, construct your code similar to thefollowing:

    <esri:InfoSymbolid="infoSymbol1" infoRenderer="MyInfoRenderer"/>

    Limitations

    InfoSymbol canonly be assigned to points. To add InfoSymbols to multipoints, convert them topoints. To add InfoSymbols to lines or polygons, youcan find a label point of the line or polygon and either change the graphic'sgeometry to centerpoint or create a new point graphic at the location of thecenterpoint.

    For example:

    varpolygon: Polygon;

    var centerPt: MapPoint;

    polygon = myGraphic.geometry as Polygon;

    centerPt = polygon.extent.center;

    myGraphic.geometry= centerPt;

    一旦定义,infoRenderer可以被AS文件或者MXML文件中的任何InfoSymbol使用。为了用ActionScripte定义infoRenderer,创建你的代码和下面的类似。

    varmySymbol:InfoSymbol = new InfoSymbol();

    mySymbol.infoRenderer= new ClassFactory(MyInfoRenderer);

    myGraphic.symbol= mySymbol;

    为了在MXML文件中定义infoRenderer,创建你的代码和下面的类似。

    <esri:InfoSymbolid="infoSymbol1" infoRenderer="MyInfoRenderer"/>

    限制

    InfoSymbol只能赋值给points。我了给Multtipoints添加InfoSymbols,将multipoints转换为points。 为来向lines或者polygons添加InfoSymbols。。你可以找到line或者polygon的一个labelpont,可以改变graphic的Geometry到他们的centerPoint或者在他们的centerPoint位置创建一个新的Graphic。

    比如:

    varpolygon: Polygon;

    varcenterPt: MapPoint;

    polygon= myGraphic.geometry as Polygon;

    centerPt= polygon.extent.center;

  • 相关阅读:
    第二十七节(多线程、线程的创建和启动、生命周期、调度、控制、同步)
    第二十六节(对象流,File类)
    第二十五节(转换流,打印流)
    第二十四节(Java文件流,缓冲流)
    第二十三节(String,StringBuffer,基础类型对应的 8 个包装类,日期相关类、 Random 数字 ,Enum枚举)下
    【转】perl如何避免脚本在windows中闪一下就关闭
    计算机基础(二)
    计算机基础(一)
    04 数据结构
    03 逻辑与结构
  • 原文地址:https://www.cnblogs.com/xingchen/p/1804157.html
Copyright © 2020-2023  润新知