Restrict the min/max zoom on a Bing Map with v7 of the AJAX control? -
i'm working on site makes use of v7 of bing maps ajax control. 1 of things need restrict zoom level prevent users zoom in past level, or zoom out past level.
i found "getzoomrange" method on map object, after inspecting it, returns object literal "min" , "max" properties. so, figured overloading trick:
// "map" our bing maps object map.getzoomrange = function () { return { max: 14 min: 5 }; };
...but no. has no effect (it has appearance of zoom slider when using default dashboard).
hijacking event , preventing proceeding seems have no effect.
according bing maps support, way (which isn't particularly elegant, , results in unwelcome jitter on map) follows:
// "map" our bing maps object, overload built-in getzoomrange function // set our own min/max zoom map.getzoomrange = function () { return { max: 14, min: 5 }; }; // attach handler event gets fired whenever map's view change microsoft.maps.events.addhandler(map,'viewchangestart',restrictzoom); // forcibly set zoom our min/max whenever view starts change beyond them var restrictzoom = function () { if (map.getzoom() <= map.getzoomrange().min) { map.setview({ 'zoom': map.getzoomrange().min, 'animate': false }); } else if (map.getzoom() >= map.getzoomrange().max) { map.setview({ 'zoom': map.getzoomrange().max, 'animate': false }); } };
Comments
Post a Comment