(function webpackUniversalModuleDefinition(root, factory) {
	if(typeof exports === 'object' && typeof module === 'object')
		module.exports = factory();
	else if(typeof define === 'function' && define.amd)
		define("olInteractionLayerSpyglass", [], factory);
	else if(typeof exports === 'object')
		exports["olInteractionLayerSpyglass"] = factory();
	else
		root["olInteractionLayerSpyglass"] = 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 = 116);
/******/ })
/************************************************************************/
/******/ ({

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

"use strict";


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

var _Events = __webpack_require__(2);

var Events = _interopRequireWildcard(_Events);

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.interaction.LayerSpyglass = function (params) {
  this.options = params || {};
  if (this.options['spyLayer']) {
    this.spyLayer = this.options['spyLayer'];
  } else {
    throw new Error('图层必须传入！');
  }

  this._currentLayerIndex = null;

  this.radius = typeof this.options['radius'] === 'number' ? this.options['radius'] : 75;

  this.minRadius = typeof this.options['minRadius'] === 'number' ? this.options['minRadius'] : 150;

  this.maxRadius = typeof this.options['maxRadius'] === 'number' ? this.options['maxRadius'] : 25;

  this.lineWidth = typeof this.options['lineWidth'] === 'number' ? this.options['lineWidth'] : 5;

  this.strokeStyle = this.options['strokeStyle'] ? this.options['strokeStyle'] : 'rgba(0, 0, 0, 0.5)';

  this.zoomInKeyCode = this.options['zoomInKeyCode'] !== undefined ? this.options['zoomInKeyCode'] : 38;

  this.zoomOutKeyCode = this.options['zoomOutKeyCode'] !== undefined ? this.options['zoomOutKeyCode'] : 40;

  this.mousePosition = null;
  ol.interaction.Pointer.call(this, {
    handleEvent: ol.interaction.LayerSpyglass.handleEvent_,
    handleMoveEvent: ol.interaction.LayerSpyglass.handleMoveEvent_
  });
};

ol.inherits(ol.interaction.LayerSpyglass, ol.interaction.Pointer);

ol.interaction.LayerSpyglass.handleMoveEvent_ = function (mapBrowserEvent) {
  this.mousePosition = mapBrowserEvent['pixel'];
  this.getMap().render();
};

ol.interaction.LayerSpyglass.handleEvent_ = function (evt) {
  return ol.interaction.Pointer.handleEvent.call(this, evt);
};

ol.interaction.LayerSpyglass.prototype.initEvents_ = function () {
  if (this.getMap()) {
    Events.listen(this.getMap().getTargetElement(), 'mouseout', this.handleMouseOut_, this);
    Events.listen(document, 'keydown', this.handleKeyDown_, this);
    var layers = this.getMap().getLayers().getArray();
    var layerIndexs = [];
    this._currentLayerIndex = this.spyLayer.getZIndex();
    layers.every(function (layer) {
      layerIndexs.push(layer.getZIndex());
    });
    var maxIndex = Math.max.apply(Math, layerIndexs);

    this.spyLayer.setZIndex(maxIndex + 10);
    this.spyLayer.setVisible(true);

    this.spyLayer.on('precompose', this.handlePrecompose_, this);

    this.spyLayer.on('postcompose', this.handlePostcompose_, this);
  }
};

ol.interaction.LayerSpyglass.prototype.handleMouseOut_ = function (event) {
  this.mousePosition = null;
  this.getMap().render();
};

ol.interaction.LayerSpyglass.prototype.handleKeyDown_ = function (event) {
  if (event.which === this.zoomInKeyCode) {
    this.radius = Math.min(this.radius + 5, 150);
    this.getMap().render();
    event.preventDefault();
  } else if (event.which === this.zoomOutKeyCode) {
    this.radius = Math.max(this.radius - 5, 25);
    this.getMap().render();
    event.preventDefault();
  }
};

ol.interaction.LayerSpyglass.prototype.handlePrecompose_ = function (event) {
  var ctx = event.context;
  var pixelRatio = event.frameState.pixelRatio;
  ctx.save();
  ctx.beginPath();
  if (this.mousePosition) {
    ctx.arc(this.mousePosition[0] * pixelRatio, this.mousePosition[1] * pixelRatio, this.radius * pixelRatio, 0, 2 * Math.PI);
    ctx.lineWidth = this.lineWidth * pixelRatio;
    ctx.strokeStyle = this.strokeStyle;
    ctx.stroke();
  }
  ctx.clip();
};

ol.interaction.LayerSpyglass.prototype.handlePostcompose_ = function (event) {
  var ctx = event.context;
  ctx.restore();
};

ol.interaction.LayerSpyglass.prototype.setMap = function (map) {
  if (map && map instanceof ol.Map) {
    ol.interaction.Interaction.prototype.setMap.call(this, map);
    this.initEvents_();
  } else {
    Events.unListen(this.getMap().getTargetElement(), 'mouseout', this.handleMouseOut_, this);
    Events.unListen(document, 'keydown', this.handleKeyDown_, this);

    this.spyLayer.un('precompose', this.handlePrecompose_, this);

    this.spyLayer.un('postcompose', this.handlePostcompose_, this);
    this.spyLayer.setVisible(false);
    this.spyLayer.setZIndex(this._currentLayerIndex);
    this._currentLayerIndex = null;
    ol.interaction.Interaction.prototype.setMap.call(this, map);
  }
};

var olInteractionLayerSpyglass = ol.interaction.LayerSpyglass;

exports.default = olInteractionLayerSpyglass;
module.exports = exports['default'];

/***/ }),

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

