修改Google地图类型的最大缩放级别 [英] Modify the max zoom level of a Google Map Type

查看:318
本文介绍了修改Google地图类型的最大缩放级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要设置 google.maps.MapTypeId.HYBRID maxZoom 级别$ c>到21.实际上,他设置为14(使用firebug控制台进行检查)。


设置 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;
$ b $ var currentMapTypeId = map .getMapTypeId();

var mapType = mapTypeRegistry.get(currentMapTypeId);

mapType.maxZoom = 21;
});

那么,有没有办法增加mapType HYBRID的缩放级别?



谢谢。

解决方案

如果您更改 mapType object的属性( maxZoom minZoom 等等),改变后的效果会占据一席之地 地图的类型将更改为 mapType 。例如,如果当前 mapType TERRAIN ,并且您更改了 TERRAIN ' maxZoom maxZoom 仅在更改 mapType 转换为另一种类型(例如 ROADMAP HYBRID 等),然后返回到地形



除了设置 mapType maxZoom 选项外,使用核心映射的 maxZoom 选项。为maptypeid_changed事件添加侦听器,并在事件发生时更改地图的 maxZoom 选项

  google.maps.event.addListener(map,'maptypeid_changed',function(event) {
if(map.getMapTypeId()=== google.maps.MapTypeId.TERRAIN){
map.setOptions({maxZoom:/ *例如* / 5});
}其他
if(map.getMapTypeId()=== google.maps.MapTypeId.ROADMAP){
map.setOptions({maxZoom:/ *例如* / 8});
} //等等...
else {
map.setOptions({maxZoom:/ *例如* / 21});
}
});



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).

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.

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 ?

Thanks.

解决方案

If you changed mapType object's property ( maxZoom, minZoom, etc... ), the changed effect will take a place ONLY AFTER the 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.

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:

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});
    }
});

这篇关于修改Google地图类型的最大缩放级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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