fix count from query if needed
[google-map-tiles.git] / koha.html
1 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
2  <head>
3   <link rel="SHORTCUT ICON" href="/favicon.ico" type="image/x-icon" />
4   <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
5   <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
6   <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
7   <title>Where are our books comming from?</title>
8   <script type="text/javascript">
9   //<![CDATA[
10
11    var map ;
12    var infoWindow ;
13    var maxZoom = 10 ;
14    var minZoom = 2 ;
15
16    // Load the map script...
17
18    function loadScript() {
19     detectBrowser();
20     var script = document.createElement("script");
21     script.type = "text/javascript";
22     script.src = "http://maps.google.com/maps/api/js?sensor=false&callback=initialize";
23     document.body.appendChild(script);
24    }
25  
26    // Load the map...
27
28    function initialize() {
29     var myLatlng = new google.maps.LatLng(45,15);
30
31     // Create the volcano tile layer...
32
33     var volcanoOptions = {
34      getTileUrl: function(tile, zoom) {
35       var n = 1 << zoom;
36       var x = tile.x % n;
37       if (x < 0) {
38        x += n;
39       } 
40       return "koha/tiles/" + zoom + "/v_" + x + "_" + tile.y + ".png";
41      },
42      tileSize: new google.maps.Size(256, 256),
43      opacity:1,
44      minZoom:3,
45      maxZoom:9,
46      isPng: true
47     };
48
49     var volcanoMapType = new google.maps.ImageMapType(volcanoOptions);
50
51     // Map options...
52
53     var myOptions = {
54       zoom: 6,
55       scrollwheel: false,
56       center: myLatlng,
57       mapTypeId: google.maps.MapTypeId.TERRAIN
58     };
59     map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
60     map.overlayMapTypes.insertAt(0, volcanoMapType);
61
62     // Keep zoom within limits...
63
64     google.maps.event.addListener(map, 'zoom_changed', function() {
65      if ( map.getZoom() > maxZoom ) {
66       map.setZoom( maxZoom ) ;
67      } else if ( map.getZoom() < minZoom ) {
68       map.setZoom( minZoom ) ;
69      }
70     });
71
72     // Initialize an infoWindow...
73
74     infoWindow = new google.maps.InfoWindow();
75
76     // Add a click listener...
77
78     google.maps.event.addListener(map, 'click', function(event) {
79      processClick(event.latLng);
80     });
81    }
82
83    // Set the map size based on the type of agent...
84
85    function detectBrowser() {
86     var useragent = navigator.userAgent;
87     var mapdiv = document.getElementById("map_canvas");
88     if ( useragent.indexOf('iPhone') != -1 || useragent.indexOf('Android') != -1 ) {
89      mapdiv.style.width = '100%';
90      mapdiv.style.height = '100%';
91     } else {     
92 /*
93      mapdiv.style.width = '800px';
94      mapdiv.style.height = '600px';
95 */
96      mapdiv.style.width = '100%';
97      mapdiv.style.height = '100%';
98     }
99    }
100
101    // Check for an active click (on a map icon)...
102
103    function processClick ( point )
104    {
105     var request = window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest;
106     var parms = "POINT=" + point.toUrlValue() + "&ZOOM=" + map.getZoom() ;
107     request.open("POST", "koha.pl", true);
108     request.setRequestHeader('Content-Type','application/x-www-form-urlencoded') ;      // Thanks to Darkstar 3D!
109     request.onreadystatechange = function() 
110     {
111      document.getElementById("loading").innerHTML = "Loading, please wait..." ;
112
113      if (request.readyState == 4)
114      {
115       var xmlDoc = request.responseXML ;
116       try
117       {
118        var info = xmlDoc.documentElement.getElementsByTagName("info") ;
119        var error = info[0].getAttribute("error") ; 
120
121        if ( error )
122        {
123         alert(error) ;
124        } else
125        {
126         var name = info[0].getAttribute("name") ;
127         var lat = parseFloat(info[0].getAttribute("lat")) ;
128         var lng = parseFloat(info[0].getAttribute("lng")) ;
129         var clickLatlng = new google.maps.LatLng(lat,lng) ;
130         var description = info[0].getElementsByTagName("description")[0].firstChild.nodeValue ;
131         var html = "<div style='height:300px; width:350px;overflow:auto;'>" + description + "</div>" ;
132
133         infoWindow.close();
134         infoWindow.setOptions({
135          content: html,
136          position: clickLatlng
137         });
138         infoWindow.open(map); 
139        }
140       } catch(e)
141       {
142        alert("Some error occured during program processing:" + e) ;
143       }       
144       document.getElementById("loading").innerHTML = "" ;
145      }
146     }
147     request.send(parms);
148    }
149
150   //]]>
151   </script>
152
153  </head>
154  <body bgcolor="#D1D0CD" text="black" link="#444444" alink="gray" vlink="#111111" onload="loadScript();">
155   <div id="map_canvas"></div>
156   <div id="loading" title="loading message for map" style="background-color:#D1D0CD; position:absolute; left:120px; top:200px;"></div>
157  </body>
158 </html>
159