arcgis for ios

序言

记录自己对接arcgis for ios version100.4 中加载瓦块图遇到的坑,地图是从服务器上一块一块获取的情况可以参考。

开始前准备

1.去arcgis for iOS SDK 下载SDK (注:需要翻墙注册账号才能下载) 下载之后按着文档一步一步来。
2.申请License key 去除水印

ArcGIS Online试用入口:https://www.arcgis.com/home/signin.html
Runtime 100 许可政策官方说明:https://developers.arcgis.com/arcgis-runtime/licensing/
使用前一步注册的online账户登陆,点击lite下方的sign up按钮登录成功进去就可以看到 Runtime Lite license key(有时间的完全去除水印就得购买)。

具体的方法
[AGSArcGISRuntimeEnvironment setLicenseKey:@"申请的license key" error:&erro];

集成的代码

1.首先找服务器那面拿到对应服务器上的瓦块初始化数据

#import 
#define X_MIN_2000 103.79859
#define Y_MIN_2000 27.85081
#define X_MAX_2000 111.41286
#define Y_MAX_2000 32.49937
#define X_ORIGIN -180
#define Y_ORIGIN 90
#define _tileWidth 256
#define _tileHeight 256
#define _dpi 96
#define _GCS2000 4326

2.从服务器拉取数据还需要提供对应的 resolution数组 和 scale数组 ,下面是初始化的代码

self.mapView = [[AGSMapView alloc]init];
    [self.view addSubview:self.mapView];
    [self.mapView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.searchV.mas_bottom);
        make.bottom.left.right.equalTo(self.view);
    }];
    self.map = [[AGSMap alloc] init];
    self.mapView.attributionTextVisible = false;
    NSMutableArray *lods = [NSMutableArray array];
    NSArray *relus = @[@(0.0047589220116605602), @(0.0021415149052472515), @(0.00090419518221550614), @(0.00030457100874627579), @(0.0001522855043731379), @(7.6142752186568948e-005), @(3.8071376093284474e-005), @(1.9035688046642237e-005), @(9.5178440233211185e-006)];
    NSArray *scales = @[@2000000, @900000, @380000, @128000, @64000, @32000, @16000, @8000, @4000];
    for(int i = 0; i<=8 ;i++){
        AGSLevelOfDetail *level = [AGSLevelOfDetail levelOfDetailWithLevel:i resolution:[relus[i] doubleValue] scale:[scales[i] doubleValue]];
        [lods addObject:level];
    }
    AGSSpatialReference *sp = [AGSSpatialReference spatialReferenceWithWKID:_GCS2000];
    AGSEnvelope *fullExtent = [AGSEnvelope envelopeWithXMin:X_MIN_2000 yMin:Y_MIN_2000 xMax:X_MAX_2000 yMax:Y_MAX_2000 spatialReference:sp];
    AGSPoint *origin = [AGSPoint pointWithX: X_ORIGIN y: Y_ORIGIN spatialReference:sp];
    AGSTileInfo *tilInfo = [AGSTileInfo tileInfoWithDPI:_dpi format:AGSTileImageFormatPNG32 levelsOfDetail:lods origin:origin spatialReference:sp tileHeight:_tileHeight tileWidth:_tileWidth];
    AGSImageTiledLayer *titleLayer = [[AGSImageTiledLayer alloc]initWithTileInfo:tilInfo fullExtent:fullExtent];
    titleLayer.maxScale = 4000;
    titleLayer.minScale = 7000000;
    __weak typeof(titleLayer) weakTile = titleLayer;
    [titleLayer setTileRequestHandler:^(AGSTileKey * _Nonnull tileKey) {
        NSString *mainURL = @"服务器地址";
        //此处拼接为服务器要求的完整的URL格式
        NSString *requestUrl1= [mainURL stringByAppendingString:@"layer=cqmap_2d&col=%lx&row=%lx&level=%ld"];
        NSString *requestUrl = [NSString stringWithFormat:requestUrl1,tileKey.column,tileKey.row, tileKey.level];
        NSURL* aURL = [NSURL URLWithString:requestUrl];
        NSData *imageData = [[NSData alloc] initWithContentsOfURL:aURL];
        UIImage *img = [UIImage imageWithData:imageData];
        [weakTile respondWithTileKey:tileKey data:UIImagePNGRepresentation(img) error:nil];
    }];
    [self.map.basemap.baseLayers addObject:titleLayer];
    self.mapView.map = self.map;

这些就是从服务器拉取瓦块图的主要代码了,也算研究了很多天才弄出来。第一次用macDown写有不好的地方还请见谅。

你可能感兴趣的:(arcgis for ios)