(function webpackUniversalModuleDefinition(root, factory) {
	if(typeof exports === 'object' && typeof module === 'object')
		module.exports = factory();
	else if(typeof define === 'function' && define.amd)
		define("olControlLoading", [], factory);
	else if(typeof exports === 'object')
		exports["olControlLoading"] = factory();
	else
		root["olControlLoading"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId]) {
/******/ 			return installedModules[moduleId].exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			i: moduleId,
/******/ 			l: false,
/******/ 			exports: {}
/******/ 		};
/******/
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ 		// Flag the module as loaded
/******/ 		module.l = true;
/******/
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/
/******/
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
/******/
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
/******/
/******/ 	// identity function for calling harmony imports with the correct context
/******/ 	__webpack_require__.i = function(value) { return value; };
/******/
/******/ 	// define getter function for harmony exports
/******/ 	__webpack_require__.d = function(exports, name, getter) {
/******/ 		if(!__webpack_require__.o(exports, name)) {
/******/ 			Object.defineProperty(exports, name, {
/******/ 				configurable: false,
/******/ 				enumerable: true,
/******/ 				get: getter
/******/ 			});
/******/ 		}
/******/ 	};
/******/
/******/ 	// getDefaultExport function for compatibility with non-harmony modules
/******/ 	__webpack_require__.n = function(module) {
/******/ 		var getter = module && module.__esModule ?
/******/ 			function getDefault() { return module['default']; } :
/******/ 			function getModuleExports() { return module; };
/******/ 		__webpack_require__.d(getter, 'a', getter);
/******/ 		return getter;
/******/ 	};
/******/
/******/ 	// Object.prototype.hasOwnProperty.call
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "../";
/******/
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(__webpack_require__.s = 111);
/******/ })
/************************************************************************/
/******/ ({

/***/ 111:
/***/ (function(module, exports, __webpack_require__) {

"use strict";


Object.defineProperty(exports, "__esModule", {
  value: true
});

var _constants = __webpack_require__(9);

var _domUtils = __webpack_require__(3);

var htmlUtils = _interopRequireWildcard(_domUtils);

__webpack_require__(129);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

ol.control.Loading = function (params) {
  this.options = params || {};

  this.mapListeners = [];

  this.tileListeners = [];

  this.loadStatus_ = false;

  this.isFirstRander = true;

  this.loadProgress_ = [0, 1];

  if (this.options['widget']) {
    if (['animatedGif', 'progressBar'].indexOf(this.options['widget']) === -1) {
      throw Error('不支持的挂件类型');
    } else {
      this.widget = this.options['widget'] ? this.options['widget'] : 'animatedGif';
    }
  }

  if (this.options['progressMode']) {
    if (['tile', 'layer'].indexOf(this.options['progressMode']) === -1) {
      throw Error('不支持的进度条模式');
    }
    this.loadProgressByTile_ = this.options['progressMode'] === 'layer' ? !(this.options['progressMode'] === 'layer') : true;
  }

  this.showPanel = typeof this.options['showPanel'] === 'boolean' ? this.options['showPanel'] : true;
  var className = this.options.className !== undefined ? this.options.className : 'hmap-loading-panel';

  var elementDom = this.widget === 'animatedGif' ? 'span' : 'progress';
  var element = htmlUtils.create(elementDom, className + ' ' + _constants.BASE_CLASS_NAME.CLASS_UNSELECTABLE);
  if (this.widget === 'progressBar') {
    var div = htmlUtils.create('div', 'hmap-progress-bar');
    htmlUtils.create('span', '', div);
  }
  this.onCustomStart = this.options['onStart'] ? this.options['onStart'] : false;
  this.onCustomProgress = this.options['onProgress'] ? this.options['onProgress'] : false;
  this.onCustomEnd = this.options['onEnd'] ? this.options['onEnd'] : false;
  ol.control.Control.call(this, {
    element: element,
    target: this.options['target']
  });
};

ol.inherits(ol.control.Loading, ol.control.Control);

ol.control.Loading.prototype.setup = function () {
  var _this = this;

  this.setDomPosition();
  this.resize();
  var pointerDown = this.getMap().on('pointerdown', function () {
    _this.hide();
  });
  var beforeRander = this.getMap().on('precompose', function () {
    if (_this.isFirstRander) {
      _this.isFirstRander = false;
      _this.registerLayersLoadEvents_();
      _this.show();
      if (_this.onCustomStart) {
        var args = [];
        _this.onCustomStart.apply(_this, args);
      }
    }
  });
  var afterRander = this.getMap().on('postrender', function () {
    _this.updateLoadStatus_();
    if (_this.loadStatus_) {
      if (_this.onCustomEnd) {
        var args = [];
        _this.onCustomEnd.apply(_this, args);
      }
      _this.hide();
    }
  });
  this.mapListeners.push(pointerDown);
  this.mapListeners.push(beforeRander);
  this.mapListeners.push(afterRander);
};

ol.control.Loading.prototype.setDomPosition = function () {
  var size = this.getMap().getSize();
  var domSize = [this.element.clientWidth, this.element.clientHeight];
  this.element.style.left = String(Math.round((size[0] - domSize[0]) / 2)) + 'px';
  this.element.style.bottom = String(Math.round((size[1] - domSize[1]) / 2)) + 'px';
};

ol.control.Loading.prototype.resize = function () {
  var resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize';
  var doc = window.document;
  var that = this;
  window.addEventListener(resizeEvt, function () {
    setTimeout(function () {
      that.setDomPosition();
    }, 50);
  }, false);
  window.addEventListener('pageshow', function (e) {
    if (e.persisted) {
      setTimeout(function () {
        that.setDomPosition();
      }, 50);
    }
  }, false);
  if (doc.readyState === 'complete') {
    setTimeout(function () {
      that.setDomPosition();
    }, 50);
  } else {
    doc.addEventListener('DOMContentLoaded', function (e) {
      setTimeout(function () {
        that.setDomPosition();
      }, 50);
    }, false);
  }
};

ol.control.Loading.prototype.updateSourceLoadStatus_ = function (source) {
  return Math.round(source.loaded / source.loading * 100) === 100;
};

ol.control.Loading.prototype.registerLayerLoadEvents_ = function (layer) {
  var that = this;
  layer.getSource().on('tileloadstart', function (event) {
    if (that.loadStatus_) {
      that.loadStatus_ = false;
      that.loadProgress_ = [0, 1];
      if (that.widget === 'progressBar') {
        that.element.value = that.loadProgress_[0];
        that.element.max = that.loadProgress_[1];
      }
      that.show();
      if (that.onCustomStart) {
        var args = [];
        that.onCustomStart.apply(that, args);
      }
    }
    this.loading = this.loading ? this.loading + 1 : 1;
    this.isLoaded = that.updateSourceLoadStatus_(this);
    if (that.loadProgressByTile_) {
      this.loadProgress_[1] += 1;
      if (this.widget === 'progressBar') {
        that.element.max = that.loadProgress_[1];
        var progressBarDiv = that.element.getElementsByClassName('hmap-progress-bar');
        if (progressBarDiv.length > 0) progressBarDiv[0].children()[0].width = String(parseInt(100 * that.progress(), 0)) + '%';
      }
    }
  });
  layer.getSource().on(['tileloadend', 'tileloaderror'], function (e) {
    if (e.tile.getState() === 3) {
      console.warn('Loading tile failed for resource \'' + e.tile.src_ + '\'');
    }
    this.loaded = this.loaded ? this.loaded + 1 : 1;
    this.isLoaded = that.updateSourceLoadStatus_(this);
    if (that.loadProgressByTile_) {
      that.loadProgress_[0] += 1;
      if (that.widget === 'progressBar') {
        that.element.value = that.loadProgress_[0];
        var progressBarDiv = this.element.getElementsByClassName('hmap-progress-bar');
        if (progressBarDiv.length > 0) {
          progressBarDiv[0].children()[0].width = String(parseInt(100 * that.progress(), 0)) + '%';
        }
      }
      if (that.onCustomProgress) {
        that.onCustomProgress.apply(that, that.loadProgress_);
      }
    }
  });
};

ol.control.Loading.prototype.registerLayersLoadEvents_ = function () {
  var groups = this.getMap().getLayers().getArray();
  for (var i = 0; i < groups.length; i++) {
    var layer = groups[i];
    if (layer instanceof ol.layer.Group) {
      var layers = layer.getLayers().getArray();
      for (var j = 0; j < layers.length; j++) {
        var l = layers[j];
        if (!(l instanceof ol.layer.Vector)) {
          this.tileListeners.push(this.registerLayerLoadEvents_(l));
        }
      }
    } else if (layer instanceof ol.layer.Layer) {
      if (!(layer instanceof ol.layer.Vector)) {
        this.tileListeners.push(this.registerLayerLoadEvents_(layer));
      }
    }
  }
};

ol.control.Loading.prototype.updateLoadStatus_ = function () {
  var loadStatusArray = [];
  var groups = this.getMap().getLayers().getArray();
  for (var i = 0; i < groups.length; i++) {
    var layer = groups[i];
    if (layer instanceof ol.layer.Group) {
      var layers = layer.getLayers().getArray();
      for (var j = 0; j < layers.length; j++) {
        var l = layers[j];
        if (!(l instanceof ol.layer.Vector)) {
          loadStatusArray.push(l.getSource().isLoaded);
        }
      }
    } else {
      loadStatusArray.push(layer.getSource().isLoaded);
    }
  }
  this.loadStatus_ = loadStatusArray.indexOf(false) === -1 && loadStatusArray.indexOf(true) !== -1;
  if (!this.loadProgressByTile_) {
    var count = {};
    loadStatusArray.forEach(function (i) {
      count[i] = (count[i] || 0) + 1;
    });
    var loaded = count[true] ? count[true] : 0;

    if (loaded > this.loadProgress_[0]) {
      this.loadProgress_ = [loaded, loadStatusArray.length];
      if (this.widget === 'progressBar') {
        this.element.max = this.loadProgress_[1];
        this.element.value = this.loadProgress_[0];
      }
      if (this.onCustomProgress) this.onCustomProgress.apply(this, this.loadProgress_);
    }
  }
};

ol.control.Loading.prototype.show = function () {
  if (this.showPanel) {
    this.element.style.display = 'block';
  }
};

ol.control.Loading.prototype.hide = function () {
  if (this.showPanel) {
    this.element.style.display = 'none';
  }
};

ol.control.Loading.prototype.progressDetails = function () {
  return this.loadProgress_;
};

ol.control.Loading.prototype.progress = function () {
  return this.loadProgress_[0] / this.loadProgress_[1];
};

ol.control.Loading.prototype.setMap = function (map) {
  var _this2 = this;

  if (this.mapListeners && this.mapListeners.length > 0) {
    this.mapListeners.forEach(function (listener) {
      _this2.getMap().unByKey(listener);
    });
  }
  this.mapListeners.length = 0;
  ol.control.Control.prototype.setMap.call(this, map);
  if (map) {
    this.setup();
  }
};

var olControlLoading = ol.control.Loading;
exports.default = olControlLoading;
module.exports = exports['default'];

/***/ }),

/***/ 129:
/***/ (function(module, exports) {

// removed by extract-text-webpack-plugin

/***/ }),

/***/ 3:
/***/ (function(module, exports, __webpack_require__) {

"use strict";


Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.createHidden = exports.setClass = exports.removeClass = exports.addClass = exports.hasClass = exports.toBack = exports.toFront = exports.empty = exports.remove = exports.create = exports.getStyle = exports.getClass = exports.getElementsByClassName = exports.getChildByTagName = exports.get = undefined;

var _utils = __webpack_require__(4);

var get = exports.get = function get(id) {
  return typeof id === 'string' ? document.getElementById(id) : id;
};

var getChildByTagName = exports.getChildByTagName = function getChildByTagName(str, container) {
  return container.getElementsByTagName(str);
};

var getElementsByClassName = exports.getElementsByClassName = function getElementsByClassName(str, container, root) {
  var _root = root || window;
  var $ = _root.document.querySelector.bind(_root.document);

  var target = $(str);
  return target;
};

var getClass = exports.getClass = function getClass(elem) {
  return elem.getAttribute && elem.getAttribute('class') || '';
};

var getStyle = exports.getStyle = function getStyle(el, style) {
  var value = el.style[style] || el.currentStyle && el.currentStyle[style];
  if ((!value || value === 'auto') && document.defaultView) {
    var css = document.defaultView.getComputedStyle(el, null);
    value = css ? css[style] : null;
  }
  return value === 'auto' ? null : value;
};

var create = exports.create = function create(tagName, className, container, id) {
  var el = document.createElement(tagName);
  el.className = className || '';
  if (id) {
    el.id = id;
  }
  if (container) {
    container.appendChild(el);
  }
  return el;
};

var remove = exports.remove = function remove(el) {
  var parent = el.parentNode;
  if (parent) {
    parent.removeChild(el);
  }
};

var empty = exports.empty = function empty(el) {
  while (el.firstChild) {
    el.removeChild(el.firstChild);
  }
};

var toFront = exports.toFront = function toFront(el) {
  el.parentNode.appendChild(el);
};

var toBack = exports.toBack = function toBack(el) {
  var parent = el.parentNode;
  parent.insertBefore(el, parent.firstChild);
};

var hasClass = exports.hasClass = function hasClass(el, name) {
  if (el.classList !== undefined) {
    return el.classList.contains(name);
  }
  var className = getClass(el);
  return className.length > 0 && new RegExp('(^|\\s)' + name + '(\\s|$)').test(className);
};

var addClass = exports.addClass = function addClass(el, name) {
  if (el.classList !== undefined) {
    var classes = (0, _utils.splitWords)(name);
    for (var i = 0, len = classes.length; i < len; i++) {
      el.classList.add(classes[i]);
    }
  } else if (!hasClass(el, name)) {
    var className = getClass(el);
    setClass(el, (className ? className + ' ' : '') + name);
  }
};

var removeClass = exports.removeClass = function removeClass(el, name) {
  if (el.classList !== undefined) {
    el.classList.remove(name);
  } else {
    setClass(el, String.trim((' ' + getClass(el) + ' ').replace(' ' + name + ' ', ' ')));
  }
};

var setClass = exports.setClass = function setClass(el, name) {
  if (el.className.baseVal === undefined) {
    el.className = name;
  } else {
    el.className.baseVal = name;
  }
};

var createHidden = exports.createHidden = function createHidden(tagName, parent, id) {
  var element = document.createElement(tagName);
  element.style.display = 'none';
  if (id) {
    element.id = id;
  }
  if (parent) {
    parent.appendChild(element);
  }
  return element;
};

/***/ }),

/***/ 4:
/***/ (function(module, exports, __webpack_require__) {

"use strict";


Object.defineProperty(exports, "__esModule", {
  value: true
});
var getrandom = exports.getrandom = function getrandom(t1, t2, t3) {
  if (!t1 || isNaN(t1)) {
    t1 = 0;
  }
  if (!t2 || isNaN(t2)) {
    t2 = 1;
  }
  if (!t3 || isNaN(t3)) {
    t3 = 0;
  }
  t3 = t3 > 15 ? 15 : t3;
  var _ref = [Math.random() * (t2 - t1) + t1, Math.pow(10, t3)],
      ra = _ref[0],
      du = _ref[1];

  ra = Math.round(ra * du) / du;
  return ra;
};

var getuuid = exports.getuuid = function getuuid() {
  var s = [],
      hexDigits = '0123456789abcdef';

  for (var i = 0; i < 36; i++) {
    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
  }
  s[14] = '4';
  s[19] = hexDigits.substr(s[19] & 0x3 | 0x8, 1);
  s[8] = s[13] = s[18] = s[23] = '-';
  return s.join('');
};

var stamp = exports.stamp = function stamp(obj) {
  var key = '_event_id_';
  obj[key] = obj[key] || getuuid();
  return obj[key];
};

var trim = exports.trim = function trim(str) {
  return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g, '');
};

var splitWords = exports.splitWords = function splitWords(str) {
  return trim(str).split(/\s+/);
};

var firstUpperToCase = exports.firstUpperToCase = function firstUpperToCase(str) {
  return str.toLowerCase().replace(/( |^)[a-z]/g, function (L) {
    return L.toUpperCase();
  });
};
var upperFirstChart = exports.upperFirstChart = function upperFirstChart(str) {
  return str.replace(/( |^)[a-z]/g, function (L) {
    return L.toUpperCase();
  });
};

var arrayRemove = exports.arrayRemove = function arrayRemove(arr, obj) {
  var i = arr.indexOf(obj);
  var found = i > -1;
  if (found) {
    arr.splice(i, 1);
  }
  return found;
};

/***/ }),

/***/ 9:
/***/ (function(module, exports, __webpack_require__) {

"use strict";


Object.defineProperty(exports, "__esModule", {
  value: true
});


var BASE_CLASS_NAME = {
  CLASS_HIDDEN: 'ol-hidden',
  CLASS_SELECTABLE: 'ol-selectable',
  CLASS_UNSELECTABLE: 'ol-unselectable',
  CLASS_CONTROL: 'ol-control'
};

exports.BASE_CLASS_NAME = BASE_CLASS_NAME;

/***/ })

/******/ });
});
//# sourceMappingURL=olControlLoading.js.map