use strict ;
use GD ;
use USNaviguide_Google_Tiles ;
+use File::Path;
+
+my $name = shift @ARGV || die "usage: $0 database\n";
+
+warn "WORKING on $name\n";
my $zoom = 0 ;
my $lat = 0 ;
my $yiconoff = 12 ; # Y Icon offset in pixels (height or lat)
my $xiconpix = 24 ; # Icon width in pixels
my $yiconpix = 24 ; # Icon width in pixels
-my $path = 'tiles/' ;
+my $path = "$name/tiles" ;
my $icon1 = 'images/gvp_icon_1.png' ; # Zooms up to 7
my $icon2 = 'images/gvp_icon_2.png' ; # Zooms after 7
-my $dbh = DBI->connect ( "dbi:Pg:dbname=volcano" , "" , "" , { AutoCommit => 1 } ) ;
+my $dbh = DBI->connect ( "dbi:Pg:dbname=$name" , "" , "" , { AutoCommit => 1 } ) ;
# Make sure icon file exists...
# (35,-89),(34,-90)
-$dbh->do("drop table gvp_world_tiles") ;
+eval { $dbh->do("drop table gvp_world_tiles") };
$dbh->do("create table gvp_world_tiles (zoom int2,tilex int4,tiley int4,latpix int4,lngpix int4)") ;
-$sth = $dbh->prepare("select (volpnt)[0] as lat, (volpnt)[1] as lng from gvp_world") ;
+my $sql = "select (volpnt)[0] as lat, (volpnt)[1] as lng from gvp_world" ;
+$sql = "select (point)[0] as lat, (point) [1] as lng from geo_count" if $name =~ m/koha/;
+$sth = $dbh->prepare( $sql );
$sth->execute ;
for ( $zoom = $minzoom; $zoom <= $maxzoom; $zoom++ )
{
- system("rm tiles/$zoom/*") ;
+ warn "clean $path/$zoom\n";
+ rmtree "$path/$zoom";
+ mkpath "$path/$zoom";
}
# Open up map icon files as images...
# Calculate tile fields...
- $file = $path . $zoom . '/v_' . $tilex . '_' . $tiley . '.png' ;
+ $file = $path . '/' . $zoom . '/v_' . $tilex . '_' . $tiley . '.png' ;
($top,$left) = &Google_Tile_to_Pix( $value, $tiley, $tilex ) ;
$imicon = $imicon1 ;
}
+ my $custom_icon = "$name/icons/$zoom.png";
+ $imicon = GD::Image->newFromPng( $custom_icon ) if -e $custom_icon;
+
$sti = $dbh->prepare("select latpix,lngpix from gvp_world_tiles where zoom = $zoom and tilex = $tilex and tiley = $tiley") ;
$sti->execute ;
$im->copy($imicon,$ix,$iy,0,0,$xiconpix,$yiconpix) ;
}
- open PNG, ">$file" ;
- print PNG $im->png ;
- close PNG ;
- chmod(0444, $file) ;
+ open(my $PNG, '>', $file) || die "$file: $!";
+ print $PNG $im->png ;
+ close $PNG ;
+# chmod(0444, $file) ;
if ( int($count/100)*100 == $count )
{
print "Processed $count tiles...\n" ;
}
print "Processed $count total tiles...\n" ;
-$dbh->do("drop table gvp_world_tiles") ;
+#$dbh->do("drop table gvp_world_tiles") ;
+
+# allow web server to select data
+$dbh->do("grant select on gvp_world to public") ;
$dbh->disconnect ;