Guest User

Untitled

a guest
Jan 18th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. google.maps.event.addListener(map, 'zoom_changed', function() {
  2. setTimeout(moveMap, 10);
  3. });
  4.  
  5. function moveMap() {
  6. map.panBy(300, 0);
  7. }
  8.  
  9. var map, // Your map object
  10. mapWidth = $('#map').css('width'); // Width of map container
  11. nCentre,
  12. cCentre,
  13. visibleWidth = 200; // Visible area in PX you want map to be centered in
  14.  
  15. // Make sure width is an Int
  16. mapWidth = parseInt(mapWidth.replace(/px$/, ''), 10);
  17.  
  18. // Get the center of viewable area
  19. cCentre = visibleWidth / 2;
  20.  
  21. // Create the new position variable
  22. nCentre = cCentre - (mapWidth / 2);
  23.  
  24. // Pan the map to the centre of the visible area
  25. if (nCentre !== 0) {
  26. map.panBy(nCentre, 0);
  27. }
Add Comment
Please, Sign In to add comment