none
Setting same bounds results in zoomed out view RRS feed

  • Question

  • When i save the maps bounds and restore them at a later point in time i get a different view which is zoomed out. It can be triggered with the following piece of code:

    map.setView({
        bounds: map.getBounds()
    });

    How can i restore the exact same view when using the bounds option?

    Wednesday, January 31, 2018 5:23 PM

Answers

  • Check to see this occurs in the experimental branch. If it does then I suspect what is happening is that when the map view is being calculated when loading it is notices the coordinates are right on the edge of the map view and ends up zoom out one level. You may find using center and zoom level to be a better option for you.

    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Wednesday, January 31, 2018 11:07 PM
    • Marked as answer by Ricky_Brundritt Wednesday, February 21, 2018 11:10 PM
    Wednesday, January 31, 2018 11:07 PM
  • I tried the experimental branch using the following code

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8"/>
            <title></title>
            <script src="https://www.bing.com/api/maps/mapcontrol?callback=GetMap&branch=experimental&key=[key]" async defer></script>
            <script>
    function GetMap() {
        const map = new Microsoft.Maps.Map('#map', {
            center: new Microsoft.Maps.Location(50, 50)
        });
        document.getElementById("reset").addEventListener("click", () => {
            map.setView({
                bounds: map.getBounds()
            });
        });
    }
            </script>
        </head>
        <body>
            <button id="reset">Reset</button>
            <div id="map" style="width: 800px; height: 600px;"></div>
        </body>
    </html>

    But i still get the same behavior.


    Thursday, February 1, 2018 8:41 AM

All replies

  • Check to see this occurs in the experimental branch. If it does then I suspect what is happening is that when the map view is being calculated when loading it is notices the coordinates are right on the edge of the map view and ends up zoom out one level. You may find using center and zoom level to be a better option for you.

    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Wednesday, January 31, 2018 11:07 PM
    • Marked as answer by Ricky_Brundritt Wednesday, February 21, 2018 11:10 PM
    Wednesday, January 31, 2018 11:07 PM
  • I tried the experimental branch using the following code

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8"/>
            <title></title>
            <script src="https://www.bing.com/api/maps/mapcontrol?callback=GetMap&branch=experimental&key=[key]" async defer></script>
            <script>
    function GetMap() {
        const map = new Microsoft.Maps.Map('#map', {
            center: new Microsoft.Maps.Location(50, 50)
        });
        document.getElementById("reset").addEventListener("click", () => {
            map.setView({
                bounds: map.getBounds()
            });
        });
    }
            </script>
        </head>
        <body>
            <button id="reset">Reset</button>
            <div id="map" style="width: 800px; height: 600px;"></div>
        </body>
    </html>

    But i still get the same behavior.


    Thursday, February 1, 2018 8:41 AM
  • I believe this is a known issue at this time that the team plans to look into. I'm currently on parental leave so a bit out of the loop on timelines.

    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Wednesday, February 21, 2018 11:10 PM
    • Marked as answer by Ricky_Brundritt Wednesday, February 21, 2018 11:10 PM
    • Unmarked as answer by Ricky_Brundritt Wednesday, February 21, 2018 11:10 PM
    • Unproposed as answer by Ricky_Brundritt Wednesday, February 21, 2018 11:10 PM
    Friday, February 2, 2018 5:41 AM