mousebird-consulting-inc / WhirlyGlobe

WhirlyGlobe Development
Other
828 stars 254 forks source link

cacheDir does not work in iOS #1509

Closed zhujianyang closed 2 years ago

zhujianyang commented 2 years ago

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

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

return urlReq;

}

in the controller

}

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

mousebird commented 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.

zhujianyang commented 2 years ago

if I have three URLs to load。what should i do to add those URL the layer can only be loaded once?

the following was wrong? all of them are remote layer [theViewC addLayer:firstLayer]; [theViewC addLayer:secondLayer]; [theViewC addLayer:threeLayer];

mousebird commented 2 years ago

If you need three URLs at different levels, then the best way is to make your own RemoteTileSource.

zhujianyang commented 2 years ago

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 IMG_1635 IMG_1636 IMG_1637 )

zhujianyang commented 2 years ago

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;
zhujianyang commented 2 years ago

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

mousebird commented 2 years ago

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.

zhujianyang commented 2 years ago

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

zhujianyang commented 2 years ago

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?

mousebird commented 2 years ago

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.