Pregunta

So I am trying to limit the zoom using javascript with the Bing Map API. Now I have seen this question asked on here but the solutions are not exactly what I am looking for.

There is the ability to see the zoomRange by calling these:

map.getZoomRange().max;
map.getZoomRange().min;

What I want is to be able to set these. I can't seem to find anything in the MapOption object.

An example of what I want is at this site here: http://www.suncadiaresort.com/interactive-resort-map

Now if you try zooming using their controls on the map there is a definite max and min zoom.

But the solution given here, Restrict the min/max zoom on a Bing Map with v7 of the AJAX control? does not make a definite max or min. It is checking to see if the user has scrolled past that point and then setting the zoom. This causes jittering and doesn't always catch.

I really just want to be able to set a max zoom and min zoom so that the map can not be scrolled farther out(or in, if necessary) than what they have just like in the example site.

As for code I am using the second suggestion from the other question, but I will show it here too.

I call the function from an event handler:

Microsoft.Maps.Events.addHandler(map, 'targetviewchanged', restrictZoom(map, 12, 18, mapCenter));

Here is the function:

function restrictZoom(map,min,max, mapCenter)
{
    Microsoft.Maps.Events.addHandler(map, 'targetviewchanged',function()
    {
        var targetZoom = map.getTargetZoom();
        var adjZoom = targetZoom;

        if(targetZoom > max)
        {

            adjZoom = max;  
        }
        else if(targetZoom < min)
        {
            adjZoom = min;  
        }

        if(targetZoom != adjZoom)
        {
            map.setView({center: mapCenter, zoom:adjZoom}); 
        }
   });
}
¿Fue útil?

Solución 2

So with more research and lots of fiddling around with this, the answer from Restrict the min/max zoom on a Bing Map with v7 of the AJAX control? still seems to be the only solution I can find. It would be really nice if the MapOptions Object had the ability to set the zoomRange levels. But to my knowledge this is not possible.

Otros consejos

In v8 this is now available by setting options on the MapOptions object.

var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {
    credentials: 'YOUR_BING_MAPS_KEY',
    minZoom: 4,
    maxZoom: 12
});
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top