怎么判断子元素距离父元素顶部位置_二、ArcGIS Runtime SDK for iOS 100.X教程系列之点击图层元素检索并高亮...

首先需要遵守AGSMapView的AGSGeoViewTouchDelegate协议,实现其代理方法,在点击地图某一个点时会获得回调,在回调的位置需要进行检索查询,在PC端就是所谓的i查询:

- (void)geoView:(AGSGeoView *)geoView didTapAtScreenPoint:(CGPoint)screenPoint mapPoint:(AGSPoint *)mapPoint {
    //进行i查询,tolerance大致是指精确的范围,api有英文解释
    __weak __typeof(self)weakSelf = self;
    [geoView identifyLayersAtScreenPoint:screenPoint tolerance:2.0 returnPopupsOnly:NO completion:^(NSArray<AGSIdentifyLayerResult *> * _Nullable identifyResults, NSError * _Nullable error) {
        if (identifyResults.count) {
            //得到的i查询结果一般是最大层的图层信息,这里得到的是动态图层信息
            AGSIdentifyLayerResult *result = identifyResults.firstObject;
            if (result.sublayerResults.count) {
                //当然,咱们要的是图层上的元素信息,此处取第一个来高亮
                AGSIdentifyLayerResult *oneLayer = result.sublayerResults.firstObject;
                id<AGSGeoElement> geo = oneLayer.geoElements.firstObject;
                if (geo.geometry.geometryType == AGSGeometryTypePolyline || geo.geometry.geometryType == AGSGeometryTypePolygon) {
                    //这里用空心实线来高亮用户点击的元素,具体用什么符号渲染,自行根据点击的元素类型枚举选择
                    AGSSimpleFillSymbol *fillSymble = [AGSSimpleFillSymbol simpleFillSymbolWithStyle:AGSSimpleFillSymbolStyleSolid color:[UIColor clearColor] outline:[AGSSimpleLineSymbol simpleLineSymbolWithStyle:AGSSimpleLineSymbolStyleSolid color:[UIColor redColor] width:2.0]];
                    //创建并将符号渲染到overlayer
                    AGSGraphic *myGraphic = [AGSGraphic graphicWithGeometry:geo.geometry symbol:fillSymble attributes:geo.attributes];
                    [weakSelf.overlayer.graphics removeAllObjects];
                    [weakSelf.overlayer.graphics addObject:myGraphic];
                    //移动到用户点击的点,自行选择是否需要,自带动画
                    [weakSelf.mapView setViewpointCenter:mapPoint completion:^(BOOL finished) {
                        //结束回调
                    }];
                }
            }
        }else{
                //父图层没有子图层时
                id<AGSGeoElement> geo = result.geoElements.firstObject;
                [weakSelf.mapView setViewpointGeometry:geo.geometry padding:1.0 completion:^(BOOL finished) {
                    
                }];
            }
    }];
}

元素的类型或者说形状类型为一个枚举:

typedef NS_ENUM(NSInteger, AGSGeometryType)  {
    AGSGeometryTypeUnknown = -1,    /*!< Undefined未定义 */
    AGSGeometryTypePoint = 1,           /*!< Point点 */
    AGSGeometryTypeEnvelope = 2,          /*!< Envelope包络线 */
    AGSGeometryTypePolyline = 3,        /*!< Polyline 线*/
    AGSGeometryTypePolygon = 4,         /*!< Polygon 多边形*/
    AGSGeometryTypeMultipoint = 5,      /*!< Multipoint 多个点*/
};
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值