Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "Source/MapKitTest/vendor/OCHamcrest"]
path = Source/MapKitTest/vendor/OCHamcrest
url = https://github.com/hamcrest/OCHamcrest.git
[submodule "Source/MapKitTest/vendor/ocmock"]
path = Source/MapKitTest/vendor/ocmock
url = https://github.com/erikdoe/ocmock.git
6 changes: 4 additions & 2 deletions Source/Framework/Classes/MKCircle.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@

@interface MKCircle : MKShape <MKOverlay> {
@package
CLLocationCoordinate2D coordinate;
CLLocationDistance radius;
CLLocationCoordinate2D coordinate;
CLLocationDistance radius;
MKMapRect boundingMapRect;
}

+ (MKCircle *)circleWithCenterCoordinate:(CLLocationCoordinate2D)coord radius:(CLLocationDistance)radius;

@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic, readonly) CLLocationDistance radius;
@property (nonatomic, readonly) MKCoordinateRegion region;
@property (nonatomic, readonly) MKMapRect boundingMapRect;

@end
6 changes: 6 additions & 0 deletions Source/Framework/Classes/MKCircle.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ - (id)initWithCenterCoordinate:(CLLocationCoordinate2D)aCoord radius:(CLLocation
@implementation MKCircle

@synthesize coordinate, radius;
@synthesize boundingMapRect;

+ (MKCircle *)circleWithCenterCoordinate:(CLLocationCoordinate2D)aCoord radius:(CLLocationDistance)aRadius
{
Expand All @@ -43,6 +44,11 @@ - (id)initWithCenterCoordinate:(CLLocationCoordinate2D)aCoord radius:(CLLocation
{
coordinate = aCoord;
radius = aRadius;


//TODO: set the boundingMapRect


}
return self;
}
Expand Down
11 changes: 11 additions & 0 deletions Source/Framework/Classes/MKGeometry+Private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// MKGeometry+Private.h
// MapKit
//
// Created by Markus on 17.10.12.
//
//

#import "MKGeometry.h"


88 changes: 88 additions & 0 deletions Source/Framework/Classes/MKGeometry+Private.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//
// MKGeometry+Private.m
// MapKit
//
// Created by Markus on 17.10.12.
//
//

#import "MKGeometry+Private.h"

// Number of pixels for zoom level 20
#define MK_NUMBER_OF_PIXELS_AT_ZOOM_20 268435456.0f

const MKMapSize MKMapSizeWorld = {MK_NUMBER_OF_PIXELS_AT_ZOOM_20,MK_NUMBER_OF_PIXELS_AT_ZOOM_20};

const MKMapRect MKMapRectWorld ={{0,0},{MK_NUMBER_OF_PIXELS_AT_ZOOM_20,MK_NUMBER_OF_PIXELS_AT_ZOOM_20}};



// Functions taken from http://troybrant.net/blog/2010/01/mkmapview-and-zoom-levels-a-visual-guide/

#define MERCATOR_OFFSET (MKMapSizeWorld.width/2.0f)
#define MERCATOR_RADIUS (MERCATOR_OFFSET/M_PI)
#define MKPOINTS_PER_METER (6.74355336508965f)
#define WGS_EARTH_RADIUS 6378137.0f


double longitudeToPixelSpaceX(double longitude)
{
// return MERCATOR_OFFSET + MERCATOR_RADIUS * longitude * M_PI / 180.0f;
return MERCATOR_OFFSET * (1.0f + (longitude / 180.0f));
}

double latitudeToPixelSpaceY(double latitude)
{
return MERCATOR_OFFSET - MERCATOR_RADIUS * log((1.0f + sin(latitude * M_PI / 180.0f)) / (1.0f - sin(latitude * M_PI / 180.0f))) / 2.0f;
}

double pixelSpaceXToLongitude(double pixelX)
{
return (((pixelX/MERCATOR_OFFSET)-1.0f) * 180.0f);
}

double pixelSpaceYToLatitude(double pixelY)
{
return (M_PI / 2.0f - 2.0f * atan(exp((pixelY - MERCATOR_OFFSET) / MERCATOR_RADIUS))) * 180.0f / M_PI;
}




extern MKMapPoint MKMapPointForCoordinate(CLLocationCoordinate2D coordinate)
{
return MKMapPointMake(longitudeToPixelSpaceX(coordinate.longitude), latitudeToPixelSpaceY(coordinate.latitude));

}

extern CLLocationCoordinate2D MKCoordinateForMapPoint(MKMapPoint mapPoint)
{
return CLLocationCoordinate2DMake(pixelSpaceYToLatitude(mapPoint.y), pixelSpaceXToLongitude(mapPoint.x));
}


//FIXME: Conversion functions do not return the same values as iOS MapKit.

double MKMapPointsPerMeterAtLatitude(CLLocationDegrees latitude)
{
return (cos((latitude * M_PI/ 180.0f)) * MK_NUMBER_OF_PIXELS_AT_ZOOM_20)/(2.0f * M_PI * WGS_EARTH_RADIUS);
}

CLLocationDistance MKMetersPerMapPointAtLatitude(CLLocationDegrees longitude)
{
return 1.0/MKMapPointsPerMeterAtLatitude(longitude);
}


MKCoordinateRegion MKCoordinateRegionForMapRect(MKMapRect rect)
{
CLLocationCoordinate2D center = MKCoordinateForMapPoint(MKMapPointMake(MKMapRectGetMidX(rect), MKMapRectGetMidY(rect)));


CLLocationCoordinate2D northWest = MKCoordinateForMapPoint(rect.origin);
CLLocationCoordinate2D southEast = MKCoordinateForMapPoint(MKMapPointMake(MKMapRectGetMaxX(rect), MKMapRectGetMaxY(rect)));


return MKCoordinateRegionMake(center, MKCoordinateSpanMake(northWest.latitude - southEast.latitude, southEast.longitude - northWest.longitude));

}
8 changes: 7 additions & 1 deletion Source/Framework/Classes/MKGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ typedef struct {
// 0.5, 1 screen point = 2 MKMapPoints.
typedef CGFloat MKZoomScale;

// The map point for the coordinate (-90,180)
*/


extern const MKMapSize MKMapSizeWorld;
// The rect that contains every map point in the world.
extern const MKMapRect MKMapRectWorld;
Expand All @@ -70,10 +72,12 @@ extern const MKMapRect MKMapRectWorld;
extern MKMapPoint MKMapPointForCoordinate(CLLocationCoordinate2D coordinate);
extern CLLocationCoordinate2D MKCoordinateForMapPoint(MKMapPoint mapPoint);


// Conversion between distances and projected coordinates
extern CLLocationDistance MKMetersPerMapPointAtLatitude(CLLocationDegrees latitude);
extern double MKMapPointsPerMeterAtLatitude(CLLocationDegrees latitude);

/*
extern CLLocationDistance MKMetersBetweenMapPoints(MKMapPoint a, MKMapPoint b);

extern const MKMapRect MKMapRectNull;*/
Expand Down Expand Up @@ -154,9 +158,11 @@ extern void MKMapRectDivide(MKMapRect rect, MKMapRect *slice, MKMapRect *remaind
extern BOOL MKMapRectContainsPoint(MKMapRect rect, MKMapPoint point);
extern BOOL MKMapRectContainsRect(MKMapRect rect1, MKMapRect rect2);
extern BOOL MKMapRectIntersectsRect(MKMapRect rect1, MKMapRect rect2);
*/

extern MKCoordinateRegion MKCoordinateRegionForMapRect(MKMapRect rect);

/*
extern BOOL MKMapRectSpans180thMeridian(MKMapRect rect);
// For map rects that span the 180th meridian, this returns the portion of the rect
// that lies outside of the world rect wrapped around to the other side of the
Expand Down
6 changes: 6 additions & 0 deletions Source/Framework/Classes/MKMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
- (void)setCenterCoordinate:(CLLocationCoordinate2D)coordinate animated:(BOOL)animated;
- (void)setRegion:(MKCoordinateRegion)region animated:(BOOL)animated;

// Access the visible region of the map in projected coordinates.
@property (nonatomic) MKMapRect visibleMapRect;
- (void)setVisibleMapRect:(MKMapRect)mapRect animated:(BOOL)animate;



// Overlays
- (void)addOverlay:(id < MKOverlay >)overlay;
- (void)addOverlays:(NSArray *)overlays;
Expand Down
17 changes: 16 additions & 1 deletion Source/Framework/Classes/MKMapView.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

@implementation MKMapView

@synthesize delegate, mapType, userLocation, showsUserLocation;
@synthesize delegate, mapType, userLocation, showsUserLocation,visibleMapRect;


- (id)initWithFrame:(NSRect)frame {
Expand Down Expand Up @@ -173,6 +173,21 @@ - (void)setRegion:(MKCoordinateRegion)region animated:(BOOL)animated
[self delegateRegionDidChangeAnimated:animated];
}


- (void)setVisibleMapRect:(MKMapRect)mapRect animated:(BOOL)animate
{
[self willChangeValueForKey:@"visibleMapRect"];
visibleMapRect = mapRect;

[self setRegion:MKCoordinateRegionForMapRect(visibleMapRect) animated:NO];

[self didChangeValueForKey:@"visibleMapRect"];

}




- (void)setShowsUserLocation:(BOOL)show
{
BOOL oldValue = showsUserLocation;
Expand Down
2 changes: 2 additions & 0 deletions Source/Framework/Classes/MKOverlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@
// From MKAnnotation, for areas this should return the centroid of the area.
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;

@property (nonatomic, readonly) MKMapRect boundingMapRect;

@end
26 changes: 25 additions & 1 deletion Source/Framework/Classes/MKPolygon.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ - (id)initWithCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)cou

@implementation MKPolygon



@synthesize boundingMapRect;
@synthesize interiorPolygons;

+ (MKPolygon *)polygonWithCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)count
Expand Down Expand Up @@ -48,10 +51,26 @@ - (id)initWithCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)cou
if (self = [super init])
{
coordinates = malloc(sizeof(CLLocationCoordinate2D) * count);

MKMapPoint minXY = MKMapPointForCoordinate(*coords);
MKMapPoint maxXY = MKMapPointForCoordinate(*coords);

for (int i = 0; i < count; i++)
{
coordinates[i] = coords[i];
}

MKMapPoint mapPoint = MKMapPointForCoordinate(coords[i]);

minXY.x= MIN(minXY.x,mapPoint.x);
minXY.y= MIN(minXY.y,mapPoint.y);
maxXY.x= MAX(maxXY.x,mapPoint.x);
maxXY.y= MAX(maxXY.y,mapPoint.y);


}

boundingMapRect = MKMapRectMake(minXY.x, minXY.y, (double)(maxXY.x-minXY.x), (double) maxXY.y-minXY.y);

coordinateCount = count;
}
return self;
Expand All @@ -66,4 +85,9 @@ - (id)initWithCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)cou
return self;
}






@end
17 changes: 17 additions & 0 deletions Source/Framework/Classes/MKPolyline.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ - (id)initWithCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)cou

@implementation MKPolyline


@synthesize boundingMapRect;

+ (MKPolyline *)polylineWithCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)count
{
return [[[MKPolyline alloc] initWithCoordinates:coords count:count] autorelease];
Expand All @@ -39,12 +42,26 @@ - (id)initWithCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)cou
{
if (self = [super init])
{

MKMapPoint minXY = MKMapPointForCoordinate(*coords);
MKMapPoint maxXY = MKMapPointForCoordinate(*coords);

coordinates = malloc(sizeof(CLLocationCoordinate2D) * count);
for (int i = 0; i < count; i++)
{
coordinates[i] = coords[i];
MKMapPoint mapPoint = MKMapPointForCoordinate(coords[i]);

minXY.x= MIN(minXY.x,mapPoint.x);
minXY.y= MIN(minXY.y,mapPoint.y);
maxXY.x= MAX(maxXY.x,mapPoint.x);
maxXY.y= MAX(maxXY.y,mapPoint.y);

}
coordinateCount = count;

boundingMapRect = MKMapRectMake(minXY.x, minXY.y, (double)(maxXY.x-minXY.x), (double) maxXY.y-minXY.y);

}
return self;
}
Expand Down
Loading