e-civ-planet
Version:
A WebGL virtual globe and map engine based on webglobe
1,376 lines (1,338 loc) • 1.35 MB
JavaScript
/******/ (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] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.loaded = 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;
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
__webpack_require__(1);
module.exports = __webpack_require__(57);
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
var require;var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;/* WEBPACK VAR INJECTION */(function(process, global) {"use strict";
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; };
!function (t, e) {
"object" == ( false ? "undefined" : _typeof(exports)) && "undefined" != typeof module ? module.exports = e() : true ? !(__WEBPACK_AMD_DEFINE_FACTORY__ = (e), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.call(exports, __webpack_require__, exports, module)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)) : t.ES6Promise = e();
}(undefined, function () {
"use strict";
function t(t) {
var e = typeof t === "undefined" ? "undefined" : _typeof(t);return null !== t && ("object" === e || "function" === e);
}function e(t) {
return "function" == typeof t;
}function n(t) {
I = t;
}function r(t) {
J = t;
}function o() {
return function () {
return process.nextTick(a);
};
}function i() {
return "undefined" != typeof H ? function () {
H(a);
} : c();
}function s() {
var t = 0,
e = new V(a),
n = document.createTextNode("");return e.observe(n, { characterData: !0 }), function () {
n.data = t = ++t % 2;
};
}function u() {
var t = new MessageChannel();return t.port1.onmessage = a, function () {
return t.port2.postMessage(0);
};
}function c() {
var t = setTimeout;return function () {
return t(a, 1);
};
}function a() {
for (var t = 0; t < G; t += 2) {
var e = $[t],
n = $[t + 1];e(n), $[t] = void 0, $[t + 1] = void 0;
}G = 0;
}function f() {
try {
var t = require,
e = __webpack_require__(3);return H = e.runOnLoop || e.runOnContext, i();
} catch (n) {
return c();
}
}function l(t, e) {
var n = arguments,
r = this,
o = new this.constructor(p);void 0 === o[et] && k(o);var i = r._state;return i ? !function () {
var t = n[i - 1];J(function () {
return x(i, o, t, r._result);
});
}() : E(r, o, t, e), o;
}function h(t) {
var e = this;if (t && "object" == (typeof t === "undefined" ? "undefined" : _typeof(t)) && t.constructor === e) return t;var n = new e(p);return g(n, t), n;
}function p() {}function v() {
return new TypeError("You cannot resolve a promise with itself");
}function d() {
return new TypeError("A promises callback cannot return that same promise.");
}function _(t) {
try {
return t.then;
} catch (e) {
return it.error = e, it;
}
}function y(t, e, n, r) {
try {
t.call(e, n, r);
} catch (o) {
return o;
}
}function m(t, e, n) {
J(function (t) {
var r = !1,
o = y(n, e, function (n) {
r || (r = !0, e !== n ? g(t, n) : S(t, n));
}, function (e) {
r || (r = !0, j(t, e));
}, "Settle: " + (t._label || " unknown promise"));!r && o && (r = !0, j(t, o));
}, t);
}function b(t, e) {
e._state === rt ? S(t, e._result) : e._state === ot ? j(t, e._result) : E(e, void 0, function (e) {
return g(t, e);
}, function (e) {
return j(t, e);
});
}function w(t, n, r) {
n.constructor === t.constructor && r === l && n.constructor.resolve === h ? b(t, n) : r === it ? (j(t, it.error), it.error = null) : void 0 === r ? S(t, n) : e(r) ? m(t, n, r) : S(t, n);
}function g(e, n) {
e === n ? j(e, v()) : t(n) ? w(e, n, _(n)) : S(e, n);
}function A(t) {
t._onerror && t._onerror(t._result), T(t);
}function S(t, e) {
t._state === nt && (t._result = e, t._state = rt, 0 !== t._subscribers.length && J(T, t));
}function j(t, e) {
t._state === nt && (t._state = ot, t._result = e, J(A, t));
}function E(t, e, n, r) {
var o = t._subscribers,
i = o.length;t._onerror = null, o[i] = e, o[i + rt] = n, o[i + ot] = r, 0 === i && t._state && J(T, t);
}function T(t) {
var e = t._subscribers,
n = t._state;if (0 !== e.length) {
for (var r = void 0, o = void 0, i = t._result, s = 0; s < e.length; s += 3) {
r = e[s], o = e[s + n], r ? x(n, r, o, i) : o(i);
}t._subscribers.length = 0;
}
}function M() {
this.error = null;
}function P(t, e) {
try {
return t(e);
} catch (n) {
return st.error = n, st;
}
}function x(t, n, r, o) {
var i = e(r),
s = void 0,
u = void 0,
c = void 0,
a = void 0;if (i) {
if (s = P(r, o), s === st ? (a = !0, u = s.error, s.error = null) : c = !0, n === s) return void j(n, d());
} else s = o, c = !0;n._state !== nt || (i && c ? g(n, s) : a ? j(n, u) : t === rt ? S(n, s) : t === ot && j(n, s));
}function C(t, e) {
try {
e(function (e) {
g(t, e);
}, function (e) {
j(t, e);
});
} catch (n) {
j(t, n);
}
}function O() {
return ut++;
}function k(t) {
t[et] = ut++, t._state = void 0, t._result = void 0, t._subscribers = [];
}function Y(t, e) {
this._instanceConstructor = t, this.promise = new t(p), this.promise[et] || k(this.promise), B(e) ? (this.length = e.length, this._remaining = e.length, this._result = new Array(this.length), 0 === this.length ? S(this.promise, this._result) : (this.length = this.length || 0, this._enumerate(e), 0 === this._remaining && S(this.promise, this._result))) : j(this.promise, q());
}function q() {
return new Error("Array Methods must be provided an Array");
}function F(t) {
return new Y(this, t).promise;
}function D(t) {
var e = this;return new e(B(t) ? function (n, r) {
for (var o = t.length, i = 0; i < o; i++) {
e.resolve(t[i]).then(n, r);
}
} : function (t, e) {
return e(new TypeError("You must pass an array to race."));
});
}function K(t) {
var e = this,
n = new e(p);return j(n, t), n;
}function L() {
throw new TypeError("You must pass a resolver function as the first argument to the promise constructor");
}function N() {
throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
}function U(t) {
this[et] = O(), this._result = this._state = void 0, this._subscribers = [], p !== t && ("function" != typeof t && L(), this instanceof U ? C(this, t) : N());
}function W() {
var t = void 0;if ("undefined" != typeof global) t = global;else if ("undefined" != typeof self) t = self;else try {
t = Function("return this")();
} catch (e) {
throw new Error("polyfill failed because global object is unavailable in this environment");
}var n = t.Promise;if (n) {
var r = null;try {
r = Object.prototype.toString.call(n.resolve());
} catch (e) {}if ("[object Promise]" === r && !n.cast) return;
}t.Promise = U;
}var z = void 0;z = Array.isArray ? Array.isArray : function (t) {
return "[object Array]" === Object.prototype.toString.call(t);
};var B = z,
G = 0,
H = void 0,
I = void 0,
J = function J(t, e) {
$[G] = t, $[G + 1] = e, G += 2, 2 === G && (I ? I(a) : tt());
},
Q = "undefined" != typeof window ? window : void 0,
R = Q || {},
V = R.MutationObserver || R.WebKitMutationObserver,
X = "undefined" == typeof self && "undefined" != typeof process && "[object process]" === {}.toString.call(process),
Z = "undefined" != typeof Uint8ClampedArray && "undefined" != typeof importScripts && "undefined" != typeof MessageChannel,
$ = new Array(1e3),
tt = void 0;tt = X ? o() : V ? s() : Z ? u() : void 0 === Q && "function" == "function" ? f() : c();var et = Math.random().toString(36).substring(16),
nt = void 0,
rt = 1,
ot = 2,
it = new M(),
st = new M(),
ut = 0;return Y.prototype._enumerate = function (t) {
for (var e = 0; this._state === nt && e < t.length; e++) {
this._eachEntry(t[e], e);
}
}, Y.prototype._eachEntry = function (t, e) {
var n = this._instanceConstructor,
r = n.resolve;if (r === h) {
var o = _(t);if (o === l && t._state !== nt) this._settledAt(t._state, e, t._result);else if ("function" != typeof o) this._remaining--, this._result[e] = t;else if (n === U) {
var i = new n(p);w(i, t, o), this._willSettleAt(i, e);
} else this._willSettleAt(new n(function (e) {
return e(t);
}), e);
} else this._willSettleAt(r(t), e);
}, Y.prototype._settledAt = function (t, e, n) {
var r = this.promise;r._state === nt && (this._remaining--, t === ot ? j(r, n) : this._result[e] = n), 0 === this._remaining && S(r, this._result);
}, Y.prototype._willSettleAt = function (t, e) {
var n = this;E(t, void 0, function (t) {
return n._settledAt(rt, e, t);
}, function (t) {
return n._settledAt(ot, e, t);
});
}, U.all = F, U.race = D, U.resolve = h, U.reject = K, U._setScheduler = n, U._setAsap = r, U._asap = J, U.prototype = { constructor: U, then: l, "catch": function _catch(t) {
return this.then(null, t);
} }, U.polyfill = W, U.Promise = U, U.polyfill(), U;
});
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(2), (function() { return this; }())))
/***/ }),
/* 2 */
/***/ (function(module, exports) {
'use strict';
// shim for using process in browser
var process = module.exports = {};
// cached from whatever global is present so that test runners that stub it
// don't break things. But we need to wrap it in a try catch in case it is
// wrapped in strict mode code which doesn't define any globals. It's inside a
// function because try/catches deoptimize in certain engines.
var cachedSetTimeout;
var cachedClearTimeout;
function defaultSetTimout() {
throw new Error('setTimeout has not been defined');
}
function defaultClearTimeout() {
throw new Error('clearTimeout has not been defined');
}
(function () {
try {
if (typeof setTimeout === 'function') {
cachedSetTimeout = setTimeout;
} else {
cachedSetTimeout = defaultSetTimout;
}
} catch (e) {
cachedSetTimeout = defaultSetTimout;
}
try {
if (typeof clearTimeout === 'function') {
cachedClearTimeout = clearTimeout;
} else {
cachedClearTimeout = defaultClearTimeout;
}
} catch (e) {
cachedClearTimeout = defaultClearTimeout;
}
})();
function runTimeout(fun) {
if (cachedSetTimeout === setTimeout) {
//normal enviroments in sane situations
return setTimeout(fun, 0);
}
// if setTimeout wasn't available but was latter defined
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
cachedSetTimeout = setTimeout;
return setTimeout(fun, 0);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedSetTimeout(fun, 0);
} catch (e) {
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedSetTimeout.call(null, fun, 0);
} catch (e) {
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
return cachedSetTimeout.call(this, fun, 0);
}
}
}
function runClearTimeout(marker) {
if (cachedClearTimeout === clearTimeout) {
//normal enviroments in sane situations
return clearTimeout(marker);
}
// if clearTimeout wasn't available but was latter defined
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
cachedClearTimeout = clearTimeout;
return clearTimeout(marker);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedClearTimeout(marker);
} catch (e) {
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedClearTimeout.call(null, marker);
} catch (e) {
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
return cachedClearTimeout.call(this, marker);
}
}
}
var queue = [];
var draining = false;
var currentQueue;
var queueIndex = -1;
function cleanUpNextTick() {
if (!draining || !currentQueue) {
return;
}
draining = false;
if (currentQueue.length) {
queue = currentQueue.concat(queue);
} else {
queueIndex = -1;
}
if (queue.length) {
drainQueue();
}
}
function drainQueue() {
if (draining) {
return;
}
var timeout = runTimeout(cleanUpNextTick);
draining = true;
var len = queue.length;
while (len) {
currentQueue = queue;
queue = [];
while (++queueIndex < len) {
if (currentQueue) {
currentQueue[queueIndex].run();
}
}
queueIndex = -1;
len = queue.length;
}
currentQueue = null;
draining = false;
runClearTimeout(timeout);
}
process.nextTick = function (fun) {
var args = new Array(arguments.length - 1);
if (arguments.length > 1) {
for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}
}
queue.push(new Item(fun, args));
if (queue.length === 1 && !draining) {
runTimeout(drainQueue);
}
};
// v8 likes predictible objects
function Item(fun, array) {
this.fun = fun;
this.array = array;
}
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
process.title = 'browser';
process.browser = true;
process.env = {};
process.argv = [];
process.version = ''; // empty string to avoid regexp issues
process.versions = {};
function noop() {}
process.on = noop;
process.addListener = noop;
process.once = noop;
process.off = noop;
process.removeListener = noop;
process.removeAllListeners = noop;
process.emit = noop;
process.prependListener = noop;
process.prependOnceListener = noop;
process.listeners = function (name) {
return [];
};
process.binding = function (name) {
throw new Error('process.binding is not supported');
};
process.cwd = function () {
return '/';
};
process.chdir = function (dir) {
throw new Error('process.chdir is not supported');
};
process.umask = function () {
return 0;
};
/***/ }),
/* 3 */
/***/ (function(module, exports) {
/* (ignored) */
/***/ }),
/* 4 */,
/* 5 */
/***/ (function(module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var REAL_EARTH_RADIUS = 6378137;
var EARTH_RADIUS = 500;
var SCALE_FACTOR = EARTH_RADIUS / REAL_EARTH_RADIUS;
var MAX_PROJECTED_COORD = Math.PI * EARTH_RADIUS;
var MAX_REAL_RESOLUTION = 156543.03392800014;
var MAX_RESOLUTION = MAX_REAL_RESOLUTION * SCALE_FACTOR;
var Kernel = (function () {
function Kernel() {
}
Kernel.gl = null;
Kernel.idCounter = 0;
Kernel.version = "0.0.1";
Kernel.SCALE_FACTOR = SCALE_FACTOR;
Kernel.REAL_EARTH_RADIUS = REAL_EARTH_RADIUS;
Kernel.EARTH_RADIUS = EARTH_RADIUS;
Kernel.MAX_RESOLUTION = MAX_RESOLUTION;
Kernel.MAX_REAL_RESOLUTION = MAX_REAL_RESOLUTION;
Kernel.MAX_PROJECTED_COORD = MAX_PROJECTED_COORD;
Kernel.BASE_LEVEL = 6;
Kernel.MAX_LEVEL = 16;
Kernel.MIN_LEVEL = 2;
Kernel.MIN_PITCH_LEVEL = 8;
Kernel.proxy = "";
return Kernel;
}());
exports.default = Kernel;
;
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Kernel_1 = __webpack_require__(5);
var Utils_1 = __webpack_require__(7);
var Renderer_1 = __webpack_require__(8);
var Camera_1 = __webpack_require__(9);
var Scene_1 = __webpack_require__(20);
var Image_1 = __webpack_require__(22);
var EventHandler_1 = __webpack_require__(23);
var Google_1 = __webpack_require__(24);
var Atmosphere_1 = __webpack_require__(40);
var LocationGraphic_1 = __webpack_require__(43);
var PoiLayer_1 = __webpack_require__(47);
var RouteLayer_1 = __webpack_require__(50);
var Extent_1 = __webpack_require__(19);
var Service_1 = __webpack_require__(48);
var initLevel = Utils_1.default.isMobile() ? 11 : 3;
var initLonlat = [116.3975, 39.9085];
var GlobeOptions = (function () {
function GlobeOptions() {
this.pauseRendering = false;
this.satellite = true;
this.level = 'auto';
this.lonlat = 'auto';
this.key = "";
}
return GlobeOptions;
}());
exports.GlobeOptions = GlobeOptions;
var Globe = (function () {
function Globe(canvas, options) {
var _this = this;
this.canvas = canvas;
this.options = options;
this.renderer = null;
this.scene = null;
this.camera = null;
this.tiledLayer = null;
this.labelLayer = null;
this.poiLayer = null;
this.routeLayer = null;
this.locationGraphic = null;
this.debugStopRefreshTiles = false;
this.REFRESH_INTERVAL = 150;
this.lastRefreshTimestamp = -1;
this.lastRefreshCameraCore = null;
this.eventHandler = null;
this.allRefreshCount = 0;
this.realRefreshCount = 0;
this.afterRenderCallbacks = [];
this.gl = null;
if (!this.options) {
this.options = new GlobeOptions();
}
this.renderer = new Renderer_1.default(canvas, this._onBeforeRender.bind(this), this._onAfterRender.bind(this));
this.gl = this.renderer.gl;
this.scene = new Scene_1.default();
var radio = canvas.width / canvas.height;
var level = this.options.level >= 0 ? this.options.level : initLevel;
var lonlat = (this.options.lonlat && this.options.lonlat.length === 2) ? this.options.lonlat : initLonlat;
this.camera = new Camera_1.default(canvas, 30, radio, 1, Kernel_1.default.EARTH_RADIUS * 2, level, lonlat, options.resolutionFactor);
this.renderer.setScene(this.scene);
this.renderer.setCamera(this.camera);
this._setTiledLayer(new Google_1.GoogleTiledLayer("Road"), this.options.pauseRendering);
var atmosphere = Atmosphere_1.default.getInstance();
this.scene.add(atmosphere);
this.routeLayer = RouteLayer_1.default.getInstance(this.camera, this.options.key);
this.scene.add(this.routeLayer);
this.poiLayer = PoiLayer_1.default.getInstance();
this.poiLayer.globe = this;
this.scene.add(this.poiLayer);
this.locationGraphic = LocationGraphic_1.default.getInstance(this);
this.scene.add(this.locationGraphic);
this.eventHandler = new EventHandler_1.default(this);
if (this.options.pauseRendering !== true) {
this.renderer.resumeRendering();
}
var locationCallback = function (location) {
if (location) {
_this.afterRenderCallbacks.push(function () {
_this.updateUserLocation(location);
});
}
};
Service_1.default.getCurrentPosition().then(locationCallback);
}
Globe.getInstance = function (options) {
if (!this.globe) {
var canvas = document.createElement("canvas");
canvas.width = document.documentElement.clientWidth;
canvas.height = document.documentElement.clientHeight;
this.globe = new Globe(canvas, options);
}
return this.globe;
};
Globe.prototype.placeAt = function (container) {
if (this.canvas.parentNode) {
if (this.canvas.parentNode !== container) {
container.appendChild(this.canvas);
}
}
else {
container.appendChild(this.canvas);
}
};
Globe.prototype.resize = function (width, height) {
this.canvas.width = width;
this.canvas.height = height;
this.camera.setAspect(this.canvas.width / this.canvas.height);
Utils_1.default.publish("extent-change");
};
Globe.prototype.updateUserLocation = function (location) {
this.locationGraphic.setLonLat(location.lon, location.lat);
var _a = this.camera.getLonlat(), lon = _a[0], lat = _a[1];
if (this.options.lonlat === 'auto') {
lon = location.lon;
lat = location.lat;
}
var level = this.getLevel();
if (this.options.level === 'auto') {
level = 8;
if (location.accuracy <= 100) {
level = 16;
}
else if (location.accuracy <= 1000) {
level = 13;
}
else {
level = 11;
}
}
this.centerTo(lon, lat, level);
};
Globe.prototype.getLonlat = function () {
return this.camera.getLonlat();
};
Globe.prototype.isRenderingPaused = function () {
return this.renderer.isRenderingPaused();
};
Globe.prototype.pauseRendering = function () {
this.renderer.pauseRendering();
};
Globe.prototype.resumeRendering = function () {
this.renderer.resumeRendering();
this.refresh(true);
};
Globe.prototype._setTiledLayer = function (tiledLayer, dontRefresh) {
if (dontRefresh === void 0) { dontRefresh = false; }
Image_1.default.clear();
if (this.tiledLayer) {
var b = this.scene.remove(this.tiledLayer);
if (!b) {
console.error("this.scene.remove(this.tiledLayer)失败");
}
this.scene.tiledLayer = null;
}
tiledLayer.globe = this;
this.tiledLayer = tiledLayer;
this.scene.add(this.tiledLayer, true);
if (!dontRefresh) {
this.refresh(true);
}
};
Globe.prototype.showLabelLayer = function () {
if (this.labelLayer) {
this.labelLayer.visible = true;
}
};
Globe.prototype.hideLabelLayer = function () {
if (this.labelLayer) {
this.labelLayer.visible = false;
}
};
Globe.prototype.getLevel = function () {
return this.camera.getLevel();
};
Globe.prototype.zoomIn = function () {
this.setLevel(this.getLevel() + 1);
};
Globe.prototype.setLevel = function (level) {
if (this.camera) {
this.camera.setLevel(level);
}
};
Globe.prototype.centerTo = function (lon, lat, level) {
if (level === void 0) { level = this.getLevel(); }
return this.camera.centerTo(lon, lat, level);
};
Globe.prototype.animateTo = function (newLon, newLat, newLevel, duration) {
if (newLevel === void 0) { newLevel = this.getLevel(); }
if (duration === void 0) { duration = 1000; }
return this.camera.animateTo(newLon, newLat, newLevel, duration);
};
Globe.prototype.setExtent = function (extent) {
return this.camera.setExtent(extent);
};
Globe.prototype.animateToExtent = function (extent, duration) {
if (duration === void 0) { duration = 1000; }
return this.camera.animateToExtent(extent, duration);
};
Globe.prototype.isAnimating = function () {
return this.camera.isAnimating();
};
Globe.prototype.animateToLevel = function (level, cb) {
if (!this.isAnimating()) {
if (level < Kernel_1.default.MIN_LEVEL) {
level = Kernel_1.default.MIN_LEVEL;
}
if (level > Kernel_1.default.MAX_LEVEL) {
level = Kernel_1.default.MAX_LEVEL;
}
if (level !== this.getLevel()) {
this.camera.animateToLevel(level, cb);
}
}
};
Globe.prototype.animateOut = function (cb) {
this.animateToLevel(this.getLevel() - 1, cb);
};
Globe.prototype.animateIn = function (cb) {
this.animateToLevel(this.getLevel() + 1, cb);
};
Globe.prototype._onBeforeRender = function (renderer) {
this.refresh();
};
Globe.prototype._onAfterRender = function (render) {
this.afterRenderCallbacks.forEach(function (callback) { return callback(); });
this.afterRenderCallbacks = [];
};
Globe.prototype.logRefreshInfo = function () {
console.log(this.realRefreshCount, this.allRefreshCount, this.realRefreshCount / this.allRefreshCount);
};
Globe.prototype.refresh = function (force) {
if (force === void 0) { force = false; }
this.allRefreshCount++;
var timestamp = Date.now();
this.camera.update(force);
if (!this.tiledLayer || !this.scene || !this.camera) {
return;
}
if (this.debugStopRefreshTiles) {
return;
}
var newCameraCore = this.camera.getCameraCore();
var isNeedRefresh = false;
if (force) {
isNeedRefresh = true;
}
else {
if (this.isRenderingPaused()) {
isNeedRefresh = false;
}
else {
if (newCameraCore.equals(this.lastRefreshCameraCore)) {
isNeedRefresh = false;
}
else {
isNeedRefresh = timestamp - this.lastRefreshTimestamp >= this.REFRESH_INTERVAL;
}
}
}
this.tiledLayer.updateSubLayerCount();
if (isNeedRefresh) {
this.realRefreshCount++;
this.lastRefreshTimestamp = timestamp;
this.lastRefreshCameraCore = newCameraCore;
this.tiledLayer.refresh();
}
this.tiledLayer.updateTileVisibility();
if (!this.isRenderingPaused()) {
var a = !!(this.labelLayer && this.labelLayer.visible);
if (a) {
var lastLevelTileGrids = this.tiledLayer.getLastLevelVisibleTileGrids();
this.labelLayer.updateTiles(this.getLevel(), lastLevelTileGrids);
}
}
};
Globe.prototype.getExtent = function () {
var extents = [];
var layerExtent = this.tiledLayer.getExtent();
if (layerExtent) {
extents.push(layerExtent);
}
var cameraExtent = this.camera.getExtent();
if (cameraExtent) {
extents.push(cameraExtent);
}
if (extents.length === 0) {
return null;
}
else if (extents.length === 1) {
return extents[0];
}
else {
return Extent_1.default.intersect(extents);
}
};
Globe.prototype.pick = function (canvasX, canvasY) {
var pickInfo = this.camera.getPickInfoByCanvas(canvasX, canvasY, false);
var line = pickInfo.line;
this.scene.pickByWorldLine(line);
};
Globe.prototype.test = function () {
this.debugStopRefreshTiles = true;
this.labelLayer.hideAllTiles();
this.tiledLayer.children.forEach(function (subLayer) { return subLayer.hideAllTiles(); });
var subLayer = this.tiledLayer.children[this.tiledLayer.children.length - 1];
subLayer.visible = true;
subLayer.children[0].visible = true;
return subLayer;
};
Globe.globe = null;
return Globe;
}());
exports.default = Globe;
;
/***/ }),
/* 7 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Kernel_1 = __webpack_require__(5);
var topic = {};
var Utils = (function () {
function Utils() {
}
Utils.isNumber = function (v) {
return typeof v === "number";
};
Utils.isInteger = function (v) {
var isInt = false;
var isNum = this.isNumber(v);
if (isNum) {
var numFloat = parseFloat(v);
var numInt = parseInt(v);
if (numFloat === numInt) {
isInt = true;
}
else {
isInt = false;
}
}
else {
isInt = false;
}
return isInt;
};
Utils.isPositive = function (v) {
return v > 0;
};
Utils.isNegative = function (v) {
return v < 0;
};
Utils.isNonNegative = function (v) {
return v >= 0;
};
Utils.isNonPositive = function (v) {
return v <= 0;
};
Utils.isPositiveInteger = function (v) {
return this.isPositive(v) && this.isInteger(v);
};
Utils.isNonNegativeInteger = function (v) {
return this.isNonNegative(v) && this.isInteger(v);
};
Utils.isArray = function (v) {
return Object.prototype.toString.call(v) === '[object Array]';
};
Utils.isFunction = function (v) {
return typeof v === 'function';
};
Utils.forEach = function (arr, func) {
return this.isFunction(arr.forEach) ? arr.forEach(func) : Array.prototype.forEach.call(arr, func);
};
Utils.filter = function (arr, func) {
return this.isFunction(arr.filter) ? arr.filter(func) : Array.prototype.filter.call(arr, func);
};
Utils.map = function (arr, func) {
return this.isFunction(arr.map) ? arr.map(func) : Array.prototype.map.call(arr, func);
};
Utils.some = function (arr, func) {
return this.isFunction(arr.some) ? arr.some(func) : Array.prototype.some.call(arr, func);
};
Utils.every = function (arr, func) {
return this.isFunction(arr.every) ? arr.every(func) : Array.prototype.every.call(arr, func);
};
Utils.filterRepeatArray = function (arr) {
var cloneArray = arr.map(function (item) {
return item;
});
var simplifyArray = [];
while (cloneArray.length > 0) {
var e = cloneArray[0];
var exist = simplifyArray.some(function (item) {
return e.equals(item);
});
if (!exist) {
simplifyArray.push(e);
}
cloneArray.splice(0, 1);
}
return simplifyArray;
};
Utils.isMobile = function () {
return !!window.navigator.userAgent.match(/Android|webOS|iPhone|iPad|iPod|BlackBerry|Windows Phone|IEMobile|Opera Mini/i);
};
Utils.isWindows = function () {
var platform = window.navigator.platform;
return platform.toLowerCase().indexOf('win') === 0;
};
Utils.wrapUrlWithProxy = function (url) {
if (Kernel_1.default.proxy) {
return Kernel_1.default.proxy + "?" + url;
}
return url;
};
Utils.subscribe = function (topicName, callback) {
if (!topic[topicName]) {
topic[topicName] = [];
}
topic[topicName].push(callback);
};
Utils.publish = function (topicName, data) {
var callbacks = topic[topicName];
if (callbacks && callbacks.length > 0) {
callbacks.forEach(function (callback) {
callback(data);
});
}
};
return Utils;
}());
exports.default = Utils;
;
/***/ }),
/* 8 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Kernel_1 = __webpack_require__(5);
var Renderer = (function () {
function Renderer(canvas, onBeforeRender, onAfterRender) {
this.canvas = canvas;
this.onBeforeRender = onBeforeRender;
this.onAfterRender = onAfterRender;
this.scene = null;
this.camera = null;
this.renderingPaused = true;
this.gl = null;
this.gl = this._getWebGLContext(this.canvas);
Kernel_1.default.gl = this.gl;
if (!this.gl) {
console.debug("浏览器不支持WebGL或将WebGL禁用!");
}
var gl = this.gl;
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.clearColor(0, 0, 0, 1);
gl.enable(gl.DEPTH_TEST);
gl.depthFunc(gl.LEQUAL);
gl.depthMask(true);
gl.enable(gl.CULL_FACE);
gl.frontFace(gl.CCW);
gl.cullFace(gl.BACK);
}
Renderer.prototype._getWebGLContext = function (canvas) {
var gl = null;
try {
var contextList = [
"webgl",
"experimental-webgl",
"webkit-3d",
"moz-webgl"
];
for (var i = 0; i < contextList.length; i++) {
gl = canvas.getContext(contextList[i], {
antialias: true
});
if (gl) {
break;
}
}
}
catch (e) {
console.error(e);
}
return gl;
};
Renderer.prototype.render = function (scene, camera) {
var gl = this.gl;
gl.viewport(0, 0, this.canvas.width, this.canvas.height);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.clearColor(0, 0, 0, 1);
try {
camera.update();
}
catch (e) {
console.error(e);
}
try {
if (this.onBeforeRender) {
this.onBeforeRender(this);
}
}
catch (e) {
console.error(e);
}
try {
if (!this.renderingPaused) {
scene.draw(camera);
}
}
catch (e) {
console.error(e);
}
try {
if (this.onAfterRender) {
this.onAfterRender(this);
}
}
catch (e) {
console.error(e);
}
};
Renderer.prototype.setScene = function (scene) {
this.scene = scene;
};
Renderer.prototype.setCamera = function (camera) {
this.camera = camera;
};
Renderer.prototype._tick = function () {
if (this.scene && this.camera) {
this.render(this.scene, this.camera);
}
window.requestAnimationFrame(this._tick.bind(this));
};
Renderer.prototype.isRenderingPaused = function () {
return this.renderingPaused;
};
Renderer.prototype.pauseRendering = function () {
this.renderingPaused = true;
};
Renderer.prototype.resumeRendering = function () {
this.renderingPaused = false;
this._tick();
};
return Renderer;
}());
exports.default = Renderer;
/***/ }),
/* 9 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var Kernel_1 = __webpack_require__(5);
var Utils_1 = __webpack_require__(7);
var Events_1 = __webpack_require__(10);
var Utils_2 = __webpack_require__(11);
var Vertice_1 = __webpack_require__(12);
var Vector_1 = __webpack_require__(13);
var Line_1 = __webpack_require__(14);
var TileGrid_1 = __webpack_require__(16);
var Matrix_1 = __webpack_require__(17);
var Object3D_1 = __webpack_require__(18);
var Extent_1 = __webpack_require__(19);
var CameraCore = (function () {
function CameraCore(fov, aspect, near, far, floatLevel, matrix) {
this.fov = fov;
this.aspect = aspect;
this.near = near;
this.far = far;
this.floatLevel = floatLevel;
this.matrix = matrix;
}
CameraCore.prototype.getFov = function () {
return this.fov;
};
CameraCore.prototype.getAspect = function () {
return this.aspect;
};
CameraCore.prototype.getNear = function () {
return this.near;
};
CameraCore.prototype.getFar = function () {
return this.far;
};
CameraCore.prototype.getFloatLevel = function () {
return this.floatLevel;
};
CameraCore.prototype.getMatrix = function () {
return this.matrix;
};
CameraCore.prototype.equals = function (other) {
if (!other) {
return false;
}
return (this.fov === other.getFov() &&
this.aspect === other.getAspect() &&
this.near === other.getNear() &&
this.far === other.getFar() &&
this.floatLevel === other.getFloatLevel() &&
this.matrix.equals(other.getMatrix()));
};
return CameraCore;
}());
exports.CameraCore = CameraCore;
var realResolutionCache = {};
(function () {
for (var i = 0; i <= Kernel_1.default.MAX_LEVEL; i++) {
realResolutionCache[i] = Kernel_1.default.MAX_REAL_RESOLUTION / Math.pow(2, i);
}
})();
var Camera = (function (_super) {
__extends(Camera, _super);
function Camera(canvas, fov, aspect, near, far, level, lonlat, resolutionFactor) {
if (fov === void 0) { fov = 45; }
if (aspect === void 0) { aspect = 1; }
if (near === void 0) { near = 1; }
if (far === void 0) { far = 100; }
if (level === void 0) { level = 3; }
if (lonlat === void 0) { lonlat = [0, 0]; }
if (resolutionFactor === void 0) { resolutionFactor = Math.pow(2, 0.375295); }
var _this = _super.call(this) || this;
_this.canvas = canvas;
_this.fov = fov;
_this.aspect = aspect;
_this.near = near;
_this.far = far;
_this.animationDuration = 200;
_this.nearFactor = 0.6;
_this.maxPitch = 40;
_this.isZeroPitch = true;
_this.level = -1;
_this.floatLevel = -2;
_this.lastFloatLevel = -3;
_this.lastFov = -1;
_this.lastAspect = -1;
_this.lastNear = -1;
_this.lastFar = -1;
_this.lonlatsOfBoundary = null;
_this.animating = false;
_this.eventEmitter = null;
if (!(resolutionFactor > 0)) {
resolutionFactor = Math.pow(2, 0.375295);
}
_this.resolutionFactor1 = resolutionFactor;
_this.resolutionFactor2 = _this.resolutionFactor1 * 2;
_this.eventEmitter = new Events_1.EventEmitter();
_this.lonlatsOfBoundary = [];
_this.initFov = _this.fov;
_this.lastMatrix = new Matrix_1.default();
_this.lastMatrix.setUniqueValue(0);
_this.projMatrix = new Matrix_1.default();
_this._rawSetPerspectiveMatrix(_this.fov, _this.aspect, _this.near, _this.far);
_this._initCameraPosition(level, lonlat[0], lonlat[1]);
_this.update(true);
return _this;
}
Camera.prototype.getExtent = function () {
var extent = null;
if (this.isEarthFullOverlapScreen()) {
var lons = [];
var lats = [];
this.lonlatsOfBoundary.forEach(function (lonlat) {
lons.push(lonlat[0]);
lats.push(lonlat[1]);
});
var minLon = Math.min.apply(Math, lons);
var maxLon = Math.max.apply(Math, lons);
var minLat = Math.min.apply(Math, lats);
var maxLat = Math.max.apply(Math, lats);
extent = new Extent_1.default(minLon, minLat, maxLon, maxLat);
}
return extent;
};
Camera.prototype.getEventEmitter = function () {
return this.eventEmitter;
};
Camera.prototype.isEarthFullOverlapScreen = function () {
return this.lonlatsOfBoundary.length === 8;
};
Camera.prototype.getTileGridsOfBoundary = function (level, filterRepeat) {
var tileGridsOfBoundary = this.lonlatsOfBoundary.map(function (lonlat) {
return TileGrid_1.default.getTileGridByGeo(lonlat[0], lonlat[1], level);
});
return filterRepeat
? Utils_1.default.filterRepeatArray(tileGridsOfBoundary)
: tileGridsOfBoundary;
};
Camera.prototype.toJson = function () {
function matrixToJson(mat) {
return mat ? mat.toJson() : null;
}
var json = {
matrix: matrixToJson(this.matrix),
isZeroPitch: this.isZeroPitch,
level: this.level,
floatLevel: this.floatLevel,
lastFloatLevel: this.lastFloatLevel,
lastMatrix: matrixToJson(this.lastMatrix),
lastFov: this.lastFov,
lastAspect: this.lastAspect,
lastNear: this.lastNear,
lastFar: this.lastFar,
viewMatrix: matrixToJson(this.viewMatrix),
projMatrix: matrixToJson(this.projMatrix),
projViewMatrix: matrixToJson(this.projViewMatrix),
matrixForDraw: matrixToJson(this.matrixForDraw),
viewMatrixForDraw: matrixToJson(this.viewMatrixForDraw),
projMatrixForDraw: matrixToJson(this.projMatrixForDraw),
projViewMatrixForDraw: matrixToJson(this.projViewMatrixForDraw),
animating: this.animating
};
return json;
};
Camera.prototype.toJsonString = function () {
return JSON.stringify(this.toJson());
};
Camera.prototype.fromJson = function (json) {
this.matrix = Matrix_1.default.fromJson(json.matrix);
this.isZeroPitch = json.isZeroPitch;
this.level = json.level;
this.floatLevel = json.floatLevel;
this.lastFloatLevel = json.lastFloatLevel;
this.lastMatrix = Matrix_1.default.fromJson(json.lastMatrix);
this.lastFov = json.lastFov;
this.lastAspect = json.lastAspect;
this.lastNear = json.lastNear;
this.lastFar = json.lastFar;
this.viewMatrix = Matrix_1.default.fromJson(json.viewMatrix);
this.projMatrix = Matrix_1.default.fromJson(json.projMatrix);
this.projViewMatrix = Matrix_1.default.fromJson(json.projViewMatrix);
this.matrixForDraw = Matrix_1.default.fromJson(json.matrixForDraw);
this.viewMatrixForDraw = Matrix_1.default.fromJson(json.viewMatrixForDraw);
this.projMatrixForDraw = Matrix_1.default.fromJson(json.projMatrixForDraw);
this.projViewMatrixForDraw = Matrix_1.default.fromJson(json.projViewMatrixForDraw);
this.animating = json.animating;
this.update(true);
};
Camera.prototype.fromJsonString = function (jsonStr) {
this.fromJson(JSON.parse(jsonStr));
};
Camera.prototype._setPerspectiveMatrix = function (fov, aspect, near, far) {
this._rawSetPerspectiveMatrix(fov, aspect, near, far);
this._updateFar();
};
Camera.prototype._rawSetPerspectiveMatrix = function (fov, aspect, near, far, projMatrix) {
if (projMatrix === void 0) { projMatrix = this.projMatrix; }
if (this.projMatrix === projMatrix) {
this.fov = fov;
this.aspect = aspect;
this.near = near;
this.far = far;
}
var mat = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
var halfFov = fov * Math.PI / 180 / 2;
var f = 1 / Math.tan(halfFov);
var nf = 1 / (near - far);
mat[0] = f / aspect;
mat[5] = f;
mat[10] = (far + near) * nf;
mat[11] = -1;
mat[14] = 2 * near * far * nf;
mat[15] = 0;
projMatrix.setElements(mat[0], mat[1], mat[2], mat[3], mat[4], mat[5], mat[6], mat[7], mat[8], mat[9], mat[10], mat[11], mat[12], mat[13], mat[14], mat[15]);
};
Camera.prototype._setFov = function (fov) {
if (!(fov > 0)) {
throw "invalid fov:" + fov;
}
this._setPerspectiveMatrix(fov, this.aspect, this.near, this.far);
};
Camera.prototype.setAspect = function (aspect) {
if (!(aspect > 0)) {
throw "invalid aspect:" + aspect;
}
this._setPerspectiveMatrix(this.fov, aspect, this.near, this.far);
this.setLevel(this.level, true);
};
Camera.prototype._updateFar = function () {
};
Camera.prototype._getMinimalFar = function (cameraPosition) {
var distance2EarthOrigin = Vector_1.default.fromVertice(cameraPosition).getLength();
var far = Math.sqrt(distance2EarthOrigin * distance2EarthOrigin -
Kernel_1.default.EARTH_RADIUS * Kernel_1.default.EARTH_RADIUS);
far *= 1.05;
return far;
};
Camera.prototype.update = function (force) {
if (force === void 0) { force = false; }
var shouldUpdate = this._updateCore(force);
if (shouldUpdate) {
this._updateTileGridsOfBoundary();
}
return shouldUpdate;
};
Camera.prototype._updateCore = function (force) {
if (force === void 0) { force = false; }
var shouldUpdate = force || this._isNeedUpdate();
if (shouldUpdate) {
this._normalUpdate();
this._updateProjViewMatrixForDraw();
}
this.lastFov = this.fov;
this.lastAspect = this.aspect;
this.lastNear = this.near;
this.lastFar = this.far;
this.lastFloatLevel = this.floatLevel;
this.lastMatrix.setMatrixByOther(this.matrix);
return shouldUpdate;
};
Camera.prototype._updateTileGridsOfBoundary = function () {
var _this = this;
var lonlatsOfBoundary = [];
var ndcs = [
[-1, 1],
[-1, 0],
[-1, -1],
[1, 1],
[1, 0],
[1, -1],
[0, 1],
[0, -1]
];
ndcs.forEach(function (ndcXY) {
var lonlat = _this._getPickLonLatByNDC(ndcXY[0], ndcXY[1]);
if (lonlat && lonlat.length > 0) {
lonlatsOfBoundary.push(lonlat);
}
});
this.lonlatsOfBoundary = lonlatsOfBoundary;
};
Camera.prototype.getCameraCore = function () {
return new CameraCore(this.fov, this.aspect, this.near, this.far, this.floatLevel, this.matrix.clone());
};
Camera.prototype._isNeedUpdate = function () {
return (this.fov !== this.lastFov ||
this.aspect !== this.lastAspect ||
this.near !== this.lastNear ||
this.far !== this.lastFar ||
this.floatLevel !== this.lastFloatLevel ||
!this.matrix.equals(this.lastMatrix));
};
Camera.prototype.getPro