1
votes

I have a content type with geo data that I'd like to display on a map based on some contextual filters. There are multiple views on the site with different configs. I have defined my map, its behaviors, default layer, etc. and it works with an "all nodes of x type" view using an Openlayers data overlay and a map display.

A second view has it's own data overlay with a different set of points and a map display. I'd like to reuse the same Openlayers map so that any future changes to behaviors, zoom levels, etc. don't need to be made across multiple maps.

The problem I'm having is that whatever layer I define as activated in the Openlayers map is the default layer for all the views using that map. I need some way to define a default activated layer based on the view, url, or something else. Any ideas on how to achieve this?

2

2 Answers

0
votes

First you have to create or clone and modify a view. Second, you have to create another Openlayers map in /admin/structure/openlayers/maps/list/, and at the layers and styles/overlay layers you have to enable the layer of the newly created view. Third, you have to edit the view and at the view format's settings you can select the new map.

0
votes

Came up with a single view solution awhile back and forgot to post it. This allows you to create a single view using a single OpenLayers Map block with multiple data overlays within the same view, setting the active one based on URL. The benefits of this approach are that a change to one field populates across all of the displays and changing the map's styling, behavior, etc. only needs to be done once. This simplifies maintenance and changes for folks.

Here's what worked: 1. Create you OpenLayers map, layer definitions, etc. as you normally would. 2. Create a new view with the Format: OpenLayers Map. Configure it as you normally would. 3. To the OpenLayers Map view, add new OpenLayers Data Overlay displays for each source. 4. Edit the OpenLayers Map. Under Overlay Layers, check enabled and in switcher for each new Data Overlay. In my case, the Activated checkboxes are all unchecked. 5. Implement hook_openlayers_map_preprocess_alter(). Here's what mine looks like

    function mymoduleortheme_openlayers_map_preprocess_alter(&$map = array()) {
      //$displayLayer['URL param'] = "map_data_overlay_machine_name";
      $displayLayer = array();
      $displayLayer['first-page'] = "openlayers_maps_openlayers_first_page_data";
      $displayLayer['another-page'] = "openlayers_maps_openlayers_another_page_data";

      $currentURI = array();
      $currentURI = explode("/", $_SERVER['REQUEST_URI']);

      foreach ($map['layer_switcher'] as $idx => $val) {    
        //Map data found, activate the correct
        if (isset($currentURI[2]) && isset($displayLayer[$currentURI[2]]) && $idx == $displayLayer[$currentURI[2]]) {
          $map['layer_activated'][$displayLayer[$currentURI[2]]] = $displayLayer[$currentURI[2]];
        }
        else
          $map['layer_switcher'][$idx] = 0;
      }
    }

Probably room for improvement, but it's working and does the trick. The switcher isn't used on this site so it's just CSS'd out.