...
|
...
|
@@ -33,7 +33,7 @@ |
|
|
|
|
|
#import "RMInteractiveSource.h"
|
|
|
|
|
|
#import "RMMapView.h"
|
|
|
#import "RMCompositeSource.h"
|
|
|
|
|
|
#import "FMDatabase.h"
|
|
|
#import "FMDatabaseQueue.h"
|
...
|
...
|
@@ -185,7 +185,7 @@ RMTilePoint RMInteractiveSourceNormalizedTilePointForMapView(CGPoint point, RMMa |
|
|
{
|
|
|
NSString *formattedOutput = nil;
|
|
|
|
|
|
id <RMTileSource>source = mapView.tileSource;
|
|
|
id <RMTileSource, RMInteractiveSource>source = [mapView interactiveTileSource];
|
|
|
|
|
|
NSDictionary *interactivityDictionary = [(id <RMInteractiveSourcePrivate>)source interactivityDictionaryForPoint:point inMapView:mapView];
|
|
|
|
...
|
...
|
@@ -291,6 +291,78 @@ RMTilePoint RMInteractiveSourceNormalizedTilePointForMapView(CGPoint point, RMMa |
|
|
@end
|
|
|
|
|
|
#pragma mark -
|
|
|
#pragma mark RMMapView Interactivity
|
|
|
|
|
|
@interface RMMapView (RMInteractiveSourcePrivate) <RMInteractiveSourcePrivate>
|
|
|
|
|
|
- (id <RMTileSource, RMInteractiveSource>)interactiveTileSource;
|
|
|
- (NSDictionary *)interactivityDictionaryForPoint:(CGPoint)point;
|
|
|
- (NSString *)interactivityFormatterTemplate;
|
|
|
|
|
|
@end
|
|
|
|
|
|
@implementation RMMapView (RMInteractiveSource)
|
|
|
|
|
|
- (id <RMTileSource, RMInteractiveSource>)interactiveTileSource
|
|
|
{
|
|
|
id <RMTileSource, RMInteractiveSource>interactiveTileSource = nil;
|
|
|
|
|
|
if ([self.tileSource isKindOfClass:[RMCompositeSource class]])
|
|
|
{
|
|
|
// currently, we iterate top-down and return the first interactive source
|
|
|
//
|
|
|
for (id <RMTileSource>source in [[((RMCompositeSource *)self.tileSource).compositeSources reverseObjectEnumerator] allObjects])
|
|
|
{
|
|
|
NSLog(@"checking %@", source);
|
|
|
|
|
|
if (([source isKindOfClass:[RMMBTilesSource class]] || [source isKindOfClass:[RMMapBoxSource class]]) &&
|
|
|
[source conformsToProtocol:@protocol(RMInteractiveSource)] &&
|
|
|
[(id <RMInteractiveSource>)source supportsInteractivity])
|
|
|
{
|
|
|
interactiveTileSource = (id <RMTileSource, RMInteractiveSource>)source;
|
|
|
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (([self.tileSource isKindOfClass:[RMMBTilesSource class]] || [self.tileSource isKindOfClass:[RMMapBoxSource class]]) &&
|
|
|
[self.tileSource conformsToProtocol:@protocol(RMInteractiveSource)] &&
|
|
|
[(id <RMInteractiveSource>)self.tileSource supportsInteractivity])
|
|
|
{
|
|
|
interactiveTileSource = (id <RMTileSource, RMInteractiveSource>)self.tileSource;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
NSLog(@"determined interactive source as %@", interactiveTileSource);
|
|
|
|
|
|
return interactiveTileSource;
|
|
|
}
|
|
|
|
|
|
- (BOOL)supportsInteractivity
|
|
|
{
|
|
|
return ([self interactiveTileSource] != nil);
|
|
|
}
|
|
|
|
|
|
- (NSDictionary *)interactivityDictionaryForPoint:(CGPoint)point
|
|
|
{
|
|
|
return [(id <RMInteractiveSourcePrivate>)[self interactiveTileSource] interactivityDictionaryForPoint:point inMapView:self];
|
|
|
}
|
|
|
|
|
|
- (NSString *)interactivityFormatterTemplate
|
|
|
{
|
|
|
return [(id <RMInteractiveSourcePrivate>)[self interactiveTileSource] interactivityFormatterTemplate];
|
|
|
}
|
|
|
|
|
|
- (NSString *)formattedOutputOfType:(RMInteractiveSourceOutputType)outputType forPoint:(CGPoint)point
|
|
|
{
|
|
|
return [(id <RMInteractiveSourcePrivate>)[self interactiveTileSource] formattedOutputOfType:outputType forPoint:point inMapView:self];
|
|
|
}
|
|
|
|
|
|
@end
|
|
|
|
|
|
#pragma mark -
|
|
|
#pragma mark MBTiles Interactivity
|
|
|
|
|
|
@interface RMMBTilesSource (RMInteractiveSourcePrivate) <RMInteractiveSourcePrivate>
|
...
|
...
|
@@ -414,7 +486,7 @@ RMTilePoint RMInteractiveSourceNormalizedTilePointForMapView(CGPoint point, RMMa |
|
|
[results close];
|
|
|
}];
|
|
|
|
|
|
return template;
|
|
|
return ([template length] ? template : nil);
|
|
|
}
|
|
|
|
|
|
- (NSString *)formattedOutputOfType:(RMInteractiveSourceOutputType)outputType forPoint:(CGPoint)point inMapView:(RMMapView *)mapView
|
...
|
...
|
@@ -459,7 +531,14 @@ RMTilePoint RMInteractiveSourceNormalizedTilePointForMapView(CGPoint point, RMMa |
|
|
|
|
|
- (NSDictionary *)interactivityDictionaryForPoint:(CGPoint)point inMapView:(RMMapView *)mapView;
|
|
|
{
|
|
|
if ([self.infoDictionary objectForKey:@"grids"])
|
|
|
NSString *gridURLString = nil;
|
|
|
|
|
|
if ([self.infoDictionary objectForKey:@"grids"] && [[self.infoDictionary objectForKey:@"grids"] isKindOfClass:[NSArray class]])
|
|
|
gridURLString = [[self.infoDictionary objectForKey:@"grids"] objectAtIndex:0];
|
|
|
else
|
|
|
gridURLString = [self.infoDictionary objectForKey:@"gridURL"];
|
|
|
|
|
|
if ([gridURLString length])
|
|
|
{
|
|
|
RMTilePoint tilePoint = RMInteractiveSourceNormalizedTilePointForMapView(point, mapView);
|
|
|
|
...
|
...
|
@@ -467,8 +546,6 @@ RMTilePoint RMInteractiveSourceNormalizedTilePointForMapView(CGPoint point, RMMa |
|
|
NSInteger x = tilePoint.tile.x;
|
|
|
NSInteger y = tilePoint.tile.y;
|
|
|
|
|
|
NSString *gridURLString = [[self.infoDictionary objectForKey:@"grids"] objectAtIndex:0];
|
|
|
|
|
|
gridURLString = [gridURLString stringByReplacingOccurrencesOfString:@"{z}" withString:[[NSNumber numberWithInteger:zoom] stringValue]];
|
|
|
gridURLString = [gridURLString stringByReplacingOccurrencesOfString:@"{x}" withString:[[NSNumber numberWithInteger:x] stringValue]];
|
|
|
gridURLString = [gridURLString stringByReplacingOccurrencesOfString:@"{y}" withString:[[NSNumber numberWithInteger:y] stringValue]];
|
...
|
...
|
@@ -525,7 +602,7 @@ RMTilePoint RMInteractiveSourceNormalizedTilePointForMapView(CGPoint point, RMMa |
|
|
|
|
|
- (NSString *)interactivityFormatterTemplate
|
|
|
{
|
|
|
if ([self.infoDictionary objectForKey:@"template"])
|
|
|
if ([self.infoDictionary objectForKey:@"template"] && [[self.infoDictionary objectForKey:@"template"] length])
|
|
|
return [self.infoDictionary objectForKey:@"template"];
|
|
|
|
|
|
return nil;
|
...
|
...
|
|