2

WMS サーバーから WMS タイルを表示しようとしています。古いものでこれを達成しましたMKOverlayが、使用するために更新しようとしてMKTileOverlayいますが、タイルを表示できません。これが私のクラスです:

@interface WMSTileOverlay ()

@property (strong, nonatomic) NSString *API, *mapContext, *IDToken;

@end

@implementation WMSTileOverlay

-(instancetype)initWithAPI:(NSString *)API IDToken:(NSString *)IDToken andMapContext:(NSString *)mapContext {
    self = [super init];

    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 = [self createWMSURLStringForTileX:path.x tileY:path.y zoomLevel:path.z];
    DLog(@"resolvedURL: %@", resolvedURL);
    return  [NSURL URLWithString:resolvedURL];
}

-(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 stringWithFormat:@"%d+%d+%d", tileX, tileY, zoomLevel];
    NSString *WMSFormat = @"image/png";
    NSString *WMSTransparancy = @"true";
    NSString *WMSSRS = @"EPSG:4326";
    NSString *WMSLayer = @"displayimg";

    DLog(@"%@", [NSString stringWithFormat:@"%@?map=%@&idtoken=%@&service=%@&version=%@&request=%@&SRS=%@&layers=%@&mode=%@&tile=%@&format=%@&transparent=%@", self.API, self.mapContext, self.IDToken, WMSservice, WMSversion, WMSrequest, WMSSRS, WMSLayer, WMSMode, WMSTile, WMSFormat, WMSTransparancy]);

    return [NSString stringWithFormat:@"%@?map=%@&idtoken=%@&service=%@&version=%@&request=%@&SRS=%@&layers=%@&mode=%@&tile=%@&format=%@&transparent=%@", self.API, self.mapContext, self.IDToken, WMSservice, WMSversion, WMSrequest, WMSSRS, WMSLayer, WMSMode, WMSTile, WMSFormat, WMSTransparancy];

}

-(void)loadTileAtPath:(MKTileOverlayPath)path result:(void (^)(NSData *, NSError *))result {
    DLog(@"fired");

    NSURLRequest *request = [NSURLRequest requestWithURL:[self URLForTilePath:path]];
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        if (connectionError) {
            result (nil, connectionError);
        }
        else {
            result (data, nil);
        }
    }];
}

@end

タイル リクエストの URL を生成しています。

DEBUG | -[WMSTileOverlay URLForTilePath:] | path | x:60597 y: 92299 z: 18 scale: 1.000000
DEBUG | -[WMSTileOverlay createWMSURLStringForTileX:tileY:zoomLevel:] | 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

私はデータを取り戻しています(MKOverlay動作する古いクラスで行ったのと同じURL呼び出しです)。クラスはデータを返しています。しかし、タイルは描かれていません。次のようなクラスを作成します。

WMSTileOverlay *wmsTileOverlay = [[WMSTileOverlay alloc] initWithAPI:functionCall.API IDToken:functionCall.IDToken andMapContext:[self.mapper fetchMapContextForState:self.activeBoundarier.state]];
wmsTileOverlay.canReplaceMapContent = FALSE;

[self.mapView insertOverlay:wmsTileOverlay atIndex:0];

メソッドを実装しましたmapView:rendererForOverlay:

-(MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay {
    DLog(@"fired");

    if ([overlay isKindOfClass:[MKTileOverlay class]]) {
        MKTileOverlay *tileOverlay = (MKTileOverlay *)overlay;

        if ([tileOverlay isKindOfClass:[WMSTileOverlay class]]) {
            WMSTileOverlay *wmsTileOverlay = (WMSTileOverlay *)tileOverlay;
            DLog(@"wmsTileOverlay.URLTemplate: %@", wmsTileOverlay.URLTemplate);

            MKTileOverlayRenderer *renderer = [[MKTileOverlayRenderer alloc] initWithTileOverlay:tileOverlay];

            return renderer;
        }
    }

    return nil;
}

私は何を間違っていますか?

4

1 に答える 1

2

MKMapViewデリゲートを設定し、mapView:rendererForOverlay:呼び出されましたか?

私はあなたとほとんど同じことをしており、私の側ではうまく機能しています。

#pragma mark - UIViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    WMSTileOverlay *overlay = [WMSTileOverlay new];
    overlay.canReplaceMapContent = YES;

    [self.mapView addOverlay:overlay level:MKOverlayLevelAboveLabels];
}

#pragma mark - MKMapViewDelegate

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id <MKOverlay>)overlay
{
    if ([overlay isKindOfClass:[WMSTileOverlay class]]) {
        return [[MKTileOverlayRenderer alloc] initWithTileOverlay:overlay];
    }

    return nil;
}

と、

- (NSURL *)URLForTilePath:(MKTileOverlayPath)path
{
    double left, bottom, right, top;

    // Conversion to bbox mechanism
    // ...

    NSString *urlString = [NSString stringWithFormat:@"%@&bbox=%f,%f,%f,%f", kWMSServerURL, left, bottom, right, top];

    return [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
}

- (void)loadTileAtPath:(MKTileOverlayPath)path result:(void (^)(NSData *data, NSError *error))result
{
    if (!result) {
        return;
    }

    // Cache
    // ...
    if (cache) {
        // ...      
    } else {
        NSURLRequest *request = [NSURLRequest requestWithURL:[self URLForTilePath:path]];
        [NSURLConnection sendAsynchronousRequest:request queue:self.operationQueue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
            // Caching mechanism
            // ...

            result(data, connectionError);
        }];
    }
}
于 2014-11-14T22:22:56.310 に答える