Authored by Obrand69

Added method for retrieving a screen lat/lon bound

Added method for retrieving all markers on the screen bound
added sample code in MapViewViewController
... ... @@ -70,6 +70,12 @@
// Put the marker back
[mapView addDefaultMarkerAt:[[mapView contents] mapCenter]];
markers = [mapView getMarkersForScreenBounds];
NSLog(@"Nb Markers in Screen: %d", [markers count]);
[mapView getScreenCoordinateBounds];
... ...
... ... @@ -43,6 +43,7 @@ typedef struct {
} CLLocationCoordinate2D;
#endif
#endif
\ No newline at end of file
... ...
... ... @@ -12,6 +12,11 @@
#import "RMLatLong.h"
#import "RMTile.h"
typedef struct {
CLLocationCoordinate2D northWest;
CLLocationCoordinate2D southEast;
} CLLocationCoordinate2DBounds;
// constants for boundingMask
enum {
// Map can be zoomed out past view limits
... ... @@ -122,5 +127,9 @@ enum {
- (void) removeMarker:(RMMarker *)marker;
- (CGPoint) getMarkerScreenCoordinate: (RMMarker *)marker;
- (CLLocationCoordinate2D) getMarkerCoordinate2D: (RMMarker *) marker;
- (NSArray *) getMarkersForScreenBounds;
- (CLLocationCoordinate2DBounds) getScreenCoordinateBounds;
@end
... ...
... ... @@ -584,4 +584,53 @@ static BOOL _performExpensiveOperations = YES;
return [self pixelToLatLong:[self getMarkerScreenCoordinate:marker]];
}
- (NSArray *) getMarkersForScreenBounds
{
NSMutableArray *markers;
markers = [NSMutableArray array];
CGRect rect = [mercatorToScreenProjection screenBounds];
NSArray *allMarkers = [self getMarkers];
NSEnumerator *markerEnumerator = [allMarkers objectEnumerator];
RMMarker *aMarker;
while (aMarker = (RMMarker *)[markerEnumerator nextObject])
{
CGPoint markerCoord = [self getMarkerScreenCoordinate:aMarker];
if( ((markerCoord.x > rect.origin.x) && (markerCoord.y > rect.origin.y)) &&
((markerCoord.x < (rect.origin.x + rect.size.width)) && (markerCoord.y < (rect.origin.y + rect.size.height))))
{
[markers addObject:aMarker];
}
}
return markers;
}
- (CLLocationCoordinate2DBounds) getScreenCoordinateBounds
{
CLLocationCoordinate2DBounds bounds;
CGRect rect = [mercatorToScreenProjection screenBounds];
CGPoint northWest = rect.origin;
CGPoint southEast;
southEast.x = rect.origin.x + rect.size.width;
southEast.y = rect.origin.y + rect.size.height;
NSLog(@"NortWest x:%lf y:%lf", northWest.x, northWest.y);
NSLog(@"SouthEast x:%lf y:%lf", southEast.x, southEast.y);
bounds.northWest = [self pixelToLatLong:northWest];
bounds.southEast = [self pixelToLatLong:southEast];
NSLog(@"NortWest Lat:%lf Lon:%lf", bounds.northWest.latitude, bounds.northWest.longitude);
NSLog(@"SouthEast Lat:%lf Lon:%lf", bounds.southEast.latitude, bounds.southEast.longitude);
return bounds;
}
@end
... ...
... ... @@ -12,6 +12,7 @@
#import "RMFoundation.h"
#import "RMLatLong.h"
#import "RMMapViewDelegate.h"
#import "RMMapContents.h"
// iPhone-specific mapview stuff.
// Handles event handling, whatnot.
... ... @@ -65,5 +66,9 @@ typedef struct {
- (void) removeMarker:(RMMarker *)marker;
- (CGPoint) getMarkerScreenCoordinate: (RMMarker *)marker;
- (CLLocationCoordinate2D) getMarkerCoordinate2D: (RMMarker *) marker;
- (NSArray *) getMarkersForScreenBounds;
- (CLLocationCoordinate2DBounds) getScreenCoordinateBounds;
@end
... ...
... ... @@ -364,4 +364,14 @@
return [contents getMarkerCoordinate2D:marker];
}
- (NSArray *) getMarkersForScreenBounds
{
return [contents getMarkersForScreenBounds];
}
- (CLLocationCoordinate2DBounds) getScreenCoordinateBounds
{
return [contents getScreenCoordinateBounds];
}
@end
... ...