4. ArcGIS Runtime SDK for iOS 100.X tutorial series layer control display hide

        For layer loading, see the previous tutorial: https://blog.csdn.net/qq_31672459/article/details/79729826

        When there are multiple layers on one layer service, it will be more convenient to write code in combination with the link address of the service to access and view detailed information, as in the following arcgis service:

        http://arcgis.wuhanrt.cn:6080/arcgis/rest/services/Base/DLG/MapServer

        Generally, the data of enterprises that use arcgis services is more or less confidential, so here is only a layer screenshot for reference:

       

        It is very convenient to control the layer with reference to this information, and the iOS control code is also very simple, as follows (for example, only the range line is displayed):

//加载动态图层,一般该图层拿来展示元素以供展示管线数据、管控数据等,还有查询等用途
    AGSArcGISMapImageLayer *dynamicLayer = [AGSArcGISMapImageLayer ArcGISMapImageLayerWithURL:[NSURL URLWithString:@"http://地址及端口号/arcgis/rest/services/CJXCMap/CJXCMapService/MapServer"]];
    [self.map.operationalLayers addObject:dynamicLayer];
    [dynamicLayer loadWithCompletion:^(NSError * _Nullable error) {
        if (!error) {
            //获取子图层
            for (AGSArcGISMapImageSublayer *subLayer in dynamicLayer.mapImageSublayers) {
                if (subLayer.sublayerID != 14) {
                    //控制隐藏或者显示
                    [subLayer setVisible:NO];
                }
            }
        }
    }];

It may be that 100.2.1 has not been written yet. Obviously the AGSArcGISMapImageSublayer class has a sublayers attribute, but once it is called, it will cause an infinite loop and the project will crash. Therefore, multiple element layer levels need to be obtained in a detour. The code is as follows:

[dynamicLayer loadWithCompletion:^(NSError * _Nullable error) {
        if (!error) {
            //获取子图层
            for (AGSArcGISMapImageSublayer *subLayer in dynamicLayer.mapImageSublayers) {
                NSLog(@"所有图层id:%@",@(subLayer.sublayerID));//第一层级元素图层
                for (id<AGSLayerContent>subSubLayer in subLayer.subLayerContents) {
                    if ([subLayer isKindOfClass:[AGSArcGISSublayer class]]) {
                        AGSArcGISSublayer *subSubGisLayer = (AGSArcGISSublayer *)subSubLayer;
                        NSLog(@"所有子图层id:%@",@(subSubGisLayer.sublayerID));//第二层级元素图层
                        [subSubGisLayer setVisible:NO];//控制显示隐藏
                    }
                }
            }
        }
    }];

 

Guess you like

Origin blog.csdn.net/qq_31672459/article/details/79737666