Arcgis API For IOS扩展AGSDynamicLayer新旧版API对比

AGSDynamicLayer(ForSubclassEyesOnly) Category Reference
Description

This category organizes the methods that are relevant to subclassing a dynamic layer. Developer can create custom dynamic layers by paying special attention to the methods in this category when subclassing AGSDynamicLayer.

Sub-classes must provide valid values for AGSLayer::spatialReference, AGSLayer::fullEnvelope, and AGSLayer::initialEnvelope properties. Other properties on AGSLayer are optional.

Since
    10.1.1 

See also
    AGSLayer(ForSubclassEyesOnly) 

Instance Methods
(void)     - requestImageWithWidth:height:envelope:timeExtent:

(void)     - setImageData:forEnvelope:

Properties
NSOperationQueue *     queue

BOOL     wrapAroundSupported

1、根据新版API(Since10.1.1)看到实例方法已改变,所以需要重写对应的方法requestImageWithWidth:height:envelope:timeExtent:和setImageData:forEnvelope:;

2、不啰嗦,新版扩展代码参考贴上:

#import "CustomDynamicLayer.h"

@interface CustomDynamicLayer ()
@property (nonatomic, strong, readwrite) AGSEnvelope *fullEnvelope;
@property (nonatomic, strong, readwrite) AGSSpatialReference *spatialReference;
@end

@implementation CustomDynamicLayer
@synthesize fullEnvelope = _fullEnvelope;
@synthesize spatialReference = _spatialReference;

#pragma mark - Init Methods

- (id)initWithFullEnvelope:(AGSEnvelope*)fullEnvelope {
    self = [super init];
    if (self) {
        _spatialReference = fullEnvelope.spatialReference;
        _fullEnvelope = fullEnvelope;
        [self layerDidLoad];
    }
    return self;
}

#pragma mark - Request Image
-(void)requestImageWithWidth:(NSInteger)width height:(NSInteger)height envelope:(AGSEnvelope*)env timeExtent:(AGSTimeExtent*)timeExtent {
    // get an image,实际项目中有NameID,URL等形式来表达UIImage,    // 如UIImage* img = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imgUrl]]];
    UIImage *img = [UIImage imageNamed:@"esri_campus"];

    // if request envelope instersect with full envelope
    // of layer then only set image data
    if ([env intersectsWithEnvelope:self.fullEnvelope]) {
        [self setImageData:UIImagePNGRepresentation(img) forEnvelope:self.fullEnvelope];
    }
    else {
        [self setImageData:nil forEnvelope:self.fullEnvelope];
    }
}

@end

3、旧版API方法有差异,通过《AGSDynamicLayerDrawingOperation》类扩展,源码:

#import "CustomDynamicLayer.h"
@class AGSLayers;

@implementation CustomDynamicLayer
@synthesize URL=_URL,imageId=_imageId,envelope=_envelope;

#pragma mark - Init

- (id)initWithURL:(NSURL*)url imageId:(NSString*)imageId envelope:(AGSEnvelope*)envelope {

    if (self = [self init]) {
        self.URL = url;
        self.imageId = imageId;
        self.envelope = _envelope;
        _loaded = YES;
    }
    return self;
}

#pragma mark - 

- (AGSUnits)units {
    return AGSUnitsUnknown;
}

- (AGSSpatialReference*) spatialReference {
    return self.envelope.spatialReference;
}

- (AGSEnvelope*)fullEnvelope {
    return self.envelope;
}

- (AGSEnvelope*)initialEnvelope {
    return self.envelope;
}

#pragma mark AGSDynamicLayer
- (void)imageRequestOperation:(NSOperation<AGSDynamicLayerDrawingOperation>*)op didGetImage:(UIImage *)image {
    NSLog(@"image: %@",image);
    [self.exportDelegate dynamicLayer:self exportMapImageOperation:op didFinishWithImage:image];
}

- (void)imageRequestOperation:(NSOperation<AGSDynamicLayerDrawingOperation>*)op didFailWithError:(NSError *)error {
    NSLog(@"Error: %@",error);
    if ([self.exportDelegate respondsToSelector:@selector(dynamicLayer:exportMapImageOperation:didFailWithError:)]) {
        [self.exportDelegate dynamicLayer:self exportMapImageOperation:op didFailWithError:error];
    }
}

-(NSOperation<AGSDynamicLayerDrawingOperation>*)exportMapImage:(AGSExportImageParams*)exportImageParams {
    if (exportImageParams.envelope == nil || CGSizeEqualToSize(CGSizeZero, exportImageParams.size)) {
        return nil;
    }
    NSMutableDictionary *exportParams = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                         @"png", @"type",
                                         self.imageId, @"id",
                                         nil];
    AGSDynamicLayerImageRequestOperation *operation = [[AGSDynamicLayerImageRequestOperation alloc] initWithURL:self.URL
                                                                                                  resource:@""                                                                                     queryParameters:exportParams];
    operation.target = self;
    operation.action = @selector(imageRequestOperation:didGetImage:);
    operation.errorAction = @selector(imageRequestOperation:didFailWithError:);
    operation.exportImageParams = exportImageParams;

    [[AGSRequestOperation sharedOperationQueue] addOperation:operation];
    return [operation autorelease];
}

