Pretty Up that GMap

Author: 

Pretty Up that GMap

Posted on: Thursday, July 19th 2012 by Bono Fung

GMap module has been around for quite some time. Combined with GMap Location and the Location module you can create views or blocks that can show locations of your nodes and users. There are a few tricks to pretty up the gmap view as well as adding some useful features to the map. There are other ways to add map view to Drupal now but GMap is still the most common one I found on other sites so far.

Create a view

When you have GMap and GMap location configured properly you can create a GMap view. The method is pretty straight forward and is just like creating a new display. You will need to create your default view and then create a new display. It can be either a block or a page. In order to have a GMap view you will need to change the display's Style to 'GMap'. By default, the node or user's location in the view will be used to display a marker on the map.

Setup Macro

Inside the GMap module there are Default map settings which will allow you to generate the default setting. But what if you want to have a particular view that needs to look different? For example, if you need to create a new block with a map that uses the satellite view instead of the standard map then you will need to configure that block differently. For doing something like that we will need to create a new macro for just that display. After you setup the modules and have completed your default configuration you can go to '/map/macro' to create your customized map macro text. There are a few settings and styles like size, marker style, color, default map type, control size etc that you can update. Once you are done then you can copy and paste the generated Macro Text at the bottom of the page.

Now open up the view that you need to have your GMap view customized. Go to the correct display and edit the Style. You will notice there is a 'Macro' field with a textarea underneath it. Simply copy and paste the new macro text from the '/map/macro' page setup into this textarea and save. You will notice that now your view will be using its own customized settings. Please also note that you cannot view the maps in preview. To view the changes you will have to open up a new page to go to the page or view the actual block on the site.

Customized location

By default, map view will grab the node or user's location data. The map will only show a marker if the location is saved correctly with valid data. One simple way to verify if the location is saved correctly is to check the latitude and longitude of that location. If the location does not display any latitude and longitude data then the location might not be valid and therefore might not show up on the view.

Now what if your view does not retrieve any node or user data directly or for some reason your view has multiple node types; then you can retrieve the specific location data and configure your view to use that location data. You will need to update your Data Source field. By default it will set to location.module but you can set it to 'Choose latitude and longitude fields' instead. By choosing that you will need to specify which exact field you are using for location reference.

Customized popup bubble

When you click on the map marker a bubble will popup. You can completely customize these bubbles with the help of a customized tpl. Please note that if you have multiple displays then you should customize your tpl at the display level; otherwise all your other displays will be affected as well.

So with some additional configurations you can now make your GMap blocks all unique.

Original Post: