Reputation: 1707
I have a button that adds an InfoWindow to a Google Map, but the disableAutoPan
property seems to be ignored.
var map;
function initialiseMap() {
map = new google.maps.Map(document.getElementById('mapCanvas'), {
zoom: 9
});
var currentIndicator = new google.maps.InfoWindow({
map: map,
position: new google.maps.LatLng(53.8526, -2.7454),
content: "Start location"
});
map.setCenter(currentIndicator.position);
}
function plotMyLocation() {
var pos = new google.maps.LatLng(53.05, -1.25);
new google.maps.InfoWindow({
map: map,
position: pos,
content: "My Location",
disableAutoPan: true
});
}
google.maps.event.addDomListener(window, 'load', initialiseMap);
When the plotMyLocation
function is invoked, the map always pans to show the position of the newly-added InfoWindow, regardless of the value of the disableAutoPan
property.
The example at http://jsfiddle.net/H3XLx/ demonstrates the issue.
What am I doing wrong that's preventing disablement of the auto-panning?
Upvotes: 1
Views: 2716
Reputation: 11258
You can resolve it using option list without map
and calling function open(map)
:
function plotMyLocation() {
var pos = new google.maps.LatLng(53.05, -1.25);
var infowindow = new google.maps.InfoWindow({
//map: map,
position: pos,
content: "My Location",
disableAutoPan: true
});
infowindow.open(map);
}
See updated jsfiddle.
From google docs: Unless auto-pan is disabled, an InfoWindow will pan the map to make itself visible when it is opened. After constructing an InfoWindow, you must call open to display it on the map.
You provided map property in option list which is not documented.
Upvotes: 3