Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS google maps change urlTemplate on button press #2200

Closed
OsvaldasSk opened this issue Apr 17, 2018 · 3 comments
Closed

iOS google maps change urlTemplate on button press #2200

OsvaldasSk opened this issue Apr 17, 2018 · 3 comments
Labels

Comments

@OsvaldasSk
Copy link

Is this a bug report?

Yes

Have you read the Installation Instructions?

Yes

Environment

react-native: 0.55.2
react: 16.3.1
react-native-maps: 0.21.0
iOS GoogleMaps

Steps to Reproduce

The problem: We have a floor picker and on floor select we change urlTemplate for UrlTiles component. On android everything works fine, but on iOS google maps tiles are not rerendered and old urlTemplate is used.

  1. Create MapView with UrlTile and set urlTemplate to empty string.
  2. Change urlTemplate on button press to for e.g. http://c.tile.stamen.com/watercolor/{z}/{x}/{y}.jpg

Expected Behavior

Tiles from new urlTemplate should be rendered.

Actual Behavior

iOS google maps after button press and urlTemplate changed to different url, still initial urlTemplate is used -> new tiles from new urlTemplate is not rendered.
Android - works fine, urlTemplate can be changed on button press.

Reproducible Demo

Snack url https://snack.expo.io/r1bIYXQnf

Code used from https://github.com/react-community/react-native-maps/blob/master/example/examples/CustomTiles.js

only change I have made is that urlTemplate is stored and retrieved from state. Initial urlTemplate is empty string and changed to http://c.tile.stamen.com/watercolor/{z}/{x}/{y}.jpg on TouchableOpacity press

@BDomantas
Copy link

Hi Osvaldas,

I have encountered exact same problem, which is a critical feature for me. I managed to solve this exact issue by modifying objective-c source code.

However, even though it changes url now, it seems there is still something wrong with cache clearing. First time I change url it works flawlessly. Second time I change templateUrl it seems to not clear cache and you have to zoom map view to see new tiles, otherwise you can still see old tiles (cached?). I am not competent with objective-c at all so maybe someone will notice the mistake I made and will help implement proper cache clearing

//  AIRGoogleMapURLTile.h
// changed urlTemplate NSString variable to NSMutableString

@property (nonatomic, strong) NSMutableString *urlTemplate;

and

//
//  AIRGoogleMapURLTile.m
//  Created by Nick Italiano on 11/5/16.
//

#ifdef HAVE_GOOGLE_MAPS

#import "AIRGoogleMapUrlTile.h"

@implementation AIRGoogleMapUrlTile

- (void)setZIndex:(int)zIndex
{
  _zIndex = zIndex;
  _tileLayer.zIndex = zIndex;
}



- (void)setUrlTemplate:(NSString *)urlTemplate
{
    _urlTemplate = [NSMutableString stringWithString:urlTemplate]; //changed this line
     tileLayer = [GMSURLTileLayer tileLayerWithURLConstructor:[self getTileURLConstructor]];
    _tileLayer.tileSize = [[UIScreen mainScreen] scale] * 256;
    //Added this line
    [_tileLayer clearTileCache];
}

- (GMSTileURLConstructor)_getTileURLConstructor{
    
  NSInteger *maximumZ = self.maximumZ;
  NSInteger *minimumZ = self.minimumZ;
  NSLog(@"test CONSTRUCTOR 1");
    
   GMSTileURLConstructor urls = ^NSURL*(NSUInteger x, NSUInteger y, NSUInteger zoom) {
    NSString *url = [NSString stringWithString:self.urlTemplate]; // changed this line
    url = [url stringByReplacingOccurrencesOfString:@"{x}" withString:[NSMutableString stringWithFormat: @"%ld", (long)x]];
    url = [url stringByReplacingOccurrencesOfString:@"{y}" withString:[NSMutableString stringWithFormat: @"%ld", (long)y]];
    url = [url stringByReplacingOccurrencesOfString:@"{z}" withString:[NSMutableString stringWithFormat: @"%ld", (long)zoom]];

   if(maximumZ && (long)zoom > (long)maximumZ) {
      return nil;
    }

    if(minimumZ  && (long)zoom < (long)minimumZ ) {
      return nil;
    }
    // You can see that second time you change url it does not seem to make requests for tiles and 
   // and you don't see them being logged here
    NSLog(url); 
    return [NSURL URLWithString:url];
  };
  return urls;
}

@end

#endif

@gilliM
Copy link

gilliM commented Sep 5, 2019

Any news in this issue ?

@stale
Copy link

stale bot commented Oct 3, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 3, 2020
@stale stale bot closed this as completed Oct 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants