123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707 |
- import combine from "../Core/combine.js";
- import Credit from "../Core/Credit.js";
- import defaultValue from "../Core/defaultValue.js";
- import defined from "../Core/defined.js";
- import DeveloperError from "../Core/DeveloperError.js";
- import Event from "../Core/Event.js";
- import Rectangle from "../Core/Rectangle.js";
- import Resource from "../Core/Resource.js";
- import WebMercatorTilingScheme from "../Core/WebMercatorTilingScheme.js";
- import when from "../ThirdParty/when.js";
- import ImageryProvider from "./ImageryProvider.js";
- import TimeDynamicImagery from "./TimeDynamicImagery.js";
- var defaultParameters = Object.freeze({
- service: "WMTS",
- version: "1.0.0",
- request: "GetTile",
- });
- function WebMapTileServiceImageryProvider(options) {
- options = defaultValue(options, defaultValue.EMPTY_OBJECT);
-
- if (!defined(options.url)) {
- throw new DeveloperError("options.url is required.");
- }
- if (!defined(options.layer)) {
- throw new DeveloperError("options.layer is required.");
- }
- if (!defined(options.style)) {
- throw new DeveloperError("options.style is required.");
- }
- if (!defined(options.tileMatrixSetID)) {
- throw new DeveloperError("options.tileMatrixSetID is required.");
- }
- if (defined(options.times) && !defined(options.clock)) {
- throw new DeveloperError(
- "options.times was specified, so options.clock is required."
- );
- }
-
-
- this.defaultAlpha = undefined;
-
- this.defaultNightAlpha = undefined;
-
- this.defaultDayAlpha = undefined;
-
- this.defaultBrightness = undefined;
-
- this.defaultContrast = undefined;
-
- this.defaultHue = undefined;
-
- this.defaultSaturation = undefined;
-
- this.defaultGamma = undefined;
-
- this.defaultMinificationFilter = undefined;
-
- this.defaultMagnificationFilter = undefined;
- var resource = Resource.createIfNeeded(options.url);
- var style = options.style;
- var tileMatrixSetID = options.tileMatrixSetID;
- var url = resource.url;
- if (url.indexOf("{") >= 0) {
- var templateValues = {
- style: style,
- Style: style,
- TileMatrixSet: tileMatrixSetID,
- };
- resource.setTemplateValues(templateValues);
- this._useKvp = false;
- } else {
- resource.setQueryParameters(defaultParameters);
- this._useKvp = true;
- }
- this._resource = resource;
- this._layer = options.layer;
- this._style = style;
- this._tileMatrixSetID = tileMatrixSetID;
- this._tileMatrixLabels = options.tileMatrixLabels;
- this._format = defaultValue(options.format, "image/jpeg");
- this._tileDiscardPolicy = options.tileDiscardPolicy;
- this._tilingScheme = defined(options.tilingScheme)
- ? options.tilingScheme
- : new WebMercatorTilingScheme({ ellipsoid: options.ellipsoid });
- this._tileWidth = defaultValue(options.tileWidth, 256);
- this._tileHeight = defaultValue(options.tileHeight, 256);
- this._minimumLevel = defaultValue(options.minimumLevel, 0);
- this._maximumLevel = options.maximumLevel;
- this._rectangle = defaultValue(
- options.rectangle,
- this._tilingScheme.rectangle
- );
- this._dimensions = options.dimensions;
- var that = this;
- this._reload = undefined;
- if (defined(options.times)) {
- this._timeDynamicImagery = new TimeDynamicImagery({
- clock: options.clock,
- times: options.times,
- requestImageFunction: function (x, y, level, request, interval) {
- return requestImage(that, x, y, level, request, interval);
- },
- reloadFunction: function () {
- if (defined(that._reload)) {
- that._reload();
- }
- },
- });
- }
- this._readyPromise = when.resolve(true);
-
-
-
- var swTile = this._tilingScheme.positionToTileXY(
- Rectangle.southwest(this._rectangle),
- this._minimumLevel
- );
- var neTile = this._tilingScheme.positionToTileXY(
- Rectangle.northeast(this._rectangle),
- this._minimumLevel
- );
- var tileCount =
- (Math.abs(neTile.x - swTile.x) + 1) * (Math.abs(neTile.y - swTile.y) + 1);
-
- if (tileCount > 4) {
- throw new DeveloperError(
- "The imagery provider's rectangle and minimumLevel indicate that there are " +
- tileCount +
- " tiles at the minimum level. Imagery providers with more than four tiles at the minimum level are not supported."
- );
- }
-
- this._errorEvent = new Event();
- var credit = options.credit;
- this._credit = typeof credit === "string" ? new Credit(credit) : credit;
- this._subdomains = options.subdomains;
- if (Array.isArray(this._subdomains)) {
- this._subdomains = this._subdomains.slice();
- } else if (defined(this._subdomains) && this._subdomains.length > 0) {
- this._subdomains = this._subdomains.split("");
- } else {
- this._subdomains = ["a", "b", "c"];
- }
- }
- function requestImage(imageryProvider, col, row, level, request, interval) {
- var labels = imageryProvider._tileMatrixLabels;
- var tileMatrix = defined(labels) ? labels[level] : level.toString();
- var subdomains = imageryProvider._subdomains;
- var staticDimensions = imageryProvider._dimensions;
- var dynamicIntervalData = defined(interval) ? interval.data : undefined;
- var resource;
- if (!imageryProvider._useKvp) {
- var templateValues = {
- TileMatrix: tileMatrix,
- TileRow: row.toString(),
- TileCol: col.toString(),
- s: subdomains[(col + row + level) % subdomains.length],
- };
- resource = imageryProvider._resource.getDerivedResource({
- request: request,
- });
- resource.setTemplateValues(templateValues);
- if (defined(staticDimensions)) {
- resource.setTemplateValues(staticDimensions);
- }
- if (defined(dynamicIntervalData)) {
- resource.setTemplateValues(dynamicIntervalData);
- }
- } else {
-
- var query = {};
- query.tilematrix = tileMatrix;
- query.layer = imageryProvider._layer;
- query.style = imageryProvider._style;
- query.tilerow = row;
- query.tilecol = col;
- query.tilematrixset = imageryProvider._tileMatrixSetID;
- query.format = imageryProvider._format;
- if (defined(staticDimensions)) {
- query = combine(query, staticDimensions);
- }
- if (defined(dynamicIntervalData)) {
- query = combine(query, dynamicIntervalData);
- }
- resource = imageryProvider._resource.getDerivedResource({
- queryParameters: query,
- request: request,
- });
- }
- return ImageryProvider.loadImage(imageryProvider, resource);
- }
- Object.defineProperties(WebMapTileServiceImageryProvider.prototype, {
-
- url: {
- get: function () {
- return this._resource.url;
- },
- },
-
- proxy: {
- get: function () {
- return this._resource.proxy;
- },
- },
-
- tileWidth: {
- get: function () {
- return this._tileWidth;
- },
- },
-
- tileHeight: {
- get: function () {
- return this._tileHeight;
- },
- },
-
- maximumLevel: {
- get: function () {
- return this._maximumLevel;
- },
- },
-
- minimumLevel: {
- get: function () {
- return this._minimumLevel;
- },
- },
-
- tilingScheme: {
- get: function () {
- return this._tilingScheme;
- },
- },
-
- rectangle: {
- get: function () {
- return this._rectangle;
- },
- },
-
- tileDiscardPolicy: {
- get: function () {
- return this._tileDiscardPolicy;
- },
- },
-
- errorEvent: {
- get: function () {
- return this._errorEvent;
- },
- },
-
- format: {
- get: function () {
- return this._format;
- },
- },
-
- ready: {
- value: true,
- },
-
- readyPromise: {
- get: function () {
- return this._readyPromise;
- },
- },
-
- credit: {
- get: function () {
- return this._credit;
- },
- },
-
- hasAlphaChannel: {
- get: function () {
- return true;
- },
- },
-
- clock: {
- get: function () {
- return this._timeDynamicImagery.clock;
- },
- set: function (value) {
- this._timeDynamicImagery.clock = value;
- },
- },
-
- times: {
- get: function () {
- return this._timeDynamicImagery.times;
- },
- set: function (value) {
- this._timeDynamicImagery.times = value;
- },
- },
-
- dimensions: {
- get: function () {
- return this._dimensions;
- },
- set: function (value) {
- if (this._dimensions !== value) {
- this._dimensions = value;
- if (defined(this._reload)) {
- this._reload();
- }
- }
- },
- },
- });
- WebMapTileServiceImageryProvider.prototype.getTileCredits = function (
- x,
- y,
- level
- ) {
- return undefined;
- };
- WebMapTileServiceImageryProvider.prototype.requestImage = function (
- x,
- y,
- level,
- request
- ) {
- var result;
- var timeDynamicImagery = this._timeDynamicImagery;
- var currentInterval;
-
- if (defined(timeDynamicImagery)) {
- currentInterval = timeDynamicImagery.currentInterval;
- result = timeDynamicImagery.getFromCache(x, y, level, request);
- }
-
- if (!defined(result)) {
- result = requestImage(this, x, y, level, request, currentInterval);
- }
-
- if (defined(result) && defined(timeDynamicImagery)) {
- timeDynamicImagery.checkApproachingInterval(x, y, level, request);
- }
- return result;
- };
- WebMapTileServiceImageryProvider.prototype.pickFeatures = function (
- x,
- y,
- level,
- longitude,
- latitude
- ) {
- return undefined;
- };
- export default WebMapTileServiceImageryProvider;
|