Skip to content

Commit cfc41ff

Browse files
akmjenkinsrborn
authored andcommitted
Modifications/Enhancements to MapView.UrlTile (react-native-maps#2136)
* 1. Allow canReplaceMapContent to be set on the JS side (via prop shouldReplaceMapContent) for iOS, MapKit only 2. Allow GoogleMaps on iOS to obey maximumZ 3. Added prop minimumZ for MapKit and GoogleMaps on iOS and Android * Removed debug NSLogs * MaximumZ was not being obeyed correctly for google maps (convert to long to compare). Get rid of compiler warnings (accidentally wrote NSUInteger instead of NSInteger) * Typings for v0.21.0 (react-native-maps#2165) * Update mapview.md (react-native-maps#2171) Add 'none' option to docs for mapType * Fixed crash for Android API level below 18 on isFromMockProvider (react-native-maps#2172) * Add Mock Provider boolean on each location update * Update mapview.md Update docs to specify that coordinate includes mock provider boolean * Check API is 18 or above for isFromMockProvider * Update docs to mention API * 1. Allow canReplaceMapContent to be set on the JS side (via prop shouldReplaceMapContent) for iOS, MapKit only 2. Allow GoogleMaps on iOS to obey maximumZ 3. Added prop minimumZ for MapKit and GoogleMaps on iOS and Android * Removed debug NSLogs * MaximumZ was not being obeyed correctly for google maps (convert to long to compare). Get rid of compiler warnings (accidentally wrote NSUInteger instead of NSInteger)
1 parent e16d09d commit cfc41ff

File tree

9 files changed

+103
-7
lines changed

9 files changed

+103
-7
lines changed

lib/android/src/main/java/com/airbnb/android/react/maps/AirMapUrlTile.java

+25
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ public synchronized URL getTileUrl(int x, int y, int zoom) {
2828
.replace("{y}", Integer.toString(y))
2929
.replace("{z}", Integer.toString(zoom));
3030
URL url = null;
31+
32+
if(this.maximumZ && zoom > maximumZ) {
33+
return url;
34+
}
35+
36+
if(this.minimumZ && zoom < minimumZ) {
37+
return url;
38+
}
39+
3140
try {
3241
url = new URL(s);
3342
} catch (MalformedURLException e) {
@@ -47,6 +56,8 @@ public void setUrlTemplate(String urlTemplate) {
4756

4857
private String urlTemplate;
4958
private float zIndex;
59+
private float maximumZ;
60+
private float minimumZ;
5061

5162
public AirMapUrlTile(Context context) {
5263
super(context);
@@ -69,6 +80,20 @@ public void setZIndex(float zIndex) {
6980
}
7081
}
7182

83+
public void setMaximumZ(float maximumZ) {
84+
this.maximumZ = maximumZ;
85+
if (tileOverlay != null) {
86+
tileOverlay.clearTileCache();
87+
}
88+
}
89+
90+
public void setMinimumZ(float minimumZ) {
91+
this.minimumZ = minimumZ;
92+
if (tileOverlay != null) {
93+
tileOverlay.clearTileCache();
94+
}
95+
}
96+
7297
public TileOverlayOptions getTileOverlayOptions() {
7398
if (tileOverlayOptions == null) {
7499
tileOverlayOptions = createTileOverlayOptions();

lib/android/src/main/java/com/airbnb/android/react/maps/AirMapUrlTileManager.java

+10
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,14 @@ public void setZIndex(AirMapUrlTile view, float zIndex) {
4545
view.setZIndex(zIndex);
4646
}
4747

48+
@ReactProp(name = "minimumZ", defaultFloat = 0.0f)
49+
public void setMinimumZ(AirMapUrlTile view, float minimumZ) {
50+
view.setMinimumZ(minimumZ)
51+
}
52+
53+
@ReactProp(name = "maximumZ", defaultFloat = 100.0f)
54+
public void setMaximumZ(AirMapUrlTile view, float maximumZ) {
55+
view.setMaximumZ(maximumZ);
56+
}
57+
4858
}

lib/components/MapUrlTile.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,23 @@ const propTypes = {
3232
*/
3333
zIndex: PropTypes.number,
3434
/**
35-
* The maximum zoom level for this tile overlay. Corresponds to the maximumZ setting in
36-
* MKTileOverlay. iOS only.
35+
* The maximum zoom level for this tile overlay.
3736
*
38-
* @platform ios
3937
*/
4038
maximumZ: PropTypes.number,
39+
40+
/**
41+
* The minimum zoom level for this tile overlay.
42+
*
43+
*/
44+
minimumZ: PropTypes.number,
45+
46+
/**
47+
* Corresponds to MKTileOverlay canReplaceMapContent.
48+
*
49+
* @platform ios
50+
*/
51+
shouldReplaceMapContent: PropTypes.bool,
4152
};
4253

4354
class MapUrlTile extends React.Component {

lib/ios/AirGoogleMaps/AIRGoogleMapURLTileManager.m

+2
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,7 @@ - (UIView *)view
2222

2323
RCT_EXPORT_VIEW_PROPERTY(urlTemplate, NSString)
2424
RCT_EXPORT_VIEW_PROPERTY(zIndex, int)
25+
RCT_EXPORT_VIEW_PROPERTY(maximumZ, NSInteger)
26+
RCT_EXPORT_VIEW_PROPERTY(minimumZ, NSInteger)
2527

2628
@end

lib/ios/AirGoogleMaps/AIRGoogleMapUrlTile.h

+2
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@
1111
@property (nonatomic, strong) GMSURLTileLayer *tileLayer;
1212
@property (nonatomic, assign) NSString *urlTemplate;
1313
@property (nonatomic, assign) int zIndex;
14+
@property NSInteger *maximumZ;
15+
@property NSInteger *minimumZ;
1416

1517
@end

lib/ios/AirGoogleMaps/AIRGoogleMapUrlTile.m

+14-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,25 @@ - (void)setUrlTemplate:(NSString *)urlTemplate
2222
- (GMSTileURLConstructor)_getTileURLConstructor
2323
{
2424
NSString *urlTemplate = self.urlTemplate;
25-
GMSTileURLConstructor urls = ^(NSUInteger x, NSUInteger y, NSUInteger zoom) {
25+
NSInteger *maximumZ = self.maximumZ;
26+
NSInteger *minimumZ = self.minimumZ;
27+
GMSTileURLConstructor urls = ^NSURL* _Nullable (NSUInteger x, NSUInteger y, NSUInteger zoom) {
2628
NSString *url = urlTemplate;
2729
url = [url stringByReplacingOccurrencesOfString:@"{x}" withString:[NSString stringWithFormat: @"%ld", (long)x]];
2830
url = [url stringByReplacingOccurrencesOfString:@"{y}" withString:[NSString stringWithFormat: @"%ld", (long)y]];
2931
url = [url stringByReplacingOccurrencesOfString:@"{z}" withString:[NSString stringWithFormat: @"%ld", (long)zoom]];
32+
33+
if(maximumZ && (long)zoom > (long)maximumZ) {
34+
return nil;
35+
}
36+
37+
if(minimumZ && (long)zoom < (long)minimumZ) {
38+
return nil;
39+
}
40+
3041
return [NSURL URLWithString:url];
3142
};
3243
return urls;
3344
}
34-
@end
45+
46+
@end

lib/ios/AirMaps/AIRMapUrlTile.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222

2323
@property (nonatomic, strong) MKTileOverlay *tileOverlay;
2424
@property (nonatomic, strong) MKTileOverlayRenderer *renderer;
25-
2625
@property (nonatomic, copy) NSString *urlTemplate;
2726
@property NSInteger maximumZ;
27+
@property NSInteger minimumZ;
28+
@property BOOL shouldReplaceMapContent;
2829

2930
#pragma mark MKOverlay protocol
3031

lib/ios/AirMaps/AIRMapUrlTile.m

+32-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,32 @@ @implementation AIRMapUrlTile {
1313
BOOL _urlTemplateSet;
1414
}
1515

16+
- (void)setShouldReplaceMapContent:(BOOL)shouldReplaceMapContent
17+
{
18+
_shouldReplaceMapContent = shouldReplaceMapContent;
19+
if(self.tileOverlay) {
20+
self.tileOverlay.canReplaceMapContent = _shouldReplaceMapContent;
21+
}
22+
[self update];
23+
}
24+
25+
- (void)setMaximumZ:(NSUInteger)maximumZ
26+
{
27+
_maximumZ = maximumZ;
28+
if(self.tileOverlay) {
29+
self.tileOverlay.maximumZ = _maximumZ;
30+
}
31+
[self update];
32+
}
33+
34+
- (void)setMinimumZ:(NSUInteger)minimumZ
35+
{
36+
_minimumZ = minimumZ;
37+
if(self.tileOverlay) {
38+
self.tileOverlay.minimumZ = _minimumZ;
39+
}
40+
[self update];
41+
}
1642

1743
- (void)setUrlTemplate:(NSString *)urlTemplate{
1844
_urlTemplate = urlTemplate;
@@ -25,7 +51,12 @@ - (void) createTileOverlayAndRendererIfPossible
2551
{
2652
if (!_urlTemplateSet) return;
2753
self.tileOverlay = [[MKTileOverlay alloc] initWithURLTemplate:self.urlTemplate];
28-
self.tileOverlay.canReplaceMapContent = YES;
54+
55+
self.tileOverlay.canReplaceMapContent = self.shouldReplaceMapContent;
56+
57+
if(self.minimumZ) {
58+
self.tileOverlay.minimumZ = self.minimumZ;
59+
}
2960
if (self.maximumZ) {
3061
self.tileOverlay.maximumZ = self.maximumZ;
3162
}

lib/ios/AirMaps/AIRMapUrlTileManager.m

+2
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,7 @@ - (UIView *)view
3434

3535
RCT_EXPORT_VIEW_PROPERTY(urlTemplate, NSString)
3636
RCT_EXPORT_VIEW_PROPERTY(maximumZ, NSInteger)
37+
RCT_EXPORT_VIEW_PROPERTY(minimumZ, NSInteger)
38+
RCT_EXPORT_VIEW_PROPERTY(shouldReplaceMapContent, BOOL)
3739

3840
@end

0 commit comments

Comments
 (0)