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

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

Add support for tilenames in various layers

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