Last active
January 3, 2016 16:19
-
-
Save PiotrKrosniak/8488589 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script type="text/javascript"> | |
| google.load('visualization', '1', {packages: ['corechart']}); | |
| //pass the infowindow as argument, we need it later | |
| function drawVisualization(infowindow) { | |
| var queryText = encodeURIComponent("SELECT Year, Austria, Bulgaria, \ | |
| Denmark, Greece FROM 641716"); | |
| /*note: we don't need the ContainerId here, | |
| we use the node-reference with draw | |
| *also note: we use ChartWrapper here, because we need | |
| the ready-event of the chart to redraw the infowindow | |
| */ | |
| var chart=new google.visualization.ChartWrapper({ | |
| "dataSourceUrl": 'https://www.google.com/fusiontables/gvizdata?tq=', | |
| "query":"SELECT Year, Austria, Bulgaria, Denmark, Greece FROM 641716", | |
| "refreshInterval": 5, | |
| "chartType": "PieChart", | |
| "options": { | |
| "title":"Yearly Coffee Consumption by Country", | |
| "vAxis": {"title": "Year"}, | |
| "hAxis": {"title": "Cups"} | |
| } | |
| }); | |
| var ready=google.visualization.events.addListener(chart, 'ready', function(){ | |
| //re-assign the map-property to redraw the | |
| //infowindow when the chart has been drawn | |
| infowindow.setMap(infowindow.getMap()); | |
| //remove the ready-listener | |
| google.visualization.events.removeListener(ready); | |
| }); | |
| //draw the chart | |
| chart.draw(infowindow.getContent().lastChild); | |
| } | |
| function initialize() { | |
| map = new google.maps.Map(document.getElementById('map-canvas'), { | |
| center: new google.maps.LatLng(29.296435107347698, -29.54822280000008), | |
| zoom: 2, | |
| mapTypeId: google.maps.MapTypeId.ROADMAP | |
| }); | |
| var layer = new google.maps.FusionTablesLayer({ | |
| query: { | |
| select: 'col0', | |
| from: '1PoUAVtdJKOKnJT_ZYkoM7yDpGw-wNJMHXakPeC0' | |
| }, | |
| map: map, | |
| //don't use the infowindows of the FTLayer | |
| suppressInfoWindows:true | |
| }); | |
| //a custom infowindow | |
| infowindow=new google.maps.InfoWindow(); | |
| google.maps.event.addListener(layer, 'click', function(e) { | |
| //call drawVisualization when the infowindow is ready | |
| google.maps.event.addListenerOnce(infowindow,'domready',function(){ | |
| drawVisualization(infowindow); | |
| }); | |
| //create the content for the infowindow | |
| var node=document.createElement('div'); | |
| node.innerHTML=e.infoWindowHtml; | |
| //create the node where the chart will be drawn | |
| node.appendChild(document.createElement('div')); | |
| //open the infowindow | |
| infowindow.setOptions({position:e.latLng,content:node,map:map}); | |
| }); | |
| } | |
| google.maps.event.addDomListener(window, 'load', initialize); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment