none
Bing maps V8 Change View Dynamically RRS feed

  • Question

  • I have initial map load with the following code..... can't see to get it to zoom to just surround the layers. Map stays at initial zoom of 7. What am I doing wrong here? Bounds not set correctly???

                        function loadMapScenario() {
                            map = new Microsoft.Maps.Map('#myMap1', {
                                credentials: "******",
                                center: new Microsoft.Maps.Location(document.MapForm.CCLatitude.value,
                                     document.MapForm.CCLongitude.value),
                                zoom: 7
                            });

    Then I add some layers

    var CCStormLine = new Microsoft.Maps.Polyline ([new Microsoft.Maps.Location(CCLatitude, CCLongitude), new Microsoft.Maps.Location(ClosestStormLat, ClosestStormLong)], { strokeColor: 'grey', strokeThickness: 3, strokeDashArray: [1, 2, 1, 2] }); Stormlayer.add(CCStormLine);

                            map.setView({ bounds: Stormlayer.bestView });
                            map.layers.insert(Stormlayer);


    Wednesday, March 14, 2018 9:41 PM

Answers

  • I'm assuming your Stormlayer is a Microsoft.Maps.Layer object, if so, there is no bestView property which is why this isn't working for you. Instead do this:

    map.setView({ bounds: Microsoft.Maps.LocationRect.fromShapes(Stormlayer.getPrimitives()) });


    [Blog] [twitter] [LinkedIn]


    • Proposed as answer by Ricky_Brundritt Wednesday, March 14, 2018 10:13 PM
    • Edited by Ricky_Brundritt Wednesday, March 14, 2018 10:14 PM
    • Marked as answer by DDL19 Wednesday, March 14, 2018 11:43 PM
    Wednesday, March 14, 2018 10:13 PM