There may be times when you don’t want to have a draggable map. Oh, yes all the flexibility of draggable maps makes AJAX and Virtual Earth so much fun! And, knowing you maybe be wreaking havoc on the image tile servers is so stimulating. Plus, with AJAX, Microsoft has to deal with all the throughput to the client and not your web servers – yay!
However, if you do want to lock a map you can do so in one of two ways.
1. If you know you want a locked map when you load a Virtual Earth map you can simply pass in “true” for the Boolean parameter of the map.LoadMap() method.
VEMap.LoadMap(VELatLong, zoom, style, fixed, mode, showSwitch);
2. Sometimes, you may want a map to be draggable but then lock it to disallow a user from scrolling beyond a certain area. To do that, you’ll want to override the onMouseDown event. Overriding the onMouseDown event is easy. First, attach an event to override onMouseDown:
Then, you’ll want to include a function to basically do nothing when onMouseDown event is fired (instead of the default Virtual Earth actions):
That’s it! Here’s the whole solution so you can just copy, paste, run.
var map = null;
map = new VEMap(‘myMap’);
// Attach an event handler for a mousedown event.
// So when the mouse is down, DisableMap function gets called
// returning true will disable the mousedown event therefore disabes dragging