1 | <?php |
---|

2 | |
---|

3 | function 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 | } |
---|

17 | function 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 | |
---|

23 | function 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 | # Gets the tileset this tile is in |
---|

37 | #---------------------------------------------------------------------- |
---|

38 | function WhichTileset($X,$Y,$Z){ |
---|

39 | if($Z < 12 || $Z > 20) |
---|

40 | return(array(0,0,0)); |
---|

41 | if($Z == 12) |
---|

42 | return(array(1,$X,$Y)); |
---|

43 | |
---|

44 | $X2 = $X >> ($Z - 12); |
---|

45 | $Y2 = $Y >> ($Z - 12); |
---|

46 | |
---|

47 | return(array(1, $X2, $Y2)); |
---|

48 | } |
---|

49 | |
---|

50 | #---------------------------------------------------------------------- |
---|

51 | # Tests if a tile coordinate is valid |
---|

52 | # |
---|

53 | # See [[Slippy Map Tilenames]] on openstreetmap wiki for details |
---|

54 | #---------------------------------------------------------------------- |
---|

55 | function TileValid($X,$Y,$Z){ |
---|

56 | |
---|

57 | # Zoom depth is limited to 17 |
---|

58 | if($Z > 17) |
---|

59 | return(0); |
---|

60 | |
---|

61 | if($Z < 0) |
---|

62 | return(0); |
---|

63 | |
---|

64 | # Check that the specified x,y exist at this zoom level |
---|

65 | if($X < 0 || $Y < 0) |
---|

66 | return(0); |
---|

67 | $Limit = pow(2,$Z); |
---|

68 | if($X >= $Limit || $Y >= $Limit) |
---|

69 | return(0); |
---|

70 | return(1); |
---|

71 | } |
---|

72 | ?> |
---|