how to create a padding around the edge of a google map

I have a very busy Google Maps app that I have built and I'm trying to create a "buffer zone" around the outside edge of the map so that the google map commands won't put things there. My solution was to create invisible divs and add them to the map as controls, one for each of the edges. This seems to work great as all of the google commands see them and adjust accordingly, and the map appears normally. For example, fitBounds ensures my bounds is not under the invisible layers. For the top where I have a control bar it's a perfect solution, but for the other edges where there is nothing, it creates a problem - I can't click on the map or info windows under these controls as they take the click event.

So I'm looking for one of 2 solutions: 1) can I make my invisible controls pass clicks through to the map, or; 2) is there a better way to pad the edge of the map; something that doesn't involve a much of math every time I want to call a fitBounds or panTo would be preferred as I automate a lot of map motion



Try to give the invisible DIV a negative z-index, e.g. -10


I managed to solve this.

The best way to add padding to your maps is with invisible controls. It creates the padding that all other map functions obey without any additional coding when call them. Here is how to do it for everyone else who needs this. First.. I create a function to simplify creating the divs.

function createDummyDiv(w, h){ var out = $(document.createElement('div')).addClass('dummy-div').css('width', w).css('height', h); return out[0]; }

Then I add the controls as needed. In this case I have the normal zoom control in the LEFT_CENTER position, so I had to create 2 for the left side. This creates a 10% padding on the left, right and bottom, and a 55px padding at the top under my own control bar.

map.controls[google.maps.ControlPosition.TOP_CENTER].push(createDummyDiv('100%', '55px')); map.controls[google.maps.ControlPosition.LEFT_TOP].push(createDummyDiv('10%', '45%')); map.controls[google.maps.ControlPosition.LEFT_BOTTOM].push(createDummyDiv('10%', '45%')); map.controls[google.maps.ControlPosition.RIGHT_CENTER].push(createDummyDiv('10%', '100%')); map.controls[google.maps.ControlPosition.BOTTOM_CENTER].push(createDummyDiv('100%', '10%'));

The.. the final fix to my problem is to put them behind the map layer with css.

.dummy-div{ z-index: -100 !important; }

I hope this helps someone else


For me, fitBounds api worked itself with second parameter (padding)

Add padding to google map bounds


  • 'SOCK_RAW' option in 'socket' system call
  • Regex is not working as expected?
  • use rvest and css selector to extract table from scraped search results
  • how to populate a SQLite database and use that database in phonegap?
  • What Makes These Two Array Adds Different?
  • New Firebase failed: First argument must be a valid firebase URL and the path can't contain “.”
  • JSON encode and decode on PHP
  • Building Qt project for C++11 standard
  • Creating a DropDownList
  • Bigquery event streaming and table creation
  • Cannot upload to OneDrive using the new SDK
  • Authentication in Play! and RestEasy
  • d3 v4 drag and drop with TypeScript
  • How to match http request and response using Jersey ContainerRequestFilter and ContainerResponseFilt
  • JQuery Internet Explorer and ajaxstop
  • Change multiple background-images with jQuery
  • Change Inet root folder for iis 7
  • Algorithm for a smudge tool?
  • How to rebase a series of branches?
  • Update CALayer sublayers immediately
  • Nant, Vault & Windows Integrated Authentication
  • Why ng-show works with ng-repeat but ng-if doesn't? [duplicate]
  • C# - Serializing and deserializing static member
  • Opengl-es onTouchEvents problem or a draw problem? [closed]
  • Bug in WPF DataGrid
  • Can Jackson SerializationFeature be overridden per field or class?
  • Sony Xperia Z Tablet not found by adb
  • Join two tables and save into third-sql
  • Javascript convert timezone issue
  • How to model a transition system with SPIN
  • Why is the timeout on a windows udp receive socket always 500ms longer than set by SO_RCVTIMEO?
  • ORA-29908: missing primary invocation for ancillary operator
  • jquery mobile loadPage not working
  • jQuery tmpl and DataLink beta
  • How can I estimate amount of memory left with calling System.gc()?
  • Data Validation Drop Down Box Arrow Disappearing
  • Android Studio and gradle
  • How do you join a server to an Active Directory (domain)?
  • Linking SubReports Without LinkChild/LinkMaster
  • Converting MP3 duration time