graphicsLayer 中增加多个graphic 后, 进行缩放定位。然后画一个表示范围的框

来源:互联网 发布:淘宝开店上货教程 编辑:程序博客网 时间:2024/06/04 01:16

主要思路就是在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/max            double 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中加入一个 画好方框的graphic            AGSCompositeSymbol *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];                });            }            // 主线程刷新界面结束        }


0 0
原创粉丝点击