4

Given a bunch of pushpins in Bing Maps, is there a quick and easy way to zoom in on those pushpins such that they are all visible, and fairly spread out? For example, say I have hundreds of pins all over Australia. Then I would want to zoom in to Australia as a continent, but seeing other continents would be too big, yet seeing only Sydney would be too small.

  • 1
    This is often called "Zoom to Extents (of the layer or data)" – jvangeld Jul 7 '15 at 21:17
3

The solution to this is to set the bounds property of the viewOptions object.

The bounds property takes a locationRect. Since I knew the maximum and minimum longitudes and latitudes, I used the fromEdges constructor. There are other ways of making a locationRect, go here for more information on how to make a locationRect.

Once you have the locationRect, simply set the bounds property either at the initial creation of the map, or later using the setView method for the map class. Here is my code:

box=new Microsoft.Maps.LocationRect.fromEdges(maxLat,minLong,minLat,maxLong); map=new Microsoft.Maps.Map(document.getElementById("mapDiv"), { credentials:"Your bing map developer key", bounds: box });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.