Map Tiles

Map tiles are small images tiled together to create a map, usually the base layer for a web map. A tileset is a specific set of these images. What tileset you choose can have a drastic effect on the visual nature of your map.

Adding Base Layers to GMap

GMap can be extended to add base layers. This has to be done directly with code. We will not go into great detail here, but will give a short overview.

  1. To add some layer options in the GMap configuration form, we will use hook_gmap() again (this function was previously explained in Add geolocation options to maps). In hook_gmap(), for the baselayers operation, return an array structured like the following:

    $layers['Section Name']['layer_id'] = array(
      'title' => t('Title of layer'),
      'default' => TRUE,
      'help' => t('Description of layer'),
    );
  2. Also, within hook_gmap(), in the pre_theme_map operation, use drupal_add_js() to include the JavaScript that will add the layer to the map.

  3. Within the JavaScript file referenced in the previous step, include code similar to the following:

    Drupal.gmap.addHandler('gmap',function(elem) {
      var gmap = this;
      
      obj.bind('bootstrap_options', function() {
        var opts = gmap.opts;
        var layers = gmap.vars.baselayers;
        
        // Put layers here (??)
        opts.mapTypes.push();
        opts.mapTypeNames.push();
      });
    });

Note

The MapBox module has an implementation for adding base layers to GMap and will be the easiest way to do this, though it is still fairly undocumented. The MapBox module is discussed more at MapBox.

Adding Base Layers ...

Get Mapping with Drupal now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.