Fraggle
Fraggle

Reputation: 8727

How to disable "auto panning" when dragging a marker near edge of Google Maps?

Basically I don't want the map to start automatically panning when someone is dragging a marker. Today, whenever someone drags a marker near the map edge, the map starts panning, panning even continues when they are outside the boundaries of the map canvas.

Pretty sure this "auto" panning is the default for any map (Google javascript Maps API 3.x) that has draggable markers and "normal" panning capabilities.

I want to keep the ability to pan the map with the mouse but I need to disable the "auto" panning that occurs when someone is dragging a marker near the edges of the map. (also need to keep draggable markers).

Thanks in advance.

Upvotes: 2

Views: 1326

Answers (1)

puckhead
puckhead

Reputation: 1891

Use the dragstart and dragend events of the marker to switch on and off the draggable property of the map. The map object does not have a setDraggable method so you need to use the set method.

google.maps.event.addListener(marker, 'dragstart', function(){
    map.set('draggable', false);
});
google.maps.event.addListener(marker, 'dragend', function(){
    map.set('draggable', true);
}); 

Upvotes: 2

Related Questions