Javascript 从谷歌地图中删除所有控件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6302991/
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
Removing all controls from a google map
提问by Atticus
I am trying to remove all the controls (zoom, map type drop down, and street view) from my map.
我正在尝试从我的地图中删除所有控件(缩放、地图类型下拉菜单和街景视图)。
There's a method
有个方法
map.removeControl(GControl)
but I haven't been able to successfully remove any default ones that I hadn't added myself.
但是我无法成功删除我自己没有添加的任何默认值。
Any tips on remove/clearing all controls from the map?
从地图中删除/清除所有控件的任何提示?
回答by corroded
Have you tried this:
你有没有试过这个:
http://code.google.com/apis/maps/documentation/javascript/controls.html#DisablingDefaults
http://code.google.com/apis/maps/documentation/javascript/controls.html#DisablingDefaults
function initialize() {
var myOptions = {
zoom: 4,
center: new google.maps.LatLng(-33, 151),
disableDefaultUI: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
}
回答by DragonKnight
You may see this: google map api by w3schools
您可能会看到:w3schools 的 google map api
As you see in the link, this disables all controls:
正如您在链接中看到的,这将禁用所有控件:
disableDefaultUI:true
and the bellow is the options to make them enabled or disabled.
下面是使它们启用或禁用的选项。
panControl:true,
zoomControl:true,
mapTypeControl:true,
scaleControl:true,
streetViewControl:true,
overviewMapControl:true,
rotateControl:true
回答by HeshamSalama
just disableDefaultUI: true
只是 disableDefaultUI:true
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: {lat: -33, lng: 151},
disableDefaultUI: true
});
}
回答by benosteen
I believe you can create a copy of the GMapUIOptions object and then remove the items you don't want to appear.
我相信您可以创建 GMapUIOptions 对象的副本,然后删除您不想出现的项目。
From http://code.google.com/apis/maps/documentation/javascript/v2/controls.html#MapUIOptions
来自http://code.google.com/apis/maps/documentation/javascript/v2/controls.html#MapUIOptions
"Using the GMapUIOptions Object
"使用 GMapUIOptions 对象
The GMapUIOptions object contains a set of properties that specify control placement and UI behavior, which you may modify. For a full set of properties, see the GMapUIOptions reference. Rather than write a GMapUIOptions structure from scratch, you may wish to prepopulate it with the UI behavior available on Google Maps. To do so, use the GMap2.getDefaultUI() method. Once populated, you can modify individual properties to tweak the behavior and initialize the map's UI controls using the GMap2.setUI() method. The following code retrieves the default UI on a "large" map, removes the GScaleControl and resets the map to use the modified UI.
GMapUIOptions 对象包含一组指定控件位置和 UI 行为的属性,您可以修改这些属性。有关完整的属性集,请参阅 GMapUIOptions 参考。与其从头开始编写 GMapUIOptions 结构,您可能希望使用 Google Maps 上可用的 UI 行为预先填充它。为此,请使用 GMap2.getDefaultUI() 方法。填充后,您可以修改各个属性以调整行为并使用 GMap2.setUI() 方法初始化地图的 UI 控件。以下代码检索“大”地图上的默认 UI,移除 GScaleControl 并重置地图以使用修改后的 UI。
map = new GMap2(document.getElementById("map_canvas"),
{ size: new GSize(400,150) } );
map.setCenter(new GLatLng(41.897997,-87.790203), 11);
var customUI = map.getDefaultUI();
customUI.controls.scalecontrol = false;
map.setUI(customUI);
"
”