-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathGeo.php
120 lines (101 loc) · 3.45 KB
/
Geo.php
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
<?php
require_once 'Core.php';
class MMaps_Location
{
var $lat;
var $lon;
function MMaps_Location($lat, $lon)
{
$this->lat = $lat;
$this->lon = $lon;
}
function toString()
{
return sprintf('(%.3f, %.3f)', $this->lat, $this->lon);
}
}
class MMaps_Transformation
{
var $ax;
var $bx;
var $cx;
var $ay;
var $by;
var $cy;
function MMaps_Transformation($ax, $bx, $cx, $ay, $by, $cy)
{
$this->ax = $ax;
$this->bx = $bx;
$this->cx = $cx;
$this->ay = $ay;
$this->by = $by;
$this->cy = $cy;
}
function transform($point)
{
return new MMaps_Point($this->ax * $point->x + $this->bx * $point->y + $this->cx,
$this->ay * $point->x + $this->by * $point->y + $this->cy);
}
function untransform($point)
{
return new MMaps_Point(($point->x * $this->by - $point->y * $this->bx - $this->cx * $this->by + $this->cy * $this->bx) / ($this->ax * $this->by - $this->ay * $this->bx),
($point->x * $this->ay - $point->y * $this->ax - $this->cx * $this->ay + $this->cy * $this->ax) / ($this->bx * $this->ay - $this->by * $this->ax));
}
}
class MMaps_Linear_Projection
{
var $zoom;
var $transformation;
function MMaps_Linear_Projection($zoom, $transformation=null)
{
$this->zoom = $zoom;
$this->transformation = is_null($transformation) ? new MMaps_Transformation(1, 0, 0, 0, 1, 0) : $transformation;
}
function rawProject($point)
{
return $point->copy();
}
function rawUnproject($point)
{
return $point->copy();
}
function project($point)
{
$point = $this->rawProject($point);
$point = $this->transformation->transform($point);
return $point;
}
function unproject($point)
{
$point = $this->transformation->untransform($point);
$point = $this->rawUnproject($point);
return $point;
}
function locationCoordinate($location)
{
$point = new MMaps_Point(M_PI * $location->lon / 180, M_PI * $location->lat / 180);
$point = $this->project($point);
$coordinate = new MMaps_Coordinate($point->y, $point->x, $this->zoom);
return $coordinate;
}
function coordinateLocation($coordinate)
{
$coordinate = $coordinate->zoomTo($this->zoom);
$point = new MMaps_Point($coordinate->column, $coordinate->row);
$point = $this->unproject($point);
$location = new MMaps_Location(180 * $point->y / M_PI, 180 * $point->x / M_PI);
return $location;
}
}
class MMaps_Mercator_Projection extends MMaps_Linear_Projection
{
function rawProject($point)
{
return new MMaps_Point($point->x, log(tan(0.25 * M_PI + 0.5 * $point->y)));
}
function rawUnproject($point)
{
return new MMaps_Point($point->x, 2 * atan(pow(M_E, $point->y)) - 0.5 * M_PI);
}
}
?>