六、ArcGIS Runtime SDK for iOS 100.2.1教程系列之弹框

ArcGIS有为用户提供了两种弹框,一个是AGSCallout:

这种弹框提供简单信息展示,点击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) {
                    [weakSelf.mapView setViewpointGeometry:geo.geometry padding:1.0 completion:^(BOOL finished) {

                    }];
                    //计算面积
                    double areaNumber = [AGSGeometryEngine geodeticAreaOfGeometry:geo.geometry areaUnit:[AGSAreaUnit unitWithUnitID:AGSAreaUnitIDSquareMeters] curveType:AGSGeodeticCurveTypeShapePreserving];
                    //标题取图层元素名称
                    weakSelf.mapView.callout.title = oneLayer.layerContent.name;
                    weakSelf.mapView.callout.detail = [NSString stringWithFormat:@"面积:%.2f平米",areaNumber];
//                    weakSelf.mapView.callout.accessoryButtonType = UIButtonTypeCustom;//去掉自带的i图标
//                    weakSelf.mapView.callout.accessoryButtonImage = nil;//自定义i图标
                    weakSelf.mapView.callout.delegate = weakSelf;
                    [weakSelf.mapView.callout showCalloutAt:geo.geometry.extent.center screenOffset:CGPointZero rotateOffsetWithMap:YES animated:YES];            
                }
            }
        }
    }];
}
AGSCallout提供了一些代理回调事件,比如点击i图标,详见AGSCalloutDelegate。

还一个是AGSPopup:

这种弹框展示可以承载多页与更多的信息。

使用代码:

- (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) {
                    AGSPopup *pop = [AGSPopup popupWithGeoElement:geo];//创建一个pop
                    AGSPopupsViewController *popCon = [[AGSPopupsViewController alloc] initWithPopups:@[pop]];//一个pop控制器可以显示多个pop
                    popCon.delegate = self;
                    [weakSelf presentViewController:popCon animated:YES completion:nil];
                    
                }
            }
        }
    }];
}

AGSPopupsViewControllerDelegate代理提供了完成按钮的点击事件回调:

-(void)popupsViewControllerDidFinishViewingPopups:(AGSPopupsViewController *)popupsViewController {
    [popupsViewController dismissViewControllerAnimated:YES completion:nil];
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章