X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=tiles.pl;h=647dd3e989d73ceb0fc3a0986e4642ce4493b757;hb=8e1b6c231b7ff790d7d166f34494c1f161487b75;hp=a8d699885637d899bb228f3a1401779f3791159e;hpb=32a78b5ea8ec99f5e237a5bfea4c9467a695dace;p=google-map-tiles.git diff --git a/tiles.pl b/tiles.pl index a8d6998..647dd3e 100755 --- a/tiles.pl +++ b/tiles.pl @@ -19,8 +19,6 @@ my $lng = 0 ; my $latpix = 0 ; my $lngpix = 0 ; my %tiles = ( ) ; -my $tilex = 0 ; -my $tiley = 0 ; my $nacount = 0 ; my %tile = ( ) ; my $top = 0 ; @@ -45,10 +43,6 @@ my $imicon1 = '' ; my $imicon2 = '' ; my $maxzoom = 10 ; my $minzoom = 2 ; -my $xiconoff = 12 ; # X Icon offset in pixels (width or lng) -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 = "$name/tiles" ; my $icon1 = 'images/gvp_icon_1.png' ; # Zooms up to 7 my $icon2 = 'images/gvp_icon_2.png' ; # Zooms after 7 @@ -62,6 +56,28 @@ if ( !(-e $icon1) or !(-e $icon2)) # Icon file missing - bad thing exit ; } +sub get_icon { + my $zoom = shift; + + # Calculate which icon to use based on zoom... + $imicon = GD::Image->newFromPng( $zoom > 7 ? $icon2 : $icon1 ) ; + my $merge = 90; + + my $custom_icon = "$name/icons/$zoom.png"; + if ( -e $custom_icon ) { + $imicon = GD::Image->newFromPng( $custom_icon ); + $merge = 50; + } + + my $xiconpix = $imicon->width; + my $yiconpix = $imicon->height; + + # FIXME make click position configurable + my $xiconoff = $xiconpix / 2; + my $yiconoff = $yiconpix / 2; + + return ( $xiconpix, $yiconpix, $xiconoff, $yiconoff, $merge ); +} # Relations: # Y,Top,N,S,Lat,Height @@ -69,10 +85,12 @@ if ( !(-e $icon1) or !(-e $icon2)) # Icon file missing - bad thing # (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 ; @@ -82,14 +100,16 @@ while ( ($lat,$lng) = $sth->fetchrow_array ) # Figure out what tiles are needed... - for ( $zoom = $minzoom; $zoom <= $maxzoom; $zoom++ ) + for ( my $zoom = $minzoom; $zoom <= $maxzoom; $zoom++ ) { $value = &Google_Tile_Factors($zoom) ; # Calculate Tile Factors ($latpix,$lngpix) = &Google_Coord_to_Pix( $value, $lat, $lng ) ; %tiles = ( ) ; - ($tiley,$tilex) = &Google_Pix_to_Tile( $value, $latpix + $yiconoff, $lngpix + $xiconoff ) ; + my ( $xiconpix, $yiconpix, $xiconoff, $yiconoff ) = get_icon $zoom; + + my ($tiley,$tilex) = &Google_Pix_to_Tile( $value, $latpix + $yiconoff, $lngpix + $xiconoff ) ; $tiles{"$tiley $tilex"} = [$tilex, $tiley] ; ($tiley,$tilex) = &Google_Pix_to_Tile( $value, $latpix + $yiconoff, $lngpix - $xiconoff ) ; @@ -135,9 +155,6 @@ for ( $zoom = $minzoom; $zoom <= $maxzoom; $zoom++ ) } # Open up map icon files as images... -$imicon1 = GD::Image->newFromPng( $icon1 ) ; -$imicon2 = GD::Image->newFromPng( $icon2 ) ; - # Create index... $dbh->do("create index gvp_world_tiles_main on gvp_world_tiles (zoom,tilex,tiley)") ; @@ -151,7 +168,7 @@ $sth->execute ; $count = 0 ; -while ( ($zoom,$tilex,$tiley) = $sth->fetchrow_array ) +while ( my ($zoom,$tilex,$tiley) = $sth->fetchrow_array ) { $count++ ; @@ -173,15 +190,7 @@ while ( ($zoom,$tilex,$tiley) = $sth->fetchrow_array ) $im->setThickness(1) ; - # Calculate which icon to use based on zoom... - - if ( $zoom > 7 ) - { - $imicon = $imicon2 ; - } else - { - $imicon = $imicon1 ; - } + my ( $xiconpix, $yiconpix, $xiconoff, $yiconoff, $merge ) = get_icon $zoom; $sti = $dbh->prepare("select latpix,lngpix from gvp_world_tiles where zoom = $zoom and tilex = $tilex and tiley = $tiley") ; @@ -191,7 +200,8 @@ while ( ($zoom,$tilex,$tiley) = $sth->fetchrow_array ) { $ix = $lngpix - $left - $xiconoff ; # Remove half image size $iy = $latpix - $top - $yiconoff ; # Remove half image size - $im->copy($imicon,$ix,$iy,0,0,$xiconpix,$yiconpix) ; +# $im->copy($imicon,$ix,$iy,0,0,$xiconpix,$yiconpix) ; + $im->copyMerge($imicon,$ix,$iy,0,0,$xiconpix,$yiconpix,$merge) ; } open(my $PNG, '>', $file) || die "$file: $!";