-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathimagemap_projection.php
53 lines (39 loc) · 1.04 KB
/
imagemap_projection.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
<?php
function imagemap_xy2ll($x, $y, $Data)
{
$CLat = $Data['lat'];
$CLon = $Data['lon'];
$Z = $Data['z'];
$W = $Data['w'];
$H = $Data['h'];
// Centre of the screen in Mercator units
list($CX, $CY) = latlon2xy($CLat,$CLon,$Z);
// Click's offset in pixels from centre of screen
$PX = $x - 0.5 * $W;
$PY = $y - 0.5 * $H;
// Click's position in Mercator units
$X2 = $CX + $PX / 256.0;
$Y2 = $CY + $PY / 256.0;
// Click's position in lat/lon
list($Lat, $Lon) = xy2latlon($X2,$Y2,$Z);
return(array($Lat,$Lon));
}
function imagemap_ll2xy($Lat, $Lon, $Data)
{
$CLat = $Data['lat'];
$CLon = $Data['lon'];
$Z = $Data['z'];
$W = $Data['w'];
$H = $Data['h'];
// Centre of the screen in Mercator units
list($CX, $CY) = latlon2xy($CLat,$CLon,$Z);
// Position in Mercator units
list($X2, $Y2) = latlon2xy($Lat,$Lon,$Z);
// Position's offset in pixels from centre of image
$PX = ($X2 - $CX) * 256.0;
$PY = ($Y2 - $CY) * 256.0;
$x = 0.5 * $W + $PX;
$y = 0.5 * $H + $PY;
return(array($x,$y));
}
?>