UNPKG

@vtx/cs-map

Version:

React components for Vortex

154 lines (152 loc) 6.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _cesium = require("cesium"); var _BaiduMercatorTilingScheme = _interopRequireDefault(require("./BaiduMercatorTilingScheme")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 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(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } 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; // 饱和度 } } _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); } }]); return BaiduImageryProvider; }(); var _default = exports["default"] = BaiduImageryProvider; //# sourceMappingURL=BaiduImageryProvider.js.map