6

I am trying to add custom zoom buttons to a Microsoft Map that I am instantiating in a constructor function.

    function Planner(options, $mapPanel) {
        this.settings = $.extend(true, {}, options);
        this.$panel = $mapPanel;
        this.map = new Microsoft.Maps.Map($panel, this.settings.map);
    }

The default map settings include a default zoom level, center location, and disabling the logo and dashboard.

Instantiation of the map works well. It loads correctly and zoom on scroll and panning are functioning as expected.

    var planner = new Planner(options, $mapPanel);

The problem is that planner.map.setView() is not working correctly. When I call planner.map.setView({ zoom: 8 }) nothing happens, but if I change the center of my map to a different location zoom via setView starts working again. For example, this works:

    planner.map.setView({ center: someCompletelyNewLoc });
    planner.map.setView({ center: myOldLoc });
    planner.map.setView({ zoom: newZoomLevel }); 

I can't figure out what is going wrong here. Any ideas?

P.s. This is my first post, so let me know if this code/explanation is too brief/simple.

  • You should set the zoom directly in the viewOptions while initialize the map control if you want to have it at zoom level without animation and without having to change the element. See: https://www.bingmapsportal.com/isdk/ajaxv7#CreateMapWithViewOptions5 – Nicolas Boonaert May 20 '15 at 19:30
  • 2
    Setting zoom directly in the viewOptions during the initialization works fine. It's when I attempt to update the zoom after initialization using the **setView** method. I can create the map without issue, but I need to update the zoom afterwards via custom zoom buttons. – Blake Feggans May 20 '15 at 19:48
  • @BlakeFeggans, I am having a very similar issue. Did you find any solution to this problem? – puddinman13 Jul 27 '15 at 18:04
  • @puddinman13 I couldn't figure this out. What I was attempting to do was add custom zoom buttons to a map and link them up to the setZoom functionality. Instead, I showed the entire controls menu and then used CSS to hide pieces of the menu and enhance the zoom buttons accordingly. Hopefully this helps... – Blake Feggans Jul 28 '15 at 18:18

0 Answers0