简体   繁体   English

如何在Google Visualization Map API中设置zoomLevel?

[英]How to set zoomLevel in google Visualization Map api?

I am trying to implement visualization map api,following this link https://developers.google.com/chart/interactive/docs/gallery/map 我正在尝试通过以下链接实现可视化地图API :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. 我成功在Google地图上绘制了点,但无法设置缩放级别。 For single point the zoomlevel automatic set to 19(max level). 对于单点,缩放级别自动设置为19(最大级别)。

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. 我已经尝试过这个map.setZoom(12)但是它不起作用。

The name of the property that defines the zoom-level in google.visualization.Map is not zoom , google.visualization.Map中定义缩放级别的属性名称不是zoom

it's called zoomLevel (funny, the title of your question contains the correct answer^^) 它称为zoomLevel (有趣,问题的标题包含正确的答案^^)


However, it's curious that the visualization-API does not provide a method to access the underlying google.maps.Map -instance. 但是,奇怪的是,可视化API没有提供访问底层google.maps.Map -instance的方法。

You may add such a method (on your own risk), add this to the onload-callback: 您可以添加这样的方法(风险自担),将其添加到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. 你现在可以访问google.maps.Map通过调用方法-instance getMap的的google.visualization.Map -instance。

Example: 例:

map.getMap().setZoom(12);

That is because the map object has no setZoom method according to the documentation page that you have given. 这是因为根据您提供的文档页面,地图对象没有setZoom方法。

You can probably try redrawing the map using using draw method like this 您可能可以尝试使用像这样的draw方法重绘地图

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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