Project

General

Profile

Revision 2bbc28c8

ID2bbc28c83e2693264d2434fd062cad50c835e775
Parent d7abe39c
Child 589a392b

Added by Andreas Kohlbecker over 7 years ago

adding support for custom wms and solving some bugs

View differences:

7.x/modules/cdm_dataportal/includes/maps.inc
78 78
}
79 79

  
80 80
/**
81
 *
81
 * @param $map_settings
82
 *   The map settings array as retrieved by e.g. get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
82 83
 * @param array $event_listeners
83 84
 *   An associative array of with OpenLayers.Map event names as key and corresponding js callbacks.
84 85
 *   In addition to the event names '#execute' as key is also allowed.
......
92 93
 *            force execution of the given callback after registration of the event handlers
93 94
 *   see http://dev.openlayers.org/apidocs/files/OpenLayers/Map-js.html#OpenLayers.Map.events for more
94 95
 */
95
function _add_js_openlayers_map(array $event_listeners = array()) {
96
function _add_js_openlayers_map($map_settings, array $event_listeners = array()) {
96 97

  
97 98
  _add_js_openlayers();
98 99

  
99
  $map_settings = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
100
  $baseLayers = $map_settings['openlayers']['base_layers'];
100
  $edit_map_service = get_edit_map_service_settings();
101

  
101 102
  $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
102 103

  
103 104
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/map/openlayers_map.js');
104 105
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/map/openlayers_layers.js');
105 106

  
106

  
107
  if (!is_array($baseLayers) || count($baseLayers) == 0) {
108
    $baseLayers = array(
109
        'metacarta_vmap0' => 'Metacarta Vmap0',
110
        'PREFERRED' => 'metacarta_vmap0',
111
    );
112
  }
113
  $layerNames = '';
114
  foreach ($baseLayers as $layerName => $layerLabel) {
115
    if ($layerName == 'PREFERRED') {
116
      $preferredLayer = $baseLayers['PREFERRED'];
107
  $cdm_openlayers_options = array(
108
      'legendPosition'  => '3',
109
      'boundingBox' => "'" . $map_settings['bbox'] . "'",
110
      'distributionOpacity' => "'" . $map_settings['distribution_opacity'] . "'",
111
      'legendOpacity' => "'" . $map_settings['legend']['opacity'] . "'",
112
      'showLayerSwitcher' => $map_settings['openlayers']['show_layer_switcher']  ==  1,
113
      'displayOutsideMaxExtent' => $map_settings['openlayers']['display_outside_max_extent'] == 1
114
      // if no baseLayerNames or defaultBaseLayerName are not defined
115
      // the defaults in cdm_openlayers.js will be used
116
  );
117

  
118
  // --- setting the base layer options
119
  if (is_array($map_settings['openlayers']['base_layers']) && count($map_settings['openlayers']['base_layers']) > 0) {
120

  
121
    $layer_names = $map_settings['openlayers']['base_layers'];
122

  
123
    if(isset($layer_names['PREFERRED'])){
124
      $cdm_openlayers_options['defaultBaseLayerName'] = $layer_names['PREFERRED'];
125
      unset($layer_names['PREFERRED']);
117 126
    }
118
    else {
119
      $layerNames .= ($layerNames ? ', ' : '') . "'$layerName'";
127

  
128
    $cdm_openlayers_options['baseLayerNames'] = array_values($layer_names);
129

  
130
    if (isset($layer_names['gmap']) || isset($layer_names['gsat']) || isset($layer_names['ghyb'])) {
131
      // gmaps version 2 (needs api key)
132
      drupal_add_js('http://maps.google.com/maps?file=api&v=2&key=' . $gmap_api_key . '', array('type' => 'external'));
133
      // gmaps version 3 (does not need api key)
134
  //     drupal_add_js('http://maps.google.com/maps?file=api&v=3&sensor=false', array('type' => 'external'));
135
      drupal_add_js('http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1', array('type' => 'external'));
120 136
    }
121
  }
122 137

  
123
  if (isset($baseLayers['gmap']) || isset($baseLayers['gsat']) || isset($baseLayers['ghyb'])) {
124
    // gmaps version 2 (needs api key)
125
    drupal_add_js('http://maps.google.com/maps?file=api&v=2&key=' . $gmap_api_key . '', array('type' => 'external'));
126
    // gmaps version 3 (does not need api key)
127
//     drupal_add_js('http://maps.google.com/maps?file=api&v=3&sensor=false', array('type' => 'external'));
128
    drupal_add_js('http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1', array('type' => 'external'));
129 138
  }
130 139

  
140
  // --- custom wms base layer
141
  $map_settings['openlayers']['custom_wms_base_layer']['params'] = json_decode($map_settings['openlayers']['custom_wms_base_layer']['params']);
142
  $cdm_openlayers_options['customWMSBaseLayerData'] = $map_settings['openlayers']['custom_wms_base_layer'];
143

  
144
  // --- eventhandlers
131 145
  $event_listeners_js = '';
132 146
  $execute_handler = '';
133 147
  foreach($event_listeners as $event=>$js_callback){
......
138 152
    }
139 153
  }
140 154

  
141
  $edit_map_service = get_edit_map_service_settings();
155
//   // combine keys and values
156
//   foreach($cdm_openlayers_options as $key=>&$val){
157
//     $val = $key . ": " . $val;
158
//   };
159

  
142 160
  // window.onload - is executed when the document and images etc is fully loaded
143 161
  // Query(document).ready - is executed much earlier, when the DOM is loaded
144 162
  drupal_add_js("
......
147 165
                  var map_container = jQuery('#openlayers_map').cdm_openlayers_map(
148 166
                   '" . $edit_map_service['base_uri'] . "',
149 167
                   '" . $edit_map_service['version'] . "',
150
                   {
151
                    legendPosition: 3,
152
                    boundingBox: '" . $map_settings['bbox'] . "',
153
                    distributionOpacity: '" . $map_settings['distribution_opacity'] . "',
154
                    legendOpacity: '" . $map_settings['legend']['opacity'] . "',
155
                    showLayerSwitcher: " . ($map_settings['openlayers']['show_layer_switcher'] ? 'true' : 'false') . ",
156
                    baseLayerNames: [" . $layerNames . "],
157
                    defaultBaseLayerName: '" . $preferredLayer . "'
158
                   }
168
                   " .  json_encode($cdm_openlayers_options) . "
159 169
                );
160 170
                map_container.each(function(){
161 171
                        this.cdmOpenlayersMap.registerEvents({" . $event_listeners_js . "});
......
195 205
 */
196 206
function get_openlayers_map($width, $height, $bounding_box = FALSE, $occurrenceQuery = FALSE, $distributionQuery = FALSE, $legendFormatQuery = FALSE, $map_caption = FALSE, array $event_listeners = array()) {
197 207

  
198
  _add_js_openlayers_map($event_listeners);
199

  
200 208
  $map_settings = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
201 209

  
210
  _add_js_openlayers_map($map_settings, $event_listeners);
211

  
202 212
  $out = '<div id="openlayers">';
203 213
  $out .= '<div id="openlayers_map" class="smallmap"';
204 214
  if($width) {
7.x/modules/cdm_dataportal/js/map/openlayers_layers.js
97 97
              return  new OpenLayers.Layer.OSM();
98 98

  
99 99
          case 'mapquest_open':
100
              baselayer = new OpenLayers.Layer.XYZ(
100
              // see http://developer.mapquest.com/web/products/open/map
101
              return new OpenLayers.Layer.XYZ(
101 102
                      "MapQuest",
102 103
                      [
103 104
                          "http://otile1.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.png",
......
106 107
                          "http://otile4.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.png"
107 108
                      ],
108 109
                      {
110
                          // If using the MapQuest-OSM tiles, OpenStreetMap must be given credit for the data
109 111
                          attribution: "Data, imagery and map information provided by <a href='http://www.mapquest.com/'  target='_blank'>MapQuest</a>, <a href='http://www.openstreetmap.org/' target='_blank'>Open Street Map</a> and contributors, <a href='http://creativecommons.org/licenses/by-sa/2.0/' target='_blank'>CC-BY-SA</a>  <img src='http://developer.mapquest.com/content/osm/mq_logo.png' border='0'>",
110 112
                          transitionEffect: "resize"
111 113
                      }
112 114
                  );
113 115

  
114 116
          case 'mapquest_sat':
115
              baselayer = new OpenLayers.Layer.XYZ(
117
              // see http://developer.mapquest.com/web/products/open/map
118
              return new OpenLayers.Layer.XYZ(
116 119
                      "MapQuest Sattelite",
117 120
                      [
118
                          "http://otile1.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.png",
119
                          "http://otile2.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.png",
120
                          "http://otile3.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.png",
121
                          "http://otile4.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.png"
121
                          "http://otile1.mqcdn.com/tiles/1.0.0/sat/${z}/${x}/${y}.png",
122
                          "http://otile2.mqcdn.com/tiles/1.0.0/sat/${z}/${x}/${y}.png",
123
                          "http://otile3.mqcdn.com/tiles/1.0.0/sat/${z}/${x}/${y}.png",
124
                          "http://otile4.mqcdn.com/tiles/1.0.0/sat/${z}/${x}/${y}.png"
122 125
                      ],
123 126
                      {
127
                          // If using the MapQuest-OSM tiles, OpenStreetMap must be given credit for the data
124 128
                          attribution: "Data, imagery and map information provided by <a href='http://www.mapquest.com/'  target='_blank'>MapQuest</a>, <a href='http://www.openstreetmap.org/' target='_blank'>Open Street Map</a> and contributors, <a href='http://creativecommons.org/licenses/by-sa/2.0/' target='_blank'>CC-BY-SA</a>  <img src='http://developer.mapquest.com/content/osm/mq_logo.png' border='0'>",
125 129
                          transitionEffect: "resize"
126 130
                      }
7.x/modules/cdm_dataportal/js/map/openlayers_map.js
35 35
         * the maxExtent if the aspect ratio of the map and of the baselayer
36 36
         * are not equal
37 37
         */
38
        displayOutsideMaxExtent: true,
38
        displayOutsideMaxExtent: false,
39 39
        customWMSBaseLayerData: {
40
            name: "Euro+Med",
41
            url: "http://edit.africamuseum.be/geoserver/topp/wms",
42
            params: {layers: "topp:em_tiny_jan2003", format:"image/png", tiled: true},
43
            projection: "EPSG:7777777",
44
            maxExtent: "-1600072.75, -1800000, 5600000, 5850093",
45
            unit: 'm'
40
            name: null,
41
            url: null,
42
            params: null,
43
            projection: null,
44
            max_extent: null,
45
            units: null
46 46
        }
47
//        customWMSBaseLayerData: {
48
//            name: "Euro+Med",
49
//            url: "http://edit.africamuseum.be/geoserver/topp/wms",
50
//            params: {layers: "topp:em_tiny_jan2003", format:"image/png", tiled: true},
51
//            projection: "EPSG:7777777",
52
//            maxExtent: "-1600072.75, -1800000, 5600000, 5850093",
53
//            units: 'm'
54
//        }
47 55
    };
48 56
})(jQuery);
49 57

  
......
87 95
   * @param mapElement
88 96
   * @param mapserverBaseUrl
89 97
   * @param mapserverVersion
90
   * @param options
98
   * @param opts
91 99
   * @returns
92 100
   */
93
window.CdmOpenLayers.Map = function(mapElement, mapserverBaseUrl, mapserverVersion, options){
101
window.CdmOpenLayers.Map = function(mapElement, mapserverBaseUrl, mapserverVersion, opts){
94 102

  
95 103
    var mapServicePath = '/edit_wp5';
96 104

  
......
99 107
        console = { log: function() { } };
100 108
    }
101 109

  
110
    // sanitize given options
111
    try {
112
        opts.customWMSBaseLayerData.max_extent = OpenLayers.Bounds.fromString(opts.customWMSBaseLayerData.max_extent);
113
    } catch(e){
114
        opts.customWMSBaseLayerData.max_extent = null;
115
    }
116

  
102 117

  
103 118
    var legendImgSrc = null;
104 119

  
......
138 153
     */
139 154
    this.init = function(){ // public function
140 155

  
141
      createLayers(options.baseLayerNames, options.defaultBaseLayerName, options.customWMSBaseLayerData);
156
      createLayers(opts.baseLayerNames, opts.defaultBaseLayerName, opts.customWMSBaseLayerData);
142 157

  
143 158
      initMap();
144 159

  
......
148 163

  
149 164
      if(distributionQuery !== undefined){
150 165
        if(typeof legendPosition == 'number'){
151
          distributionQuery = mergeQueryStrings(distributionQuery, 'legend=1&mlp=' + options.legendPosition);
166
          distributionQuery = mergeQueryStrings(distributionQuery, 'legend=1&mlp=' + opts.legendPosition);
152 167
        }
153 168

  
154 169
        distributionQuery = mergeQueryStrings(distributionQuery, 'callback=?');
......
172 187
      var occurrenceQuery = mapElement.attr('occurrenceQuery');
173 188
      if(occurrenceQuery !== undefined){
174 189
//        if(typeof legendPosition == 'number'){
175
//          occurrenceQuery = mergeQueryStrings(distributionQuery, 'legend=1&mlp=' + options.legendPosition);
190
//          occurrenceQuery = mergeQueryStrings(distributionQuery, 'legend=1&mlp=' + opts.legendPosition);
176 191
//        }
177 192

  
178 193
        occurrenceQuery = mergeQueryStrings(occurrenceQuery, 'callback=?');
......
215 230

  
216 231
    /**
217 232
     * Prints info on the current map into the jQuery element
218
     * as set in the options (options.infoElement)
233
     * as set in the options (opts.infoElement)
219 234
     * public function
220 235
     *
221 236
     * @param jQuery $element
......
227 242

  
228 243
        var info = "<dl>";
229 244
        info += "<dt>zoom:<dt><dd>" + map.getZoom() + "</dd>";
230
        info += "<dt>map resolution:<dt><dd>" + map.getResolution() + "</dd>";
231
        info += "<dt>map max resolution:<dt><dd>" + map.getMaxResolution() + "</dd>";
232
        info += "<dt>map scale:<dt><dd>" + map.getScale() + "</dd>";
233
        info += "<dt>map extent bbox:<dt><dd>" + map.getExtent().toBBOX() + " (" + mapExtendDegree.toBBOX() + ")</dd>";
234
        info += "<dt>map maxExtent bbox:<dt><dd>" + map.getMaxExtent().toBBOX() + "</dd>";
235
        info += "<dt>baselayer projection:<dt><dd>" + map.baseLayer.projection.getCode() + "</dd>";
245
        if(opts.debug){
246
            info += "<dt>map resolution:<dt><dd>" + map.getResolution() + "</dd>";
247
            info += "<dt>map max resolution:<dt><dd>" + map.getMaxResolution() + "</dd>";
248
            info += "<dt>map scale:<dt><dd>" + map.getScale() + "</dd>";
249
            info += "<dt>map extent bbox:<dt><dd>" + map.getExtent().toBBOX() + " (" + mapExtendDegree.toBBOX() + ")</dd>";
250
            info += "<dt>map maxExtent bbox:<dt><dd>" + map.getMaxExtent().toBBOX() + "</dd>";
251
            info += "<dt>baselayer projection:<dt><dd>" + map.baseLayer.projection.getCode() + "</dd>";
252
        } else {
253
            info += "<dt>bbox:<dt><dd>" + mapExtendDegree.toBBOX() + "</dd>";
254
        }
236 255
        info += "</dl>";
237 256

  
238 257
        if(infoElement == null){
......
248 267
    var initMap = function(){
249 268

  
250 269

  
251
      if(options.showLayerSwitcher === true){
270
      if(opts.showLayerSwitcher === true){
252 271
          defaultControls.push(new OpenLayers.Control.LayerSwitcher({'ascending':false}));
253 272
      }
254 273

  
......
256 275
      var maxResolution = null;
257 276
      // gmaps has no maxExtent at this point, need to check for null
258 277
      if(defaultBaseLayer.maxExtent != null){
259
          maxResolution = Math[(options.displayOutsideMaxExtent ? 'max' : 'min')](
278
          maxResolution = Math[(opts.displayOutsideMaxExtent ? 'max' : 'min')](
260 279
                      defaultBaseLayer.maxExtent.getWidth() / mapWidth,
261 280
                      defaultBaseLayer.maxExtent.getHeight() / mapHeight
262 281
                    );
......
289 308
             // fractional tiles are not supported by XYZ layers like OSM so this option would
290 309
             // however break the tile retrieval for OSM (e.g.: tile for frational zoom level
291 310
             // 1.2933333333333332 = http://b.tile.openstreetmap.org/1.2933333333333332/1/0.png)
292
             // fractionalZoom: 1,
311
             fractionalZoom: defaultBaseLayer.CLASS_NAME != "OpenLayers.Layer.OSM" && defaultBaseLayer.CLASS_NAME != "OpenLayers.Layer.XYZ",
293 312

  
294
              eventListeners: options.eventListeners
313
              eventListeners: opts.eventListeners
295 314

  
296 315
          }
297 316
      );
......
301 320
      map.setBaseLayer(defaultBaseLayer);
302 321

  
303 322
      // calculate the bounds to zoom to
304
      zoomToBounds = zoomToBoundsFor(options.boundingBox, defaultBaseLayer);
323
      zoomToBounds = zoomToBoundsFor(opts.boundingBox, defaultBaseLayer);
305 324
      zoomToBounds = cropBoundsToAspectRatio(zoomToBounds, map.getSize().w / map.getSize().h);
306 325
      console.log("zoomToBounds: " + zoomToBounds);
307 326

  
......
309 328
      map.zoomToExtent(zoomToBounds, true);
310 329

  
311 330
      // readjust if the zoom level is out side of the min max
312
//      if(map.getZoom() > options.maxZoom){
313
//        map.zoomTo(options.maxZoom);
314
//      } else if(map.getZoom() < options.minZoom){
315
//        map.zoomTo(options.minZoom);
331
//      if(map.getZoom() > opts.maxZoom){
332
//        map.zoomTo(opts.maxZoom);
333
//      } else if(map.getZoom() < opts.minZoom){
334
//        map.zoomTo(opts.minZoom);
316 335
//      }
317 336

  
318 337
    };
......
366 385
                {layers: layerByNameMap[layerData.tdwg] ,transparent:"true", format:"image/png"},
367 386
                dataLayerOptions );
368 387
            layer.params.SLD = layerData.sld;
369
            layer.setOpacity(options.distributionOpacity);
388
            layer.setOpacity(opts.distributionOpacity);
370 389
            map.addLayers([layer]);
371 390

  
372 391
          }
......
384 403
          }
385 404
          map.zoomToExtent(dataBounds, false);
386 405

  
387
          if(map.getZoom() > options.maxZoom){
388
            map.zoomTo(options.maxZoom);
389
          } else if(map.getZoom() < options.minZoom){
390
            map.zoomTo(options.minZoom);
406
          if(map.getZoom() > opts.maxZoom){
407
            map.zoomTo(opts.maxZoom);
408
          } else if(map.getZoom() < opts.minZoom){
409
            map.zoomTo(opts.minZoom);
391 410
          }
392 411
        }
393 412

  
394 413

  
395
        if(options.legendPosition !== undefined && mapResponseObj.legend !== undefined){
414
        if(opts.legendPosition !== undefined && mapResponseObj.legend !== undefined){
396 415
          var legendSrcUrl = mapResponseObj.geoserver + legendImgSrc + mapResponseObj.legend;
397 416
          addLegendAsElement(legendSrcUrl);
398 417
          //addLegendAsLayer(legendSrcUrl, map);
......
407 426
    var addLegendAsElement= function(legendSrcUrl){
408 427

  
409 428
      mapElement.after('<div class="openlayers_legend"><img src="' + legendSrcUrl + '"></div>');
410
      mapElement.next('.openlayers_legend').css('opacity', options.legendOpacity).find('img').load(function () {
429
      mapElement.next('.openlayers_legend').css('opacity', opts.legendOpacity).find('img').load(function () {
411 430
        jQuery(this).parent()
412 431
          .css('position', 'relative')
413 432
          .css('z-index', '1002')
......
423 442

  
424 443
      // 1. download imge to find height and width
425 444
      mapElement.after('<div class="openlayers_legend"><img src="' + legendSrcUrl + '"></div>');
426
      mapElement.next('.openlayers_legend').css('display', 'none').css('opacity', options.legendOpacity).find('img').load(function () {
445
      mapElement.next('.openlayers_legend').css('display', 'none').css('opacity', opts.legendOpacity).find('img').load(function () {
427 446

  
428 447
        w = mapElement.next('.openlayers_legend').find('img').width();
429 448
        h = mapElement.next('.openlayers_legend').find('img').height();
......
471 490
      *
472 491
      */
473 492
     var createLayers = function( baseLayerNames, defaultBaseLayerName, customWMSBaseLayerData){
474
       var i = 0;
475
       for(; i <  baseLayerNames.length; i++) {
476
         baseLayers[i] = window.CdmOpenLayers.getLayerByName(baseLayerNames[i]);
493

  
494
       for(var i = 0; i <  baseLayerNames.length; i++) {
495
          // create the layer
496
          if (baseLayerNames[i] == "custom_wms_base_layer_1"){
497
             baseLayers[i] = createWMSBaseLayer(
498
                     customWMSBaseLayerData.name,
499
                     customWMSBaseLayerData.url,
500
                     customWMSBaseLayerData.params,
501
                     customWMSBaseLayerData.projection,
502
                     customWMSBaseLayerData.units,
503
                     customWMSBaseLayerData.max_extent
504
                  );
505
         } else {
506
             baseLayers[i] = window.CdmOpenLayers.getLayerByName(baseLayerNames[i]);
507
         }
508
         // set default baselayer
477 509
         if(baseLayerNames[i] == defaultBaseLayerName){
478 510
           defaultBaseLayer = baseLayers[i];
479 511
         }
480
       }
481
       if(false && customWMSBaseLayerData){
482
            var wmsLayer = createWMSBaseLayer(
483
                   customWMSBaseLayerData.name,
484
                   customWMSBaseLayerData.url,
485
                   customWMSBaseLayerData.params,
486
                   customWMSBaseLayerData.projection,
487
                   customWMSBaseLayerData.unit,
488
                   OpenLayers.Bounds.fromString(customWMSBaseLayerData.maxExtent)
489
                );
490
           // FIXME remove HACK (customWMSBaseLayerData as default)
491
           baseLayers[i++] = wmsLayer;
492
           defaultBaseLayer = wmsLayer;
512

  
493 513
       }
494 514
     };
495 515

  
......
609 629
      * @param Object projection
610 630
      *    A OpenLayers.Projection object
611 631
      */
612
     var createWMSBaseLayer= function(name, url, params, projection, unit, maxExtent){
632
     var createWMSBaseLayer= function(name, url, params, projection, units, maxExtent){
613 633

  
614 634
         if(maxExtent == null){
615 635
             maxExtent = CdmOpenLayers.mapExtends.epsg_4326.clone();
......
623 643
                 {
624 644
                   maxExtent: maxExtent,
625 645
                   projection: projection,
626
                   unit: unit,
646
                   units: units,
627 647
                   isBaseLayer: true,
628 648
                   displayInLayerSwitcher: true
629 649
                 }
7.x/modules/cdm_dataportal/settings.php
261 261
      // it is sufficient to define the preferred layer,
262 262
      // since it will automatically be enabled:
263 263
      'PREFERRED' => 'osgeo_vmap0'),
264
    'show_layer_switcher' => TRUE
264
     'custom_wms_base_layer' => array(
265
            'name' => NULL,
266
            'url' => NULL,
267
            'params' =>  NULL,
268
            'projection' => NULL,
269
            'max_extent' => NULL,
270
            'units' => NULL
271
     ),
272
    'show_layer_switcher' => TRUE,
273
    'display_outside_max_extent' => FALSE
265 274
  ),
266 275
  'legend' => array(
267 276
    'show' => TRUE,
......
1605 1614
      '#title' => t('Map preview'),
1606 1615
      '#collapsible' => FALSE,
1607 1616
      '#description' => 'The preview of the map'
1608
       . ($dummy_distribution_query != null ? ' may not be accurate in case if image maps, please check the map display in the taxon pages.': '.')
1617
       . ($dummy_distribution_query != null ?
1618
           ' may not be accurate in case if image maps, please check the map display in the taxon pages.':
1619
           '.<br/>Hold down Strg and drag with your mouse to select a bbox to zoom to. <br/>The bbox of the visisble area of the map is always displayed below the map.')
1609 1620
  );
1610 1621
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL,
1611 1622
      array(
......
1701 1712
    '#default_value' => $map_distribution['bbox'],
1702 1713
    '#description' => t('The bounding box defines the area to be initially displayed in maps.
1703 1714
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
1704
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.'),
1715
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
1716
      <strong>TIP: </strong>You can use the map preview above to choose a bbox from the map. Maybe you need to change the map type to OpeLayers.
1717
      Hold down Strg and drag with your mouse to select a bbox to zoom to. The bbox of the visisble area of the map is always displayed
1718
      below the map from where you can copy the bbox string.</p>'),
1705 1719
  );
1706 1720

  
1707 1721
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
......
1795 1809
    '#description' => '',
1796 1810
  );
1797 1811

  
1812

  
1813
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
1814
      '#type' => 'checkbox',
1815
      '#title' => 'Display outside max extent',
1816
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
1817
      '#description' => t('Allows the map to display parts of the layers which are outside
1818
         the max extent if the aspect ratio of the map and of the baselayer
1819
         are not equal.'),
1820
  );
1821

  
1822
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
1823
      '#type' => 'checkbox',
1824
      '#title' => 'Show Layer Switcher',
1825
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
1826
      '#description' => 'The Layer Switcher control displays a table of contents
1827
      for the map.  This allows the user interface to switch between
1828
      base layers and to show or hide overlays.  By default the switcher is
1829
      shown minimized on the right edge of the map, the user may expand it
1830
      by clicking on the handle.',
1831
  );
1832

  
1798 1833
  if (!$open_layers_is_enabled) {
1799 1834
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
1800 1835
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
......
1812 1847
    // 'edit-vmap0_world_basic' => 'EDIT Vmap0',
1813 1848
    'edit-etopo1' => "ETOPO1 Global Relief Model",
1814 1849
    'mapnik' => 'OpenStreetMap',
1815
    'osmarender' => 'OpenStreetMap (Tiles@home)',
1850
    'mapquest_open' => "MapQuest",
1851
    'mapquest_sat' => "MapQuest Sattelite",
1852
//     'osmarender' => 'OpenStreetMap (Tiles@home)',
1816 1853
    'gmap' => 'Google Streets',
1817 1854
    'gsat' => 'Google Satellite',
1818 1855
    'ghyb' => 'Google Hybrid',
......
1822 1859
    // 'yahoo' => 'Yahoo Street',
1823 1860
    // 'yahoosat' => 'Yahoo Satellite',
1824 1861
    // 'yahoohyb' => 'Yahoo Hybrid',
1862
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
1825 1863
  );
1826 1864

  
1827 1865
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
......
1832 1870
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
1833 1871
  );
1834 1872

  
1835
  // cdm_dataportal_geoservice_showLayerSwitcher
1836
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
1837
    '#type' => 'checkbox',
1838
    '#title' => 'Show Layer Switcher',
1839
    '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
1840
    '#description' => 'The Layer Switcher control displays a table of contents
1841
      for the map.  This allows the user interface to switch between
1842
      base layers and to show or hide overlays.  By default the switcher is
1843
      shown minimized on the right edge of the map, the user may expand it
1844
      by clicking on the handle.',
1873
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = array(
1874
      '#type' => 'fieldset',
1875
      '#title' => 'Custom WMS base layer',
1876
      '#tree' => TRUE,
1877
      '#collapsible' => FALSE,
1878
      '#collapsed' => FALSE,
1879
      '#description' => 'Here you an define a custom wms layer as additional base layer.',
1880
  );
1881

  
1882
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['name'] = array(
1883
      '#type' => 'textfield',
1884
      '#title' => 'Layer name',
1885
      // Only line color by now.
1886
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['name'],
1887
      '#description' => 'A arbitrary name for the layer.',
1888
  );
1889
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['url'] = array(
1890
      '#type' => 'textfield',
1891
      '#title' => 'WMS url',
1892
      // Only line color by now.
1893
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['url'],
1894
      '#description' => 'Base url for the WMS (e.g.  http://wms.jpl.nasa.gov/wms.cgi)'
1895
  );
1896
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['params'] = array(
1897
      '#type' => 'textarea',
1898
      '#title' => 'WMS parameters',
1899
      '#element_validate' => array('form_element_validate_json'),
1900
      // Only line color by now.
1901
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['params'],
1902
      '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values, entered in valid JSON.'
1903
  );
1904
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['projection'] = array(
1905
      '#type' => 'textfield',
1906
      '#title' => 'Projection',
1907
      // Only line color by now.
1908
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['projection'],
1909
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
1910
  );
1911
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['max_extent'] = array(
1912
      '#type' => 'textfield',
1913
      '#title' => 'Maximum extent',
1914
      // Only line color by now.
1915
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['max_extent'],
1916
      '#description' => 'The maximum extent of the map as boundin box in the units of the map.'
1917
  );
1918
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['units'] = array(
1919
      '#type' => 'textfield',
1920
      '#title' => 'Units',
1921
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['units'],
1922
      '#description' => 'The layer map units.  Defaults to null.  Possible values are ‘degrees’ (or ‘dd’), ‘m’, ‘ft’, ‘km’, ‘mi’, ‘inches’.  Normally taken from the projection.  Only required if both map and layers do not define a projection, or if they define a projection which does not define units.'
1845 1923
  );
1846 1924

  
1847 1925
  /*
......
2325 2403
 * Form submission handler for textareas and textfields containing JSON.
2326 2404
 *
2327 2405
 * The contained JSON will be converted into an php array
2328
 * or object and will be stores in the variables as such.
2406
 * or object and will be stored in the variables as such.
2329 2407
 *
2330 2408
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
2331 2409
 *
7.x/modules/cdm_dataportal/theme/cdm_dataportal.descriptions.theme
1081 1081
  );
1082 1082

  
1083 1083
  // Query cdm server for map service uri parameters.
1084
  $map_data_parameters = cdm_ws_get(CDM_WS_GEOSERVICE_DISTRIBUTIONMAP, $taxon->uuid);
1085
  $out .= "<!-- map_data_parameters:" . print_r($map_data_parameters, TRUE) . " -->";
1086
  $query_string = $map_data_parameters->String;
1084
  $query_string = cdm_ws_get(CDM_WS_GEOSERVICE_DISTRIBUTIONMAP, $taxon->uuid);
1085
  $query_string = $query_string->String;
1086
  $out .= "<!-- map_data_parameters:" . print_r($query_string, TRUE) . " -->";
1087 1087
  if (!$query_string) {
1088 1088
    // The $query_string is empty if there are no distribution areas defined.
1089 1089
    return;
1090 1090
  }
1091 1091

  
1092
  // Some cleaning of the URI paramters, TODO is this still needed?
1093
  $query_string = str_replace('%3A', ":", $query_string);
1094

  
1095 1092
  /* ------ choose the display mode, either openlayers or static image ------ */
1096 1093

  
1097 1094
  $map_settings = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)