二、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 多个点*/
};

i查询的速度与服务器的性能,网络的情况也有莫大关系,所以有时候还是有点慢的。

猜你喜欢

转载自blog.csdn.net/qq_31672459/article/details/79730104