Permalink
Browse files

Checks if tiles are still in view before loading them. Fixes #21.

  • Loading branch information...
beelsebob committed Feb 19, 2012
1 parent 8d4c72f commit 8e764a450bd66382b98beb5a7ce662236555ed6b
@@ -94,7 +94,7 @@ int main (int argc, const char * argv[])
@"OSPMapCSSClass ::= <class> | '!' <class>;"
@"class ::= '.' 'Identifier';"
@"OSPMapCSSObject ::= 'node' | 'way' | 'relation' | 'area' | 'line' | 'canvas' | '*';"
- @"OSPMapCSSDeclaration ::= '{' <OSPMapCSSStyle>+ '}' | '{' '}';"
+ @"OSPMapCSSDeclaration ::= '{' <OSPMapCSSStyle>* '}';"
@"OSPMapCSSStyle ::= <Styledef> ';';"
@"Styledef ::= <OSPMapCSSKey> ':' <OSPMapCSSSpecifierList>;"
@"OSPMapCSSSpecifierList ::= <OSPMapCSSSpecifier> <OSPMapCSSCommaSpecifier>*;"
@@ -20,14 +20,7 @@ - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree
if (nil != self)
{
- if ([[syntaxTree children] count] == 3)
- {
- [self setStyles:[[syntaxTree children] objectAtIndex:1]];
- }
- else
- {
- [self setStyles:[NSArray array]];
- }
+ [self setStyles:[[syntaxTree children] objectAtIndex:1]];
}
return self;
@@ -13,6 +13,7 @@
@interface OSPTileArray : NSObject
- (void)addTile:(OSPTile)t;
+- (BOOL)containsTile:(OSPTile)t;
- (NSArray *)notIncludedSubtilesOfTile:(OSPTile)t;
@end
@@ -28,6 +28,7 @@ @interface OSPTileTree : NSObject
- (id)initWithTile:(OSPTile)initTile;
- (void)addTile:(OSPTile)tile;
+- (BOOL)containsTile:(OSPTile)tile;
- (NSArray *)notIncludedSubtilesOfTile:(OSPTile)t;
- (NSArray *)notIncludedSubtiles;
- (uint8_t)indexForChild:(OSPTile)tile;
@@ -110,6 +111,30 @@ - (uint8_t)indexForChild:(OSPTile)tile
return yHalf * 2 + xHalf;
}
+- (BOOL)containsTile:(OSPTile)tile
+{
+ @synchronized(self)
+ {
+ if ([self isIncluded])
+ {
+ return YES;
+ }
+
+ if ([self isLeaf])
+ {
+ return NO;
+ }
+
+ OSPTile t = [self representedTile];
+ if (OSPTileEqual(tile, t))
+ {
+ return NO;
+ }
+
+ return [[[self subTrees] objectAtIndex:[self indexForChild:tile]] containsTile:tile];
+ }
+}
+
- (NSArray *)notIncludedSubtilesOfTile:(OSPTile)tile
{
@synchronized(self)
@@ -186,6 +211,11 @@ - (void)addTile:(OSPTile)t
[[self tileTree] addTile:t];
}
+- (BOOL)containsTile:(OSPTile)t
+{
+ return [[self tileTree] containsTile:t];
+}
+
- (NSArray *)notIncludedSubtilesOfTile:(OSPTile)t
{
return [[self tileTree] notIncludedSubtilesOfTile:t];
@@ -15,6 +15,7 @@
@protocol OSPMapServerDelegate <NSObject>
- (void)mapServer:(OSPMapServer *)mapServer didLoadObjectsInArea:(OSPCoordinateRect)area;
+- (BOOL)mapServer:(OSPMapServer *)mapServer shouldLoadObjectsInArea:(OSPCoordinateRect)area;
@end
@@ -348,7 +348,6 @@ - (void)makeRequestForURL:(NSURL *)url ofType:(OSPRequestType)type tile:(OSPTile
[rec setRequestType:type];
[rec setDelegate:self];
[self queueConnection:rec];
- [[self requestedTiles] addTile:tile];
}
- (void)queueConnection:(OSPConnection *)newConnection
@@ -365,28 +364,34 @@ - (void)popConnectionQueue
{
OSPConnection *rec = [[self connectionQueue] objectAtIndex:0];
[[self connectionQueue] removeObjectAtIndex:0];
- [[self currentConnections] addObject:rec];
- [rec setConnection:[NSURLConnection connectionWithRequest:[rec request] delegate:rec]];
- [[rec connection] start];
- CFReadStreamRef readStream;
- CFWriteStreamRef writeStream;
- CFStreamCreateBoundPair(NULL, &readStream, &writeStream, 4096);
- NSInputStream *iStream = CFBridgingRelease(readStream);
- NSOutputStream *oStream = CFBridgingRelease(writeStream);
- [oStream setDelegate:rec];
- NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
- [iStream scheduleInRunLoop:runLoop forMode:NSDefaultRunLoopMode];
- [oStream scheduleInRunLoop:runLoop forMode:NSDefaultRunLoopMode];
- [iStream open];
- [oStream open];
- [rec setParserStream:oStream];
- NSXMLParser *parser = [[NSXMLParser alloc] initWithStream:iStream];
- [parser setDelegate:rec];
- [rec setParser:parser];
- dispatch_async(parserQueue, ^()
- {
- [parser parse];
- });
+
+ if ([[self delegate] mapServer:self shouldLoadObjectsInArea:OSPCoordinateRectFromTile([rec tile])] &&
+ ![[self requestedTiles] containsTile:[rec tile]])
+ {
+ [[self requestedTiles] addTile:[rec tile]];
+ [[self currentConnections] addObject:rec];
+ [rec setConnection:[NSURLConnection connectionWithRequest:[rec request] delegate:rec]];
+ [[rec connection] start];
+ CFReadStreamRef readStream;
+ CFWriteStreamRef writeStream;
+ CFStreamCreateBoundPair(NULL, &readStream, &writeStream, 4096);
+ NSInputStream *iStream = CFBridgingRelease(readStream);
+ NSOutputStream *oStream = CFBridgingRelease(writeStream);
+ [oStream setDelegate:rec];
+ NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
+ [iStream scheduleInRunLoop:runLoop forMode:NSDefaultRunLoopMode];
+ [oStream scheduleInRunLoop:runLoop forMode:NSDefaultRunLoopMode];
+ [iStream open];
+ [oStream open];
+ [rec setParserStream:oStream];
+ NSXMLParser *parser = [[NSXMLParser alloc] initWithStream:iStream];
+ [parser setDelegate:rec];
+ [rec setParser:parser];
+ dispatch_async(parserQueue, ^()
+ {
+ [parser parse];
+ });
+ }
}
}
}
@@ -108,6 +108,11 @@ - (void)mapServer:(OSPMapServer *)mapServer didLoadObjectsInArea:(OSPCoordinateR
[[self metaView] setNeedsDisplayInMapArea:area];
}
+- (BOOL)mapServer:(OSPMapServer *)mapServer shouldLoadObjectsInArea:(OSPCoordinateRect)area
+{
+ return OSPCoordinateRectIntersectsRect(OSPRectForMapAreaInRect([self mapArea], [self bounds]), area);
+}
+
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self setStartPoint:[self mapArea].centre];
View
Binary file not shown.

0 comments on commit 8e764a4

Please sign in to comment.