UNPKG

rlayers

Version:

React Components for OpenLayers

109 lines 4.83 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var layer_1 = require("ol/layer"); var WMTS_1 = __importStar(require("ol/source/WMTS")); var WMTSCapabilities_1 = __importDefault(require("ol/format/WMTSCapabilities")); var RLayerRaster_1 = __importDefault(require("./RLayerRaster")); var debug_1 = __importDefault(require("../debug")); /** * A layer for WMTS-compatible raster tile servers * * Requires an `RMap` context */ var RLayerWMTS = /** @class */ (function (_super) { __extends(RLayerWMTS, _super); function RLayerWMTS(props, context) { var _this = _super.call(this, props, context) || this; _this.ol = new layer_1.Tile({ source: _this.source }); _this.parser = new WMTSCapabilities_1.default(); return _this; } RLayerWMTS.prototype.createSource = function () { var _this = this; (0, debug_1.default)('createSource', this); return fetch(this.props.url) .then(function (r) { return r.text(); }) .then(function (text) { var caps = _this.parser.read(text); _this.options = (0, WMTS_1.optionsFromCapabilities)(caps, { layer: _this.props.layer }); if (_this.props.attributions) _this.options.attributions = _this.props.attributions; _this.options.crossOrigin = ''; if (_this.props.projection) _this.options.projection = _this.props.projection; _this.options.wrapX = false; _this.source = new WMTS_1.default(_this.options); _this.ol.setSource(_this.source); _this.eventSources = [_this.ol, _this.source]; if (_this.props.onCapabilities) _this.props.onCapabilities.call(_this, _this.options); return _this.source; }) .catch(function (e) { // eslint-disable-next-line no-console console.error('failed loading WMTS', _this.props.url, _this.props.layer, e); _this.source = undefined; return null; }); }; RLayerWMTS.prototype.refresh = function (prevProps) { var _this = this; _super.prototype.refresh.call(this); if ((prevProps === null || prevProps === void 0 ? void 0 : prevProps.url) !== this.props.url || (prevProps === null || prevProps === void 0 ? void 0 : prevProps.layer) !== this.props.layer) { this.createSource().then(function () { _this.ol.setSource(_this.source); _this.attachOldEventHandlers(_this.source); }); } else { if (this.props.onCapabilities) this.props.onCapabilities.call(this, this.options); } }; return RLayerWMTS; }(RLayerRaster_1.default)); exports.default = RLayerWMTS; //# sourceMappingURL=RLayerWMTS.js.map