Reputation: 8628
How can I offset the panTo function? When a marker is clicked I would like to panTo it, but not place the marker in the center of the screen.
I would like to offset it (both x and y) by a desired % of the screen width and height.
google.maps.event.addListener(marker, 'click', function() {
map.panTo(loc);
});
Thanks
Upvotes: 1
Views: 2484
Reputation: 117344
An easier approach than the calculation suggested in the comments could be to:
panTo
to center the map at the given positionThe dimensions of a element may be retrieved via offsetWidth/offsetHeight
Sample:
google.maps.event.addListener(marker, 'click', function() {
var map = this.getMap(),
div = map.getDiv();
map.panTo(this.getPosition());
map.panBy(div.offsetWidth/4, div.offsetHeight/4);
});
Upvotes: 5