Skip to content

Commit

Permalink
Add "requestTile" method, fix UI-execution
Browse files Browse the repository at this point in the history
  • Loading branch information
hansemannn committed May 21, 2017
1 parent 613f683 commit 47b13cd
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,27 @@ mapView.addTile(tile);
// Remove tile
mapView.removeTile(tile);
```
You can also request a tile image for a specified x/y/zoom position:
```js
var tile = maps.createTile({
url: "http://c.tile.openstreetmap.org/{z}/{x}/{y}.png",
});
tile.addEventListener('receivetile', function(e) {
Ti.API.info('Received new tile at ' + e.tile.x + 'x' + e.tile.y);
Ti.API.info(e);
// Add tile image to a view or process it somewhere else
// win.add(Ti.UI.createImageView({image: e.tile.image}));
});
tile.requestTile({
x: 200,
y: 200,
zoom: 3
});
```

For more information on Tile Layers: https://developers.google.com/maps/documentation/ios-sdk/tiles

In future releases you will also be able to specify local images, but that is not scheduled so far.
Expand Down
2 changes: 1 addition & 1 deletion ios/Classes/TiGooglemapsTileProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#import "TiProxy.h"
#import <GoogleMaps/GoogleMaps.h>

@interface TiGooglemapsTileProxy : TiProxy {
@interface TiGooglemapsTileProxy : TiProxy<GMSTileReceiver> {

}

Expand Down
36 changes: 35 additions & 1 deletion ios/Classes/TiGooglemapsTileProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ - (void)setFadeIn:(id)value

- (void)setSize:(id)value
{
ENSURE_UI_THREAD(setFadeIn, value);
ENSURE_UI_THREAD(setSize, value);
ENSURE_TYPE(value, NSNumber);

[[self tile] setTileSize:[TiUtils intValue:value]];
Expand All @@ -80,4 +80,38 @@ - (void)clearTileCache:(id)unused
[[self tile] clearTileCache];
}

- (void)requestTile:(id)args
{
ENSURE_UI_THREAD(requestTile, args);
ENSURE_SINGLE_ARG(args, NSDictionary);

NSNumber *x = [TiUtils numberFromObject:[args objectForKey:@"x"]];
NSNumber *y = [TiUtils numberFromObject:[args objectForKey:@"y"]];
NSNumber *zoom = [TiUtils numberFromObject:[args objectForKey:@"zoom"]];

[[self tile] requestTileForX:x.unsignedIntegerValue
y:y.unsignedIntegerValue
zoom:zoom.unsignedIntegerValue
receiver:self];
}

#pragma mark Tile Receiver Delegate

- (void)receiveTileWithX:(NSUInteger)x
y:(NSUInteger)y
zoom:(NSUInteger)zoom
image:(UIImage *)image
{
if ([self _hasListeners:@"receivetile"]) {
NSDictionary *event = @{
@"x": NUMUINTEGER(x),
@"y": NUMUINTEGER(y),
@"zoom": NUMUINTEGER(zoom),
@"image": [[TiBlob alloc] initWithImage:image]
};

[self fireEvent:@"receivetile" withObject:@{@"tile": event}];
}
}

@end
2 changes: 1 addition & 1 deletion ios/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 3.3.2
version: 3.4.0
apiversion: 2
architectures: armv7 arm64 i386 x86_64
description: ti.googlemaps
Expand Down

0 comments on commit 47b13cd

Please sign in to comment.