none
Setting Bounds When Initializing Map Doesn't Work Correctly in V8 RRS feed

  • Question

  • In version 7 I was able to set the bounds when initializing the map object. In version 8, this doesn't seem to work correctly. For example, when trying to set the bounds to the Continental U.S., it ends up zooming to my physical location (or thereabouts). 

    Not a big deal as calling map.setView immediately after initialization corrects the view.

    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
        <meta charset="utf-8" />
    </head>
    <body>
        <div id="myMap"></div>
        <script type='text/javascript' src='http://www.bing.com/api/maps/mapcontrol?callback=GetMap' async defer></script>
        <script type='text/javascript'>
        function GetMap() {
            //var bounds = Microsoft.Maps.LocationRect.fromEdges(46, -123, 45, -122);  // Portland, OR
            var bounds = Microsoft.Maps.LocationRect.fromEdges(50, -130, 20, -60); // Continental U.S.

            var map = new Microsoft.Maps.Map('#myMap', {
                credentials: 'Your Bing Maps Key',
                bounds: bounds        // this works in V7, but not V8
            });

            //map.setView( {bounds: bounds} );    // this is a workaround

            // Highlighting the border of bounds on the map
            var boundsBorder = new Microsoft.Maps.Polyline([bounds.getNorthwest(),
                new Microsoft.Maps.Location(bounds.getNorthwest().latitude, bounds.getSoutheast().longitude),
                bounds.getSoutheast(),
                new Microsoft.Maps.Location(bounds.getSoutheast().latitude, bounds.getNorthwest().longitude),
                bounds.getNorthwest()], { strokeColor: 'red', strokeThickness: 5 });
            map.entities.push(boundsBorder);
        }
        </script>
    </body>
    </html>
    Tuesday, June 28, 2016 3:47 PM

Answers

  • This should now be fixed in the experimental branch. You can test this by adding "&branch=experimental" to the map script URL, or try it out in the interactive SDK. This will be merged into the main release branch at the end of July.

    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Wednesday, July 6, 2016 11:51 PM
    • Marked as answer by Ken C Bowman Thursday, July 7, 2016 3:05 PM
    Wednesday, July 6, 2016 11:51 PM

All replies