2010年8月21日周六_SymbolizingGraphics_6.6

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

//InsideTheAPI_symbolizingGraphics

//2010年8月21_周六

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

Graphics are symbolized with "symbols". Symbols can be assigned to graphics in several different ways.

a symbol on the graphic,

a symbol on the graphics layer (works as the default for graphics that don't have a particular symbol or renderer),

a renderer (new in version 1.2 of the ArcGIS API for Flex):

Graphics使用Symbol来进行符号化。Symbol可以使用多种方式来关联到Graphics对象。

对图形符号化

对图层进行符号化(作为图形默认的符号,并且图形没有特别的符号或者renderer)。

a renderer(是ArcGIS API FOR flex 1.2版本中新的内容)

SimpleRenderer

ClassBreaksRenderer with optional default symbol

UniqueValueRenderer with optional default symbol

Note that while you can have different geometries (for example points and lines in the same graphics layer), renderers works best when the layer only have one type of geometry.

A renderer defines a set of symbols that will be used for graphics in a graphics layer. You can use renderers to symbolize features with different colors or sizes based on a particular attribute. Here is a basic MXML example from our live samples:

//

使用可以选择的默认的symbol进行ClassBreaksRenderer

使用可以选择的默认的symbol进行UniqueValueRenderer

注意:你可以有不同的geometries(比如:在同一个Graphics图层,可以含有pointsline,但是当一个图层仅仅有用一种类型的geometry的时候,renderers才能更好的工作。

<esri:SimpleMarkerSymbol id="smallSym" size="6" color="0xFF0000" alpha="0.7"/>

<esri:SimpleMarkerSymbol id="mediumSym" size="10" color="0xFF0000" alpha="0.7"/>

<esri:SimpleMarkerSymbol id="largeSym" size="16" color="0xFF0000" alpha="0.7"/>

...

<esri:GraphicsLayer id="graphicsLayer">

    <esri:renderer>

        <esri:ClassBreaksRenderer attribute="ranking">

            <esri:ClassBreakInfo maxValue="0.33" symbol="{smallSym}"/>

            <esri:ClassBreakInfo minValue="0.33" maxValue="0.67" symbol="{mediumSym}"/>

            <esri:ClassBreakInfo minValue="0.67" symbol="{largeSym}"/>

        </esri:ClassBreaksRenderer>

    </esri:renderer>

</esri:GraphicsLayer>

 

There are three renderers in the ArcGIS API for Flex: simple renderer, class breaks renderer, and unique value renderer. Corresponding classes are found in esri.renderer as SimpleRenderer  , ClassBreaksRenderer, and UniqueValueRenderer  respectively(各自的、分别的).

Simple renderer

 

A simple renderer uses the same symbol for every graphic. All you have to do is specify the symbol to be used by the renderer, then apply the renderer to the graphics layer. This is equivalenta.相等的,相当的 n.等价物,意义相同的 to setting the symbol on the graphics layer.

//ArcGIS API for Flex中有三种类型的renderersass breaks rendererunique value renderersimple renderer。响应的类在ESRI.RANDERER中可以找到,他们分别是:SimpleRendererClassBreaksRenderer UniqueValueRenderer.

Simple renderer

simple renderer为每一个Graphic使用同一个symbol。 所有需要你做的仅仅是指定被使用的symbol,然后在Graphics图层使用renderer。这些相当于在Graphics图层设置symbol.

<esri:GraphicsLayer id="graphicsLayer">

    <esri:renderer>//定义renderer变量

        <esri:SimpleRenderer symbol="{smallSym}"/>//设置graphics符号化的样式

    </esri:renderer>

</esri:GraphicsLayer>

or

<esri:GraphicsLayer id="graphicsLayer" symbol="{smallSym}"/>

 

Class breaks renderer

A class breaks renderer symbolizes each graphic based on the value of one of its attributes. Graphics with attribute values inside the class break (a.k.a. "range") will all use the same symbol. The "breaks" define the values at which the symbology changes.

For example, suppose you have a "buildings" layer with an attribute that defines the building age. You want to symbolize buildings constructed since the year 2000 in green, buildings constructed between 1980 and 2000 in yellow, and buildings built before 1980 with red. This would be a good scenario剧情说明书,剧本 for a class breaks renderer.

To use a class breaks renderer, you simply add one or more breaks. Each break specifies the symbol to use and the minimum and maximum values that will be used for that symbol. The example below shows how you can explicitly define breaks:

// class breaks renderer为一个graphic以他们的一个属性为基础设置响应的symbol。含有属性值的Graphics包含在break 类中,这些Grahics都使用同一symbolBreaks定义了symbology所改变的值。

比如:假设你含有一个”buildings”图层,它含有一个属性定义这个building的年纪。 你想要把2000年以及以后建设的楼房用绿色进行符号化、在19802000年之间建设的楼房用yellow来表示,那些建设在1980年以前的buildings使用红色来表示,对于Class breaks renderer来说,这是一个很好的说明。

//----------------------------------------------------------------------------------------------------------------------------

具体的参考代码如下所示:

var smallSym:SimpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE,6, 0xFF0000, 0.7);

var mediumSym:SimpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE,10, 0xFF0000, 0.7);

var largeSym:SimpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE,16, 0xFF0000, 0.7);

