Project

General

Profile

« Previous | Next » 

Revision ba706bf0

Added by Andreas Kohlbecker about 11 years ago

solving #3254 (geoserver hardcoded in openlayers_map.js)

View differences:

7.x/modules/cdm_dataportal/cdm_dataportal.install
27 27
}
28 28

  
29 29
/*
30
 * update funktions:
30
 * update functions:
31 31
 *
32 32
 * - 1 digit for Drupal core compatibility.
33 33
 * - 1 digit for your module's major release version (e.g., is this the 7.x-1.* (1) or 7.x-2.* (2) series of your module?). This digit should be 0 for initial porting of your module to a new Drupal core API.
......
35 35
 */
36 36

  
37 37
/**
38
 * update for RELEASE 3.13:
38
 * update for RELEASE 3.1.3:
39 39
 *  - reset edit_map_server variable to default
40 40
 */
41 41
function cdm_dataportal_update_7301() {
......
43 43
  variable_del('edit_map_server');
44 44
}
45 45

  
46
/**
47
 * update for RELEASE 3.1.4:
48
 *  - reset edit_map_server variable to default
49
 */
50
function cdm_dataportal_update_7302() {
51
  // once again reset edit_map_server variable to default
52
  variable_del('edit_map_server');
53
}
54

  
46 55
/**
47 56
 * @todo Please document this function.
48 57
 * @see http://drupal.org/node/1354
7.x/modules/cdm_dataportal/cdm_dataportal.module
147 147
    drupal_add_js('http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1', array('type' => 'external'));
148 148
  }
149 149

  
150
  $edit_map_service = get_edit_map_service_settings();
150 151
  // window.onload - is executed when the document and images etc is fully loaded
151 152
  // Query(document).ready - is executed much earlier, when the DOM is loaded
152 153
  drupal_add_js("
......
154 155

  
155 156
                window.onload = function () {
156 157
    			  // ---
157
                  jQuery('#openlayers_map').cdm_openlayers_map('"
158
                  . getEDITMapServiceURI() . "', {
158
                  jQuery('#openlayers_map').cdm_openlayers_map(
159
                   '" . $edit_map_service['base_uri'] . "',
160
                   '" . $edit_map_service['version'] . "',
161
                   {
159 162
                    legendPosition: 3,
160 163
                    displayWidth: '" . variable_get('cdm_dataportal_geoservice_display_width', FALSE) . "',
161 164
                    boundingBox: '" . variable_get('cdm_dataportal_geoservice_bounding_box', FALSE) . "',
......
164 167
                    showLayerSwitcher: " . (variable_get('cdm_dataportal_geoservice_showLayerSwitcher', TRUE) ? 'true' : 'false') . ",
165 168
                    baseLayerNames: [" . $layerNames . "],
166 169
                    defaultBaseLayerName: '" . $preferredLayer . "',
167
               	  });
168
               	  // ---
169
				};
170
               	  }
171
                );
172
               	// ---
173
			  };
170 174
          });
171 175
        ", array('type' => 'inline'));
172 176

  
......
186 190
 */
187 191
function get_image_map($width, $bounding_box = FALSE, $occurrenceQuery = FALSE, $distributionQuery = FALSE, $legendFormatQuery = FALSE, $map_caption = FALSE) {
188 192

  
189
  $server = getEDITMapServiceURI();
190

  
191
  if (!$server) {
192
    // Warning message.
193
    drupal_set_message(t(
194
      "No 'Geoservice Access Point' has been set so far.
195
      Please configure the variable 'Geoservice Access Point' here !url", array(
196
        '!url' => l(t('CDM Dataportal Settings'), 'admin/config/cdm_dataportal/geo'),
197
      )), 'warning');
198

  
199
    // Message to render.
200
    return '<p>' . t('No geoservice specified') . '</p>';
201
  }
202

  
203 193
  // Additional query parameters as set in the data portal admin section.
204 194
  $labels_on = variable_get('cdm_dataportal_geoservice_labels_on', 0);
