Google Maps API v3: Can I setZoom after fitBounds?

前端 未结 23 2474
执笔经年
执笔经年 2020-11-27 09:35

I have a set of points I want to plot on an embedded Google Map (API v3). I\'d like the bounds to accommodate all points unless the zoom level is too low (i.e., zoomed out

23条回答
  •  迷失自我
    2020-11-27 09:41

    Like me, if you are not willing to play with listeners, this is a simple solution i came up with: Add a method on map which works strictly according to your requirements like this one :

        map.fitLmtdBounds = function(bounds, min, max){
            if(bounds.isEmpty()) return;
            if(typeof min == "undefined") min = 5;
            if(typeof max == "undefined") max = 15;
    
            var tMin = this.minZoom, tMax = this.maxZoom;
            this.setOptions({minZoom:min, maxZoom:max});
            this.fitBounds(bounds);
            this.setOptions({minZoom:tMin, maxZoom:tMax});
        }
    

    then you may call map.fitLmtdBounds(bounds) instead of map.fitBounds(bounds) to set the bounds under defined zoom range... or map.fitLmtdBounds(bounds,3,5) to override the zoom range..

提交回复
热议问题