UNPKG

@vtx/cs-map

Version:

React components for Vortex

153 lines (151 loc) 6.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _cesium = require("cesium"); var _BaiduMercatorTilingScheme = _interopRequireDefault(require("./BaiduMercatorTilingScheme")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; } function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } var URL = { IMG: '//shangetu{s}.map.bdimg.com/it/u=x={x};y={y};z={z};v=009;type=sate&fm=46', VEC: '//maponline{s}.bdimg.com/tile/?qt=vtile&x={x}&y={y}&z={z}&styles=pl&scaler=2&udt=20210506&from=jsapi3_0', CUSTOM: '//maponline{s}.bdimg.com/tile/?qt=vtile&x={x}&y={y}&z={z}&styles=pl&scaler=2&udt=20210506&from=jsapi3_0', dark: '//maponline{s}.bdimg.com/tile/?qt=vtile&x={x}&y={y}&z={z}&styles=pl&scaler=2&udt=20210506&from=jsapi3_0' }; var BaiduImageryProvider = /*#__PURE__*/function () { function BaiduImageryProvider() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; _classCallCheck(this, BaiduImageryProvider); this._url = options.url || URL[options.style || 'CUSTOM']; this._tileWidth = 256; this._tileHeight = 256; this._maximumLevel = 18; this._crs = options.crs || 'BD09'; if (options.crs === 'WGS84') { var resolutions = []; for (var i = 0; i < 19; i++) { resolutions[i] = 256 * Math.pow(2, 18 - i); } this._tilingScheme = new _BaiduMercatorTilingScheme["default"]({ resolutions: resolutions, rectangleSouthwestInMeters: new _cesium.Cartesian2(-20037726.37, -12474104.17), rectangleNortheastInMeters: new _cesium.Cartesian2(20037726.37, 12474104.17) }); } else { this._tilingScheme = new _cesium.WebMercatorTilingScheme({ rectangleSouthwestInMeters: new _cesium.Cartesian2(-33554054, -33746824), rectangleNortheastInMeters: new _cesium.Cartesian2(33554054, 33746824) }); } this._rectangle = this._tilingScheme.rectangle; this._credit = undefined; this._style = options.style || 'normal'; if (options.style === 'dark') { this.defaultContrast = options.contrast || -1; // 对比度 this.defaultBrightness = options.brightness || 1; // 亮度 this.defaultHue = options.hue || 3; // 色调 this.defaultSaturation = options.saturation || 2.5; // 饱和度 } } return _createClass(BaiduImageryProvider, [{ key: "url", get: function get() { return this._url; } }, { key: "token", get: function get() { return this._token; } }, { key: "tileWidth", get: function get() { if (!this.ready) { throw new _cesium.DeveloperError('tileWidth must not be called before the imagery provider is ready.'); } return this._tileWidth; } }, { key: "tileHeight", get: function get() { if (!this.ready) { throw new _cesium.DeveloperError('tileHeight must not be called before the imagery provider is ready.'); } return this._tileHeight; } }, { key: "maximumLevel", get: function get() { if (!this.ready) { throw new _cesium.DeveloperError('maximumLevel must not be called before the imagery provider is ready.'); } return this._maximumLevel; } }, { key: "minimumLevel", get: function get() { if (!this.ready) { throw new _cesium.DeveloperError('minimumLevel must not be called before the imagery provider is ready.'); } return 0; } }, { key: "tilingScheme", get: function get() { if (!this.ready) { throw new _cesium.DeveloperError('tilingScheme must not be called before the imagery provider is ready.'); } return this._tilingScheme; } }, { key: "rectangle", get: function get() { if (!this.ready) { throw new _cesium.DeveloperError('rectangle must not be called before the imagery provider is ready.'); } return this._rectangle; } }, { key: "ready", get: function get() { return !!this._url; } }, { key: "credit", get: function get() { return this._credit; } }, { key: "hasAlphaChannel", get: function get() { return true; } }, { key: "getTileCredits", value: function getTileCredits(x, y, level) {} }, { key: "requestImage", value: function requestImage(x, y, level) { if (!this.ready) { throw new _cesium.DeveloperError('requestImage must not be called before the imagery provider is ready.'); } var xTiles = this._tilingScheme.getNumberOfXTilesAtLevel(level); var yTiles = this._tilingScheme.getNumberOfYTilesAtLevel(level); var url = this._url.replace('{z}', level).replace('{s}', String(1)).replace('{style}', this._style); if (this._crs === 'WGS84') { url = url.replace('{x}', String(x)).replace('{y}', String(-y)); } else { url = url.replace('{x}', String(x - xTiles / 2)).replace('{y}', String(yTiles / 2 - y - 1)); } return _cesium.ImageryProvider.loadImage(this, url); } }]); }(); var _default = exports["default"] = BaiduImageryProvider; //# sourceMappingURL=BaiduImageryProvider.js.map