2 # Create Map overlay of worldwide volcanoes...
3 # Author. John D. Coryat 02/2010...
4 # Copyright 1997-2010 USNaviguide LLC. All rights reserved.
9 use USNaviguide_Google_Tiles ;
43 my $xiconoff = 12 ; # X Icon offset in pixels (width or lng)
44 my $yiconoff = 12 ; # Y Icon offset in pixels (height or lat)
45 my $xiconpix = 24 ; # Icon width in pixels
46 my $yiconpix = 24 ; # Icon width in pixels
48 my $icon1 = 'images/gvp_icon_1.png' ; # Zooms up to 7
49 my $icon2 = 'images/gvp_icon_2.png' ; # Zooms after 7
50 my $dbh = DBI->connect ( "dbi:Pg:dbname=volcano" , "" , "" , { AutoCommit => 1 } ) ;
52 # Make sure icon file exists...
54 if ( !(-e $icon1) or !(-e $icon2)) # Icon file missing - bad thing
56 print "Map Icon(s) missing\n" ;
62 # Y,Top,N,S,Lat,Height
63 # X,Left,E,W,Lng,Width
67 $dbh->do("drop table gvp_world_tiles") ;
68 $dbh->do("create table gvp_world_tiles (zoom int2,tilex int4,tiley int4,latpix int4,lngpix int4)") ;
70 $sth = $dbh->prepare("select (volpnt)[0] as lat, (volpnt)[1] as lng from gvp_world") ;
74 while ( ($lat,$lng) = $sth->fetchrow_array )
78 # Figure out what tiles are needed...
80 for ( $zoom = $minzoom; $zoom <= $maxzoom; $zoom++ )
82 $value = &Google_Tile_Factors($zoom) ; # Calculate Tile Factors
84 ($latpix,$lngpix) = &Google_Coord_to_Pix( $value, $lat, $lng ) ;
87 ($tiley,$tilex) = &Google_Pix_to_Tile( $value, $latpix + $yiconoff, $lngpix + $xiconoff ) ;
88 $tiles{"$tiley $tilex"} = [$tilex, $tiley] ;
90 ($tiley,$tilex) = &Google_Pix_to_Tile( $value, $latpix + $yiconoff, $lngpix - $xiconoff ) ;
91 $tiles{"$tiley $tilex"} = [$tilex, $tiley] ;
93 ($tiley,$tilex) = &Google_Pix_to_Tile( $value, $latpix - $yiconoff, $lngpix + $xiconoff ) ;
94 $tiles{"$tiley $tilex"} = [$tilex, $tiley] ;
96 ($tiley,$tilex) = &Google_Pix_to_Tile( $value, $latpix - $yiconoff, $lngpix - $xiconoff ) ;
97 $tiles{"$tiley $tilex"} = [$tilex, $tiley] ;
99 foreach $x (keys %tiles)
102 $dbh->do("insert into gvp_world_tiles (zoom,tilex,tiley,latpix,lngpix) values ($zoom,$$y[0],$$y[1],$latpix,$lngpix)" ) ;
106 if ( int($count/100)*100 == $count )
108 print "Processed $count points...\n" ;
112 # Make sure there have been records to process before continuing...
117 print "No records to process...\n" ;
121 print "Total Points: $count\n" ;
123 # Remove old images...
125 for ( $zoom = $minzoom; $zoom <= $maxzoom; $zoom++ )
127 system("rm tiles/$zoom/*") ;
129 # Open up map icon files as images...
131 $imicon1 = GD::Image->newFromPng( $icon1 ) ;
132 $imicon2 = GD::Image->newFromPng( $icon2 ) ;
136 $dbh->do("create index gvp_world_tiles_main on gvp_world_tiles (zoom,tilex,tiley)") ;
137 $dbh->do("analyze gvp_world_tiles") ;
139 # Create tiles by zoom...
141 $sth = $dbh->prepare("select distinct zoom,tilex,tiley from gvp_world_tiles") ;
147 while ( ($zoom,$tilex,$tiley) = $sth->fetchrow_array )
151 # Calculate tile fields...
153 $file = $path . $zoom . '/v_' . $tilex . '_' . $tiley . '.png' ;
155 ($top,$left) = &Google_Tile_to_Pix( $value, $tiley, $tilex ) ;
159 $im = new GD::Image(256,256,0) ;
161 $white = $im->colorAllocate(255,255,255) ;
163 $im->interlaced('true') ;
165 $im->transparent($white) ;
167 $im->setThickness(1) ;
169 # Calculate which icon to use based on zoom...
179 $sti = $dbh->prepare("select latpix,lngpix from gvp_world_tiles where zoom = $zoom and tilex = $tilex and tiley = $tiley") ;
183 while ( ($latpix,$lngpix) = $sti->fetchrow_array )
185 $ix = $lngpix - $left - $xiconoff ; # Remove half image size
186 $iy = $latpix - $top - $yiconoff ; # Remove half image size
187 $im->copy($imicon,$ix,$iy,0,0,$xiconpix,$yiconpix) ;
194 if ( int($count/100)*100 == $count )
196 print "Processed $count tiles...\n" ;
199 print "Processed $count total tiles...\n" ;
201 $dbh->do("drop table gvp_world_tiles") ;