Closed zhujianyang closed 2 years ago
Combining tile sources in 2.x is tricky. I'm not sure I understand what you're trying to do. If you have two complete tile sources, one is always going to win out over the other unless the second one is completely transparent.
the following was wrong? all of them are remote layer [theViewC addLayer:firstLayer]; [theViewC addLayer:secondLayer]; [theViewC addLayer:threeLayer];
If you need three URLs at different levels, then the best way is to make your own RemoteTileSource.
thanks but i still have a question ,ask you for help when i locate in asia (the first picture ) and i locate in africa(the second picture ) next i locate back in asia (the third picture)。the third picture shows (the remote refresh agagin),which i do not nee how can i avoid it (i do not want refresh again )
the code: theViewC = [[WhirlyGlobeViewController alloc] init]; [self.view addSubview:theViewC.view]; theViewC.view.frame = self.view.bounds; [self addChildViewController:theViewC];
WhirlyGlobeViewController *globeViewC = nil;
MaplyViewController *mapViewC = nil;
if ([theViewC isKindOfClass:[WhirlyGlobeViewController class]])
globeViewC = (WhirlyGlobeViewController *)theViewC;
else
mapViewC = (MaplyViewController *)theViewC;
NSString *cacheDir = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, true)[0];
NSString *thisCacheDir = [cacheDir stringByAppendingString:@"/stamentiles/"];
MaplyRemoteTileInfoNew *tileInfo = [[MaplyRemoteTileInfoNew alloc] initWithBaseURL:@"http://t1.tianditu.gov.cn/img_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&tk=21acecb607e8c575b1668c600606da16&tilecol={x}&tilerow={y}&tilematrix={z}" minZoom:0 maxZoom:9];
tileInfo.cacheDir = thisCacheDir;
// Describes what the file covers and how deep
MaplySamplingParams *sampleParams = [[MaplySamplingParams alloc] init];
sampleParams.coordSys = [[MaplySphericalMercator alloc] initWebStandard];
sampleParams.coverPoles = true;
sampleParams.edgeMatching = true;
sampleParams.minZoom = tileInfo.minZoom;
sampleParams.maxZoom = tileInfo.maxZoom;
sampleParams.singleLevel = true;
// Actually loads the images
imageLoader = [[MaplyQuadImageLoader alloc] initWithParams:sampleParams tileInfo:tileInfo viewC:theViewC];
imageLoader.baseDrawPriority = kMaplyImageLayerDrawPriorityDefault;
i run AutoTester ,replace the remote URL with @"http://t1.tianditu.gov.cn/img_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&tk=21acecb607e8c575b1668c600606da16&tilecol={x}&tilerow={y}&tilematrix={z}" AND There are pictures in the cache so i Do not know what to do
Are you saying it works in the AutoTester? If so, then it's something you're doing. My suggestion is to try adding your functionality to the AutoTester bit by bit until you duplicate the problem.
Sorry I didn't describe clearly i replace the autoTester's remote URL "http://tile.stamen.com/watercolor/{z}/{x}/{y}.png" with "http://t1.tianditu.gov.cn/img_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&tk=21acecb607e8c575b1668c600606da16&tilecol={x}&tilerow={y}&tilematrix={z}" the question is still exists。 the pictures of tile are in cacheDir .i konw it . but i do not find it works
i konw the cacheDir How to work If there is no network .the whirlyglobe use cacheDir if the network can be used, the whirlyglobe load the URL Load the network instead of using the cache is is right?
Not quite, no. When WhirlyGlobe fetches a tile, it can save it in the cacheDir. When it starts to load a tile, it checks the cacheDir first.
i have some trouble in the whirlyGlobe (version2.6.5),which i could not fix it so, Ask you for help in the MaplyRemoteTileSource.mm I modify code in line 229->279
(NSURLRequest )requestForTile:(MaplyTileID)tileID { int y = ((int)(1<<tileID.level)-tileID.y)-1; NSMutableURLRequest urlReq = nil;
if (_tileURLs) { // Decide here which URL we'll use NSString *tileURL = [_tileURLs objectAtIndex:tileID.x%[_tileURLs count]];
} else { if (_replaceURL) { // Fetch the traditional way int s = arc4random() % 8; // Fetch the traditional way NSString *fullURLStr = [[[_baseURL stringByReplacingOccurrencesOfString:@"{z}" withString:[@(tileID.level) stringValue]] stringByReplacingOccurrencesOfString:@"{x}" withString:[@(tileID.x) stringValue]] stringByReplacingOccurrencesOfString:@"{y}" withString:[@(y) stringValue]]; fullURLStr = [fullURLStr stringByReplacingOccurrencesOfString:@"{s}" withString:[@(s) stringValue]];
// if (_ext) // fullURLStr = [NSString stringWithFormat:@"%@.%@",fullURLStr,(_ext ? _ext : @"unk")]; urlReq = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:fullURLStr]]; if (_timeOut != 0.0) [urlReq setTimeoutInterval:_timeOut]; } else { // Fetch the traditional way NSMutableString *fullURLStr = [NSMutableString stringWithFormat:@"%@%d/%d/%d.%@",_baseURL,tileID.level,tileID.x,y,(_ext ? _ext : @"unk")]; if (_queryStr) [fullURLStr appendFormat:@"?%@",_queryStr]; urlReq = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:fullURLStr]]; if (_timeOut != 0.0) [urlReq setTimeoutInterval:_timeOut]; } } if ([urlReq.URL.absoluteString containsString:@"tiandi"]){ [urlReq addValue:@"image/png" forHTTPHeaderField:@"Content-Type"]; } if (_xAuthToken) [urlReq addValue:_xAuthToken forHTTPHeaderField:@"x-auth-token"];
}
in the controller
(void)addlayer{
NSString *cacheDir = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, true)[0];
MaplyRemoteTileSourcebase = [[MaplyRemoteTileSource alloc]initWithBaseURL:@"http://t0.tianditu.gov.cn/img_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&tk=26d74c176517d23f7b9f41c037d8b927&tilecol={x}&tilerow={y}&tilematrix={z}" ext:@"png" minZoom:0 maxZoom:9]; base.cacheDir = [NSString stringWithFormat:@"%@/img_w_myapp/",cacheDir]; MaplyQuadImageTilesLayerbaseLayer = [[MaplyQuadImageTilesLayer alloc]initWithTileSource:base]; [theViewC addLayer:baseLayer];
MaplyRemoteTileSource tiandi1 = [[MaplyRemoteTileSource alloc] initWithBaseURL:@"http://t0.tianditu.gov.cn/ibo_w/wmts?service=wmts&request=gettile&version=1.0.0&layer=ibo&format=tiles&tilematrixset=w&tk=26d74c176517d23f7b9f41c037d8b927&tilecol={x}&tilerow={y}&tilematrix={z}" ext:@"png" minZoom:0 maxZoom:9]; tiandi1.cacheDir = [NSString stringWithFormat:@"%@/ibo_w_myapp/",cacheDir]; MaplyQuadImageTilesLayertiandi1layer = [[MaplyQuadImageTilesLayer alloc]initWithTileSource:tiandi1];
MaplyRemoteTileSource tiandi2 = [[MaplyRemoteTileSource alloc] initWithBaseURL:@"http://t0.tianditu.gov.cn/cia_w/wmts?service=wmts&request=gettile&version=1.0.0&layer=cia&format=tiles&tilematrixset=w&tk=26d74c176517d23f7b9f41c037d8b927&tilecol={x}&tilerow={y}&tilematrix={z}" ext:@"png" minZoom:0 maxZoom:9]; tiandi2.cacheDir = [NSString stringWithFormat:@"%@/cia_w_myapp/",cacheDir]; MaplyQuadImageTilesLayertiandi2layer = [[MaplyQuadImageTilesLayer alloc]initWithTileSource:tiandi2]; [theViewC addLayer:tiandi1layer]; [theViewC addLayer:tiandi2layer];
}
the question is (the cacheDir does not work)
https://user-images.githubusercontent.com/25760052/155277359-3b580028-1e2a-4e29-8785-d290f71c5cca.mov
https://user-images.githubusercontent.com/25760052/155277426-22871f4a-3c2f-4189-a897-14ba25bf0596.MOV