commit 653e9c6b9347232510f5566cd4e38b163454a090
Author: Andreas Kohlbecker <a.kohlbecker@bgbm.org>
Date:   Mon Nov 28 12:40:36 2016 +0100

    maps documentation, refactoring of unused params etc, unique map container ids

diff --git a/modules/cdm_dataportal/cdm_dataportal.css b/modules/cdm_dataportal/cdm_dataportal.css
index 82ce0f33..a36ccbcb 100644
--- a/modules/cdm_dataportal/cdm_dataportal.css
+++ b/modules/cdm_dataportal/cdm_dataportal.css
@@ -491,7 +491,7 @@ a.label:visited {
  * ==== Maps ====
  */
 
-#openlayers_container {
+.openlayers-container {
   position: relative;
   z-index: 1;
   margin-bottom: 0.75em; /* Should match the margin-bottom of .description. */
diff --git a/modules/cdm_dataportal/includes/descriptions.inc b/modules/cdm_dataportal/includes/descriptions.inc
index 8ed067de..6fb67045 100644
--- a/modules/cdm_dataportal/includes/descriptions.inc
+++ b/modules/cdm_dataportal/includes/descriptions.inc
@@ -863,7 +863,7 @@ function compose_feature_block_items_nested($node, &$media_list, $feature_block_
     if (isset($descriptionElements['DistributionInfoDTO'])) {
       $distribution_map_query_parameters = $descriptionElements['DistributionInfoDTO']->mapUriParams;
     }
-    $map_render_element = compose_distribution_map($taxon, $distribution_map_query_parameters);
+    $map_render_element = compose_distribution_map($distribution_map_query_parameters);
     $block->content[] = $map_render_element;
 
     $dto_out_array = array();
diff --git a/modules/cdm_dataportal/includes/maps.inc b/modules/cdm_dataportal/includes/maps.inc
index 4f78c7b3..e7be150c 100644
--- a/modules/cdm_dataportal/includes/maps.inc
+++ b/modules/cdm_dataportal/includes/maps.inc
@@ -25,6 +25,7 @@
  *
  * compose_hook() implementation
  *
+ * @param $map_id
  * @param string $occurrence_query
  * @param string $distribution_query
  * @param string $legend_format_query
@@ -46,17 +47,11 @@
  *   Can be used to override the map_type setting stored in the settings variable CDM_MAP_DISTRIBUTION
  *   - 1: openlayers_map
  *   - 0: image_map
- *
- * @return array
- *    A drupal render array
- *
- * Similar compose function compose_distribution_map()
- *
+ * @return array A drupal render array
+ * A drupal render array
  * @ingroup compose
  */
-function compose_map($occurrence_query = NULL, $distribution_query = NULL,
-                     $legend_format_query = NULL, array $event_listeners = array(), $resizable = false,
-                     $force_map_type = NULL) {
+function compose_map($map_id, $occurrence_query = NULL, $distribution_query = NULL, $legend_format_query = NULL, array $event_listeners = array(), $resizable = false, $force_map_type = NULL) {
 
     $map_settings = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
 
@@ -66,18 +61,19 @@ function compose_map($occurrence_query = NULL, $distribution_query = NULL,
 
     if ($force_map_type == 1) {
       _add_jquery_ui();
-    $map_html = get_openlayers_map(
+      $map_html = cdm_map_openlayers(
+        $map_id,
         $occurrence_query,
         $distribution_query,
         $legend_format_query,
         $map_settings['caption'],
         $event_listeners,
         $resizable
-    );
+      );
     }
      else {
       $map_height = round($map_settings['image_map']['width'] / (float)$map_settings['aspect_ratio']);
-      $map_html = get_image_map(
+      $map_html = cdm_map_plain_image(
         $map_settings['image_map']['width'],
         $map_height,
         $occurrence_query,
@@ -90,6 +86,9 @@ function compose_map($occurrence_query = NULL, $distribution_query = NULL,
 }
 
 /**
+ * Adds the javascript for a openlayers map to the page as well as all javascript libs.
+ *
+ *
  * @param $map_settings
  *   The map settings array as retrieved by e.g. get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
  * @param array $event_listeners
@@ -208,7 +207,7 @@ function _add_js_openlayers_map($map_settings, array $event_listeners = array(),
 
 
 /**
- * @todo Enter description here ...
+ * Creates markup for an openlayers based dynamic map.
  *
  * @param string $bounding_box
  * @param string $occurrenceQuery
@@ -229,17 +228,21 @@ function _add_js_openlayers_map($map_settings, array $event_listeners = array(),
  *   see http://dev.openlayers.org/apidocs/files/OpenLayers/Map-js.html#OpenLayers.Map.events for more
  *
  * @return String
- *    rendered html
+ *    The markup for the map
  */
-function get_openlayers_map($occurrenceQuery = FALSE, $distributionQuery = FALSE,
+function cdm_map_openlayers($map_id, $occurrenceQuery = FALSE, $distributionQuery = FALSE,
                             $legendFormatQuery = FALSE, $map_caption = FALSE, array $event_listeners = array(),
                             $resizable = false) {
 
   $map_settings = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
 
+  if($map_id == NULL){
+    $map_id = "openlayers-container-" . sha1($occurrenceQuery . $distributionQuery);
+  }
+
   _add_js_openlayers_map($map_settings, $event_listeners, $resizable);
 
-  $out = '<div id="openlayers_container" class="openlayers_width ui-widget-content" style="width: 100%;">';
+  $out = '<div id="' . $map_id . '" class="openlayers-container openlayers_width ui-widget-content" style="width: 100%;">';
   $out .= '<div id="openlayers_map" class="smallmap" style="width:100%; height:100%; margin: 10px;"';
 
   // Additional query parameters as set in the data portal admin section.
@@ -284,15 +287,16 @@ function get_openlayers_map($occurrenceQuery = FALSE, $distributionQuery = FALSE
 
 
 /**
- * Composes the render array for a distribution map of the given taxon.
+ * Composes the render array for a distribution map using the given distribution query string.
  *
  * The distribution map can either be a plain image or a dynamic open layers map
  * depending on the settings.
  *
  * compose_hook() implementation
  *
- * @param $taxon
- *   The CDM Taxon instance to create the distribution map for.
+ * @param string $query_string
+ *    An EDIT map services distribution query string
+ *
  * @return array
  *    A drupal render array
  *
@@ -300,9 +304,7 @@ function get_openlayers_map($occurrenceQuery = FALSE, $distributionQuery = FALSE
  *
  * @ingroup compose
  */
-function compose_distribution_map($taxon, $query_string) {
-
-  $out = '';
+function compose_distribution_map($query_string) {
 
   $fontStyles = array(
       0 => "plane",
@@ -335,7 +337,7 @@ function compose_distribution_map($taxon, $query_string) {
       . ";fontSize" . urlencode(':') .  $map_settings['legend']['font_size']
       . "&SLD=";
 
-    /*$out .= get_openlayers_map(
+    /*$out .= cdm_map_openlayers(
         $map_settings['bbox'],
         NULL,
         $query_string,
@@ -347,7 +349,7 @@ function compose_distribution_map($taxon, $query_string) {
   else {
     $legendFormatQueryStr = '';
     /*
-        get_image_map(
+        cdm_map_plain_image(
             $map_settings['image_map']['width'],
             $map_settings['image_map']['height'],
             $map_settings['bbox'],
@@ -358,7 +360,7 @@ function compose_distribution_map($taxon, $query_string) {
         );
     */
   }
-  $out = compose_map(NULL, $query_string, $legendFormatQueryStr);
+  $out = compose_map(NULL, NULL, $query_string, $legendFormatQueryStr);
 
   return $out;
 }
@@ -367,19 +369,19 @@ function compose_distribution_map($taxon, $query_string) {
 
 
 /**
- * @todo Enter description here ...
+ * Composes the markup for a plain image map.
  *
- * @param unknown_type $width
- * @param unknown_type $occurrenceQuery
- * @param unknown_type $distributionQuery
- * @param unknown_type $legendFormatQuery
- * @param unknown_type $map_caption
+ * @param int $width
+ * @param string $occurrenceQuery
+ * @param string $distributionQuery
+ * @param string $legendFormatQuery
+ * @param string $map_caption
  *
 * @return String
  *    rendered html
  */
-function get_image_map($width, $height= NULL, $occurrenceQuery = FALSE, $distributionQuery = FALSE,
-                       $legendFormatQuery = FALSE, $map_caption = FALSE) {
+function cdm_map_plain_image($width, $height= NULL, $occurrenceQuery = FALSE, $distributionQuery = FALSE,
+                             $legendFormatQuery = FALSE, $map_caption = FALSE) {
 
   $map_settings = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
 
diff --git a/modules/cdm_dataportal/includes/pages.inc b/modules/cdm_dataportal/includes/pages.inc
index 083f295c..28a4bce5 100644
--- a/modules/cdm_dataportal/includes/pages.inc
+++ b/modules/cdm_dataportal/includes/pages.inc
@@ -94,7 +94,7 @@ function cdm_dataportal_taxon_page_specimens($taxon) {
             $occurrence_query = $occurrence_queryDto->occurrenceQuery;
             $legend_format_query = null;
             $distribution_query = NULL;
-            $render_array['map'] = compose_map($occurrence_query, $distribution_query, $legend_format_query, array());
+            $render_array['map'] = compose_map(NULL, $occurrence_query, $distribution_query, $legend_format_query, array());
         }
     }
     if(variable_get('cdm_dataportal_compressed_specimen_derivate_table')){
diff --git a/modules/cdm_dataportal/settings.php b/modules/cdm_dataportal/settings.php
index 2c8fefe2..6cf7011c 100644
--- a/modules/cdm_dataportal/settings.php
+++ b/modules/cdm_dataportal/settings.php
@@ -2613,12 +2613,10 @@ function cdm_settings_geo($form, &$form_state) {
            ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
            '.<br/>Hold down Strg and drag with your mouse to select a bbox to zoom to. <br/>The bbox of the visible area of the map is always displayed below the map.')
   );
-  $form['map_preview']['openlayers_map'] = compose_map(NULL, $dummy_distribution_query, NULL,
-    array(
-      'move' => "this.cdmOpenlayersMap.printInfo",
-      '#execute' => "this.cdmOpenlayersMap.printInfo"
-    ),
-    true // resizable
+  $form['map_preview']['openlayers_map'] = compose_map(NULL, NULL, $dummy_distribution_query, NULL, array(
+    'move' => "this.cdmOpenlayersMap.printInfo",
+    '#execute' => "this.cdmOpenlayersMap.printInfo"
+  ), true // resizable
   );
 
   /*
