简体   繁体   English

如何在Google Map API中覆盖或删除控件

[英]How to override or remove a control in Google Map API

I was playing with Google maps for last two days and started understanding little bit about its functionality. 最近两天我一直在玩Google地图,并开始对它的功能有所了解。

I was using Large Map ie 700 X 300 resolution map size and i was trying to implement controls used in small maps. 我正在使用大型地图,即700 X 300分辨率的地图大小,并且我试图实现在小地图中使用的控件。

eg. 例如。

var map = new GMap2(document.getElementById("map_canvas"));
 map.setCenter(new GLatLng(37.4419, -122.1419), 18);
 map.setMapType(G_HYBRID_MAP);
 **map.setUIToDefault();**
 map.enableContinuousZoom();

 var customUI = map.getDefaultUI();     
 customUI.controls.smallzoomcontrol3d=true;   //1. trying to override largezoomcontrol3d 
 customUI.controls.menumaptypecontrol=true;   //2. trying to override largezoomcontrol3d 
 map.setUI(customUI);

 map.enableRotation(); //3. Enabling rotation

Here in 1(a). 在1(a)中。 Small zoom control is not getting visible until i remove the line map.setUIToDefault() and add one more line customUI.controls.largezoomcontrol3d=false . 直到我删除线map.setUIToDefault()并再添加一行customUI.controls.largezoomcontrol3d=false小型缩放控件才变得可见。 Although I was expecting that by writing above code those control will get overridden. 尽管我期望通过编写上述代码来控制这些控件。

1(b). 1(b)。 I tried to use map.removeControl(Control:GControl) where i was not able to pass the correct parameter. 我试图在无法传递正确参数的地方使用map.removeControl(Control:GControl) I wanted to remove largezoomcontrol3d from map but i was not able to make out how to refer to this control in the current map. 我想从地图上删除largezoomcontrol3d ,但是无法确定如何在当前地图中引用此控件。

  1. Same overriding problem is occuring here also. 同样的首要问题也在这里发生。 The only difference here is that both the controls are visible here menumaptypecontrol and maptypecontrol , here menumaptypecontrol is overlapping on maptypecontrol 唯一的区别是,这两个控件在这里都是可见的menumaptypecontrolmaptypecontrol ,这里的menumaptypecontrolmaptypecontrol上是重叠的

  2. I am trying to enable rotation on map but it is not working for me. 我正在尝试在地图上启用旋转功能,但对我来说不起作用。

thinking about map.removeControl you were quite closely to solution (if I got what you need). 考虑map.removeControl,您就非常接近解决方案(如果我得到了您所需要的)。 take a look here: 在这里看看:

Controls 控制项

so, you need just use map.addControl function to add exactly what you need instead of what you did. 因此,您只需要使用map.addControl函数添加所需的确切内容即可。

sorry, forgot about map rotation. 抱歉,忘记了地图旋转。 I think the following simple example of Google Map can help you (I just never played with rotation, but example looks very simple to learnt from it): 我认为以下Google Map的简单示例可以为您提供帮助(我从没有玩过旋转,但是从中学习起来很简单):
Google Map rotation example Google Map轮换示例

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

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