Given that I already have a bunch of nodes to create a Map View with, I want to also display a map on each of the nodes for that location or place. I also want the node maps to be customize for each node.
The main reason I would like this functionality is because I think in the context of a node that is a location, it should have a map with the node itself. Also, I think its a really nice feature to have control how that map looks. There are certain locations that I would like to be zoomed in real close, or that I want a map view, or a satellite view. This will give us that control.
The following is a list of assumptions in this process. If the following are not true, then this tutorial may not work for you.
There are some inconsistencies between the API.txt file and the actual way to use the GMap API. See http://drupal.org/node/236352 for more information. For our purposes, the following needs to be noted for the associateive array that will be used to create each map:
Use controltype instead of control.
Use maptype instead of type.
Map Content Type
The first thing we need to do is set up a custom Content Type. This is where CCK and Location are going to come in.
First ensure, that Locative Information is added. When creating the Content Type, it will be at the top of the form. It's kind of hard to notice. Make sure that Maximum number of locations allowed for this type. is at least 1 and Default number of location forms is also at least 1. Plaese note that this tutorial is assuming one location per node. This could easily be changed so that it handled more that one location. Enabling this Location information, will ensure that Latitude and Longitude are collected. Again this could be changed to CCK fields instead.
[img_assist|nid=16|title=Screen: Locative Information on Content Type Creation|desc=Screenshot to point out where the Locative Information section is when creating a new Content Type.|link=none|align=left|width=570|height=379]
CCK Map Parameters
Now you will want to create a set of fields to represent your map parameters. You can add or remove the ones you want. You will want to look at the GMap Macro Creator page that comes with GMap. Here is a brief description of my fields:
CCK Map Macro Parameters
[img_assist|nid=15|title=Screen: Macro Parameters as GMap Node Fields|desc=Screenshot of the CCK fields that are used to create a custom GMap per node.|link=none|align=left|width=570|height=395]
The Select Lists should be filled appropriately from the GMap Macro Creator page. Hint: changes some values and note the macro at the bottom. Please note that these values are Case Sensitive.
Now that we have our content type set up, now we just have to determine how it is going to render all this information. Feel free to make a couple nodes with this new content type, as it will help you see what is happening.
We will create a function in our template.php file, in our theme directory, so that calling the map in the theme will be simple.
This should be pretty straightforward. It would not be too difficult to actually put this in the theme itself, but this way we could do some processing if necessary.
Calling the Function in the Theme
There is a couple ways to do this depending on how you like to make or edit themes. You can use the Content Template Module. But I like to stick with the traditional file method.
Here is my sample node-ct-map.tpl.php file:
Check Our Work
Now, when going to the nodes that we have created, there should be a map with the parameteres we have set on them. For instance:
This should be a fairly easy process. Create a new view.
click Provide Page View
choose a URL
this is where the magic happens; under View Type choose GMap View
Location: Longitude (This is where the CCK fields could be substituted.)
I would also suggest choosing the Node: Title field so that there is link in each info bubble
Node: Published is Yes
Node: Type is One Of Map Type (This is the type that we defined above)
Please feel free to add a comment or contact me about this post. This is just a brief look into what can be done with these powerful technologies.