#pragma mark - dealloc
-(void)dealloc{
    self.URL = nil;
    self.imageId = nil;
    self.envelope = nil;
    [super dealloc];
}
@end

内容供参考。

目前针对JS\FLEX\Android\IOS都有调用在线地图、天地图等情况,需要根据对应的API版本进行相关方法重载。

时间: 2024-10-31 23:01:25

Arcgis API For IOS扩展AGSDynamicLayer新旧版API对比的相关文章

Hbase新旧版的API

1 package com.felix.hbaseapi_test; 2 3 /* 这是旧版的 API操作 */ 16 public class hbaseapifelix { 17 18 public static final String TABLE_NAME = "testapi"; 19 public static final String COLUMNFAMILY_NAME = "cf"; 20 public static final String ROW

(转)Resources和AssetBundle(新旧版)学习

Resources: Resources的缺点:1.与显示Inspector上直接引用相比,Resources使用不方便. 2.不管你Resources上的资源是否调用了,当你发布的时候,Resources上的资源会全部一起打包掉,无法作更新. Resources里的方法: Resources.Load :动态加载特殊文件夹Resources里的文件. Resources.UnloadAsset:回收指定的缓存. Resources.UnloadUnusedAsset:回收没有被引用的缓存 这里

Resources和AssetBundle(新旧版)学习(来自蛮牛)

Resources: Resources的缺点:1.与显示Inspector上直接引用相比,Resources使用不方便. 2.不管你Resources上的资源是否调用了,当你发布的时候,Resources上的资源会全部一起打包掉,无法作更新. Resources里的方法: Resources.Load :动态加载特殊文件夹Resources里的文件. Resources.UnloadAsset:回收指定的缓存. Resources.UnloadUnusedAsset:回收没有被引用的缓存 这里

JavaScript 兼容新旧版chrome和firefox的桌面通知

1.新/旧版本的chrome和firefox都可支持,IE下不支持因此设置为了在最小化窗口处闪烁显示提示文字. 2.设置为提示窗口显示5秒即关闭. 3.可设置图标和点击提示窗口要跳转到的页面(见输入参数). var timer = null, title = $('title').text(); $('body').on('click', function() { clearInterval(timer); $('title').text(title); }); function showMsg

Windows系列远程桌面工具2020年新旧版使用

 IIS7远程桌面程序截图更新日志:2020版远程桌面截图于2020年1月8日更新,由于有客户依旧使用旧版,此页面将保留旧版截图  IIS7远程桌面程序:http://yczm.iis7.com/?lxmd 旧版远程连接工具截图 新版远程桌面工具截图 原文地址:https://www.cnblogs.com/cclxm99/p/12335104.html

HIVE自定义TextInputFormat (旧版MapReduceAPI ok, 新版MapReduceAPI实现有BUG?)

我们的输入文件 hello0, 内容如下: xiaowang 28 [email protected][email protected] 38 [email protected][email protected] 100 unknown 逻辑上有3条记录, 它们以@[email protected]分隔. 我们将分别用旧版MapReduce API 和新版MapReduce API实现自定义TextInputFormat,然后在hive配置使用, 加载数据. 首先用旧版API 1, 自定义For

5.hadoop流原理、实例和新旧API下Wordcount详解

前四篇文章讲了Hadoop的配置和测试以及eclipse下的使用,有兴趣的可以先看下. 1.Hadoop流简介 用可执行文件作为Mapper和Reducer,接受的都是标准输入,输出的都是标准输出. 当一个可执行文件作为Mapper时,每一个Map任务会以一个独立的进程启动这个可执行文件,然后在Map任务运行时,会把输入切分成行提供给可 执行文件,并作为它的标准输入(stdin)内容.当可执行文件运行出结果时,Map从标准输出(stdout)中收集数据,并将其转化 为<key, value>对

MapReduce简述、工作流程及新旧API对比

什么是MapReduce? 你想数出一摞牌中有多少张黑桃.直观方式是一张一张检查并且数出有多少张是黑桃. MapReduce方法则是: 1. 给在座的所有玩家中分配这摞牌. 2. 让每个玩家数自己手中的牌有几张是黑桃,然后把这个数目汇报给你. 3. 你把所有玩家告诉你的数字加起来,得到最后的结论. MapReduce概述 MapReduce是一种分布式计算模型,由Google提出,主要用于搜索领域,解决海量数据的计算问题.它的核心设计理念是移动计算,而不是移动数据. MapReduce合并了两种

Hadoop日记Day15---MapReduce新旧api的比较

我使用hadoop的是hadoop1.1.2,而很多公司也在使用hadoop0.2x版本,因此市面上的hadoop资料版本不一,为了扩充自己的知识面,MapReduce的新旧api进行了比较研究. hadoop版本1.x的包一般是mapreduce hadoop版本0.x的包一般是mapred 我们还是以单词统计为例进行研究,代码如下,如代码1.1所示: package old; import java.io.IOException; import java.net.URI; import ja