关于图层的加载,参见前面的教程:https://blog.csdn.net/qq_31672459/article/details/79729826
当图层加载完毕,我们将可以获取到图层所有的图例信息,100.2.1版本的api并未通过代理的方式回传加载状态,而是通过block回调,见代码:
//加载动态图层,一般该图层拿来展示元素以供展示管线数据、管控数据等,还有查询等用途
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 (id<AGSLayerContent> sublayer in dynamicLayer.subLayerContents) {
//一般无法抓取到有子图层的图层图例,为了得到所有的图例只能遍历出来
//此处以最多两层图层为例,若图层层级较多,自行封装递归方法遍历所有图例
if (sublayer.subLayerContents.count) {
for (id<AGSLayerContent> subSublayer in sublayer.subLayerContents) {
//抓取图例信息
[subSublayer fetchLegendInfosWithCompletion:^(NSArray<AGSLegendInfo *> * _Nullable legendInfos, NSError * _Nullable error) {
//得到的图例信息自行展示
if (legendInfos.count) {
AGSLegendInfo *legend = legendInfos.firstObject;
AGSPictureMarkerSymbol *picSymble = (AGSPictureMarkerSymbol *)legend.symbol;
NSLog(@"得到的图例名称:%@,图例图片:%@",legend.name,picSymble.image);
}
}];
}
}else{
//抓取图例信息
[sublayer fetchLegendInfosWithCompletion:^(NSArray<AGSLegendInfo *> * _Nullable legendInfos, NSError * _Nullable error) {
//得到的图例信息自行展示
}];
}
}
}
}];
最新版本的图例获取比较10.+版本略显麻烦,但是看得出来,分的更细了。