ios - 子类化的 MKTileOverlay 不在 map 上显示
<p><p>我正在尝试从我们的 WMS 服务器显示 WMS 磁贴。我用旧的 <code>MKOverlay</code> 实现了这一点,但我现在正在尝试更新它以使用 <code>MKTileOverlay</code> 但我无法显示瓷砖。这是我的课:</p>
<pre><code>@interface WMSTileOverlay ()
@property (strong, nonatomic) NSString *API, *mapContext, *IDToken;
@end
@implementation WMSTileOverlay
-(instancetype)initWithAPI:(NSString *)API IDToken:(NSString *)IDToken andMapContext:(NSString *)mapContext {
self = ;
if (self) {
self.API = API;
self.mapContext = mapContext;
self.IDToken = IDToken;
}
return self;
}
-(NSURL *)URLForTilePath:(MKTileOverlayPath)path {
DLog(@"fired");
DLog(@"path | x:%ld y: %ld z: %ld scale: %f", (long)path.x, (long)path.y, (long)path.z, path.contentScaleFactor);
NSString *resolvedURL = ;
DLog(@"resolvedURL: %@", resolvedURL);
return;
}
-(NSString *)createWMSURLStringForTileX:(NSInteger)tileX tileY:(NSInteger)tileY zoomLevel:(NSInteger)zoomLevel {
NSString *WMSservice = @"wms";
NSString *WMSversion = @"1.1.1";
NSString *WMSrequest = @"GetMap";
NSString *WMSMode = @"tiled";
NSString *WMSTile = ;
NSString *WMSFormat = @"image/png";
NSString *WMSTransparancy = @"true";
NSString *WMSSRS = @"EPSG:4326";
NSString *WMSLayer = @"displayimg";
DLog(@"%@", );
return ;
}
-(void)loadTileAtPath:(MKTileOverlayPath)path result:(void (^)(NSData *, NSError *))result {
DLog(@"fired");
NSURLRequest *request = ];
completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if (connectionError) {
result (nil, connectionError);
}
else {
result (data, nil);
}
}];
}
@end
</code></pre>
<p>我正在生成磁贴请求的 URL:</p>
<pre><code>DEBUG | - | path | x:60597 y: 92299 z: 18 scale: 1.000000
DEBUG | - | https://WMS_SERVER?map=yupv9bvejd15fbmc0i1k62bvmdsbcafn.map&idtoken=852a468e65e5ed4023e7b704ea8c768f53c2df13da44e2f0c68fb5a559a130c8&service=wms&version=1.1.1&request=GetMap&SRS=EPSG:4326&layers=displayimg&mode=tiled&tile=60597+92299+18&format=image/png&transparent=true
</code></pre>
<p>我正在取回数据(它与我使用有效的旧 <code>MKOverlay</code> 类进行的 URL 调用相同)并且该类正在传回数据。但是没有绘制瓷砖。我这样创建类:</p>
<pre><code>WMSTileOverlay *wmsTileOverlay = [ initWithAPI:functionCall.API IDToken:functionCall.IDToken andMapContext:];
wmsTileOverlay.canReplaceMapContent = FALSE;
;
</code></pre>
<p>并实现了方法<code>mapView:rendererForOverlay:</code>:</p>
<pre><code>-(MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay {
DLog(@"fired");
if (]) {
MKTileOverlay *tileOverlay = (MKTileOverlay *)overlay;
if (]) {
WMSTileOverlay *wmsTileOverlay = (WMSTileOverlay *)tileOverlay;
DLog(@"wmsTileOverlay.URLTemplate: %@", wmsTileOverlay.URLTemplate);
MKTileOverlayRenderer *renderer = [ initWithTileOverlay:tileOverlay];
return renderer;
}
}
return nil;
}
</code></pre>
<p>我做错了什么?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您是否设置了您的 <code>MKMapView</code> 委托(delegate)并被 <code>mapView:rendererForOverlay:</code> 调用?</p>
<p>我做的事情和你几乎一样,而且对我来说效果很好。</p>
<pre><code>#pragma mark - UIViewController
- (void)viewDidLoad
{
;
WMSTileOverlay *overlay = ;
overlay.canReplaceMapContent = YES;
;
}
#pragma mark - MKMapViewDelegate
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id <MKOverlay>)overlay
{
if (]) {
return [ initWithTileOverlay:overlay];
}
return nil;
}
</code></pre>
<p>还有,</p>
<pre><code>- (NSURL *)URLForTilePath:(MKTileOverlayPath)path
{
double left, bottom, right, top;
// Conversion to bbox mechanism
// ...
NSString *urlString = ;
return ];
}
- (void)loadTileAtPath:(MKTileOverlayPath)path result:(void (^)(NSData *data, NSError *error))result
{
if (!result) {
return;
}
// Cache
// ...
if (cache) {
// ...
} else {
NSURLRequest *request = ];
[NSURLConnection sendAsynchronousRequest:request queue:self.operationQueue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
// Caching mechanism
// ...
result(data, connectionError);
}];
}
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 子类化的 MKTileOverlay 不在 map 上显示,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/26763085/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/26763085/
</a>
</p>
页:
[1]