"use strict";


Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.removeListener = exports.addListener = exports.getDomEventKey = exports.unlistenAll = exports.clear = exports.unListenByKey = exports.unListen = exports.listenOnce = exports.listen = exports.removeListeners = exports.getListenerMap = exports.getListeners = exports.findListener = exports.bindListener = undefined;

var _utils = __webpack_require__(4);

var bindListener = exports.bindListener = function bindListener(listenerObj) {
  var boundListener = function boundListener(evt) {
    var listener = listenerObj.listener;
    var bindTo = listenerObj.bindTo || listenerObj.target;
    if (listenerObj.callOnce) {
      unListenByKey(listenerObj);
    }
    return listener.call(bindTo, evt);
  };
  listenerObj.boundListener = boundListener;
  return boundListener;
};

var findListener = exports.findListener = function findListener(listeners, listener, optThis, optSetDeleteIndex) {
  var listenerObj = null;
  for (var i = 0, ii = listeners.length; i < ii; ++i) {
    listenerObj = listeners[i];
    if (listenerObj.listener === listener && listenerObj.bindTo === optThis) {
      if (optSetDeleteIndex) {
        listenerObj.deleteIndex = i;
      }
      return listenerObj;
    }
  }
  return undefined;
};

var getListeners = exports.getListeners = function getListeners(target, type) {
  var listenerMap = target.vlm;
  return listenerMap ? listenerMap[type] : undefined;
};

var getListenerMap = exports.getListenerMap = function getListenerMap(target) {
  var listenerMap = target.vlm;
  if (!listenerMap) {
    listenerMap = target.vlm = {};
  }
  return listenerMap;
};

var removeListeners = exports.removeListeners = function removeListeners(target, type) {
  var listeners = getListeners(target, type);
  if (listeners) {
    for (var i = 0, ii = listeners.length; i < ii; ++i) {
      target.removeEventListener(type, listeners[i].boundListener);
      clear(listeners[i]);
    }
    listeners.length = 0;
    var listenerMap = target.vlm;
    if (listenerMap) {
      delete listenerMap[type];
      if (Object.keys(listenerMap).length === 0) {
        delete target.vlm;
      }
    }
  }
};

var listen = exports.listen = function listen(target, type, listener, optThis, optOnce) {
  var listenerMap = getListenerMap(target);
  var listeners = listenerMap[type];
  if (!listeners) {
    listeners = listenerMap[type] = [];
  }
  var listenerObj = findListener(listeners, listener, optThis, false);
  if (listenerObj) {
    if (!optOnce) {
      listenerObj.callOnce = false;
    }
  } else {
    listenerObj = {
      bindTo: optThis,
      callOnce: !!optOnce,
      listener: listener,
      target: target,
      type: type
    };
    target.addEventListener(type, bindListener(listenerObj));
    listeners.push(listenerObj);
  }
  return listenerObj;
};

var listenOnce = exports.listenOnce = function listenOnce(target, type, listener, optThis) {
  return listen(target, type, listener, optThis, true);
};

var unListen = exports.unListen = function unListen(target, type, listener, optThis) {
  var listeners = getListeners(target, type);
  if (listeners) {
    var listenerObj = findListener(listeners, listener, optThis, true);
    if (listenerObj) {
      unListenByKey(listenerObj);
    }
  }
};

var unListenByKey = exports.unListenByKey = function unListenByKey(key) {
  if (key && key.target) {
    key.target.removeEventListener(key.type, key.boundListener);
    var listeners = getListeners(key.target, key.type);
    if (listeners) {
      var i = 'deleteIndex' in key ? key.deleteIndex : listeners.indexOf(key);
      if (i !== -1) {
        listeners.splice(i, 1);
      }
      if (listeners.length === 0) {
        removeListeners(key.target, key.type);
      }
    }
    clear(key);
  }
};

var clear = exports.clear = function clear(object) {
  for (var property in object) {
    delete object[property];
  }
};

var unlistenAll = exports.unlistenAll = function unlistenAll(target) {
  var listenerMap = getListenerMap(target);
  for (var type in listenerMap) {
    removeListeners(target, type);
  }
};

var getDomEventKey = exports.getDomEventKey = function getDomEventKey(type, fn, context) {
  return '_dom_event_' + type + '_' + (0, _utils.stamp)(fn) + (context ? '_' + (0, _utils.stamp)(context) : '');
};

var addListener = exports.addListener = function addListener(element, type, fn, context) {
  var eventKey = getDomEventKey(type, fn, context);
  var handler = element[eventKey];
  if (handler) {
    return this;
  }
  handler = function handler(e) {
    return fn.call(context || element, e);
  };
  if ('addEventListener' in element) {
    element.addEventListener(type, handler, false);
  } else if ('attachEvent' in element) {
    element.attachEvent('on' + type, handler);
  }
  element[eventKey] = handler;
  return this;
};

var removeListener = exports.removeListener = function removeListener(element, type, fn, context) {
  var eventKey = getDomEventKey(type, fn, context);
  var handler = element[eventKey];
  if (!handler) {
    return this;
  }
  if ('removeEventListener' in element) {
    element.removeEventListener(type, handler, false);
  } else if ('detachEvent' in element) {
    element.detachEvent('on' + type, handler);
  }
  element[eventKey] = null;
  return this;
};

/***/ }),

/***/ 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;
};

/***/ })

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