source: subversion/sites/other/tilesAtHome/lib/tilenames.inc @ 2888

Last change on this file since 2888 was 2888, checked in by ojw, 13 years ago

Allow splitting tiles over two layers

File size: 1.2 KB
Line 
1<?php
2
3function TileName($X,$Y,$Z,$Layer="Tiles",$Old=0){
4  if(!$Layer)
5    return("");
6  if(!TileValid($X,$Y,$Z))
7    return("");
8
9  if($Old==1 && $Layer == "Tiles")
10    $BaseDir = "/home/ojw/tiles-ojw";
11  else
12    $BaseDir = "/home/ojw/tiles-ojw2";
13
14  $Filename = $BaseDir . "/" . $Layer . "/" . TilePartName($X,$Y,$Z);
15  return($Filename);
16}
17function TileURL($X,$Y,$Z,$Layer="tile"){
18  if(!TileValid($X,$Y,$Z))
19    return("");
20  return(sprintf("/~ojw/Tiles/%s.php/%d/%d/%d.png",$Layer,$Z,$X,$Y));
21}
22 
23function TilePartName($X,$Y,$Z){
24  if(!TileValid($X,$Y,$Z))
25    return("");
26  return sprintf(
27    "%02d/%03d/%03d/%03d/%03d.png",
28    $Z,
29    $X/1000,
30    $X%1000,
31    $Y/1000,
32    $Y%1000);
33}
34
35
36#----------------------------------------------------------------------
37# Tests if a tile coordinate is valid
38#
39# See [[Slippy Map Tilenames]] on openstreetmap wiki for details
40#----------------------------------------------------------------------
41function TileValid($X,$Y,$Z){
42 
43  # Zoom depth is limited to 17
44  if($Z > 17)
45    return(0);
46   
47  if($Z < 0)
48    return(0);
49   
50  # Check that the specified x,y exist at this zoom level
51  if($X < 0 || $Y < 0)
52    return(0);
53  $Limit = pow(2,$Z);
54  if($X >= $Limit || $Y >= $Limit)
55    return(0);
56  return(1);
57}
58?>
Note: See TracBrowser for help on using the repository browser.