I easily added a map to the zzolo sandbox using [openlayers default], but I can't get the filter to work on my own website (and I do have the Openlayers Filters module enabled). I've tried both [openlayers default] and [openlayers test]... test was a new preset I created to see if there was just a problem with default.

Comments

mcengland’s picture

OK... I figured out the need mess with filter settings (I'm sorry, I just started using Drupal a week ago and have no experience with PHP). I have finally been able to add a preset... but now I want to add KML or other layers. I can't find documentation of how to create a basic map using PHP snippets. The documentation shows all kinds of code for adding layers, etc... but assumes you understand PHP and Openlayers. Is there some way I can see how to create a basic map?

mcengland’s picture

As an example... the documentation in "Advanced Help" gives code that it describes as a default map. So I took that code, and stuck it between php tags. This gives me the following:

<?php
  $default_map = array(
    'projection' => '4326',
    'width' => 'auto',
    'default_layer' => 'openlayers_default_wms',
    'height' => '300px',
    'center' => array(
      'lat' => '0',
      'lon' => '0',
      'zoom' => '2',
    ),
    'options' => array(
      'displayProjection' => '4326',
    ),
    'controls' => array(
      'LayerSwitcher' => TRUE,
      'Navigation' => TRUE,
      'PanZoomBar' => TRUE,
      'MousePosition' => TRUE,
    ),
  );
?>

Can someone tell me why that doesn't work? I've used used other PHP snippets from the Drupal site without any problems, but this produces nothing.

zzolo’s picture

Version: 6.x-1.0-beta3 » 6.x-1.x-dev

Hey @mcengland. Sorry for the delayed response. How is this going?

So, what you have above is a PHP map array that can get rendered as a map with this module. The problem is that you have to let the module know about it by implementing a hook.

This is the implementation from the openlayers module.

/**
 * Implementation of hook_openlayers_presets().
 */
function openlayers_openlayers_presets() {
  $presets = array();

  // Create map array
  $default_map = array(
    'projection' => '4326',
    'width' => 'auto',
    'default_layer' => 'openlayers_default_wms',
    'height' => '300px',
    'center' => array(
      'lat' => '0',
      'lon' => '0',
      'zoom' => '2',
    ),
    'options' => array(
      'displayProjection' => '4326',
    ),
    'controls' => array(
      'LayerSwitcher' => TRUE,
      'Navigation' => TRUE,
      'PanZoomBar' => TRUE,
      'MousePosition' => TRUE,
    ),
  );

  // Create full preset array
  $presets['default'] = array(
    'preset_name' => 'default',
    'preset_title' => t('Default Map'),
    'preset_description' => t('This is the default map preset that comes with the OpenLayers module.'),
    'preset_data' => $default_map,
  );

  return $presets;
}

For your case, you would make a small Drupal module that implements this hook:

/**
 * Implementation of hook_openlayers_presets().
 */
function YOURMODULE_openlayers_presets() {
  // your map array here ..
}

Then this would show up in the preset interface and you can use it where ever you can use other maps.

zzolo’s picture

Title: Can't get filters to work » Adding custom maps with code
Component: OpenLayers Filters » OpenLayers API
zzolo’s picture

Closing. @mcengland let me/us know if we can help out some more. Hopefully I can add more docs soon.

zzolo’s picture

Status: Active » Closed (fixed)