Skip to content

Commit

Permalink
Modifications/Enhancements to MapView.UrlTile (react-native-maps#2136)
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
akmjenkins authored and rborn committed Apr 9, 2018
1 parent bacb33b commit 67d63ef
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ public synchronized URL getTileUrl(int x, int y, int zoom) {
.replace("{y}", Integer.toString(y))
.replace("{z}", Integer.toString(zoom));
URL url = null;

if(this.maximumZ && zoom > maximumZ) {
return url;
}

if(this.minimumZ && zoom < minimumZ) {
return url;
}

try {
url = new URL(s);
} catch (MalformedURLException e) {
Expand All @@ -47,6 +56,8 @@ public void setUrlTemplate(String urlTemplate) {

private String urlTemplate;
private float zIndex;
private float maximumZ;
private float minimumZ;

public AirMapUrlTile(Context context) {
super(context);
Expand All @@ -69,6 +80,20 @@ public void setZIndex(float zIndex) {
}
}

public void setMaximumZ(float maximumZ) {
this.maximumZ = maximumZ;
if (tileOverlay != null) {
tileOverlay.clearTileCache();
}
}

public void setMinimumZ(float minimumZ) {
this.minimumZ = minimumZ;
if (tileOverlay != null) {
tileOverlay.clearTileCache();
}
}

public TileOverlayOptions getTileOverlayOptions() {
if (tileOverlayOptions == null) {
tileOverlayOptions = createTileOverlayOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,14 @@ public void setZIndex(AirMapUrlTile view, float zIndex) {
view.setZIndex(zIndex);
}

@ReactProp(name = "minimumZ", defaultFloat = 0.0f)
public void setMinimumZ(AirMapUrlTile view, float minimumZ) {
view.setMinimumZ(minimumZ)
}

@ReactProp(name = "maximumZ", defaultFloat = 100.0f)
public void setMaximumZ(AirMapUrlTile view, float maximumZ) {
view.setMaximumZ(maximumZ);
}

}
17 changes: 14 additions & 3 deletions lib/components/MapUrlTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,23 @@ const propTypes = {
*/
zIndex: PropTypes.number,
/**
* The maximum zoom level for this tile overlay. Corresponds to the maximumZ setting in
* MKTileOverlay. iOS only.
* The maximum zoom level for this tile overlay.
*
* @platform ios
*/
maximumZ: PropTypes.number,

/**
* The minimum zoom level for this tile overlay.
*
*/
minimumZ: PropTypes.number,

/**
* Corresponds to MKTileOverlay canReplaceMapContent.
*
* @platform ios
*/
shouldReplaceMapContent: PropTypes.bool,
};

class MapUrlTile extends React.Component {
Expand Down
2 changes: 2 additions & 0 deletions lib/ios/AirGoogleMaps/AIRGoogleMapURLTileManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ - (UIView *)view

RCT_EXPORT_VIEW_PROPERTY(urlTemplate, NSString)
RCT_EXPORT_VIEW_PROPERTY(zIndex, int)
RCT_EXPORT_VIEW_PROPERTY(maximumZ, NSInteger)
RCT_EXPORT_VIEW_PROPERTY(minimumZ, NSInteger)

@end
2 changes: 2 additions & 0 deletions lib/ios/AirGoogleMaps/AIRGoogleMapUrlTile.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
@property (nonatomic, strong) GMSURLTileLayer *tileLayer;
@property (nonatomic, assign) NSString *urlTemplate;
@property (nonatomic, assign) int zIndex;
@property NSInteger *maximumZ;
@property NSInteger *minimumZ;

@end
16 changes: 14 additions & 2 deletions lib/ios/AirGoogleMaps/AIRGoogleMapUrlTile.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,25 @@ - (void)setUrlTemplate:(NSString *)urlTemplate
- (GMSTileURLConstructor)_getTileURLConstructor
{
NSString *urlTemplate = self.urlTemplate;
GMSTileURLConstructor urls = ^(NSUInteger x, NSUInteger y, NSUInteger zoom) {
NSInteger *maximumZ = self.maximumZ;
NSInteger *minimumZ = self.minimumZ;
GMSTileURLConstructor urls = ^NSURL* _Nullable (NSUInteger x, NSUInteger y, NSUInteger zoom) {
NSString *url = urlTemplate;
url = [url stringByReplacingOccurrencesOfString:@"{x}" withString:[NSString stringWithFormat: @"%ld", (long)x]];
url = [url stringByReplacingOccurrencesOfString:@"{y}" withString:[NSString stringWithFormat: @"%ld", (long)y]];
url = [url stringByReplacingOccurrencesOfString:@"{z}" withString:[NSString stringWithFormat: @"%ld", (long)zoom]];

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

if(minimumZ && (long)zoom < (long)minimumZ) {
return nil;
}

return [NSURL URLWithString:url];
};
return urls;
}
@end

@end
3 changes: 2 additions & 1 deletion lib/ios/AirMaps/AIRMapUrlTile.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@

@property (nonatomic, strong) MKTileOverlay *tileOverlay;
@property (nonatomic, strong) MKTileOverlayRenderer *renderer;

@property (nonatomic, copy) NSString *urlTemplate;
@property NSInteger maximumZ;
@property NSInteger minimumZ;
@property BOOL shouldReplaceMapContent;

#pragma mark MKOverlay protocol

Expand Down
33 changes: 32 additions & 1 deletion lib/ios/AirMaps/AIRMapUrlTile.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,32 @@ @implementation AIRMapUrlTile {
BOOL _urlTemplateSet;
}

- (void)setShouldReplaceMapContent:(BOOL)shouldReplaceMapContent
{
_shouldReplaceMapContent = shouldReplaceMapContent;
if(self.tileOverlay) {
self.tileOverlay.canReplaceMapContent = _shouldReplaceMapContent;
}
[self update];
}

- (void)setMaximumZ:(NSUInteger)maximumZ
{
_maximumZ = maximumZ;
if(self.tileOverlay) {
self.tileOverlay.maximumZ = _maximumZ;
}
[self update];
}

- (void)setMinimumZ:(NSUInteger)minimumZ
{
_minimumZ = minimumZ;
if(self.tileOverlay) {
self.tileOverlay.minimumZ = _minimumZ;
}
[self update];
}

- (void)setUrlTemplate:(NSString *)urlTemplate{
_urlTemplate = urlTemplate;
Expand All @@ -25,7 +51,12 @@ - (void) createTileOverlayAndRendererIfPossible
{
if (!_urlTemplateSet) return;
self.tileOverlay = [[MKTileOverlay alloc] initWithURLTemplate:self.urlTemplate];
self.tileOverlay.canReplaceMapContent = YES;

self.tileOverlay.canReplaceMapContent = self.shouldReplaceMapContent;

if(self.minimumZ) {
self.tileOverlay.minimumZ = self.minimumZ;
}
if (self.maximumZ) {
self.tileOverlay.maximumZ = self.maximumZ;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/ios/AirMaps/AIRMapUrlTileManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@ - (UIView *)view

RCT_EXPORT_VIEW_PROPERTY(urlTemplate, NSString)
RCT_EXPORT_VIEW_PROPERTY(maximumZ, NSInteger)
RCT_EXPORT_VIEW_PROPERTY(minimumZ, NSInteger)
RCT_EXPORT_VIEW_PROPERTY(shouldReplaceMapContent, BOOL)

@end

0 comments on commit 67d63ef

Please sign in to comment.