Skip to content

Instantly share code, notes, and snippets.

@lpdumas
Created September 13, 2012 15:28
Show Gist options
  • Save lpdumas/3715089 to your computer and use it in GitHub Desktop.
Save lpdumas/3715089 to your computer and use it in GitHub Desktop.
Simple pan method for Google map API v3 to pan the map with a certain offset. In this case, used within a custom infoWindow class.
CustomInfoWindow.prototype.panMap = function(marker, map) {
var offsetX = 100
var offsetY = 75
var scale = Math.pow(2,map.getZoom())
var center = map.getProjection().fromLatLngToPoint(marker.getPosition())
var newCenterPoint = new google.maps.Point(
center.x - offsetX/scale,
center.y + offsetY/scale
)
var newCenter = this.map.getProjection().fromPointToLatLng(newCenterPoint)
this.map.panTo(newCenter)
}
@webdevs-pro
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment