六、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];
}

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