Online Book Reader

Home Category

Mapping With Drupal - Alan Palazzolo [44]

By Root 498 0
(see Figure 6-1). Fortunately, some other markers come with Drupal Modules, or alternatively you can add your own custom markers.

Figure 6-1. Google Maps typical marker

OpenLayers Styles


In OpenLayers styles we showed how to add a new color of circular marker. As well as changing the line thickness, color, and opacity, it is possible to use images for markers. When adding a new style at admin/structure/openlayers/styles, you can enter the path to an image file in the “externalGraphic” field. Normally this file will be in your custom module or theme. Some examples of custom images used as markers are shown in Figure 6-2. An example of a vector used as a marker is shown in Figure 6-3.

Figure 6-2. OpenLayers styles marker example

Figure 6-3. OpenLayers styles vector example

GMap Markers


The GMap module provides a number of default markers to use in your maps. But if these are not what you need, you will have to manually add new ones. The GMap module searches through the markers folder and all folders within that. It collects data on markers from .ini files and stores that data in a cached object. The module then references that object when creating and displaying maps. We will go through four steps to create a new marker:

Decide on a storage location for our markers and create a folder.

Add a Marker to that folder.

Create a .ini file and add details of our marker to the file.

Regenerate the marker cache.

NOTE

The GMap module provides documentation using the Advanced Help module. The page on your site that contains help for adding markers is help/gmap/extending.

Marker location


Unfortunately, GMap does not provide a good way to store our custom marker files. By default, all markers are stored in the GMap module within the markers directory. You can add your custom markers to this directory, but you will run into problems when you upgrade the module: you may forget that you put custom markers in this directory, and so will accidentally delete them.

The alternative is to change the variable that designates the directory that contains markers. However, because of the way that the GMap module works, only the markers that are available to use on our map are the markers in this directory. We could change this variable to a directory in our custom module, but then we would no longer have all the default markers that are included in the GMap module.

So, we lose in either case. For this example’s purpose we will use the first method. We will create a new subdirectory in the GMap module called mappingdrupal and will end up with something like the following /markers/mappingdrupal/.

Add a marker


Now, we will add the image file for our new marker to this directory. You can download the marker that we created for this exercise from MappingDrupal.com. Save it as /markers/mappingdrupal/marker-black.png. Make a note of the dimensions of the image (25×41), since we will need that later.

The .ini file


Next we need to tell GMap a little about our image so that it can put it into maps. Within our new directory, we create an .ini file named mappingdrupal.ini inside the subdirectory we created earlier (the name of the file is not important, but the .ini extension is). The file will be at /markers/mappingdrupal/mappingdrupal.ini. This file can contain information about many markers, although in this example we just have one.

Add the following to that file:

; Defaults

[defaults]

;shadow = ""

anchorX = 15

anchorY = 41

infoX = 17

infoY = 6

; Marker sets

[mappingdrupal]

name = "Mapping Drupal Black"

sequence = "marker-black.png"

This defines a marker named Mapping Drupal Black shown on the map in Figure 6-4.

Figure 6-4. Displaying the Mapping Drupal marker in GMap

The following explains the different parts:

The [defaults] section defines some default values for our marker. Defaults are useful when you have dozens of markers the same size. We have commented out the shadow line because this marker

Return Main Page Previous Page Next Page

®Online Book Reader