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

主要思路就是在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
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值