Saturday 15 June 2013

ios - Subclassed MKTileOverlay not displaying on map -



ios - Subclassed MKTileOverlay not displaying on map -

i trying display wms tiles our wms server. achieved old mkoverlay trying update utilize mktileoverlay can not tiles display. here class:

@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; } homecoming 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); homecoming [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]); homecoming [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

i generating url tile request:

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

i getting info (its same url phone call create old mkoverlay class works) , class passing data. no tiles beingness drawn. create class this:

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];

and implemented method 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]; homecoming renderer; } } homecoming nil; }

what doing wrong?

did set mkmapview delegate , mapview:rendererforoverlay: called ?

i pretty much same thing , it's working on side.

#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]]) { homecoming [[mktileoverlayrenderer alloc] initwithtileoverlay:overlay]; } homecoming nil; }

and,

- (nsurl *)urlfortilepath:(mktileoverlaypath)path { double left, bottom, right, top; // conversion bbox mechanism // ... nsstring *urlstring = [nsstring stringwithformat:@"%@&bbox=%f,%f,%f,%f", kwmsserverurl, left, bottom, right, top]; homecoming [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); }]; } }

ios objective-c mapkit mktileoverlay

No comments:

Post a Comment