javascript - 更改默认的 Google Maps Api 默认缩放控件图像?

标签 javascript jquery google-maps-api-3

您能否更改 Google Maps Api 缩放控件的默认图像以便创建我自己的图像?

最佳答案

不可以,您不能将缩放控件的图像更改为 Google 提供的三个选项以外的任何其他选项:

The Zoom control may appear in one of the following style options:

google.maps.ZoomControlStyle.SMALL displays a mini-zoom control, consisting of only + and - buttons. This style is appropriate for small maps. On touch devices, this control displays as + and - buttons that are responsive to touch events.

google.maps.ZoomControlStyle.LARGE displays the standard zoom slider control. On touch devices, this control displays as + and - buttons that are responsive to touch events.

google.maps.ZoomControlStyle.DEFAULT picks an appropriate zoom control based on the map's size and the device on which the map is running.

但是您可以构建 custom controls并将它们放在 map 上。您将必须设置适当的事件处理程序并管理控件的状态,但这是可以做到的。

slider 控件可能有点棘手,但如果您只想放大和缩小按钮,则无需管理状态即可。

事件看起来类似于:

//zoom in control click event
google.maps.event.addDomListener(zoomIn, 'click', function() {
   var currentZoomLevel = map.getZoom();
   if(currentZoomLevel != 21){
     map.setZoom(currentZoomLevel + 1);
    }
 });

//zoom out control click event
google.maps.event.addDomListener(zoomOut, 'click', function() {
   var currentZoomLevel = map.getZoom();
   if(currentZoomLevel != 0){
     map.setZoom(currentZoomLevel - 1);
   }
 });

关于javascript - 更改默认的 Google Maps Api 默认缩放控件图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7838982/

相关文章:

javascript - 幻灯片不工作?

javascript - 如何防止可拖动的子元素相互拖动?

javascript - 谷歌地图 API;抑制 map 平移以启用页面滚动

javascript - Google Maps API directionsService.route 不同于 Google Maps Directions

javascript - THREE.LineDashedMaterial - 破折号不起作用

javascript - 带有ajax的动态html5音频播放列表

javascript - 我们如何使用 jquery 获取图像的位置并在该位置放置其他图像

javascript - 如何将 100 万条记录异步保存到 mongodb?

javascript - HTML 动态内容神秘消失

javascript - AngularJS/GoogleMaps(始终隐藏标记)