主要思路就是在graphicsLayer 中加入多个grpahic 后,重新计算出 包含所有graphic 后的Envelope。
然后以Envelope 范围画一个graphic 再增加到graphicsLayer
DLog(@"查询到%d条记录",featureSet.features.count)AGSSimpleLineSymbol *fillSym = [AGSSimpleLineSymbol simpleLineSymbol];fillSym.color = [UIColor whiteColor];for(int i=0; i < featureSet.features.count; i++){AGSGraphic *gra = [featureSet.features objectAtIndex:i];gra.symbol = fillSym;[self.graphicsLayer addGraphic:gra];}if ( self.query1Completed == self.query2Completed && self.query1Completed == TRUE){//开始缩放到路段集合if (self.graphicsLayer.graphics != NULL && self.graphicsLayer.graphics.count >=1) {//accumulate the min/maxdouble xmin = ((AGSGraphic *)self.graphicsLayer.graphics[0]).geometry.envelope.xmin;double ymin = ((AGSGraphic *)self.graphicsLayer.graphics[0]).geometry.envelope.ymin;double xmax = ((AGSGraphic *)self.graphicsLayer.graphics[0]).geometry.envelope.xmax;double ymax = ((AGSGraphic *)self.graphicsLayer.graphics[0]).geometry.envelope.ymax;for (int i=0;i<self.graphicsLayer.graphics.count;i++) {if (((AGSGraphic *)self.graphicsLayer.graphics[i]).geometry.envelope.xmin < xmin)xmin = ((AGSGraphic *)self.graphicsLayer.graphics[i]).geometry.envelope.xmin;if (((AGSGraphic *)self.graphicsLayer.graphics[i]).geometry.envelope.xmax > xmax)xmax = ((AGSGraphic *)self.graphicsLayer.graphics[i]).geometry.envelope.xmax;if (((AGSGraphic *)self.graphicsLayer.graphics[i]).geometry.envelope.ymin < ymin)ymin = ((AGSGraphic *)self.graphicsLayer.graphics[i]).geometry.envelope.ymin;if (((AGSGraphic *)self.graphicsLayer.graphics[i]).geometry.envelope.ymax > ymax)ymax = ((AGSGraphic *)self.graphicsLayer.graphics[i]).geometry.envelope.ymax;}AGSMutableEnvelope *extent = [AGSMutableEnvelope envelopeWithXmin:xmin ymin:ymin xmax:xmax ymax:ymax spatialReference:self.mapView.spatialReference];[extent expandByFactor:1.5];// 画一个方框,就是在graphicsLayer中加入一个 画好方框的graphicAGSCompositeSymbol *symbol = [AGSCompositeSymbol compositeSymbol];AGSSimpleLineSymbol *lineSymbol = [[AGSSimpleLineSymbol alloc] init];lineSymbol.color = [UIColor colorWithRed:0.286 green:0.690 blue:0.838 alpha:0.200];lineSymbol.width = 1;[symbol addSymbol:lineSymbol];AGSSimpleFillSymbol *fillSymbol = [[AGSSimpleFillSymbol alloc] init];fillSymbol.color = [UIColor colorWithRed:0.939 green:0.940 blue:0.422 alpha:0.200];[symbol addSymbol:fillSymbol];//graphicsLayer 中加入一个graphic。这个graphic 是 指定了 symbol 和 geometry<span style="color:#ff0000;">[self.graphicsLayer addGraphic:[AGSGraphic graphicWithGeometry:extent symbol:symbol attributes:nil]];</span><span style="white-space:pre"></span>// 主线程刷新界面开始if ([NSThread isMainThread]){[self.mapView zoomToEnvelope:extent animated:YES];}else{dispatch_sync(dispatch_get_main_queue(), ^{//Update UI in UI thread here[self.mapView zoomToEnvelope:extent animated:YES];});}// 主线程刷新界面结束}
版权声明:本文为博主原创文章,未经博主允许不得转载。
,往往为了自己的不能失败,而处心积虑前怕狼后怕虎,