Men的博客

欢迎光临!

0%

Arcgis ios 学习

最近公司接到一个基于arcgis的ipad项目,很兴奋,终于有机会能够写iOS了
用国内的高德、百度、以及公司自己的地图项目久了,确实也容易闭塞,看了Arcgis的接口后才发现,地图的项目大了以后,以及服务都开放以后,接口的设计也越开放了。
arcgis有开放的地图服务以及地图样式,当然,收费的话你也可以自己做地图样式,但是开放程度肯定跟mapbox无法相提并论,公司最近在了解mapbox,我也研究下mapbox的设计,思想确实很高级,后面再讲吧。
iOS嘛,先说一些基础的接口吧

1.地图构造

self.mapView.map = [[AGSMap alloc] initWithBasemap:[AGSBasemap lightGrayCanvasBasemap]];
这一点跟国内地图厂商非常不同,国内的地图api,都是在mapview上的,arcgis的设计很特别,所有的地图接口都在mapview 的map对象上,map对象又通过basemap创建,basemap里面其实就是地图的底图数据。你可以穿入arcgis官方的底图地址,也可以传如你的arcgis server 的地址。这样的话,你的地图才会有底图。
当然了,mapview也不是什么都没有一些坐标之类的接口开始有的,参见AGSMapViewCommon
mapview的继承关系 AGSMapView -》 AGSMapViewCommon -〉 AGSGeoView -》AGSView-〉(UIView,NSView)

2.图层Layer

所有的图层都被添加到mapView.map.operationalLayers中,这是一个可变数组,你可以用NSMutableArray的接口随意操作这个数组,比如添加一个图层,删除一个图层,切换两个图层的顺序等等,非常的方便。千万不要把图层想想成高德、百度的接口中的覆盖物,这就查远了。

3.Table

这个概念一定会刷新你的认知的,我一开始没有理解这个table,做了很多东西才发现,其实table就是服务接口。arcgis的服务是对外开放的,你可以定义各种各样的服务接口,前提是遵循arcgis 的服务接口规范,地图数据支持各种查询、分析,非常的强大,所有你可以添加很多地图服务,然后调用服务进行数据分析,前提是服务要添加到地图上,所以地图也有一个mapView也有一个tables可变数组。

4.graphicsOverlays

这个就是覆盖物了,但是跟你直观的覆盖物不同,这个是添加的覆盖物图层,每个图层才能添加覆盖物。相当于二维数组的概念,也许是为了数据分层吧,总之arcgis对数据分层看的比较重要,国内厂商大多使用index的设计模式,虽然代价低点,感觉不是太直接。
这里也不是贬低国内的厂商,只是从地图的发展这个方向,感觉国内还是与国外差距比较明显的,自我定位还是要明确的。
地图还有其他的一些组成Layer、Feature、Geomerty等等
arcgis的服务我也研究了一下有如下:
@property (nonatomic, strong) AGSGeoprocessingTask *geoprocessingTask;
@property (nonatomic, strong) AGSGeoprocessingJob * geoprocessingJob;
@property (nonatomic, strong) AGSServiceFeatureTable *serviceFeatureTable;
@property (nonatomic, strong) AGSLocatorTask *locatorTask;

地图选点查询

