Javascript 修改谷歌地图类型的最大缩放级别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10517848/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Modify the max zoom level of a Google Map Type
提问by jbrtrnd
I need to set the maxZoom
level of the google.maps.MapTypeId.HYBRID
to 21. Actually, he's set to 14 (inspected with the firebug console).
我需要将 的maxZoom
级别设置google.maps.MapTypeId.HYBRID
为 21。实际上,他设置为 14(用萤火虫控制台检查)。
Set the property of the google.maps
object 'maxZoom' doesn't work in this case, and I already try to modify the google.maps.mapTypes
object, but without success.
google.maps
在这种情况下,设置对象“maxZoom”的属性不起作用,我已经尝试修改google.maps.mapTypes
对象,但没有成功。
var options = {
center: new google.maps.LatLng(lat_centre,lng_centre),
zoom: 14,
maxZoom: 21,
mapTypeId: google.maps.MapTypeId.TERRAIN,
panControl: true,
zoomControl: true,
mapTypeControl: false,
scaleControl: false,
streetViewControl: false,
overviewMapControl: false,
disableDoubleClickZoom: true,
styles: [
{featureType: "poi", stylers: [{visibility: "off"}]}
]
};
map = new google.maps.Map(document.getElementById("map_container"),options);
AND
和
google.maps.event.addListener(map, 'tilesloaded', function(event){
var mapTypeRegistry = map.mapTypes;
var currentMapTypeId = map.getMapTypeId();
var mapType = mapTypeRegistry.get(currentMapTypeId);
mapType.maxZoom = 21;
});
So, is there a way to increase the zoom level of the mapType HYBRID ?
那么,有没有办法增加 mapType HYBRID 的缩放级别?
Thanks.
谢谢。
回答by Engineer
If you changed mapType
object's property ( maxZoom
, minZoom
, etc... ), the changed effect will take a place ONLY AFTERthe map's type will be changed to that mapType
. For example , if current mapType
is TERRAIN
, and you changed TERRAIN
's maxZoom
, maxZoom
will work only after changing mapType
to another type (e.g. ROADMAP
,HYBRID
,etc..) and back to TERRAIN
.
如果您更改了mapType
对象的属性(maxZoom
、minZoom
等... ),则更改后的效果仅在地图类型更改为该 之后才会发生mapType
。例如,如果当前mapType
是TERRAIN
的,你改变TERRAIN
的maxZoom
,maxZoom
只会改变工作后mapType
,以另一种类型(例如ROADMAP
,HYBRID
等..),并返回TERRAIN
。
Instead of setting mapType
's maxZoom
option,use core map's maxZoom
option. Add listener for "maptypeid_changed"
event, and when event occurs, change maxZoom
option of map
:
而不是设置mapType
的maxZoom
选项,使用核心地图的maxZoom
选项。添加"maptypeid_changed"
事件监听器,当事件发生时,更改maxZoom
选项map
:
google.maps.event.addListener(map, 'maptypeid_changed', function(event){
if( map.getMapTypeId() === google.maps.MapTypeId.TERRAIN ){
map.setOptions({maxZoom:/*For example*/5});
}else
if( map.getMapTypeId() === google.maps.MapTypeId.ROADMAP ){
map.setOptions({maxZoom:/*For example*/8});
}//Etc...
else{
map.setOptions({maxZoom:/*For example*/21});
}
});