forked from tolmasky/MapKit
-
Notifications
You must be signed in to change notification settings - Fork 4
/
MKGeometry.j
150 lines (127 loc) · 4.72 KB
/
MKGeometry.j
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// MKGeometry.j
// MapKit
//
// Created by Francisco Tolmasky.
// Copyright (c) 2010 280 North, Inc.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
function MKCoordinateSpan(/*CLLocationDegrees*/ aLatitudeDelta, /*CLLocationDegrees*/ aLongitudeDelta)
{
this.latitudeDelta = aLatitudeDelta;
this.longitudeDelta = aLongitudeDelta;
return this;
}
MKCoordinateSpan.prototype.toString = function()
{
return "{" + this.latitudeDelta + ", " + this.longitudeDelta + "}";
}
function MKCoordinateSpanMake(/*CLLocationDegrees*/ aLatitudeDelta, /*CLLocationDegrees*/ aLongitudeDelta)
{
return new MKCoordinateSpan(aLatitudeDelta, aLongitudeDelta);
}
function MKCoordinateSpanFromLatLng(/*LatLng*/ aLatLng)
{
return new MKCoordinateSpan(aLatLng.lat(), aLatLng.lng());
}
function CLLocationCoordinate2D(/*CLLocationDegrees*/ aLatitude, /*CLLocationDegrees*/ aLongitude)
{
if (arguments.length === 1)
{
var coordinate = arguments[0];
this.latitude = coordinate.latitude;
this.longitude = coordinate.longitude;
}
else
{
this.latitude = +aLatitude || 0;
this.longitude = +aLongitude || 0;
}
return this;
}
function CPStringFromCLLocationCoordinate2D(/*CLLocationCoordinate2D*/ aCoordinate)
{
return "{" + aCoordinate.latitude + ", " + aCoordinate.longitude + "}";
}
function CLLocationCoordinate2DFromString(/*String*/ aString)
{
var comma = aString.indexOf(',');
return new CLLocationCoordinate2D(
parseFloat(aString.substr(1, comma - 1)),
parseFloat(aString.substring(comma + 1, aString.length)));
}
CLLocationCoordinate2D.prototype.toString = function()
{
return CPStringFromCLLocationCoordinate2D(this);
}
function CLLocationCoordinate2DEqualToCLLocationCoordinate2D(/*CLLocationCoordinate2D*/ lhs, /*CLLocationCoordinate2D*/ rhs)
{
return lhs === rhs || lhs.latitude === rhs.latitude && lhs.longitude === rhs.longitude;
}
function CLLocationCoordinate2DMake(/*CLLocationDegrees*/ aLatitude, /*CLLocationDegrees*/ aLongitude)
{
return new CLLocationCoordinate2D(aLatitude, aLongitude);
}
function CLLocationCoordinate2DFromLatLng(/*LatLng*/ aLatLng)
{
return new CLLocationCoordinate2D(aLatLng.lat(), aLatLng.lng());
}
function LatLngFromCLLocationCoordinate2D(/*CLLocationCoordinate2D*/ aLocation)
{
return new google.maps.LatLng(aLocation.latitude, aLocation.longitude);
}
function MKCoordinateRegion(/*CLLocationCoordinate2D*/ aCenter, /*MKCoordinateSpan*/ aSpan)
{
this.center = aCenter;
this.span = aSpan;
return this;
}
MKCoordinateRegion.prototype.toString = function()
{
return "{" +
this.center.latitude + ", " +
this.center.longitude + ", " +
this.span.latitudeDelta + ", " +
this.span.longitudeDelta + "}";
}
function MKCoordinateRegionMake(/*CLLocationCoordinate2D*/ aCenter, /*MKCoordinateSpan*/ aSpan)
{
return new MKCoordinateRegion(aCenter, aSpan);
}
function MKCoordinateRegionFromLatLngBounds(/*LatLngBounds*/ bounds)
{
return new MKCoordinateRegion(
CLLocationCoordinate2DFromLatLng(bounds.getCenter()),
MKCoordinateSpanFromLatLng(bounds.toSpan()));
}
function LatLngBoundsFromMKCoordinateRegion(/*MKCoordinateRegion*/ aRegion)
{
var latitude = aRegion.center.latitude,
longitude = aRegion.center.longitude,
latitudeDelta = aRegion.span.latitudeDelta,
longitudeDelta = aRegion.span.longitudeDelta,
LatLng = google.maps.LatLng,
LatLngBounds = google.maps.LatLngBounds;
return new LatLngBounds(
new LatLng(latitude - latitudeDelta / 2, longitude - longitudeDelta / 2), // SW
new LatLng(latitude + latitudeDelta / 2, longitude + longitudeDelta / 2) // NE
);
}