forked from stamen/modestmaps-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Providers.php
66 lines (51 loc) · 2.01 KB
/
Providers.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
<?php
require_once 'Geo.php';
class MMaps_Templated_Spherical_Mercator_Provider
{
var $projection;
var $templates;
var $tile_width;
var $tile_height;
function MMaps_Templated_Spherical_Mercator_Provider($template)
{
$t = new MMaps_Transformation(1.068070779e7, 0, 3.355443185e7,
0, -1.068070890e7, 3.355443057e7);
$this->projection = new MMaps_Mercator_Projection(26, $t);
$this->templates = array();
while($template)
{
if(preg_match('#^(http://\S+?)(,http://\S+)?$#i', $template, $matches))
{
$this->templates[] = $matches[1];
$template = $matches[2]
? substr($template, strlen($matches[1]) + 1)
: '';
}
}
$this->tile_width = 256;
$this->tile_height = 256;
}
function locationCoordinate($location)
{
return $this->projection->locationCoordinate($location);
}
function coordinateLocation($coordinate)
{
return $this->projection->coordinateLocation($coordinate);
}
function getTileURLs($coord)
{
$urls = array();
foreach($this->templates as $template)
$urls[] = str_replace('{X}', intval($coord->column), str_replace('{Y}', intval($coord->row), str_replace('{Z}', intval($coord->zoom), $template)));
return $urls;
}
}
class MMaps_OpenStreetMap_Provider extends MMaps_Templated_Spherical_Mercator_Provider
{
function MMaps_OpenStreetMap_Provider()
{
MMaps_Templated_Spherical_Mercator_Provider::MMaps_Templated_Spherical_Mercator_Provider('http://tile.openstreetmap.org/{Z}/{X}/{Y}.png');
}
}
?>