Project

General

Profile

« Previous | Next » 

Revision 5053f04f

Added by Andreas Kohlbecker about 8 years ago

#5683 implemented loading animation for open layers map viewer

View differences:

modules/cdm_dataportal/js/map/openlayers_map.js
313 313
                defaultControls.push(new OpenLayers.Control.LayerSwitcher({'ascending':false}));
314 314
            }
315 315

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

  
316 318
//          var maxExtentByAspectRatio = cropBoundsToAspectRatio(defaultBaseLayer.maxExtent, getWidth/getHeight);
317 319
            var maxResolution = null;
318 320
            // gmaps has no maxExtent at this point, need to check for null
......
760 762
          return  wmsLayer;
761 763
        };
762 764

  
765
        var layerLoadingControl = function() {
766

  
767
          var control = new OpenLayers.Control();
768

  
769
          OpenLayers.Util.extend(control, {
770

  
771
            LAYERS_LOADING: 0,
772

  
773
            updateState: function () {
774
              if(this.div != null){
775
                if (this.LAYERS_LOADING > 0) {
776
                  this.div.style.display = "block";
777
                } else {
778
                  this.div.style.display = "none";
779
                }
780
              }
781
            },
782

  
783
            updateSize: function () {
784
              this.div.style.width = this.map.size.w + "px";
785
              this.div.style.height = this.map.size.h  + "px";
786
              this.div.style.textAlign = "center";
787
              this.div.style.lineHeight = this.map.size.h  + "px";
788
            },
789

  
790
            counterIncrease: function () {
791
              this.LAYERS_LOADING++;
792
              this.updateState();
793
            },
794

  
795
            counterDecrease: function () {
796
              this.LAYERS_LOADING--;
797
              this.updateState();
798
            },
799

  
800
            draw: function () {
801

  
802
              // call the default draw function to initialize this.div
803
              OpenLayers.Control.prototype.draw.apply(this, arguments);
804

  
805
              this.map.events.register('updatesize', this, function(e){
806
                  this.updateSize();
807
                }
808
              );
809

  
810
              var loadingIcon = document.createElement("i");
811
              var fa_class = document.createAttribute("class");
812
              // fa-circle-o-notch fa-spin
813
              // fa-spinner fa-pulse
814
              // fa-refresh
815
              fa_class.value = "fa fa-refresh fa-spin fa-5x";
816
              loadingIcon.attributes.setNamedItem(fa_class);
817

  
818
              this.updateSize();
819

  
820
              this.div.appendChild(loadingIcon);
821

  
822
              this.registerEvents();
823

  
824
              return this.div;
825
            },
826

  
827
            registerEvents: function() {
828

  
829
              this.map.events.register('preaddlayer', this, function(e){
830
                e.layer.events.register('loadstart', this, this.counterIncrease);
831
                e.layer.events.register('loadend', this, this.counterDecrease);
832
              });
833
            }
834

  
835
          });
836

  
837
          return control;
838
        }
839

  
763 840
    }; // end of CdmOpenLayers.Map
764 841
})();
765 842

  
......
768 845

  
769 846

  
770 847

  
848

  
849

  
850

  

Also available in: Unified diff