谷歌地图API V3禁用平滑缩放

7

我正在为三星智能电视2012年版制作一款应用程序,基本上是使用HTML5和JavaScript编写的。

Google Maps V3非常好用,但有一个问题。

似乎电视处理能力不足,使得平滑效果看起来很糟糕。

最大的问题是setZoom()方法的平滑效果。

所以我的问题是:是否有一种方法或参数可以禁用平滑缩放?

或者禁用整个地图的所有平滑效果?

谢谢!

2个回答

11

是的,你可以禁用平滑缩放!但需要做一些修改。在V2版本中,你只需要使用“disableContinuousZoom()”就可以解决问题,但在这个新版本中,谷歌的开发人员没有实现它。

这是第一种可能性(也是我认为最糟糕的):

 * {
  -webkit-transition-property: none!important;
  transition-property: none!important;
  /* These doesn't affect anything, but, just in case. */
  -webkit-animation: none!important;
  animation: none!important;
}

这个解决方案来自:http://code.google.com/p/gmaps-api-issues/issues/detail?id=3033&q=continuous%20zoom&colspec=ID%20Type%20Status%20Introduced%20Fixed%20Summary%20Stars%20ApiType%20Internal

另一个解决方案,我认为是最好的,就是OpenLayers实现的:

/** 
 * APIMethod: setMapObjectCenter
 * Set the mapObject to the specified center and zoom
 * 
 * Parameters:
 * center - {Object} MapObject LonLat format
 * zoom - {int} MapObject zoom format
 */
setMapObjectCenter: function(center, zoom) {
    if (this.animationEnabled === false && zoom != this.mapObject.zoom) {
        var mapContainer = this.getMapContainer();
        google.maps.event.addListenerOnce(
            this.mapObject, 
            "idle", 
            function() {
                mapContainer.style.visibility = "";
            }
        );
        mapContainer.style.visibility = "hidden";
    }
    this.mapObject.setOptions({
        center: center,
        zoom: zoom
    });
},

这很奇怪,因为你使用了带有样式的地图容器,但根据你的情况,也许最好的解决方案是这样!


2
非常感谢ferran87!! CSS的事情对我来说效果非常好!很抱歉我的声望不足以投票.. - codeTemplar

3

虽然在Google Maps文档中并没有提到,但是以下内容对我有效:

map = new google.maps.Map(el, {animatedZoom: false});

截至2017年4月17日,这个未记录的设置仍然对我起效。 - MattGerg
2
很遗憾,无法再使用Google Maps API v3.49了。 - Dennis Bauszus

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接