Openlayers

Edit: As Pol said in comments, you can use the openlayers_taxonomy module to do this. But it turns out I had to use content types as layers too, so this technique still was useful to me. Thank you Pol :)

I wanted to create layers depending on some taxonomy terms with Openlayers. But the only way to create layers with views is to add one display per layer. What if you want as many layers as terms ? Some Views trickery to the rescue !

  1. Create your Openlayers view.
  2. Add a layer display for the first term.
  3. Create a filter for the term.
  4. Export the view through code.

Then, edit the view code to create one layer per term :
/**
* Implements hook_views_default_views().
*/
function MYMODULE_views_default_views() {
$vocabulary = taxonomy_vocabulary_machine_name_load('VOCABULARY_NAME');
$terms = taxonomy_get_tree($vocabulary->vid);
// Your view code for the master display...
foreach($terms as $term) {
$handler = $view->new_display('openlayers', $term->name, 'layer_' . $term->tid);
// The display code...
$handler->display->display_options['filters']['tid']['value'] = array(

Syndicate content