如何在谷歌可视化地图api中设置zoomLevel? [英] How to set zoomLevel in google Visualization Map api?

查看:601
本文介绍了如何在谷歌可视化地图api中设置zoomLevel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现可视化地图api,在此链接 https:// developers.google.com/chart/interactive/docs/gallery/map



我成功在Google地图上绘制点,但无法设置缩放级别。
对于单点,缩放级别自动设置为19(最大级别)。



我的代码: -

  var map = new google.visualization.Map(document.getElementById('map_div')); 
$ b $ map.draw(data,{showTip:true,zoom:14,mapType:'normal',useMapTypeControl:true,enableScrollWheel:false});

我试过这个 map.setZoom(12)但它不工作。 不是 缩放



code> zoomLevel (有趣的是,您的问题的标题包含正确的答案^^)

$ hr

然而,很奇怪可视化API不提供访问底层 google.maps.Map -instance的方法。



您可以添加此类方法(根据您自己的风险),将其添加到onload回调函数中:

  google.visualization.Map.prototype.getMap = function(){
for(var k in this){
if(this [k] .constructor == google.maps .Map)返回这个[k];


您现在可以访问 google.maps.Map -instance通过调用 google.visualization.Map 的方法 getMap



$ p $ map.getMap( ).setZoom(12);


I am trying to implement visualization map api,following this link https://developers.google.com/chart/interactive/docs/gallery/map

i am successfully drawing the point on the google map but not able to set the zoomlevel. For single point the zoomlevel automatic set to 19(max level).

my code:-

var map = new google.visualization.Map(document.getElementById('map_div'));

map.draw(data, {showTip: true, zoom:14,  mapType: 'normal', useMapTypeControl:true, enableScrollWheel:false});

I have tried this map.setZoom(12) but its not working.

解决方案

The name of the property that defines the zoom-level in google.visualization.Map is not zoom,

it's called zoomLevel (funny, the title of your question contains the correct answer^^)


However, it's curious that the visualization-API does not provide a method to access the underlying google.maps.Map-instance.

You may add such a method (on your own risk), add this to the onload-callback:

google.visualization.Map.prototype.getMap=function(){
  for(var k in this){
   if(this[k].constructor==google.maps.Map)return this[k];
  }
}

you now may access the google.maps.Map-instance by calling the method getMap of the google.visualization.Map-instance.

Example:

map.getMap().setZoom(12);

这篇关于如何在谷歌可视化地图api中设置zoomLevel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