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 | return("$BaseDir/$Layer/".TilePartName($X,$Y,$Z)); |
---|

15 | } |
---|

16 | function TileURL($X,$Y,$Z,$Layer="tile"){ |
---|

17 | if(!TileValid($X,$Y,$Z)) |
---|

18 | return(""); |
---|

19 | return(sprintf("/~ojw/Tiles/%s.php/%d/%d/%d.png",$Layer,$Z,$X,$Y)); |
---|

20 | } |
---|

21 | |
---|

22 | function TilePartName($X,$Y,$Z){ |
---|

23 | if(!TileValid($X,$Y,$Z)) |
---|

24 | return(""); |
---|

25 | return sprintf( |
---|

26 | "%02d/%03d/%03d/%03d/%03d.png", |
---|

27 | $Z, |
---|

28 | $X/1000, |
---|

29 | $X%1000, |
---|

30 | $Y/1000, |
---|

31 | $Y%1000); |
---|

32 | } |
---|

33 | |
---|

34 | |
---|

35 | #---------------------------------------------------------------------- |
---|

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

37 | # |
---|

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

39 | #---------------------------------------------------------------------- |
---|

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

41 | |
---|

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

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

44 | return(0); |
---|

45 | |
---|

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

47 | return(0); |
---|

48 | |
---|

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

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

51 | return(0); |
---|

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

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

54 | return(0); |
---|

55 | return(1); |
---|

56 | } |
---|

57 | ?> |
---|