205 195

  
......
211 201
    $query_string .= '&mlp=3&mc_s=Georgia,15,blue&mc=' . $map_caption;
212 202
  }
213 203

  
214
  if (getEDITMapServiceVersionNumber() >= 1.1) {
204
  if (get_edit_map_service_version_number() >= 1.1) {
215 205

  
216 206
    // Either occurrence or distribution - combined maps will be possible
217 207
    // in the future.
......
307 297
    }
308 298
  }
309 299

  
310
  $mapUri = url("$server/$map_service_script_name?$query_string");
300
  $mapUri = url(get_edit_map_service_full_uri() . '/' . $map_service_script_name . '?' .  $query_string);
311 301
  $out = '<img class="distribution_map" src="' . $mapUri . '" alt="Map" />';
312 302
  // Showing map caption.
313 303
  if ($map_caption) {
7.x/modules/cdm_dataportal/js/openlayers_map.js
1
function CdmOpenlayersMap(mapElement, mapserverBaseUrl, options){
1
function CdmOpenlayersMap(mapElement, mapserverBaseUrl, mapserverVersion, options){
2

  
3
  var mapServicePath = '/edit_wp5';
2 4

  
3 5
  var legendImgSrc = null;
4 6

  
......
87 89
        legendImgSrc = mergeQueryStrings('/GetLegendGraphic?SERVICE=WMS&VERSION=1.1.1', legendFormatQuery);
88 90
      }
89 91

  
90
      mapServiceRequest = mapserverBaseUrl + '/areas.php?' + distributionQuery;
92
      mapServiceRequest = mapserverBaseUrl + mapServicePath + '/' + mapserverVersion + '/areas.php?' + distributionQuery;
91 93

  
92 94
      jQuery.ajax({
93 95
          url: mapServiceRequest,
......
111 113
//        legendImgSrc = mergeQueryStrings('/GetLegendGraphic?SERVICE=WMS&VERSION=1.1.1', legendFormatQuery);
112 114
//      }
113 115

  
114
      mapServiceRequest = mapserverBaseUrl + '/points.php?' + occurrenceQuery;
116
      mapServiceRequest = mapserverBaseUrl + mapServicePath + '/' + mapserverVersion + '/points.php?' + occurrenceQuery;
115 117

  
116 118
      jQuery.ajax({
117 119
          url: mapServiceRequest,
......
166 168
  var addDataLayer = function(mapResponseObj){
167 169

  
168 170
    var layer;
169
    // add additional layers, get them from
170
    // the mapResponseObj
171
    // add additional layers, get them from the mapResponseObj
171 172
    if(mapResponseObj !== undefined){
172 173
      if(mapResponseObj.points_sld !== undefined){
173 174
        // it is a response from the points.php
174
        //TODO points_sld should be renamed to sld in response + fill path to sld should be given
175 175

  
176
    	var geoserverUri;
177
    	if(mapResponseObj.geoserver) {
178
    		geoserverUri = mapResponseObj.geoserver;
179
    	} else {
180
    		// it is an old servive which is not providing the corresponding geoserver URI, so we guess it
181
    		geoserverUri = mapserverBaseUrl + "/geoserver/wms";
182
    	}
183

  
184
    	//TODO points_sld should be renamed to sld in response + fill path to sld should be given
176 185
        layer = new OpenLayers.Layer.WMS.Untiled(
177 186
            'points',
178
            "http://edit.africamuseum.be/geoserver/wms/wms",
187
            geoserverUri,
179 188
            {layers: 'topp:rest_points' ,transparent:"true", format:"image/png"},
180 189
            dataLayerOptions );
181 190

  
182 191
        var sld = mapResponseObj.points_sld;
183 192
        if(sld.indexOf("http://") !== 0){
184

  
193
          // it is an old servive which is not providing the full sdl URI, so we guess it
185 194
          //  http://edit.africamuseum.be/synthesys/www/v1/sld/
186 195
          //  http://edit.br.fgov.be/synthesys/www/v1/sld/
187
          sld = "http://edit.africamuseum.be/synthesys/www/v1/sld/" + sld;
196
          sld =  mapserverBaseUrl + "/synthesys/www/v1/sld/" + sld;
188 197

  
189 198
        }
190 199

  
......
313 322
     }
314 323
   };
315 324

  
325
   /**
326
    * returns the version number contained in the version string:
327
    *   v1.1 --> 1.1
328
    *   v1.2_dev --> 1.2
329
    */
330
   var mapServerVersionNumber = function() {
331
	   var pattern = /v([\d\.]+).*$/;
332
	   var result;
333
	   if (result = mapserverVersion.match(pattern) !== null) {
334
		   return result[0];
335
	   } else {
336
		   return null;
337
	   }
338
   }
339

  
316 340
  /**
317 341
   *
318 342
   */
......
483 507

  
484 508
(function($){
485 509

  
486
  $.fn.cdm_openlayers_map = function(mapserverBaseUrl, options) {
510
  $.fn.cdm_openlayers_map = function(mapserverBaseUrl, mapserverVersion, options) {
487 511

  
488 512
    var opts = $.extend({},$.fn.cdm_openlayers_map.defaults, options);
489 513

  
490 514
    return this.each(function(){
491 515

  
492
      var openlayers_map = new CdmOpenlayersMap($(this), mapserverBaseUrl, opts);
516
      var openlayers_map = new CdmOpenlayersMap($(this), mapserverBaseUrl, mapserverVersion, options);
493 517
      openlayers_map.init();
494 518

  
495 519
     }); // END each
7.x/modules/cdm_dataportal/settings.php
41 41
  "cdm_dataportal_media_maxRows" => 1,
42 42
);
43 43

  
44
define('EDIT_MAPSERVER_V1_URI', 'http://edit.africamuseum.be/edit_wp5/v1'); // fall back server is http://edit.br.fgov.be
45
define('EDIT_MAPSERVER_V11_URI', 'http://edit.africamuseum.be/edit_wp5/v1.1'); // fall back server is http://edit.br.fgov.be
46
define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
44
/* ---- MAP SETTING CONSTANTS ---- */
45
/**
46
 * @var array of URIs eg. http://edit.africamuseum.be"
47
 *   An options array
48
 */
49
define('EDIT_MAPSERVER_URI', serialize(
50
    array(
51
      'http://edit.africamuseum.be'=>'Primary (http://edit.africamuseum.be)',
52
      'http://edit.br.fgov.be'=>'Secondary (http://edit.br.fgov.be)',
53
    )
54
  )
55
);
56
define('EDIT_MAPSERVER_PATH', '/edit_wp5');
57
/**
58
 * @var array of versions eg. "v1.2"
59
 *   An options array
60
 */
61
define('EDIT_MAPSERVER_VERSION', serialize(
62
    array(
63
      'v1' => 'v1' ,
64
      'v1.1' => 'v1.1',
65
      'v1.2_dev' => 'v1.2_dev'
66
    )
67
  )
68
);
69
define('EDIT_MAPSERVER_URI_DEFAULT', 'http://edit.africamuseum.be');
70
define('EDIT_MAPSERVER_VERSION_DEFAULT', 'v1.1');
47 71

  
48 72
// --- Taxon profile settings --- /
49 73
define('LAYOUT_SETTING_PREFIX', 'layout_');
......
55 79
    'glue' => ' ',
56 80
  )));
57 81

  
82
define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
83

  
84

  
58 85
/**
59 86
 * @todo document this function
60 87
 */
......
1305 1332
  /*
1306 1333
  GEO SERVER
1307 1334
  */
1308
  $form['geoserver'] = array(
1335
  $form['edit_map_server'] = array(
1309 1336
    '#type' => 'fieldset',
1310
    '#title' => t('Geo Server Settings'),
1337
    '#tree' => true,
1338
    '#title' => t('EDIT map service'),
1311 1339
    '#collapsible' => TRUE,
1312 1340
    '#collapsed' => TRUE,
1313 1341
    '#description' => t('Configuration and selection of your geo server.
1314 1342
      The Geo Server is responsible for generating the maps.'),
1315 1343
  );
1316 1344

  
1317
  $form['geoserver']['edit_map_server'] = array(
1345
  $current_geoserver_settings = get_edit_map_service_settings();
1346

  
1347
  $form['edit_map_server']['base_uri'] = array(
1318 1348
    '#type' => 'select',
1319
    '#title' => t('Geoservice access point URL') . ':',
1320
    '#default_value' => variable_get('edit_map_server', EDIT_MAPSERVER_V11_URI),
1321
    '#options' => array(
1322
      EDIT_MAPSERVER_V1_URI => 'EDIT Map Server v1',
1323
      EDIT_MAPSERVER_V11_URI => 'EDIT Map Server v1.1',
1324
      'ALTERNATIVE' => '-- Alternative URL --',
1325
    ),
1326
    '#description' => t('Select the Map Server you want the data portal to
1327
      connect. If you want to introduce a custom address just select the
1328
      Alternative URL value and fill the field Geoservice Access Point
1329
      - Alternative URL with the custom ip address.'),
1349
    '#title' => t('EDIT map service') . ':',
1350
    '#default_value' => $current_geoserver_settings['base_uri'],
1351
    '#options' => unserialize(EDIT_MAPSERVER_URI),
1352
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
1330 1353
  );
1331

  
1332
  $form['geoserver']['edit_map_server_alternative'] = array(
1333
    '#type' => 'textfield',
1334
    '#title' => t('Geoservice access point - alternative URL') . ':',
1335
    '#default_value' => variable_get('edit_map_server_alternative', ''),
1336
    '#description' => t('Alternative URL of a EDIT Map Service to be used by
1337
      this portal. You must choose the option <i>-- Alternative URL --</i> in
1338
      the chooser above to enable this url.'),
1354
  $form['edit_map_server']['version'] = array(
1355
      '#type' => 'select',
1356
      '#title' => t('Version') . ':',
1357
      '#default_value' => $current_geoserver_settings['version'],
1358
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
1359
      '#description' => t('The version of the EDIT map services'),
1339 1360
  );
1340 1361

  
1341 1362
  /*
......
1420 1441
      and can only be used with the EDIT map service version 1.1 or above.'),
1421 1442
  );
1422 1443

  
1423
  $edit_mapserver_version = getEDITMapServiceVersionNumber();
1444
  $edit_mapserver_version = get_edit_map_service_version_number();
1424 1445
  if ($edit_mapserver_version < 1.1) {
1425 1446
    $form['map_image']['#description'] = '<div class="messages warning">' . t("The selected EDIT map service version has to small version number: $edit_mapserver_version") . '</div>'
1426 1447
      . $form['map_image']['#description'];
......
1707 1728
}
1708 1729

  
1709 1730
/**
1710
 * @todo document this function.
1731
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
1732
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
1733
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
1734
 *  - version: the version, e.g.: v1.1
1735
 *
1736
 * @return array
1737
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
1711 1738
 */
1712
function getEDITMapServiceURI() {
1713

  
1714
  if (variable_get('edit_map_server', FALSE) == 'ALTERNATIVE') {
1715
    return (variable_get('edit_map_server_alternative', FALSE));
1716
  }
1717
  elseif (variable_get('edit_map_server', FALSE)) {
1718
    return variable_get('edit_map_server', FALSE);
1719
  }
1720
  else {
1721
    return EDIT_MAPSERVER_V1_URI;
1739
function get_edit_map_service_settings() {
1740

  
1741
  $settings = variable_get('edit_map_server', array(
1742
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
1743
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
1744
      )
1745
  );
1746
  // replace old non tree like settings by default
1747
  // TODO to be removed after release 3.1.5
1748
  if(!is_array($settings)){
1749
    variable_del('edit_map_server');
1750
    return get_edit_map_service_settings();
1722 1751
  }
1723 1752

  
1753
  return $settings;
1724 1754
}
1725 1755

  
1726 1756
/**
1727
 * @todo document this function.
1757
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
1758
 *
1759
 * @return string
1760
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
1761
 */
1762
function get_edit_map_service_full_uri() {
1763
  $settings = get_edit_map_service_settings();
1764
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
1765
}
1766

  
1767

  
1768
/**
1769
 * Returns the version number of the currently selected edit mapserver as a float
1728 1770
 *
1729 1771
 * @return float
1730 1772
 *   The version number of the currently selected edit mapserver as a float.
1731 1773
 *   Returns 0 on error.
1732 1774
 */
1733
function getEDITMapServiceVersionNumber() {
1775
function get_edit_map_service_version_number() {
1734 1776

  
1735
  $pattern = '/v([\d\.]+)$/';
1777
  $pattern = '/v([\d\.]+).*$/';
1736 1778

  
1737
  $url = getEDITMapServiceURI();
1738
  preg_match($pattern, $url, $matches, PREG_OFFSET_CAPTURE, 3);
1779
  $settings = get_edit_map_service_settings();
1780
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
1739 1781
  if (isset($matches[1])) {
1740 1782
    // Convert string to float.
1741 1783
    $version = 1 + $matches[1][0] - 1;
......
1743 1785
  }
1744 1786
  else {
1745 1787
    // Report error.
1746
    drupal_set_message(t(" Invalid version number in EDIT map service URL: '!edit_mapserver'", array('!edit_mapserver' => variable_get('edit_map_server', EDIT_MAPSERVER_V1_URI))), 'warning');
1788
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
1789
        array(
1790
          '!version' => $settings['version'],
1791
          'warning')
1792
        )
1793
      );
1747 1794
    return 0;
1748 1795
  }
1749 1796
}
1750 1797

  
1751 1798
/**
1752
 * returns the array of selected items in a options array
1799
 * Returns the array of selected items in a options array
1753 1800
 *
1754 1801
 * @param array $options
1755 1802
 *   An options array as generated by a form element like checkoxes, select ...,
7.x/modules/cdm_dataportal/theme/cdm_dataportal.descriptions.theme
1100 1100
function theme_cdm_distribution_map($variables) {
1101 1101
  $taxon = $variables['taxon'];
1102 1102
  $out = '';
1103
  $server = getEDITMapServiceURI();
1104

  
1105
  if (!$server) {
1106
    // Warning message.
1107
    drupal_set_message(t("No 'Geoservice Access Point' has been set so far. Please configure the variable 'Geoservice Access Point' here ") . l(t('CDM Dataportal Settings'), 'admin/config/cdm_dataportal/geo'), 'warning');
1108
    // Message to render.
1109
    return "<p>No geoservice specified</p>";
1110
  }
1103
  $settings = get_edit_map_service_settings();
1111 1104

  
1112 1105
  $fontStyles = array(
1113 1106
    0 => "plane",
......
1159 1152
    $map_service_script_name = "areas.php";
1160 1153

  
1161 1154
    // Apply Plain Image map settings.
1162
    if (getEDITMapServiceVersionNumber() >= 1.1) {
1155
    if (get_edit_map_service_version_number() >= 1.1) {
1163 1156
      /*
1164 1157
       * example : title=a:Naturalized++non-invasive
1165 1158
       * &ad=cyprusdivs:bdcode:a:5&as=a:ff9900,,0.1,&l=tdwg4
......
1220 1213
      }
1221 1214
    }
1222 1215

  
1223
    $mapUri = url("$server/$map_service_script_name?$query_string");
1216
    $mapUri = url(get_edit_map_service_full_uri() . '/' . $map_service_script_name . '? '. $query_string);
1224 1217
    $out .= '<img class="distribution_map" src="' . $mapUri . '" alt="Distribution Map" />';
1225 1218
  }
1226 1219
  return $out;

Also available in: Unified diff