Skip to content

Instantly share code, notes, and snippets.

@m-coding
Forked from lpdumas/panTo.js
Created February 25, 2016 23:48
Show Gist options
  • Save m-coding/899b5715e04df9951780 to your computer and use it in GitHub Desktop.
Save m-coding/899b5715e04df9951780 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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment