單一線型符號(AGSSimpleLineSymbol),修改顏色、寬度和樣式,其中樣式預設包括:線間隔(Dash)、點間隔(Dot)、線點交替間隔(DashDot)、無間隔(Solid)等。
AGSSimpleFillSymbol* myFillSymbol = [AGSSimpleFillSymbol simpleFillSymbol]; myFillSymbol.color = [UIColor colorWithRed:0.7 green:0.1 blue:0.1 alpha:0.5]; //線的邊框還是“線”AGSSimpleLineSymbol* myOutlineSymbol = [AGSSimpleLineSymbol simpleLineSymbol]; myOutlineSymbol.color = [UIColor redColor]; myOutlineSymbol.width = 2; //set the outline property to myOutlineSymbol myFillSymbol.outline = myOutlineSymbol;
2.1.3 面狀符號 面狀符號包括:單一填充符號(AGSSimpleFillSymbol)和圖片填充符號(AGSPictureFillSymbol),屬性與點狀符號類似,圖片填充符號可以設定顯示比例:xscale\yscale。
AGSSimpleFillSymbol* myFillSymbol =[AGSSimpleFillSymbol simpleFillSymbol]; myFillSymbol.color = [UIColorcolorWithRed:0.7 green:0.1 blue:0.1 alpha:0.5]; //外輪廓AGSSimpleLineSymbol* myOutlineSymbol =[AGSSimpleLineSymbol simpleLineSymbol]; myOutlineSymbol.color = [UIColorredColor]; myOutlineSymbol.width = 2; myFillSymbol.outline = myOutlineSymbol;
2.1.4 文字型符號 文字型符號(AGSTextSymbol)可以用於任何幾何形狀,一般當做標註(Label)來用,預設是系統字型,可以設定其字型:顏色、大小,粗細等。如果想展示某屬性欄位的值,直接用textTemplate就可以完成,如${country_name},其中country_name為屬性欄位名。
圖3-3-2-4 AGSTextSymbol主要屬性和方法
AGSTextSymbol* txtSymbol = [AGSTextSymboltextSymbolWithTextTemplate:@"文字" color:[UIColor greenColor]];
txtSymbol.xoffset = -30.; txtSymbol.yoffset = 30.; txtSymbol.backgroundColor = [UIColor whiteColor]; txtSymbol.fontSize = 20.;
2.1.5 複合型符號 複合型符號(CompositeSymbol)是為了滿足特殊效果要求,對幾何形狀分部位符號化,有兩種:面複合符號(AGSCompositeSymbol)和線複合符號(AGSCompositeLineSymbol)。
面複合符號中可以加入節點符號,突出表現節點。
線複合符號中加入一系列線符號,能表現出漸層的線效果。
實際上在草圖圖層(AGSSketchLayer)表現選中要素的各個節點(端點、邊中點)時就用的是複合型符號。
2.2 渲染 渲染(Renderers)是圖層的符號化樣式,按照圖層中要素的屬性值批量進行符號化。值得注意的是渲染樣式中的符號類型和幾何形狀類型是對應的:點狀符號渲染點資料、線狀符號渲染線資料、面符號對應面資料。
圖3-3-2-5 AGSRenderer的繼承關係
2.2.1 單一渲染 單一渲染(AGSSimpleRenderer),就是用一種符號渲染所有要素,符號可以是任意一種:點狀、線狀、面狀、文字型或者複合型。
其中符號屬性是唯讀,變更的話需要重新建立一個單一渲染樣式。
//構建複合型符號 AGSCompositeSymbol*composite = [AGSCompositeSymbol compositeSymbol]; AGSSimpleMarkerSymbol*markerSymbol = [[[AGSSimpleMarkerSymbol alloc] init] autorelease]; markerSymbol.style= AGSSimpleMarkerSymbolStyleSquare; markerSymbol.color= [UIColor greenColor]; [composite.symbolsaddObject:markerSymbol]; AGSSimpleLineSymbol*lineSymbol = [[[AGSSimpleLineSymbol alloc] init] autorelease]; lineSymbol.color=[UIColor grayColor]; lineSymbol.width= 4; [composite.symbolsaddObject:lineSymbol]; AGSSimpleFillSymbol*fillSymbol = [[[AGSSimpleFillSymbol alloc] init] autorelease]; fillSymbol.color= [UIColor colorWithRed:1.0 green:1.0 blue:0 alpha:0.5] ; [composite.symbolsaddObject:fillSymbol]; //直接渲染 AGSSimpleRenderer*renderer = [AGSSimpleRenderer simpleRendererWithSymbol:composite]; AGSGraphicLayer*graphicsLayer = [AGSGraphicLayer graphicLayer]; graphicsLayer.renderer= renderer;
2.2.2 分級渲染 分級渲染(AGSClassBreaksRenderer),按照數值型屬性把所有要素進行分級,每級要素採用同一種符號。單個層級的數值區間和符號都是一個分段(AGSClassBreak),落在該數值區間內的要素就會按對應的符號渲染。比如有一批小時平均降雨量採樣資料,按照5毫米、30毫米的分界,用小雨、中雨和大到暴雨三種符號展現,就是一個典型的分級渲染樣式。
AGSClassBreaksRenderer *rainRenderer =[[[AGSClassBreaksRenderer alloc] init] autorelease]; rainRenderer.field = @"day"; //分級段AGSClassBreak* lowClassBreak = [AGSClassBreakclassBreakInfoWithLabel:@"Low" description:@"" maxValue:5symbol:lowMarkerSymbol]; AGSClassBreak* mediumClassBreak =[AGSClassBreakclassBreakInfoWithLabel:@"Medium" description:@"" maxValue:30symbol:mediumMarkerSymbol]; AGSClassBreak* highClassBreak = [AGSClassBreakclassBreakInfoWithLabel:@"High" description:@"" minValue:30symbol:highMarkerSymbol]; //添加到分級數組NSMutableArray* classBreaks = [NSMutableArray array];[classBreaks addObject:lowClassBreak]; [classBreaks addObject:mediumClassBreak];[classBreaks addObject:highClassBreak]; rainRenderer.classBreaks = classBreaks; //分級渲染AGSGraphicLayer* graphicsLayer = [AGSGraphicLayer graphicLayer];graphicsLayer.renderer = rainRenderer;
2.2.3 唯一值渲染 唯一值渲染(AGSUniqueValueRenderer),適合按非數值的屬性進行符號化,每一組唯一值(AGSUniqueValue)包括:值、標註、符號等。比如常見的POI興趣點,按照餐飲、賓館、娛樂等進行符號化,就是典型的唯一值渲染。
AGSUniqueValueRenderer *poiRenderer = [[[AGSUniqueValueRenderer alloc] init] autorelease]; //預設符號、對比欄位poiRenderer.defaultSymbol = defaultMakerSymbol; poiRenderer.field1 = @"TYPE"; //設定唯一值AGSUniqueValue* food = [[AGSUniqueValue alloc] initWithValue:@"FOOD" label:@"food" description:nil symbol:foodSymbol]; AGSUniqueValue* hotel = [[AGSUniqueValue alloc] initWithValue:@"HOTEL" label:@"hotel" description:nil symbol:hotelSymbol]; AGSUniqueValue* entertainment = [[AGSUniqueValue alloc] initWithValue:@"ENTERTAINMENT" label:@"entertainment " description:nil symbol:entertainmentSymbol]; [poiRenderer.uniqueValues addObject: food]; [poiRenderer.uniqueValues addObject: hotel]; [poiRenderer.uniqueValues addObject: entertainment]; //唯一值渲染AGSGraphicLayer* graphicsLayer = [AGSGraphicLayer graphicLayer];graphicsLayer.renderer = poiRenderer;
2.2.4 時態渲染 時態渲染(AGSTemporalRenderer),用來表現帶有時態資訊的要素圖層,包括預設渲染樣式(observation renderer)和時間插入器(interpolator)。其中渲染樣式就是普通的單一、分級和唯一值渲染,和時間有關的是插入器,它決定了某一時間點或時間段的符號大小和顏色,插入器分為兩種:漸層區間(Ramp Interpolator)和時間分級(TimeClassBreaksAger)。
漸層區間插入器定義了一個符號顏色起始/終止值、大小起始/終止值,能夠展示連續的時間特徵。
圖3-3-2-6 使用Ramp Interpolator渲染要素
AGSFeatureLayer* featLayer = ...; //ObservationrendererAGSSimpleMarkerSymbol* pointSymbol = [[[AGSSimpleMarkerSymbol alloc] init] autorelease]; pointSymbol.style = AGSSimpleMarkerSymbolStyleSquare; pointSymbol.size = 6; pointSymbol.color = [UIColor blackColor]; AGSSimpleRenderer* obsRenderer = [AGSSimpleRenderer simpleRendererWithSymbol:pointSymbol]; //Color range UIColor*startCol = [UIColor redColor]; UIColor* endCol= [UIColor yellowColor]; //Size rangeint startSize = 20;int endSize = 2; //A rampinterpolator using the color and size rangeAGSRampInterpolator* ramp = [[AGSRampInterpolatoralloc] initWithStartColor:startCol endColor:endCol startSize:startSizeendSize:endSize]; //A temporalrendererAGSTemporalRenderer* temporalRenderer =[[AGSTemporalRenderer alloc] initWithObservationRenderer:obsRendererobservationAger:ramp featureLayer:featLayer];featLayer.renderer = temporalRenderer;
時間分級裡包含了一組時間分級段AGSTimeClassBreak,每段定義了符號大小、顏色,和時間長度(maxRelativeAge)。
圖3-3-2-7 使用時間分級渲染
//A time-awarefeature layerAGSFeatureLayer* featLayer = ...; //An array tohold the class breaksNSMutableArray* classBreaks = [[[NSMutableArray alloc] init] autorelease]; //Class breakfor features upto 2 days oldAGSTimeClassBreak* tcb = [[[AGSTimeClassBreak alloc] init] autorelease]; tcb.maxRelativeAge = 2; tcb.size = 8; tcb.color = [UIColor whiteColor]; [classBreaks addObject:tcb]; //Class breakfor features upto 5 days oldtcb = [[[AGSTimeClassBreak alloc] init] autorelease]; tcb.maxRelativeAge = 5; tcb.size = 5; tcb.color = [UIColor blueColor]; [classBreaks addObject:tcb]; //Class breakfor features upto 12 days oldtcb = [[[AGSTimeClassBreak alloc] init] autorelease]; tcb.maxRelativeAge = 12; tcb.size = 3; tcb.color = [UIColor redColor]; [classBreaks addObject:tcb]; //A classbreaks ager based on the class breaks defined aboveAGSTimeClassBreaksAger *classbreaksAger = [[AGSTimeClassBreaksAger alloc] initWithTimeClassBreaks:classBreaks units:AGSTimeIntervalUnitsDays]; //ObservationrendererAGSSimpleMarkerSymbol* pointSymbol = [[[AGSSimpleMarkerSymbol alloc] init] autorelease]; pointSymbol.style = AGSSimpleMarkerSymbolStyleCircle; pointSymbol.size = 2; pointSymbol.color = [UIColor blackColor]; AGSSimpleRenderer* obsRenderer = [AGSSimpleRenderer simpleRendererWithSymbol:pointSymbol]; //Temporal renderer AGSTemporalRenderer* temporalRenderer = [[AGSTemporalRenderer alloc] initWithObservationRenderer:obsRenderer observationAger:classbreaksAger featureLayer:featLayer]; featLayer.renderer = temporalRenderer;
3 屬性資訊 空間要素的屬性資訊裝載在一個索引值對中(欄位名稱和內容),通常從已有要素直接擷取,或自己重新構建一個NSDictionary。
//擷取已有要素屬性AGSGraphic* myGraphic = [AGSGraphic graphicWithGeometry:myMarkerPoint symbol:myMarkerSymbol attributes: feature.attributesinfoTemplateDelegate:nil]; //構建屬性NSMutableDictionary* attributes = [NSMutableDictionary dictionary];[attributes setObject:Region forKey:@"Region"];[attributes setObject:Magnitude forKey:@"Magn"];[attributes setObject:Depth forKey:@"Depth"];AGSGraphic* myGraphic = [AGSGraphic graphicWithGeometry:myMarkerPoint symbol:myMarkerSymbol attributes: feature.attributesinfoTemplateDelegate:self];
代碼中的資訊模板委託(infoTemplateDelegate)聲明了屬性資訊在彈出框中的顯示內容,接下來的“資訊視窗”章節中會做詳細介紹。