merge icons 50% to better represent overlaping ones
[google-map-tiles.git] / koha.pl
1 #!/usr/bin/perl
2 # Deliver click values to volcano.htm...
3 # Author. John D. Coryat 02/2010...
4 # Copyright 2010 USNaviguide LLC. All rights reserved...
5
6 use CGI qw/:standard *table/;
7 use strict ;
8 use DBI ;
9 use USNaviguide_Google_Tiles ;
10
11 my $dbh         = DBI->connect ( "dbi:Pg:dbname=koha" , "dpavlin" , "" , { AutoCommit => 1 } ) ;
12 my $point       = param('POINT') ;
13 my $zoom        = param('ZOOM') ;
14
15 my $lat         = 0 ;
16 my $lng         = 0 ;
17 my $latpix      = 0 ;
18 my $lngpix      = 0 ;
19
20 my $volpnt      = '' ;
21 my $vlat        = 0 ;
22 my $vlng        = 0 ;
23 my $vlatpix     = 0 ;
24 my $vlngpix     = 0 ;
25
26 my $value       = '' ;
27 my $maxpix      = 15 ;                                  # Maximum pixels between click and point
28 my $descript    = '' ;
29 my $x           = '' ;
30 my $i           = 0 ;
31
32 print qq{Content-type: text/xml\r\n\r\n};
33 print qq{<?xml version="1.0" encoding="UTF-8"?>\n} ;
34 print qq!<map>\n! ;
35
36 if ( !$point )
37 {
38  print qq!<info error="No point passed..."/>\n! ;
39  print qq!</map>\n! ;
40  $dbh->disconnect ;
41  exit ;
42 }
43
44 if ( $point =~ /(.*),(.*)/ )
45 {
46  $lat   = $1 ;
47  $lng   = $2 ;
48
49  $value = &Google_Tile_Factors($zoom) ;                                 # Calculate Tile Factors
50
51  ($latpix,$lngpix) = &Google_Coord_to_Pix( $value, $lat, $lng ) ;       # Convert coordinate to pixel location
52  
53  $x = "select city,country,count,point,point'($lat,$lng)' <-> point as distance from geo_count order by distance limit 1" ;
54
55  if ( my ($city,$country,$count,$volpnt,$i) = $dbh->selectrow_array($x) )       # Got one
56  {
57   $volpnt =~ /\((.*),(.*)\)/ ; 
58   $vlat = $1 ;
59   $vlng = $2 ;
60
61   ($vlatpix,$vlngpix) = &Google_Coord_to_Pix( $value, $vlat, $vlng ) ;  # Convert coordinate to pixel location
62
63   if ( sqrt(($vlatpix - $latpix)**2  + ($vlngpix - $lngpix)**2) > $maxpix )
64   {
65    # Click not within maxpix of point...
66    print qq!<info error="No publisher is within range of your click, please try again."/>\n! ;
67   } else                                                                # Good point found
68   {
69
70         my $sth = $dbh->prepare(qq{
71 select
72         author, title, bi.biblionumber
73 from geo_city c
74 join geo_biblioitems bi on bi.city = c.city_koha
75 join biblio b on b.biblionumber = bi.biblionumber
76 where c.city = ? and country = ?
77 order by timestamp
78 limit 100
79         });
80         $sth->execute( $city, $country );
81
82         $count = $sth->rows if $sth->rows > $count;
83
84         my $descript = "<b>$city</b> <em>$country</em> $count items\n<ol>";
85
86         while ( my $row = $sth->fetchrow_hashref ) {
87                 $descript .= sprintf qq|<li><a target="koha" href="http://koha.ffzg.hr/cgi-bin/koha/opac-detail.pl?biblionumber=%d">%s</a> %s\n|,
88                         $row->{biblionumber}, $row->{title}, $row->{author}
89                 ;
90         }
91
92         $descript .= "\n</ol>\n";
93
94    print qq!<info error=""  name="${city}_${country}" lat="$vlat" lng="$vlng">\n! ;
95    print qq! <description><\![CDATA[$descript]]></description>\n! ;
96    print qq!</info>\n! ;
97   }
98  }
99 } else
100 {
101  print qq!<info error="No valid point ($point) passed. Should be: (lat,lng) format."/>\n! ;
102 }
103 $dbh->disconnect ;
104
105 print "</map>\n\n" ;
106