[self.mapView identifyLayersAtScreenPoint:screenPoint tolerance:12 returnPopupsOnly:NO completion:^(NSArray<AGSIdentifyLayerResult *> * _Nullable identifyResults, NSError * _Nullable error) {
for (int i = 0; i < identifyResults.count; i++) {
AGSIdentifyLayerResult *identifyResult = identifyResults[i];
if (identifyResult.geoElements.count > 0) {
AGSArcGISFeature *feature = (AGSArcGISFeature *)identifyResult.geoElements.firstObject;
self.selectArcGISFeature = feature;
NSLog(@”attributes = %@”,[self stringToUtf8String:feature.attributes.description]);
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@”点击结果” message:[self stringToUtf8String:feature.attributes.description] delegate:nil cancelButtonTitle:@”取消” otherButtonTitles: nil];
[alertView show];
}else{
if (identifyResult.sublayerResults.count > 0) {
NSMutableString *str = [[NSMutableString alloc] init];
NSMutableArray *array = [[NSMutableArray alloc] init];
for (int j = 0; j < identifyResult.sublayerResults.count; j++) {
AGSIdentifyLayerResult *identifyResult1 = identifyResult.sublayerResults[j];
if (identifyResult1.geoElements.count > 0) {
AGSArcGISFeature *feature = (AGSArcGISFeature *)identifyResult1.geoElements.firstObject;
[array addObject:feature];
self.selectArcGISFeature = feature;
NSLog(@”attributes = %@”,[self stringToUtf8String:feature.attributes.description]);
[str appendString:[NSString stringWithFormat:@”\nfeature%d = %@”,j+1,[self stringToUtf8String:feature.attributes.description]]];
}
}
if (completion) {
completion(array[0]);
}
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@”点击结果” message:str delegate:nil cancelButtonTitle:@”取消” otherButtonTitles: nil];
[alertView show];
}
}

}

}];

  • (void)identifyGraphicsOverlaysAtScreenPoint:(CGPoint)screenPoint completion:(ArcgisQueryCompletionBlock)completion {
    [self.mapView identifyGraphicsOverlaysAtScreenPoint:screenPoint tolerance:100 returnPopupsOnly:NO completion:^(NSArray<AGSIdentifyGraphicsOverlayResult *> * _Nullable identifyResults, NSError * _Nullable error) {
      completion(identifyResults);
    
    }];

}

  • (void)identifyLayer:(AGSLayer *)layer screenPoint:(CGPoint)screenPoint completion:(ArcgisQueryCompletionBlock)completion{
    [self.mapView identifyLayer:layer screenPoint:screenPoint tolerance:100 returnPopupsOnly:NO maximumResults:10 completion:^(AGSIdentifyLayerResult * _Nonnull identifyResult) {

      completion(identifyResult);
    

    }];
    }

    AGSQueryParameters

    AGSQueryParameters *parameters = [[AGSQueryParameters alloc] init];
    parameters.whereClause = [NSString stringWithFormat:@”NAME LIKE ‘%@%@%@’”,@”%”,text,@”%”];
    [self.addressSearchService queryFeaturesWithParameters:parameters completion:^(AGSFeatureQueryResult * _Nullable result, NSError * _Nullable error) {
    NSArray<AGSArcGISFeature *> *features = (NSArray<AGSArcGISFeature *> *)[result featureEnumerator].allObjects;
    completion(features);
    }];

    pragma mark - featureCollectionTableGeoprocessing

  • (void)featureCollectionTableGeoprocessing:(AGSGeometry *)geometry completion:(ArcgisQueryCompletionBlock)completion{
    AGSFeature *newFeature = [featureCollectionTable createFeature];
    [newFeature setGeometry:geometry];
    __block AGSFeatureCollectionTable *strongFeatureCollectionTable = featureCollectionTable;
    [featureCollectionTable addFeature:newFeature completion:^(NSError * _Nullable error) {

      [self performGeoprocessing:strongFeatureCollectionTable completion:completion];
    

    }];
    }

  • (void)performGeoprocessing:(AGSFeatureCollectionTable *)featureCollectionTable completion:(ArcgisQueryCompletionBlock)completion{
    AGSGeoprocessingParameters *params = [[AGSGeoprocessingParameters alloc] initWithExecutionType:AGSGeoprocessingExecutionTypeAsynchronousSubmit];
    AGSGeoprocessingFeatures *geoprocessingFeatures = [[AGSGeoprocessingFeatures alloc] initWithFeatureSet:featureCollectionTable];
    params.inputs = @{@”Clip_Features”:geoprocessingFeatures};

    self.geoprocessingJob = [self.geoprocessingTask geoprocessingJobWithParameters:params];

    [self.geoprocessingJob startWithStatusHandler:^(AGSJobStatus status) {

      NSLog(@"serverJobID = %@, status = %ld",self.geoprocessingJob.serverJobID,status);
    

    } completion:^(AGSGeoprocessingResult * _Nullable result, NSError * _Nullable error) {

      NSLog(@"AGSGeoprocessingResult = %ld",result.outputs.count);
      if (result.outputs.count > 0) {
          NSLog(@"AGSGeoprocessingResult = %ld",result.outputs.count);
      }
      completion(result);
      if (error) {
          NSLog(@"error = %@",[error description]);
      }
    

    }];
    }

    pragma mark - AGSLocatorTask

  • (void)geocodeWithSearchText:(NSString *)text completion:(ArcgisQueryCompletionBlock)completion{
    [self.locatorTask geocodeWithSearchText:text completion:^(NSArray<AGSGeocodeResult *> * _Nullable geocodeResults, NSError * _Nullable error) {

      completion(geocodeResults);
    

    }];
    }

  • (void)suggestWithSearchText:(NSString *)text completion:(ArcgisQueryCompletionBlock)completion{
    [self.locatorTask suggestWithSearchText:text completion:^(NSArray<AGSSuggestResult *> * _Nullable suggestResults, NSError * _Nullable error) {

      completion(suggestResults);
    

    }];
    }

    pragma mark - AGSServiceFeatureTable

  • (void)serviceFeatureTableQueryFeatures:(AGSGeometry *)geometry completion:(ArcgisQueryCompletionBlock)completion {
    AGSQueryParameters *parameters = [[AGSQueryParameters alloc] init];
    parameters.geometry = geometry;
    [self.serviceFeatureTable queryFeaturesWithParameters:parameters completion:^(AGSFeatureQueryResult * _Nullable result, NSError * _Nullable error) {

      completion(result);
    

    }];
    }

  • (void)serviceFeatureTableQueryExtent:(AGSGeometry *)geometry completion:(ArcgisQueryCompletionBlock)completion {
    AGSQueryParameters *parameters = [[AGSQueryParameters alloc] init];
    parameters.geometry = geometry;
    [self.serviceFeatureTable queryExtentWithParameters:parameters completion:^(AGSEnvelope * _Nullable extent, NSError * _Nullable error) {

      completion(extent);
    

    }];
    }

  • (void)serviceFeatureTableQueryStatistics:(AGSGeometry *)geometry completion:(ArcgisQueryCompletionBlock)completion {
    AGSStatisticDefinition *definition = [[AGSStatisticDefinition alloc] initWithOnFieldName:@”” statisticType:AGSStatisticTypeSum outputAlias:@””];
    AGSStatisticsQueryParameters *parameters = [[AGSStatisticsQueryParameters alloc] initWithStatisticDefinitions:@[definition]];
    [parameters setGeometry:geometry];
    [self.serviceFeatureTable queryStatisticsWithParameters:parameters completion:^(AGSStatisticsQueryResult * _Nullable result, NSError * _Nullable error) {

      completion(result);
    

    }];
    }