简体   繁体   中英

Google Geochart zoom to a specific canadian province

after research, I found it's not yet possible to show only a specific province in a GeoChart, but I'm asking myself if its possible to zoom in to a specific province? I can't find any information about it.

Here is the closest I could get (Showing Canada and all provinces within):

    <html>
  <head>
    <script type='text/javascript' src='https://www.google.com/jsapi'></script>
    <script type='text/javascript'>
     google.load('visualization', '1', {'packages': ['geochart']});
     google.setOnLoadCallback(drawRegionsMap);

      function drawRegionsMap() {
        var data = google.visualization.arrayToDataTable([
          ['Country', 'Popularity'],
          ['Germany', 200],
          ['United States', 300],
          ['Brazil', 400],
          ['Canada', 500],
          ['France', 600],
          ['RU', 700]
        ]);

        var options = {'region':'CA','resolution':'provinces'};

        var chart = new google.visualization.GeoChart(document.getElementById('chart_div'));
        chart.draw(data, options);
    };
    </script>
  </head>
  <body>
    <div id="chart_div" style="width: 900px; height: 500px;"></div>
  </body>
</html>​

Note that the country list is not related, I'm only testing zooming. Thanks in advance for any help.

Unfortunately,it is not possible to do it with options from the API. What I was able to do, was make some tweeks with CSS, to achieve a similar result.

I created another div around the div that will display the map, with a specific size and hidden overflow. Then I created the map in big proportions and with css margin values I would position it inside the parent div only to display the region I wanted.

For example:

#canvas {
    width:250px;
    height:300px;
    overflow:hidden;
}
#visualization {
    top:-150px;
}

Here is a working example:

http://jsfiddle.net/cmoreira/njB6m/

Hope it helps! Cheers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM