123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390 |
- define([
- '../Core/Credit',
- '../Core/defaultValue',
- '../Core/defined',
- '../Core/defineProperties',
- '../Core/DeveloperError',
- '../Core/Event',
- '../Core/Rectangle',
- '../Core/WebMercatorTilingScheme',
- './ImageryProvider'
- ], function(
- Credit,
- defaultValue,
- defined,
- defineProperties,
- DeveloperError,
- Event,
- Rectangle,
- WebMercatorTilingScheme,
- ImageryProvider) {
- "use strict";
- var trailingSlashRegex = /\/$/;
- var defaultCredit = new Credit('MapQuest, Open Street Map and contributors, CC-BY-SA');
-
- var OpenStreetMapImageryProvider = function OpenStreetMapImageryProvider(options) {
- options = defaultValue(options, {});
- var url = defaultValue(options.url, '//a.tile.openstreetmap.org/');
- if (!trailingSlashRegex.test(url)) {
- url = url + '/';
- }
- this._url = url;
- this._fileExtension = defaultValue(options.fileExtension, 'png');
- this._proxy = options.proxy;
- this._tileDiscardPolicy = options.tileDiscardPolicy;
- this._tilingScheme = new WebMercatorTilingScheme();
- this._tileWidth = 256;
- this._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();
- this._ready = true;
- var credit = defaultValue(options.credit, defaultCredit);
- if (typeof credit === 'string') {
- credit = new Credit(credit);
- }
- this._credit = credit;
- };
- function buildImageUrl(imageryProvider, x, y, level) {
- var url = imageryProvider._url + level + '/' + x + '/' + y + '.' + imageryProvider._fileExtension;
- var proxy = imageryProvider._proxy;
- if (defined(proxy)) {
- url = proxy.getURL(url);
- }
- return url;
- }
- defineProperties(OpenStreetMapImageryProvider.prototype, {
-
- url : {
- get : function() {
- return this._url;
- }
- },
-
- proxy : {
- get : function() {
- return this._proxy;
- }
- },
-
- tileWidth : {
- get : function() {
-
- if (!this._ready) {
- throw new DeveloperError('tileWidth must not be called before the imagery provider is ready.');
- }
-
- return this._tileWidth;
- }
- },
-
- tileHeight: {
- get : function() {
-
- if (!this._ready) {
- throw new DeveloperError('tileHeight must not be called before the imagery provider is ready.');
- }
-
- return this._tileHeight;
- }
- },
-
- maximumLevel : {
- get : function() {
-
- if (!this._ready) {
- throw new DeveloperError('maximumLevel must not be called before the imagery provider is ready.');
- }
-
- return this._maximumLevel;
- }
- },
-
- minimumLevel : {
- get : function() {
-
- if (!this._ready) {
- throw new DeveloperError('minimumLevel must not be called before the imagery provider is ready.');
- }
-
- return this._minimumLevel;
- }
- },
-
- tilingScheme : {
- get : function() {
-
- if (!this._ready) {
- throw new DeveloperError('tilingScheme must not be called before the imagery provider is ready.');
- }
-
- return this._tilingScheme;
- }
- },
-
- rectangle : {
- get : function() {
-
- if (!this._ready) {
- throw new DeveloperError('rectangle must not be called before the imagery provider is ready.');
- }
-
- return this._rectangle;
- }
- },
-
- tileDiscardPolicy : {
- get : function() {
-
- if (!this._ready) {
- throw new DeveloperError('tileDiscardPolicy must not be called before the imagery provider is ready.');
- }
-
- return this._tileDiscardPolicy;
- }
- },
-
- errorEvent : {
- get : function() {
- return this._errorEvent;
- }
- },
-
- ready : {
- get : function() {
- return this._ready;
- }
- },
-
- credit : {
- get : function() {
- return this._credit;
- }
- },
-
- hasAlphaChannel : {
- get : function() {
- return true;
- }
- }
- });
-
- OpenStreetMapImageryProvider.prototype.getTileCredits = function(x, y, level) {
- return undefined;
- };
-
- OpenStreetMapImageryProvider.prototype.requestImage = function(x, y, level) {
-
- if (!this._ready) {
- throw new DeveloperError('requestImage must not be called before the imagery provider is ready.');
- }
-
- var url = buildImageUrl(this, x, y, level);
- return ImageryProvider.loadImage(this, url);
- };
-
- OpenStreetMapImageryProvider.prototype.pickFeatures = function() {
- return undefined;
- };
- return OpenStreetMapImageryProvider;
- });
|