ef5c4497175821b965a652ee9651b4a3f800ea04
[google-map-tiles.git] / tiles / tileserver.pl
1 #!/usr/bin/perl
2 # Serve Map Tiles...
3 # Author. John D. Coryat 08/2007...
4
5 use CGI qw/:standard *table/ ;
6 use strict ;
7
8 my $zoom        = param('Z') ;                          # Zoom
9 my $py          = param('Y') ;                          # Y Tile Name
10 my $px          = param('X') ;                          # X Tile Name
11 my $path        = $ENV{'DOCUMENT_ROOT'} . "/ws-2010-08/tiles" ;
12 my $i           = 0 ;
13 my $size        = 0 ;
14 my $x           = '' ;
15 my $file        = '' ;
16
17 if ( !defined($zoom) or !$zoom )                        # Has to be a zoom
18 {
19  exit ;
20 }
21
22 # v_9_6.png
23
24 $file   = "$path/$zoom/v_$px" . "_$py" . ".png" ;
25
26 print STDERR "$file\n" ;
27
28 $size   = ( -s $file ) ;
29
30 if ( !$size )                                           # not found
31 {
32  $file  = $path . "/notiles.png" ;
33  $size  = ( -s $file ) ;
34 }
35
36 if ( $size and open ( PNG, $file ) )
37 {
38  read ( PNG, $x, $size ) ;
39  close( PNG ) ;
40  print header(-type=> 'image/png', -expires=> '+1d', -Pragma=> 'no-cache') ;
41
42  print $x ;
43
44
45 # END
46