Community Documentation

Custom Markers

Last updated August 24, 2012. Created by nicoz on May 16, 2012.
Edited by ekes, ifrik. Log in to edit this page.

Basic custom marker

To add a marker select the 'Styles' tab under Home » Administration » Structure » OpenLayers. Here you can [+ Add] a new marker.

Once you have created a marker you can choose it for the style of your layer. Go to edit your map from the 'Maps' tab under Home » Administration » Structure » OpenLayers. In the 'Layers & Styles' selection you should now be able to select your new style.

Selecting markers dynamically

You can change the file that is accessed for the marker based on replacement tokens from your view.

Go to your view, and select the 'OpenLayers Data' display. At the top of the preview you will see some text like:

You can use the following parameters in your styles as dynamic values

${title_rendered}
${title}
${field_point_rendered}
${field_point}
${name}

These tokens can be used in the externalGraphic url field of your style.

Example: Selecting by icon by Content Type

In your view:

  1. Go to your view 'Openlayers Data' display.
  2. Add the 'Content: Type' field

You should now see additional tokens in the preview section:

${type_rendered}
${type}

In Openlayers styles section:

  1. Go to the 'OpenLayers' settings page select the 'Styles' tab and add a new 'Style'.
  2. Under 'externalGraphic' in the section 'Style Properties', enter the URL to where you are going to store your icons using the new token
    ${type_rendered} to be replaced with the content type name e.g. sites/all/themes/[YOUR-THEME_NAME]/css/images/icons/icon-${type_rendered}.png

Add your icons:

Add your icon images to this folder. E.g. for a content type with a human readable name of 'Location', your icon's file name will be icon-Location.png

Openlayers preview in the view does not give examples of the exact replacement. For some fields you might not be sure what is going to be replaced. One way to work out the exact filenames is to try using the style and check the logs for the filenames of the not found images.

In your map:

In the Layers & Styles section you can now select this style to be used for your layer. If you use this style with a view without the field, for the token, 'undefined' with be used instead (so in this example: icon-undefined.png).

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 7.x
Level
Beginner, Intermediate, Advanced
Audience
Designers/themers, Programmers, Site builders
Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here