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) {

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)