Project

General

Profile

Revision 669f08ee

ID669f08ee073432d163976f10b59f1d516e71f827
Parent 4c21ffdb
Child 378bc1ce

Added by Andreas Kohlbecker over 3 years ago

fix #5938 unique ids for each openlayers block elements

View differences:

modules/cdm_dataportal/includes/maps.inc
89 89
 * Adds the javascript for a openlayers map to the page as well as all javascript libs.
90 90
 *
91 91
 *
92
 * @param $map_id
92 93
 * @param $map_settings
93 94
 *   The map settings array as retrieved by e.g. get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
94 95
 * @param array $event_listeners
......
106 107
 * @param bool $resizable
107 108
 *   The map is made resizable when set to true
108 109
 */
109
function _add_js_openlayers_map($map_settings, array $event_listeners = array(), $resizable = false) {
110
function _add_js_openlayers_map($map_id, $map_settings, array $event_listeners = array(), $resizable = false) {
110 111

  
111 112
  font_awesome_icon_markup(); // no icon specified, only used to add the font and styles
112 113

  
......
200 201
  drupal_add_js("
201 202
          jQuery(document).ready(function() {
202 203
                jQuery(window).load(function () {
203
                  var map_container = jQuery('#openlayers_map').cdm_openlayers_map(
204
                  var map_container = jQuery('#openlayers-map-" . $map_id . "').cdm_openlayers_map(
204 205
                   '" . $mapserver_base_uri . "',
205 206
                   '" . $edit_map_service['version'] . "',
206 207
                   " .  json_encode($cdm_openlayers_options) . "
......
249 250
  $map_settings = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
250 251

  
251 252
  if($map_id == NULL){
252
    $map_id = "openlayers-container-" . sha1($occurrenceQuery . $distributionQuery);
253
    $map_id = sha1($occurrenceQuery . $distributionQuery);
253 254
  }
254 255

  
255
  _add_js_openlayers_map($map_settings, $event_listeners, $resizable);
256
  _add_js_openlayers_map($map_id, $map_settings, $event_listeners, $resizable);
256 257

  
257
  $out = '<div id="' . $map_id . '" class="openlayers-container openlayers_width ui-widget-content" style="width: 100%;">';
258
  $out .= '<div id="openlayers_map" class="smallmap" style="width:100%; height:100%; margin: 10px;"';
258
  $out = '<div id=""openlayers-container-' . $map_id . '" class="openlayers-container openlayers_width ui-widget-content" style="width: 100%;">';
259
  $out .= '<div id="openlayers-map-' . $map_id . '" class="smallmap" style="width:100%; height:100%; margin: 10px;"';
259 260

  
260 261
  // Additional query parameters as set in the data portal admin section.
261 262
  $labels_on = $map_settings['show_labels'];
modules/cdm_dataportal/js/map/openlayers_map.js
432 432
         */
433 433
        var initMap = function(){
434 434

  
435
            if(opts.showLayerSwitcher === true){
436
                defaultControls.push(new OpenLayers.Control.LayerSwitcher({'ascending':false}));
437
            }
435
          if(opts.showLayerSwitcher === true){
436
              defaultControls.push(new OpenLayers.Control.LayerSwitcher({'ascending':false}));
437
          }
438 438

  
439
            // defaultControls.unshift(layerLoadingControl()); // as first control, needs to be below all others!
439
          // defaultControls.unshift(layerLoadingControl()); // as first control, needs to be below all others!
440 440

  
441 441
//          var maxExtentByAspectRatio = cropBoundsToAspectRatio(defaultBaseLayer.maxExtent, getWidth/getHeight);
442
            var maxResolution = null;
443
            // gmaps has no maxExtent at this point, need to check for null
444
            if(defaultBaseLayer.maxExtent != null){
445
                maxResolution = Math[(opts.displayOutsideMaxExtent ? 'max' : 'min')](
446
                        defaultBaseLayer.maxExtent.getWidth() / getWidth(),
447
                        defaultBaseLayer.maxExtent.getHeight() / getHeight()
448
                );
449
            }
450
            console.log("mapOptions.maxResolution: " + maxResolution);
451
            console.log("mapOptions.restrictedExtent: " + defaultBaseLayer.maxExtent);
452

  
453
            map = new OpenLayers.Map(
454
                    "openlayers_map",
455
                    {
456
                        // defines the map ui elements and interaction features
457
                        controls: defaultControls,
458

  
459
                        // maxResolution determines the lowest zoom level and thus places the map
460
                        // in its maximum extent into the available view port so that no additinal
461
                        // gutter is visible and no parts of the map are hidden
462
                        // see http://trac.osgeo.org/openlayers/wiki/SettingZoomLevels
463
                        // IMPORTANT!!!
464
                        // the maxResulution set here will be overwritten if the baselayers maxResolution
465
                        // it is set
466
                        maxResolution: maxResolution,
467

  
468
                        // setting restrictedExtent the the maxExtent prevents from panning the
469
                        // map out of its bounds
470
                        restrictedExtent: defaultBaseLayer.maxExtent,
442
          var maxResolution = null;
443
          // gmaps has no maxExtent at this point, need to check for null
444
          if(defaultBaseLayer.maxExtent != null){
445
              maxResolution = Math[(opts.displayOutsideMaxExtent ? 'max' : 'min')](
446
                      defaultBaseLayer.maxExtent.getWidth() / getWidth(),
447
                      defaultBaseLayer.maxExtent.getHeight() / getHeight()
448
              );
449
          }
450
          console.log("mapOptions.maxResolution: " + maxResolution);
451
          console.log("mapOptions.restrictedExtent: " + defaultBaseLayer.maxExtent);
452

  
453
          map = new OpenLayers.Map(
454
            mapElement.attr('id'),
455
            {
456
              // defines the map ui elements and interaction features
457
              controls: defaultControls,
458

  
459
              // maxResolution determines the lowest zoom level and thus places the map
460
              // in its maximum extent into the available view port so that no additinal
461
              // gutter is visible and no parts of the map are hidden
462
              // see http://trac.osgeo.org/openlayers/wiki/SettingZoomLevels
463
              // IMPORTANT!!!
464
              // the maxResulution set here will be overwritten if the baselayers maxResolution
465
              // it is set
466
              maxResolution: maxResolution,
467

  
468
              // setting restrictedExtent the the maxExtent prevents from panning the
469
              // map out of its bounds
470
              restrictedExtent: defaultBaseLayer.maxExtent,
471 471
//                      maxExtent: defaultBaseLayer.maxExtent,
472 472

  
473
                        // Setting the map.fractionalZoom property to true allows zooming to an arbitrary level
474
                        // (between the min and max resolutions).
475
                        // fractional tiles are not supported by XYZ layers like OSM so this option would
476
                        // break the tile retrieval for OSM (e.g.: tile for fractional zoom level
477
                        // 1.2933333333333332 = http://b.tile.openstreetmap.org/1.2933333333333332/1/0.png)
478
                        fractionalZoom: defaultBaseLayer.CLASS_NAME != "OpenLayers.Layer.OSM" && defaultBaseLayer.CLASS_NAME != "OpenLayers.Layer.XYZ",
473
              // Setting the map.fractionalZoom property to true allows zooming to an arbitrary level
474
              // (between the min and max resolutions).
475
              // fractional tiles are not supported by XYZ layers like OSM so this option would
476
              // break the tile retrieval for OSM (e.g.: tile for fractional zoom level
477
              // 1.2933333333333332 = http://b.tile.openstreetmap.org/1.2933333333333332/1/0.png)
478
              fractionalZoom: defaultBaseLayer.CLASS_NAME != "OpenLayers.Layer.OSM" && defaultBaseLayer.CLASS_NAME != "OpenLayers.Layer.XYZ",
479 479

  
480
                        eventListeners: opts.eventListeners,
481
                        // creating the map with a null theme, since we include the stylesheet directly in the page
482
                        theme: null
480
              eventListeners: opts.eventListeners,
481
              // creating the map with a null theme, since we include the stylesheet directly in the page
482
              theme: null
483 483

  
484
                    }
485
            );
484
            }
485
          );
486 486

  
487
            //add the base layers
487
          //add the base layers
488 488

  
489
            addLayers(baseLayers);
490
            map.setBaseLayer(defaultBaseLayer);
489
          addLayers(baseLayers);
490
          map.setBaseLayer(defaultBaseLayer);
491 491

  
492
            // calculate the bounds to zoom to
493
            zoomToBounds = zoomToBoundsFor(opts.boundingBox ? opts.boundingBox : defaultBaseLayerBoundingBox, defaultBaseLayer);
494
            zoomToBounds = cropBoundsToAspectRatio(zoomToBounds, map.getSize().w / map.getSize().h);
495
            console.log("baselayer zoomToBounds: " + zoomToBounds);
492
          // calculate the bounds to zoom to
493
          zoomToBounds = zoomToBoundsFor(opts.boundingBox ? opts.boundingBox : defaultBaseLayerBoundingBox, defaultBaseLayer);
494
          zoomToBounds = cropBoundsToAspectRatio(zoomToBounds, map.getSize().w / map.getSize().h);
495
          console.log("baselayer zoomToBounds: " + zoomToBounds);
496 496

  
497 497
        };
498 498

  
src/test/java/eu/etaxonomy/dataportal/selenium/tests/cichorieae/Lactuca_triquetra_TaxonProfileTest.java
146 146
            assertEquals("Expecting 7 Footnotes", 7, featureBlock.countFootNotes());
147 147
        }
148 148

  
149
        assertNotNull("Expecting an OpenLayers map", featureBlock.getElement().findElement(By.id("openlayers_map")));
149
        assertNotNull("Expecting an OpenLayers map", featureBlock.getElement().findElement(By.id("openlayers-map-distribution")));
150 150
        WebElement mapCaptionElement = null;
151 151
        try {
152 152
            mapCaptionElement = featureBlock.getElement().findElement(By.className("distribution_map_caption"));
src/test/java/eu/etaxonomy/dataportal/selenium/tests/palmae/Calamus_acanthospathus_TaxonProfileTest.java
108 108
        assertTrue(LinkElement.testIfLinkElement(featureBlock.getOriginalSourcesSections().get(0).getLinksInElement().get(0), "World Checklist of Monocotyledons", this.getContext().getBaseUri().toString()));
109 109
        assertTrue(LinkElement.testIfLinkElement(featureBlock.getOriginalSourcesSections().get(1).getLinksInElement().get(0), "T. Evans et al. 2002", this.getContext().getBaseUri().toString() + "?q=cdm_dataportal/reference/706c5e5e-1dac-4fb2-b849-8e99ad7d63aa"));
110 110

  
111
        assertNotNull("Expecting an OpenLayers map", featureBlock.getElement().findElement(By.id("openlayers_map")));
111
        assertNotNull("Expecting an OpenLayers map", featureBlock.getElement().findElement(By.id("openlayers-map-distribution")));
112 112
        assertEquals("Map accurate to TDWG level 3 distributions", featureBlock.getElement().findElement(By.className("distribution_map_caption")).getText());
113 113

  
114 114

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)