msapkal
msapkal

Reputation: 8346

Disable touch in bing map after map is initialized

How to disable mobile touch event after the bing map is initialized?

We can disable before initializing by below code, using MapOptions object. However I'm looking after the Bing Map is initialized.

// Set the map and view options, setting the map style to Road and
// removing the user's ability to change the map style
var mapOptions = {credentials:"Bing Maps Key",
                  height: 400,
                  width: 400,
                  mapTypeId: Microsoft.Maps.MapTypeId.road,
                  disableTouchInput : true,
};

// Initialize the map
var map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), mapOptions); 

Any help is highly appreciated. Thanks in advance!!!

Upvotes: 2

Views: 837

Answers (2)

rbrundritt
rbrundritt

Reputation: 17954

Most of the MapOptions do work when passed into the setOptions method of the map. For instance try this: map.setOptions({disableTouchInput: true});

Note that I've only tested this in IE. If you simply want to disable panning and zooming you can do this in a number of different ways. The first is to use map options, the other is to use the viewchange event, store the original map position and keep setting the map to the same view to lock it.

Upvotes: 3

Bryant
Bryant

Reputation: 8670

Since you can't set most of the MapOptions once the map is created you can only do this by swapping out your map for a new map with the options you want. This is a very basic example, but here is an example that shows and hides the bing logo which is one of the settings that you can't change with setOptions.

function switchMapOptions(active, inactive) {

    try {
        var newMap = new MM.Map($(inactive)[0], options);

        for (var i = 0; i < map.entities.getLength(); i++) {
            var loc = map.entities.get(i).getLocation();
            newMap.entities.push(new MM.Pushpin(loc));
        }

        newMap.setView({center: map.getCenter(), zoom: map.getZoom(), animate: false});

        map.dispose();
        map = newMap;
    }
    catch (e) {
        alert(e.message);
    }
}

Full code at Jsfiddle: http://jsfiddle.net/bryantlikes/zhH5g/4/

Upvotes: 1

Related Questions