var classBreaksRenderer:ClassBreaksRenderer = new ClassBreaksRenderer();

classBreaksRenderer.attribute = "BUILD_DATE";

var classBreakInfos:Array = [

    new ClassBreakInfo(smallSym, Number.NEGATIVE_INFINITY, 1980),

    new ClassBreakInfo(mediumSym, 1980, 2000),

    new ClassBreakInfo(largeSym, 2000, Number.POSITIVE_INFINITY)

];

classBreaksRenderer.infos = classBreakInfos;

graphicsLayer.renderer = classBreaksRenderer;

//----------------------------------------------------------------------------------------------------------------------------

 

Note that if there is no maximum limit on a break, you can use "Number.POSITIVE_INFINITY" for the maximum value. Similarly, you can use "Number.NEGATIVE_INFINITY" when there is no minimum.

Any value that is greater than or equal to the minimum will be included in the break. Any value that is less than the maximum will be included in the break. Thus, if you have two breaks 0 - 10 and 10 - 20, the value 10 would fall in the second break (10 - 20). Avoid creating overlapping(adj. 相互重叠的) breaks or gaps between breaks.

You can also define breaks mathematicallyadv. 精确地, 以数学. For example, you can do some basic arithmetic(算术) to ensure that each break falls an equal distance apart given the input data (sometimes known as an "equal interval" classification分类,分级;类别,级别):

注意:如果在break里面没有一个maximum限制,你可以似乎"Number.POSITIVE_INFINITY"代替maximum值。相应的,你可以使用"Number.NEGATIVE_INFINITY",当没有minimum限制的时候。

任何包大于或者等于minimum的值都将会包含在break里面。任何小于或者等于maximum将会包含在break中。因此,如果你有两个区间,0-10或者10-20,那么10就落在了第二个区间(10--20)。避免创建重叠的区间和在两个区间之间留下空白。

你也可以精确的创建划分区间。 比如:你可以使用一些基本的算术来保证每一个区间分配在相等距离内,这些距离是基于用户输入的数据。(用写时候成为相等间距分级)

var numRanges : int = 10;

var breaks:Number = (max - min) / numRanges;

for (var i:int = 0; i < numRanges; i++)

{

    classBreakInfos.push(new ClassBreakInfo(

        new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, (i+1)*5, 0xFF0000, 0.7),

        min + (i*breaks),

        min + ((i+1)*breaks)

        )

    );

}

//

Unique value renderer

A unique value renderer symbolizes groups of graphics that have matching attributes. For example, you could use a unique value renderer to symbolize zoning(区域) designations指定,名称,称呼: red for "Residential", green for "Industrial", blue for "Commercial", and so on.

To define a unique value renderer you specify the attribute on which to base it on, and an optional defaultSymbol for values that are not covered by a specific UniqueValueInfo. Each "UniqueValueInfo" contains the specific value and symbol to use for each "unique value".

unique value renderer符号化一组含有想匹配属性的图形。比如:你可以使用一个unique value renderer来符号化区域名称:红色为住宅区、绿色为工业区、蓝色为商业区等等。

为了定义一个unique value renderer ,你需要指定一个属性来绑定unique value renderer,和一个用于value的可以选择的默认符号,这个符号不为指定的UniqueValueInfo覆盖。每一个UniqueValueInfo都包含指定的值和用于每一个唯一值的符号。

//具体的参考代码如下所示:

<esri:SimpleFillSymbol id="rFill" alpha="0.5" color="0xFF0000"/>

<esri:SimpleFillSymbol id="gFill" alpha="0.5" color="0x00FF00"/>

<esri:SimpleFillSymbol id="bFill" alpha="0.5" color="0x0000FF"/>

//

<esri:UniqueValueRenderer id="uniqueValueRenderer" attribute="ZONING">

    <esri:UniqueValueInfo value="Residential" symbol="{rFill}"/>

    <esri:UniqueValueInfo value="Industrial" symbol="{gFill}"/>

    <esri:UniqueValueInfo value="Commercial" symbol="{bFill}"/>

</esri:UniqueValueRenderer>

The equivalent code with ActionScript:

var rFill:SimpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, 0xFF0000, 0.5);

var gFill:SimpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, 0x00FF00, 0.5);

var bFill:SimpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, 0x0000FF, 0.5);

//下面的代码使用代码来定义

var uniqueValuerenderer:UniqueValueRenderer = new UniqueValueRenderer();

uniqueValuerenderer.attribute = "ZONING";

var uniqueValueInfos:Array =[];

uniqueValueInfos.push(new UniqueValueInfo(rFill, "Residential"));

uniqueValueInfos.push(new UniqueValueInfo(gFill, "Industrial"));

uniqueValueInfos.push(new UniqueValueInfo(bFill, "Commercial"));

uniqueValuerenderer.infos = uniqueValueInfos;

graphicsLayer.renderer = uniqueValuerenderer;

Values that you don't add to the list are not drawn - unless you specify a defaultSymbol on the UniqueValueRenderer, in which case those graphics will be drawn with the default symbol.

Live renderer samples

//没有被添加列表的值将不会被绘制-除非你为UniqueValueRenderer指定了一个默认的符号,在这中情况下,这些图形将会使默认的符号来绘制。

原文地址:https://www.cnblogs.com/xingchen/p/1805189.html