rajeev-openlayer-extent
Version:
a JavaScript library for openlayers extent
1,697 lines (1,437 loc) • 195 kB
JavaScript
/*!
* author: FDD <smileFDD@gmail.com>
* ol-extent v2.0.1
* build-time: 2023-11-23 15:14
* LICENSE: MIT
* (c) 2017-2023 https://sakitam-fdd.github.io/ol-extent/
*/
import ol from 'openlayers';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
var inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
};
var possibleConstructorReturn = function (self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return call && (typeof call === "object" || typeof call === "function") ? call : self;
};
var _arguments = arguments;
var SPECIAL_CHARS_REGEXP = /([\:\-\_]+(.))/g;
var MOZ_HACK_REGEXP = /^moz([A-Z])/;
var byteToHex = [];
var rnds = new Array(16);
for (var i = 0; i < 256; ++i) {
byteToHex[i] = (i + 0x100).toString(16).substr(1);
}
var has = function has(object_, key_) {
return (typeof object_ === 'undefined' ? 'undefined' : _typeof(object_)) === 'object' && object_.hasOwnProperty(key_);
};
var trim = function trim(string) {
return (string || '').replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g, '');
};
var camelCase = function camelCase(name) {
return name.replace(SPECIAL_CHARS_REGEXP, function (_, separator, letter, offset) {
return offset ? letter.toUpperCase() : letter;
}).replace(MOZ_HACK_REGEXP, 'Moz$1');
};
var stamp = function stamp(obj) {
var key = '_event_id_';
obj[key] = obj[key] || uuid();
return obj[key];
};
var isNull = function isNull(obj) {
return obj == null;
};
var isNumber = function isNumber(val) {
return typeof val === 'number' && !isNaN(val);
};
var isObject = function isObject(value) {
var type = typeof value === 'undefined' ? 'undefined' : _typeof(value);
return value !== null && (type === 'object' || type === 'function');
};
var isString = function isString(value) {
if (value == null) {
return false;
}
return typeof value === 'string' || value.constructor !== null && value.constructor === String;
};
var bytesToUuid = function bytesToUuid(buf, offset) {
var i = offset || 0;
var bth = byteToHex;
return bth[buf[i++]] + bth[buf[i++]] + bth[buf[i++]] + bth[buf[i++]] + '-' + bth[buf[i++]] + bth[buf[i++]] + '-' + bth[buf[i++]] + bth[buf[i++]] + '-' + bth[buf[i++]] + bth[buf[i++]] + '-' + bth[buf[i++]] + bth[buf[i++]] + bth[buf[i++]] + bth[buf[i++]] + bth[buf[i++]] + bth[buf[i++]];
};
var mathRNG = function mathRNG() {
for (var _i = 0, r; _i < 16; _i++) {
if ((_i & 0x03) === 0) r = Math.random() * 0x100000000;
rnds[_i] = r >>> ((_i & 0x03) << 3) & 0xff;
}
return rnds;
};
var uuid = function uuid(options, buf, offset) {
var i = buf && offset || 0;
if (typeof options === 'string') {
buf = options === 'binary' ? new Array(16) : null;
options = null;
}
options = options || {};
var rnds = options.random || (options.rng || mathRNG)();
rnds[6] = rnds[6] & 0x0f | 0x40;
rnds[8] = rnds[8] & 0x3f | 0x80;
if (buf) {
for (var ii = 0; ii < 16; ++ii) {
buf[i + ii] = rnds[ii];
}
}
return buf || bytesToUuid(rnds);
};
var merge = function merge(target) {
for (var _i2 = 1, j = _arguments.length; _i2 < j; _i2++) {
var source = _arguments[_i2] || {};
for (var prop in source) {
if (source.hasOwnProperty(prop)) {
var value = source[prop];
if (value !== undefined) {
target[prop] = value;
}
}
}
}
return target;
};
var getRandom = function getRandom(min, max) {
var r = Math.random() * (max - min);
var re = Math.round(r + min);
re = Math.max(Math.min(re, max), min);
return re;
};
var cloneDeep = function cloneDeep(obj) {
var keys = Object.keys(obj);
var newObject = {};
for (var _i3 = 0; _i3 < keys.length; _i3++) {
var key = keys[_i3];
if (_typeof(obj[key]) === 'object') {
newObject[key] = cloneDeep(obj[key]);
} else {
newObject[key] = obj[key];
}
}
return newObject;
};
var create = function create(tagName, className, container, id) {
var el = document.createElement(tagName);
if (id) el.id = id;
if (className) addClass(el, className);
if (container) {
container.appendChild(el);
}
return el;
};
var createCanvas = function createCanvas(width, height, Canvas) {
if (typeof document !== 'undefined') {
var canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
return canvas;
} else {
return new Canvas(width, height);
}
};
var getElement = function getElement(id) {
return typeof id === 'string' ? document.getElementById(id) : id;
};
var remove = function remove(node) {
return node && node.parentNode ? node.parentNode.removeChild(node) : null;
};
var empty = function empty(el) {
while (el.firstChild) {
el.removeChild(el.firstChild);
}
};
var 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;
};
var hasClass = function hasClass(el, cls) {
if (!el || !cls) return false;
if (cls.indexOf(' ') !== -1) throw new Error('className should not contain space.');
if (el.classList) {
return el.classList.contains(cls);
} else {
return (' ' + el.className + ' ').indexOf(' ' + cls + ' ') > -1;
}
};
var addClass = function addClass(el, cls) {
if (!el) return;
var curClass = el.className;
var classes = (cls || '').split(' ');
for (var i = 0, j = classes.length; i < j; i++) {
var clsName = classes[i];
if (!clsName) continue;
if (el.classList) {
el.classList.add(clsName);
} else if (!hasClass(el, clsName)) {
curClass += ' ' + clsName;
}
}
if (!el.classList) {
el.className = curClass;
}
};
var removeClass = function removeClass(el, cls) {
if (!el || !cls) return;
var classes = cls.split(' ');
var curClass = ' ' + el.className + ' ';
for (var i = 0, j = classes.length; i < j; i++) {
var clsName = classes[i];
if (!clsName) continue;
if (el.classList) {
el.classList.remove(clsName);
} else if (hasClass(el, clsName)) {
curClass = curClass.replace(' ' + clsName + ' ', ' ');
}
}
if (!el.classList) {
el.className = trim(curClass);
}
};
var getStyle = function getStyle(element, styleName) {
if (!element || !styleName) return null;
styleName = camelCase(styleName);
if (styleName === 'float') {
styleName = 'cssFloat';
}
try {
var computed = document.defaultView.getComputedStyle(element, '');
return element.style[styleName] || computed ? computed[styleName] : null;
} catch (e) {
return element.style[styleName];
}
};
var setStyle = function setStyle(element, styleName, value) {
if (!element || !styleName) return;
if ((typeof styleName === 'undefined' ? 'undefined' : _typeof(styleName)) === 'object') {
for (var prop in styleName) {
if (styleName.hasOwnProperty(prop)) {
setStyle(element, prop, styleName[prop]);
}
}
} else {
styleName = camelCase(styleName);
if (styleName === 'opacity') {
element.style.filter = isNaN(value) ? '' : 'alpha(opacity=' + value * 100 + ')';
} else {
element.style[styleName] = value;
}
}
};
var getDomEventKey = function getDomEventKey(type, fn, context) {
return '_dom_event_' + type + '_' + stamp(fn) + (context ? '_' + stamp(context) : '');
};
var addListener = function addListener(element, type, fn, context, isOnce) {
var eventKey = getDomEventKey(type, fn, context);
var handler = element[eventKey];
if (handler) {
if (!isOnce) {
handler.callOnce = false;
}
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 on = addListener;
var 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;
};
var off = removeListener;
var once = function once(element, type, fn, context) {
return addListener(element, type, fn, context, true);
};
var preventDefault = function preventDefault(event) {
if (event.preventDefault) {
event.preventDefault();
} else {
event.returnValue = false;
}
return this;
};
var stopPropagation = function stopPropagation(event) {
if (event.stopPropagation) {
event.stopPropagation();
} else {
event.cancelBubble = true;
}
return this;
};
var index = Object.freeze({
has: has,
merge: merge,
stamp: stamp,
uuid: uuid,
trim: trim,
isNull: isNull,
isString: isString,
isObject: isObject,
isNumber: isNumber,
camelCase: camelCase,
getRandom: getRandom,
cloneDeep: cloneDeep,
create: create,
createCanvas: createCanvas,
getElement: getElement,
remove: remove,
empty: empty,
createHidden: createHidden,
hasClass: hasClass,
addClass: addClass,
removeClass: removeClass,
getStyle: getStyle,
setStyle: setStyle,
on: on,
once: once,
addListener: addListener,
off: off,
removeListener: removeListener,
preventDefault: preventDefault,
stopPropagation: stopPropagation
});
var CanvasLayer = function (_ol$layer$Image) {
inherits(CanvasLayer, _ol$layer$Image);
function CanvasLayer() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
classCallCheck(this, CanvasLayer);
var _this = possibleConstructorReturn(this, _ol$layer$Image.call(this, options));
_this._canvas = null;
_this.options = options;
_this.setSource(new ol.source.ImageCanvas({
logo: options.logo,
state: options.state,
attributions: options.attributions,
resolutions: options.resolutions,
canvasFunction: _this.canvasFunction.bind(_this),
projection: options.hasOwnProperty('projection') ? options.projection : 'EPSG:3857',
ratio: options.hasOwnProperty('ratio') ? options.ratio : 1
}));
_this.on('precompose', _this.redraw, _this);
return _this;
}
CanvasLayer.prototype.redraw = function redraw() {
var _extent = this.options.extent || this._getMapExtent();
this.setExtent(_extent);
};
CanvasLayer.prototype.getContext = function getContext() {
return this._canvas.getContext(this.get('context') || '2d');
};
CanvasLayer.prototype._getMapExtent = function _getMapExtent() {
if (!this.getMap()) return;
var size = this._getMapSize();
var _view = this.getMap().getView();
return _view && _view.calculateExtent(size);
};
CanvasLayer.prototype._getMapSize = function _getMapSize() {
if (!this.getMap()) return;
return this.getMap().getSize();
};
CanvasLayer.prototype.canvasFunction = function canvasFunction(extent, resolution, pixelRatio, size, projection) {
if (!this._canvas) {
this._canvas = createCanvas(size[0], size[1]);
} else {
this._canvas.width = size[0];
this._canvas.height = size[1];
}
if (resolution <= this.get('maxResolution')) {
var context = this.getContext();
this.get('render') && this.get('render')({
context: context,
extent: extent,
size: size,
pixelRatio: pixelRatio,
projection: projection
});
} else {}
return this._canvas;
};
CanvasLayer.prototype.setMap = function setMap(map) {
ol.layer.Image.prototype.setMap.call(this, map);
};
CanvasLayer.prototype.getMap = function getMap() {
return this.get('map');
};
return CanvasLayer;
}(ol.layer.Image);
var DozensLayer = function (_ol$layer$Image) {
inherits(DozensLayer, _ol$layer$Image);
function DozensLayer() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
classCallCheck(this, DozensLayer);
var _this = possibleConstructorReturn(this, _ol$layer$Image.call(this, options));
_this._canvas = null;
_this._context = null;
_this._style = null;
_this.features = [];
_this.options = options;
_this.setSource(new ol.source.ImageCanvas({
logo: options.logo,
state: options.state,
attributions: options.attributions,
resolutions: options.resolutions,
canvasFunction: _this.canvasFunction.bind(_this),
projection: options.hasOwnProperty('projection') ? options.projection : 'EPSG:3857',
ratio: options.hasOwnProperty('ratio') ? options.ratio : 1
}));
_this.setStyle(options.style);
_this.on('precompose', _this.redraw, _this);
return _this;
}
DozensLayer.prototype.addFeature = function addFeature(feature) {
this.features.push(feature);
};
DozensLayer.prototype.addFeatures = function addFeatures(features) {
this.features = this.features.concat(features);
};
DozensLayer.prototype.getFeatures = function getFeatures() {
return this.features;
};
DozensLayer.prototype.getFeatureById = function getFeatureById(id) {};
DozensLayer.prototype.getStyle = function getStyle() {
return this._style;
};
DozensLayer.prototype.setStyle = function setStyle(style) {
this._style = style;
};
DozensLayer.prototype._drawFeature = function _drawFeature() {
var that = this;
if (!this.getMap()) return;
if (!this._context) this._context = this.getContext();
var _length = this.features.length;
var imageStyle = that._style.getImage();
function render_(beauty) {
for (var i = 0; i < _length; i++) {
var geometry = that.features[i].getGeometry();
var coordinates = geometry && geometry.getCoordinates();
if (coordinates) {
var pixel = that.getMap().getPixelFromCoordinate(coordinates);
var _imageStyle = that._style.getImage();
var size = _imageStyle.getSize();
that._context.drawImage(beauty, pixel[0], pixel[1], size[0], size[1]);
}
}
}
if (imageStyle) {
var beauty = new Image();
beauty.src = imageStyle.getSrc();
if (beauty.complete) {
render_(beauty);
}
}
};
DozensLayer.prototype.redraw = function redraw() {
var _extent = this.options.extent || this._getMapExtent();
this.setExtent(_extent);
};
DozensLayer.prototype.getContext = function getContext() {
return this._canvas.getContext(this.get('context') || '2d');
};
DozensLayer.prototype._getMapExtent = function _getMapExtent() {
if (!this.getMap()) return;
var size = this._getMapSize();
var _view = this.getMap().getView();
return _view && _view.calculateExtent(size);
};
DozensLayer.prototype._getMapSize = function _getMapSize() {
if (!this.getMap()) return;
return this.getMap().getSize();
};
DozensLayer.prototype.canvasFunction = function canvasFunction(extent, resolution, pixelRatio, size, projection) {
if (!this._canvas) {
this._canvas = createCanvas(size[0], size[1]);
} else {
this._canvas.width = size[0];
this._canvas.height = size[1];
}
if (resolution <= this.get('maxResolution')) {
var context = this.getContext();
this._drawFeature();
this.get('render') && this.get('render')({
context: context,
extent: extent,
size: size,
pixelRatio: pixelRatio,
projection: projection
});
} else {}
return this._canvas;
};
DozensLayer.prototype.setMap = function setMap(map) {
this.set('originMap', map);
};
DozensLayer.prototype.getMap = function getMap() {
return this.get('originMap');
};
return DozensLayer;
}(ol.layer.Image);
ol.layer.DozensLayer = DozensLayer;
var index$1 = Object.freeze({
CanvasLayer: CanvasLayer,
DozensLayer: DozensLayer
});
var Baidu = function (_ol$source$TileImage) {
inherits(Baidu, _ol$source$TileImage);
function Baidu() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
classCallCheck(this, Baidu);
var attributions = '';
if (options.attributions !== undefined) {
attributions = options.attributions;
} else {
attributions = [Baidu.ATTRIBUTION];
}
options.projection = options['projection'] ? options.projection : 'EPSG:3857';
var crossOrigin = options.crossOrigin !== undefined ? options.crossOrigin : 'anonymous';
var url = options.url !== undefined ? options.url : 'http://online{0-3}.map.bdimg.com/onlinelabel/?qt=tile&x={x}&y={y}&z={z}&styles={styles}&udt=20170607&scaler=1&p=1';
var hidpi = options.hidpi || (window.devicePixelRatio || window.screen.deviceXDPI / window.screen.logicalXDPI) > 1;
url = url.replace('{styles}', hidpi ? 'ph' : 'pl');
var tileUrlFunction = options.tileUrlFunction ? options.tileUrlFunction : undefined;
if (!tileUrlFunction) {
tileUrlFunction = function tileUrlFunction(tileCoord) {
var _ref = [tileCoord[0], tileCoord[2], tileCoord[1]],
z = _ref[0],
y = _ref[1],
x = _ref[2];
if (x < 0) {
x = 'M' + -x;
}
if (y < 0) {
y = 'M' + -y;
}
return url.replace('{0-3}', getRandom(0, 3)).replace('{x}', x.toString()).replace('{y}', y.toString()).replace('{z}', z.toString());
};
}
var levels = options['levels'] ? options['levels'] : 19;
var resolutions = [];
for (var z = 0; z < levels; z++) {
resolutions[z] = Math.pow(2, levels - 1 - z);
}
var tileGrid = new ol.tilegrid.TileGrid({
tileSize: options['tileSize'] ? options['tileSize'] : 256,
origin: options['origin'] ? options['origin'] : [0, 0],
extent: options['extent'] ? options['extent'] : undefined,
resolutions: resolutions,
minZoom: options['minZoom'] && typeof options['minZoom'] === 'number' ? options['minZoom'] : 0
});
return possibleConstructorReturn(this, _ol$source$TileImage.call(this, {
tileGrid: tileGrid,
attributions: attributions,
cacheSize: options.cacheSize,
projection: options.projection,
crossOrigin: crossOrigin,
opaque: options.opaque !== undefined ? options.opaque : true,
maxZoom: options.maxZoom !== undefined ? options.maxZoom : 19,
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
tileUrlFunction: tileUrlFunction,
url: url,
wrapX: options.wrapX,
tilePixelRatio: hidpi ? 2 : 1
}));
}
return Baidu;
}(ol.source.TileImage);
Baidu.ATTRIBUTION = new ol.Attribution({
html: '© ' + '<a href="http://map.baidu.com/">百度地图</a> ' + 'contributors.'
});
var Gaode = function (_ol$source$XYZ) {
inherits(Gaode, _ol$source$XYZ);
function Gaode() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
classCallCheck(this, Gaode);
var attributions = '';
if (options.attributions !== undefined) {
attributions = options.attributions;
} else {
attributions = [Gaode.ATTRIBUTION];
}
options.projection = options['projection'] ? options.projection : 'EPSG:3857';
var crossOrigin = options.crossOrigin !== undefined ? options.crossOrigin : 'anonymous';
var url = options.url !== undefined ? options.url : 'http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=6&x={x}&y={y}&z={z}';
var tileUrlFunction = options.tileUrlFunction ? options.tileUrlFunction : undefined;
return possibleConstructorReturn(this, _ol$source$XYZ.call(this, {
attributions: attributions,
cacheSize: options.cacheSize,
crossOrigin: crossOrigin,
opaque: options.opaque !== undefined ? options.opaque : true,
maxZoom: options.maxZoom !== undefined ? options.maxZoom : 19,
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
tileLoadFunction: options.tileLoadFunction,
tileUrlFunction: tileUrlFunction,
url: url,
wrapX: options.wrapX
}));
}
return Gaode;
}(ol.source.XYZ);
Gaode.ATTRIBUTION = new ol.Attribution({
html: '© ' + '<a href="http://ditu.amap.com/">高德地图</a> ' + 'contributors.'
});
var Google = function (_ol$source$XYZ) {
inherits(Google, _ol$source$XYZ);
function Google() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
classCallCheck(this, Google);
var attributions = '';
if (options.attributions !== undefined) {
attributions = options.attributions;
} else {
attributions = [Google.ATTRIBUTION];
}
options.projection = options['projection'] ? options.projection : 'EPSG:3857';
var crossOrigin = options.crossOrigin !== undefined ? options.crossOrigin : 'anonymous';
var url = options.url !== undefined ? options.url : 'http://www.google.cn/maps/vt?lyrs=m@189&gl=cn&x={x}&y={y}&z={z}';
return possibleConstructorReturn(this, _ol$source$XYZ.call(this, {
attributions: attributions,
cacheSize: options.cacheSize,
crossOrigin: crossOrigin,
opaque: options.opaque !== undefined ? options.opaque : true,
maxZoom: options.maxZoom !== undefined ? options.maxZoom : 19,
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
tileLoadFunction: options.tileLoadFunction,
url: url,
wrapX: options.wrapX
}));
}
return Google;
}(ol.source.XYZ);
Google.ATTRIBUTION = new ol.Attribution({
html: '© ' + '<a href="http://www.google.cn/maps">谷歌地图</a> ' + 'contributors.'
});
var index$2 = Object.freeze({
Baidu: Baidu,
Gaode: Gaode,
Google: Google
});
var BASE_CLASS_NAME = {
CLASS_HIDDEN: 'ole-hidden',
CLASS_SELECTABLE: 'ole-selectable',
CLASS_UNSELECTABLE: 'ole-unselectable',
CLASS_CONTROL: 'ole-control'
};
var UNITS = {
DEGREES: 'degrees',
FEET: 'ft',
METERS: 'm',
PIXELS: 'pixels',
TILE_PIXELS: 'tile-pixels',
USFEET: 'us-ft',
METERS_PER_UNIT: {}
};
UNITS.METERS_PER_UNIT[UNITS.DEGREES] = 2 * Math.PI * 6370997 / 360;
UNITS.METERS_PER_UNIT[UNITS.FEET] = 0.3048;
UNITS.METERS_PER_UNIT[UNITS.METERS] = 1;
UNITS.METERS_PER_UNIT[UNITS.USFEET] = 1200 / 3937;
var OVERVIEWMAP = {
MIN_RATIO: 0.1,
MAX_RATIO: 0.75
};
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
var screenfull = createCommonjsModule(function (module) {
/*!
* screenfull
* v3.3.3 - 2018-09-04
* (c) Sindre Sorhus; MIT License
*/
(function () {
var document = typeof window !== 'undefined' && typeof window.document !== 'undefined' ? window.document : {};
var isCommonjs = 'object' !== 'undefined' && module.exports;
var keyboardAllowed = typeof Element !== 'undefined' && 'ALLOW_KEYBOARD_INPUT' in Element;
var fn = (function () {
var val;
var fnMap = [
[
'requestFullscreen',
'exitFullscreen',
'fullscreenElement',
'fullscreenEnabled',
'fullscreenchange',
'fullscreenerror'
],
// New WebKit
[
'webkitRequestFullscreen',
'webkitExitFullscreen',
'webkitFullscreenElement',
'webkitFullscreenEnabled',
'webkitfullscreenchange',
'webkitfullscreenerror'
],
// Old WebKit (Safari 5.1)
[
'webkitRequestFullScreen',
'webkitCancelFullScreen',
'webkitCurrentFullScreenElement',
'webkitCancelFullScreen',
'webkitfullscreenchange',
'webkitfullscreenerror'
],
[
'mozRequestFullScreen',
'mozCancelFullScreen',
'mozFullScreenElement',
'mozFullScreenEnabled',
'mozfullscreenchange',
'mozfullscreenerror'
],
[
'msRequestFullscreen',
'msExitFullscreen',
'msFullscreenElement',
'msFullscreenEnabled',
'MSFullscreenChange',
'MSFullscreenError'
]
];
var i = 0;
var l = fnMap.length;
var ret = {};
for (; i < l; i++) {
val = fnMap[i];
if (val && val[1] in document) {
for (i = 0; i < val.length; i++) {
ret[fnMap[0][i]] = val[i];
}
return ret;
}
}
return false;
})();
var eventNameMap = {
change: fn.fullscreenchange,
error: fn.fullscreenerror
};
var screenfull = {
request: function (elem) {
var request = fn.requestFullscreen;
elem = elem || document.documentElement;
// Work around Safari 5.1 bug: reports support for
// keyboard in fullscreen even though it doesn't.
// Browser sniffing, since the alternative with
// setTimeout is even worse.
if (/ Version\/5\.1(?:\.\d+)? Safari\//.test(navigator.userAgent)) {
elem[request]();
} else {
elem[request](keyboardAllowed ? Element.ALLOW_KEYBOARD_INPUT : {});
}
},
exit: function () {
document[fn.exitFullscreen]();
},
toggle: function (elem) {
if (this.isFullscreen) {
this.exit();
} else {
this.request(elem);
}
},
onchange: function (callback) {
this.on('change', callback);
},
onerror: function (callback) {
this.on('error', callback);
},
on: function (event, callback) {
var eventName = eventNameMap[event];
if (eventName) {
document.addEventListener(eventName, callback, false);
}
},
off: function (event, callback) {
var eventName = eventNameMap[event];
if (eventName) {
document.removeEventListener(eventName, callback, false);
}
},
raw: fn
};
if (!fn) {
if (isCommonjs) {
module.exports = false;
} else {
window.screenfull = false;
}
return;
}
Object.defineProperties(screenfull, {
isFullscreen: {
get: function () {
return Boolean(document[fn.fullscreenElement]);
}
},
element: {
enumerable: true,
get: function () {
return document[fn.fullscreenElement];
}
},
enabled: {
enumerable: true,
get: function () {
// Coerce to boolean in case of old WebKit
return Boolean(document[fn.fullscreenEnabled]);
}
}
});
if (isCommonjs) {
module.exports = screenfull;
} else {
window.screenfull = screenfull;
}
})();
});
var FullScreen = function (_ol$control$Control) {
inherits(FullScreen, _ol$control$Control);
function FullScreen() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
classCallCheck(this, FullScreen);
var label = options.label !== undefined ? options.label : '\u2922';
var labelActive = options.labelActive !== undefined ? options.labelActive : '\xD7';
var className = options.className !== undefined ? options.className : 'ole-control-full-screen';
var element = create('div', className + ' ' + BASE_CLASS_NAME.CLASS_UNSELECTABLE);
var inner = create('span', className + '-inner', element);
inner.setAttribute('title', '全屏');
inner.innerHTML = label;
var _this = possibleConstructorReturn(this, _ol$control$Control.call(this, {
element: element,
target: options.target
}));
_this.label = label;
_this.labelActive = labelActive;
_this.keys_ = options.keys !== undefined ? options.keys : false;
_this.size_ = options.size !== undefined ? options.size : [16, 16];
_this.source_ = options.source;
on(element, 'click', _this.handleClick_, _this);
return _this;
}
FullScreen.prototype.handleClick_ = function handleClick_(event) {
var _this2 = this;
event.preventDefault();
var map = this.getMap();
if (map) {
var element = null;
if (this.source_) {
element = typeof this.source_ === 'string' ? document.getElementById(this.source_) : this.source_;
} else {
element = this.getMap().getTargetElement();
}
if (screenfull.enabled) {
screenfull.toggle(element);
screenfull.on('change', function () {
if (screenfull.isFullscreen) {
_this2.element.firstElementChild.innerHTML = _this2.labelActive;
} else {
_this2.element.firstElementChild.innerHTML = _this2.label;
}
});
}
}
};
return FullScreen;
}(ol.control.Control);
var Loading = function (_ol$control$Control) {
inherits(Loading, _ol$control$Control);
function Loading() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
classCallCheck(this, Loading);
var className = options.className !== undefined ? options.className : 'ole-loading-panel';
var widget = options['widget'] ? options['widget'] : 'animatedGif';
var elementDom = widget === 'animatedGif' ? 'span' : 'progress';
var element = create(elementDom, className + ' ' + BASE_CLASS_NAME.CLASS_UNSELECTABLE);
var _this = possibleConstructorReturn(this, _ol$control$Control.call(this, {
element: element,
target: options['target']
}));
_this.mapListeners = [];
_this.tileListeners = [];
_this.loadStatus_ = false;
_this.isFirstRander = true;
_this.loadProgress_ = [0, 1];
_this.widget = widget;
if (options['progressMode']) {
if (['tile', 'layer'].indexOf(options['progressMode']) === -1) {
throw Error('不支持的进度条模式');
}
_this.loadProgressByTile_ = options['progressMode'] === 'layer' ? !(options['progressMode'] === 'layer') : true;
}
_this.showPanel = typeof options['showPanel'] === 'boolean' ? options['showPanel'] : true;
if (_this.widget === 'progressBar') {
var div = create('div', 'ole-progress-bar');
create('span', '', div);
}
_this.onCustomStart = options['onStart'] ? options['onStart'] : false;
_this.onCustomProgress = options['onProgress'] ? options['onProgress'] : false;
_this.onCustomEnd = options['onEnd'] ? options['onEnd'] : false;
return _this;
}
Loading.prototype.setup = function setup() {
var _this2 = this;
if (!this.getMap()) return;
this.setDomPosition();
this.getMap().on('change:size', this.setDomPosition, this);
var pointerDown = this.getMap().on('pointerdown', this.hide(), this);
var beforeRander = this.getMap().on('precompose', function () {
if (_this2.isFirstRander) {
_this2.isFirstRander = false;
_this2.registerLayersLoadEvents_();
_this2.show();
if (_this2.onCustomStart) {
var args = [];
_this2.onCustomStart.apply(_this2, args);
}
}
});
var afterRander = this.getMap().on('postrender', function () {
_this2.updateLoadStatus_();
if (_this2.loadStatus_) {
if (_this2.onCustomEnd) {
var args = [];
_this2.onCustomEnd.apply(_this2, args);
}
_this2.hide();
}
});
this.mapListeners.push(pointerDown);
this.mapListeners.push(beforeRander);
this.mapListeners.push(afterRander);
};
Loading.prototype.setDomPosition = function setDomPosition() {
var size = this.getMap().getSize();
if (!size) return;
var domSize = [this.element.clientWidth, this.element.clientHeight];
setStyle(this.element, {
left: String(Math.round((size[0] - domSize[0]) / 2)) + 'px',
bottom: String(Math.round((size[1] - domSize[1]) / 2)) + 'px'
});
};
Loading.prototype.updateSourceLoadStatus_ = function updateSourceLoadStatus_(source) {
return Math.round(source.loaded / source.loading * 100) === 100;
};
Loading.prototype.registerLayerLoadEvents_ = function registerLayerLoadEvents_(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('ole-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('ole-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_);
}
}
});
};
Loading.prototype.registerLayersLoadEvents_ = function registerLayersLoadEvents_() {
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));
}
}
}
};
Loading.prototype.updateLoadStatus_ = function updateLoadStatus_() {
var loadStatusArray = [];
var groups = this.getMap().getLayers().getArray();
for (var i = 0; i < groups.length; i++) {
var layer = groups[i];
if (layer) {
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 && l.getSource() && !(l instanceof ol.layer.Vector) && l.getSource().hasOwnProperty('isLoaded')) {
loadStatusArray.push(l.getSource().isLoaded);
}
}
} else if (layer.getSource() && layer.getSource().hasOwnProperty('isLoaded')) {
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_);
}
}
};
Loading.prototype.show = function show() {
if (this.showPanel) {
this.element.style.display = 'block';
}
};
Loading.prototype.hide = function hide() {
if (this.showPanel) {
this.element.style.display = 'none';
}
};
Loading.prototype.progressDetails = function progressDetails() {
return this.loadProgress_;
};
Loading.prototype.progress = function progress() {
return this.loadProgress_[0] / this.loadProgress_[1];
};
Loading.prototype.setMap = function setMap(map) {
var _this3 = this;
if (this.mapListeners && this.mapListeners.length > 0) {
this.mapListeners.forEach(function (listener) {
_this3.getMap().unByKey(listener);
});
}
this.mapListeners.length = 0;
_ol$control$Control.prototype.setMap.call(this, map);
if (map) {
this.setup();
}
};
return Loading;
}(ol.control.Control);
var ZoomMenu = function (_ol$control$Control) {
inherits(ZoomMenu, _ol$control$Control);
function ZoomMenu() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
classCallCheck(this, ZoomMenu);
var className = options.className !== undefined ? options.className : 'ole-control-zoom';
var delta = options.delta !== undefined ? options.delta : 1;
var element_ = create('div', className + ' ' + BASE_CLASS_NAME.CLASS_UNSELECTABLE);
var zoomIn = create('span', 'zoom-in', element_);
zoomIn.setAttribute('title', '放大');
zoomIn.innerHTML = '+';
var zoomOut = create('span', 'zoom-out', element_);
zoomOut.setAttribute('title', '缩小');
zoomOut.innerHTML = '\u2212';
var duration_ = options.duration !== undefined ? options.duration : 250;
var _this = possibleConstructorReturn(this, _ol$control$Control.call(this, {
element: element_,
target: options.target
}));
_this.set('duration', duration_);
on(zoomIn, 'click', _this.handleClick_.bind(_this, delta));
on(zoomOut, 'click', _this.handleClick_.bind(_this, -delta));
return _this;
}
ZoomMenu.prototype.handleClick_ = function handleClick_(delta, event) {
event.preventDefault();
this.zoomByDelta_(delta);
};
ZoomMenu.prototype.zoomByDelta_ = function zoomByDelta_(delta) {
var map = this.getMap();
var view = map.getView();
if (!view) {
throw new Error('can not get view!');
} else {
var currentResolution = view.getResolution();
if (currentResolution) {
var newResolution = view.constrainResolution(currentResolution, delta);
if (this.get('duration') > 0) {
if (view.getAnimating()) {
view.cancelAnimations();
}
view.animate({
resolution: newResolution,
duration: this.get('duration'),
easing: ol.easing.easeOut
});
} else {
view.setResolution(newResolution);
}
}
}
};
return ZoomMenu;
}(ol.control.Control);
var ScaleLine = function (_ol$control$Control) {
inherits(ScaleLine, _ol$control$Control);
function ScaleLine() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
classCallCheck(this, ScaleLine);
var className = options.className !== undefined ? options.className : 'ole-scale-line-control';
var element_ = create('div', className + ' ' + BASE_CLASS_NAME.CLASS_UNSELECTABLE);
var innerElement_ = create('div', className + '-inner', element_);
var render = options.render ? options.render : ScaleLine.render;
var _this = possibleConstructorReturn(this, _ol$control$Control.call(this, {
element: element_,
render: render,
target: options.target
}));
_this.viewState_ = null;
_this.minWidth_ = options.minWidth !== undefined ? options.minWidth : 64;
_this.renderedVisible_ = false;
_this.renderedWidth_ = undefined;
_this.renderedHTML_ = '';
_this.innerElement_ = innerElement_;
on(_this, 'change:' + ScaleLine.Property_.UNITS, _this.handleUnitsChanged_, _this);
_this.setUnits(options.units || ScaleLine.ScaleLineUnits.METRIC);
return _this;
}
ScaleLine.prototype.getUnits = function getUnits() {
return this.get(ScaleLine.Property_.UNITS);
};
ScaleLine.prototype.handleUnitsChanged_ = function handleUnitsChanged_() {
this.updateElement_();
};
ScaleLine.prototype.setUnits = function setUnits(units) {
this.set(ScaleLine.Property_.UNITS, units);
};
ScaleLine.prototype.updateElement_ = function updateElement_() {
var viewState = this.viewState_;
if (!viewState) {
if (this.renderedVisible_) {
this.element.style.display = 'none';
this.renderedVisible_ = false;
}
return;
}
var _ref = [viewState.center, viewState.projection],
center = _ref[0],
projection = _ref[1];
var units = this.getUnits();
var pointResolutionUnits = units === ScaleLine.ScaleLineUnits.DEGREES ? UNITS.DEGREES : UNITS.METERS;
var pointResolution = ol.proj.getPointResolution(projection, viewState.resolution, center, pointResolutionUnits);
var nominalCount = this.minWidth_ * pointResolution;
var suffix = '';
if (units === ScaleLine.ScaleLineUnits.DEGREES) {
var metersPerDegree = ol.proj.METERS_PER_UNIT[UNITS.DEGREES];
if (projection.getUnits() === UNITS.DEGREES) {
nominalCount *= metersPerDegree;
} else {
pointResolution /= metersPerDegree;
}
if (nominalCount < metersPerDegree / 60) {
suffix = '\u2033';
pointResolution *= 3600;
} else if (nominalCount < metersPerDegree) {
suffix = '\u2032';
pointResolution *= 60;
} else {
suffix = '\xB0';
}
} else if (units === ScaleLine.ScaleLineUnits.IMPERIAL) {
if (nominalCount < 0.9144) {
suffix = 'in';
pointResolution /= 0.0254;
} else if (nominalCount < 1609.344) {
suffix = 'ft';
pointResolution /= 0.3048;
} else {
suffix = 'mi';
pointResolution /= 1609.344;
}
} else if (units === ScaleLine.ScaleLineUnits.NAUTICAL) {
pointResolution /= 1852;
suffix = 'nm';
} else if (units === ScaleLine.ScaleLineUnits.METRIC) {
if (nominalCount < 0.001) {
suffix = 'μm';
pointResolution *= 1000000;
} else if (nominalCount < 1) {
suffix = 'mm';
pointResolution *= 1000;
} else if (nominalCount < 1000) {
suffix = 'm';
} else {
suffix = 'km';
pointResolution /= 1000;
}
} else if (units === ScaleLine.ScaleLineUnits.US) {
if (nominalCount < 0.9144) {
suffix = 'in';
pointResolution *= 39.37;
} else if (nominalCount < 1609.344) {
suffix = 'ft';
pointResolution /= 0.30480061;
} else {
suffix = 'mi';
pointResolution /= 1609.3472;
}
} else if (units === ScaleLine.ScaleLineUnits.CHINESEMETRIC) {
if (nominalCount < 0.001) {
suffix = '微米';
pointResolution *= 1000000;
} else if (nominalCount < 1) {
suffix = '毫米';
pointResolution *= 1000;
} else if (nominalCount < 1000) {
suffix = '米';
} else {
suffix = '千米';
pointResolution /= 1000;
}
} else {
ol.asserts.assert(false, 33);
}
var i = 3 * Math.floor(Math.log(this.minWidth_ * pointResolution) / Math.log(10));
var count = undefined,
width = undefined;
while (true) {
count = ScaleLine.LEADING_DIGITS[(i % 3 + 3) % 3] * Math.pow(10, Math.floor(i / 3));
width = Math.round(count / pointResolution);
if (isNaN(width)) {
this.element.style.display = 'none';
this.renderedVisible_ = false;
return;
} else if (width >= this.minWidth_) {
break;
}
++i;
}
var html = count + ' ' + suffix;
if (this.renderedHTML_ !== html) {
this.innerElement_.innerHTML = html;
this.renderedHTML_ = html;
}
if (this.renderedWidth_ !== width) {
this.innerElement_.style.width = width + 'px';
this.renderedWidth_ = width;
}
if (!this.renderedVisible_) {
this.element.style.display = '';
this.renderedVisible_ = true;
}
};
return ScaleLine;
}(ol.control.Control);
ScaleLine.render = function (mapEvent) {
var frameState = mapEvent.frameState;
if (!frameState) {
this.viewState_ = null;
} else {
this.viewState_ = frameState.viewState;
}
this.updateElement_();
};
ScaleLine.LEADING_DIGITS = [1, 2, 5];
ScaleLine.ScaleLineUnits = {
DEGREES: 'degrees',
IMPERIAL: 'imperial',
NAUTICAL: 'nautical',
METRIC: 'metric',
CHINESEMETRIC: 'metric_cn',
US: 'us'
};
ScaleLine.Property_ = {
UNITS: 'units'
};
var RotateControl = function (_ol$control$Control) {
inherits(RotateControl, _ol$control$Control);
function RotateControl() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
classCallCheck(this, RotateControl);
var className = options.className !== undefined ? options.className : 'ole-rotate-control';
var element = create('div', className + ' ' + BASE_CLASS_NAME.CLASS_UNSELECTABLE);
var rButton = create('button', className + '-inner right-button', element);
var cButton = create('button', className + '-inner center-button', element, className + '-inner-center');
var lButton = create('button', className + '-inner left-button', element);
var render = options.render ? options.render : RotateControl.render;
var _this = possibleConstructorReturn(this, _ol$control$Control.call(this, {
element: element,
render: render,
target: options.target
}));
_this.callResetNorth_ = options.resetNorth ? options.resetNorth : undefined;
_this.duration_ = options.duration !== undefined ? options.duration : 250;
_this.autoHide_ = options.autoHide !== undefined ? options.autoHide : true;
_this.rotation_ = undefined;
_this.label_ = cButton;
on(rButton, 'click', _this.handleClick_.bind(_this, 'right'));
on(cButton, 'click', _this.handleClick_.bind(_this, 'center'));
on(lButton, 'click', _this.handleClick_.bind(_this, 'left'));
return _this;
}
RotateControl.prototype.handleClick_ = function handleClick_(type, event) {
event.preventDefault();
this.resetNorth_(type);
};
RotateControl.prototype.resetNorth_ = function resetNorth_(type) {
var rotation = 0;
if (type === 'center') {
rotation = 0;
if (this.callResetNorth_ !== undefined) {
this.callResetNorth_();
} else {
this.rotationView_(rotation, type);
}
} else if (type === 'left') {
rotation = -90;
this.rotationView_(rotation);
} else {
rotation = 90;
this.rotationView_(rotation);
}
};
RotateControl.prototype.rotationView_ = function rotationView_(rotation, type) {
var map = this.getMap();
var view = map.getView();
var r = type === 'center' ? 0 : view.getRotation() + rotation / 180 * Math.PI;
if (view && view instanceof ol.View) {
if (view.getRotation() !== undefined) {
if (this.duration_ > 0) {
view.animate({
rotation: r,
duration: this.duration_,
easing: ol.easing.easeOut
});
} else {
view.setRotation(0);
}
}
} else {
throw new Error('can not get view!');
}
};
return RotateControl;
}(ol.control.Control);
RotateControl.render = function (mapEvent) {
var frameState = mapEvent.frameState;
if (!frameState) {
return;
}
var rotation = frameState.viewState.rotation;
if (rotation !== this.rotation_) {
var transform = 'rotate(' + rotation + 'rad)';
if (this.autoHide_) {
var contains = hasClass(this.element, BASE_CLASS_NAME.CLASS_HIDDEN);
if (!contains && rotation === 0) {
addClass(this.element, BASE_CLASS_NAME.CLASS_HIDDEN);
} else if (contains && rotation !== 0) {
removeClass(this.element, BASE_CLASS_NAME.CLASS_HIDDEN);
}
}
setStyle(this.label_, {
transform: transform,
webkitTransform: transform,
msTransform: transform
});
}
this.rotation_ = rotation;
};
var OverviewMap = function (_ol$control$Control) {
inherits(OverviewMap, _ol$control$Control);
function OverviewMap() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
classCallCheck(this, OverviewMap);
var className = options.className !== undefined ? options.className : 'ole-overview-map';
var element = create('div', className + ' ' + BASE_CLASS_NAME.CLASS_UNSELECTABLE);
var render = options.render ? options.render : OverviewMap.render;
var _this = possibleConstructorReturn(this, _ol$control$Control.call(this, {
element: element,
render: render,
target: options.target
}));
_this.collapsed_ = options.collapsed !== undefined ? options.collapsed : true;
_this.collapsible_ = options.collapsible !== undefined ? options.collapsible : true;
if (!_this.collapsible_) {
_this.collapsed_ = false;
}
_this.ovmapDiv_ = create('div', 'ole-overview-map-target', element);
if (_this.collapsible_) {
_this.collapsElement_ = create(