123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397 |
- define([
- '../Core/combine',
- '../Core/Credit',
- '../Core/defaultValue',
- '../Core/defined',
- '../Core/defineProperties',
- '../Core/DeveloperError',
- '../Core/Event',
- '../Core/freezeObject',
- '../Core/objectToQuery',
- '../Core/queryToObject',
- '../Core/Rectangle',
- '../Core/WebMercatorTilingScheme',
- '../ThirdParty/Uri',
- './ImageryProvider'
- ], function(
- combine,
- Credit,
- defaultValue,
- defined,
- defineProperties,
- DeveloperError,
- Event,
- freezeObject,
- objectToQuery,
- queryToObject,
- Rectangle,
- WebMercatorTilingScheme,
- Uri,
- ImageryProvider) {
- "use strict";
-
- var WebMapTileServiceImageryProvider = 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.');
- }
- this._url = options.url;
- this._layer = options.layer;
- this._style = options.style;
- this._tileMatrixSetID = options.tileMatrixSetID;
- this._tileMatrixLabels = options.tileMatrixLabels;
- this._format = defaultValue(options.format, 'image/jpeg');
- this._proxy = options.proxy;
- this._tileDiscardPolicy = options.tileDiscardPolicy;
- this._tilingScheme = defined(options.tilingScheme) ? options.tilingScheme : new WebMercatorTilingScheme();
- this._tileWidth = defaultValue(options.tileWidth, 256);
- this._tileHeight = defaultValue(options.tileHeight, 256);
- this._minimumLevel = defaultValue(options.minimumLevel, 0);
- this._maximumLevel = defaultValue(options.maximumLevel, 18);
- this._rectangle = defaultValue(options.rectangle, this._tilingScheme.rectangle);
-
-
-
- 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;
- };
- var defaultParameters = freezeObject({
- service : 'WMTS',
- version : '1.0.0',
- request : 'GetTile'
- });
- function buildImageUrl(imageryProvider, col, row, level) {
- var uri = new Uri(imageryProvider._url);
- var queryOptions = queryToObject(defaultValue(uri.query, ''));
- var labels;
- queryOptions = combine(defaultParameters, queryOptions);
- labels = imageryProvider._tileMatrixLabels;
- queryOptions.tilematrix = defined(labels) ? labels[level] : level;
- queryOptions.layer = imageryProvider._layer;
- queryOptions.style = imageryProvider._style;
- queryOptions.tilerow = row;
- queryOptions.tilecol = col;
- queryOptions.tilematrixset = imageryProvider._tileMatrixSetID;
- queryOptions.format = imageryProvider._format;
- uri.query = objectToQuery(queryOptions);
- var url = uri.toString();
- var proxy = imageryProvider._proxy;
- if (defined(proxy)) {
- url = proxy.getURL(url);
- }
- return url;
- }
- defineProperties(WebMapTileServiceImageryProvider.prototype, {
-
- url : {
- get : function() {
- return this._url;
- }
- },
-
- proxy : {
- get : function() {
- return this._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
- },
-
- credit : {
- get : function() {
- return this._credit;
- }
- },
-
- hasAlphaChannel : {
- get : function() {
- return true;
- }
- }
- });
-
- WebMapTileServiceImageryProvider.prototype.getTileCredits = function(x, y, level) {
- return undefined;
- };
-
- WebMapTileServiceImageryProvider.prototype.requestImage = function(x, y, level) {
- var url = buildImageUrl(this, x, y, level);
- return ImageryProvider.loadImage(this, url);
- };
-
- WebMapTileServiceImageryProvider.prototype.pickFeatures = function() {
- return undefined;
- };
- return WebMapTileServiceImageryProvider;
- });
|