Use object literals and use generic tile layer
This commit is contained in:
@@ -1,189 +0,0 @@
|
||||
goog.provide('ol.layer.BingMaps');
|
||||
goog.provide('ol.source.BingMaps');
|
||||
|
||||
goog.require('goog.Uri');
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('goog.net.Jsonp');
|
||||
goog.require('ol.TileCoverageArea');
|
||||
goog.require('ol.TileSource');
|
||||
goog.require('ol.layer.TileLayer');
|
||||
goog.require('ol.tilegrid.XYZ');
|
||||
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
*/
|
||||
ol.BingMapsStyle = {
|
||||
AERIAL: 'Aerial',
|
||||
AERIAL_WITH_LABELS: 'AerialWithLabels',
|
||||
ROAD: 'Road',
|
||||
ORDNANCE_SURVEY: 'OrdnanceSurvey',
|
||||
COLLINS_BART: 'CollinsBart'
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.layer.TileLayer}
|
||||
* @param {ol.BingMapsStyle} style Bing Maps style.
|
||||
* @param {string} key Key.
|
||||
* @param {string=} opt_culture Culture.
|
||||
* @param {Object.<string, *>=} opt_values Values.
|
||||
*/
|
||||
ol.layer.BingMaps = function(style, key, opt_culture, opt_values) {
|
||||
var tileSource = new ol.source.BingMaps(style, key, opt_culture,
|
||||
function(tileSource) {
|
||||
this.dispatchEvent(goog.events.EventType.LOAD);
|
||||
}, this);
|
||||
goog.base(this, tileSource, opt_values);
|
||||
};
|
||||
goog.inherits(ol.layer.BingMaps, ol.layer.TileLayer);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.TileSource}
|
||||
* @param {ol.BingMapsStyle} style Bing Maps style.
|
||||
* @param {string} key Key.
|
||||
* @param {string=} opt_culture Culture.
|
||||
* @param {?function(ol.source.BingMaps)=} opt_callback Callback.
|
||||
* @param {*=} opt_obj Object.
|
||||
*/
|
||||
ol.source.BingMaps =
|
||||
function(style, key, opt_culture, opt_callback, opt_obj) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
this.culture_ = opt_culture || 'en-us';
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.ready_ = false;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {?function(ol.source.BingMaps)}
|
||||
*/
|
||||
this.callback_ = opt_callback || null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {*}
|
||||
*/
|
||||
this.object_ = opt_obj;
|
||||
|
||||
var uri = new goog.Uri(
|
||||
'http://dev.virtualearth.net/REST/v1/Imagery/Metadata/' + style);
|
||||
var jsonp = new goog.net.Jsonp(uri, 'jsonp');
|
||||
jsonp.send({
|
||||
'include': 'ImageryProviders',
|
||||
'key': key
|
||||
}, goog.bind(this.handleImageryMetadataResponse, this));
|
||||
|
||||
var projection = ol.Projection.getFromCode('EPSG:3857');
|
||||
var extent = projection.getExtent();
|
||||
|
||||
goog.base(
|
||||
this, projection, null, ol.TileUrlFunction.nullTileUrlFunction, extent);
|
||||
|
||||
};
|
||||
goog.inherits(ol.source.BingMaps, ol.TileSource);
|
||||
|
||||
|
||||
/**
|
||||
* @param {BingMapsImageryMetadataResponse} response Response.
|
||||
*/
|
||||
ol.source.BingMaps.prototype.handleImageryMetadataResponse =
|
||||
function(response) {
|
||||
|
||||
goog.asserts.assert(
|
||||
response.authenticationResultCode == 'ValidCredentials');
|
||||
goog.asserts.assert(response.statusCode == 200);
|
||||
goog.asserts.assert(response.statusDescription == 'OK');
|
||||
|
||||
var brandLogoUri = response.brandLogoUri;
|
||||
var copyright = response.copyright;
|
||||
goog.asserts.assert(response.resourceSets.length == 1);
|
||||
var resourceSet = response.resourceSets[0];
|
||||
goog.asserts.assert(resourceSet.resources.length == 1);
|
||||
var resource = resourceSet.resources[0];
|
||||
|
||||
var zoomMin = resource.zoomMin;
|
||||
var zoomMax = resource.zoomMax;
|
||||
var tileSize = new ol.Size(resource.imageWidth, resource.imageHeight);
|
||||
var tileGrid = new ol.tilegrid.XYZ(zoomMax, tileSize);
|
||||
this.tileGrid = tileGrid;
|
||||
|
||||
this.tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
|
||||
function(tileCoord) {
|
||||
if (tileCoord.z < zoomMin || zoomMax < tileCoord.z) {
|
||||
return null;
|
||||
}
|
||||
var n = 1 << tileCoord.z;
|
||||
var y = -tileCoord.y - 1;
|
||||
if (y < 0 || n <= y) {
|
||||
return null;
|
||||
} else {
|
||||
var x = goog.math.modulo(tileCoord.x, n);
|
||||
return new ol.TileCoord(tileCoord.z, x, y);
|
||||
}
|
||||
},
|
||||
ol.TileUrlFunction.createFromTileUrlFunctions(
|
||||
goog.array.map(
|
||||
resource.imageUrlSubdomains,
|
||||
function(subdomain) {
|
||||
var imageUrl = resource.imageUrl
|
||||
.replace('{subdomain}', subdomain)
|
||||
.replace('{culture}', this.culture_);
|
||||
return function(tileCoord) {
|
||||
if (goog.isNull(tileCoord)) {
|
||||
return undefined;
|
||||
} else {
|
||||
return imageUrl.replace(
|
||||
'{quadkey}', tileCoord.quadKey());
|
||||
}
|
||||
};
|
||||
})));
|
||||
|
||||
var projection = ol.Projection.getFromCode('EPSG:4326');
|
||||
var attributions = goog.array.map(
|
||||
resource.imageryProviders,
|
||||
function(imageryProvider) {
|
||||
var html = imageryProvider.attribution;
|
||||
var coverageAreas = goog.array.map(
|
||||
imageryProvider.coverageAreas,
|
||||
function(coverageArea) {
|
||||
var bbox = coverageArea.bbox;
|
||||
var extent = new ol.Extent(bbox[1], bbox[0], bbox[3], bbox[2]);
|
||||
var minZ = coverageArea.zoomMin;
|
||||
var maxZ = coverageArea.zoomMax;
|
||||
return new ol.TileCoverageArea(tileGrid, extent, minZ, maxZ);
|
||||
});
|
||||
return new ol.Attribution(html, coverageAreas, projection);
|
||||
});
|
||||
this.setAttributions(attributions);
|
||||
|
||||
this.ready_ = true;
|
||||
|
||||
if (!goog.isNull(this.callback_)) {
|
||||
this.callback_.call(this.object_, this);
|
||||
this.callback_ = null;
|
||||
this.object_ = null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.source.BingMaps.prototype.isReady = function() {
|
||||
return this.ready_;
|
||||
};
|
||||
+51
-15
@@ -1,9 +1,24 @@
|
||||
goog.provide('ol.layer.Layer');
|
||||
goog.provide('ol.layer.LayerOptions');
|
||||
goog.provide('ol.layer.LayerProperty');
|
||||
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('goog.math');
|
||||
goog.require('ol.Object');
|
||||
goog.require('ol.Source');
|
||||
goog.require('ol.source.Source');
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{brightness: (number|undefined),
|
||||
* contrast: (number|undefined),
|
||||
* hue: (number|undefined),
|
||||
* opacity: (number|undefined),
|
||||
* saturation: (number|undefined),
|
||||
* source: ol.source.Source,
|
||||
* visible: (boolean|undefined)}}
|
||||
*/
|
||||
ol.layer.LayerOptions;
|
||||
|
||||
|
||||
/**
|
||||
@@ -23,34 +38,47 @@ ol.layer.LayerProperty = {
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.Object}
|
||||
* @param {ol.Source} source Source.
|
||||
* @param {Object.<string, *>=} opt_values Values.
|
||||
* @param {ol.layer.LayerOptions} layerOptions LayerOptions.
|
||||
*/
|
||||
ol.layer.Layer = function(source, opt_values) {
|
||||
ol.layer.Layer = function(layerOptions) {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Source}
|
||||
* @type {ol.source.Source}
|
||||
*/
|
||||
this.source_ = source;
|
||||
this.source_ = layerOptions.source;
|
||||
|
||||
this.setBrightness(0);
|
||||
this.setContrast(0);
|
||||
this.setHue(0);
|
||||
this.setOpacity(1);
|
||||
this.setSaturation(0);
|
||||
this.setVisible(true);
|
||||
this.setBrightness(
|
||||
goog.isDef(layerOptions.brightness) ? layerOptions.brightness : 0);
|
||||
this.setContrast(
|
||||
goog.isDef(layerOptions.contrast) ? layerOptions.contrast : 0);
|
||||
this.setHue(
|
||||
goog.isDef(layerOptions.hue) ? layerOptions.hue : 0);
|
||||
this.setOpacity(
|
||||
goog.isDef(layerOptions.opacity) ? layerOptions.opacity : 1);
|
||||
this.setSaturation(
|
||||
goog.isDef(layerOptions.saturation) ? layerOptions.saturation : 0);
|
||||
this.setVisible(
|
||||
goog.isDef(layerOptions.visible) ? layerOptions.visible : true);
|
||||
|
||||
if (goog.isDef(opt_values)) {
|
||||
this.setValues(opt_values);
|
||||
if (!this.source_.isReady()) {
|
||||
goog.events.listenOnce(this.source_, goog.events.EventType.LOAD,
|
||||
this.handleSourceLoad_, false, this);
|
||||
}
|
||||
|
||||
};
|
||||
goog.inherits(ol.layer.Layer, ol.Object);
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
ol.layer.Layer.prototype.dispatchLoadEvent = function() {
|
||||
this.dispatchEvent(goog.events.EventType.LOAD);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number} Brightness.
|
||||
*/
|
||||
@@ -112,7 +140,7 @@ goog.exportProperty(
|
||||
|
||||
|
||||
/**
|
||||
* @return {ol.Source} Source.
|
||||
* @return {ol.source.Source} Source.
|
||||
*/
|
||||
ol.layer.Layer.prototype.getSource = function() {
|
||||
return this.source_;
|
||||
@@ -131,6 +159,14 @@ goog.exportProperty(
|
||||
ol.layer.Layer.prototype.getVisible);
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ol.layer.Layer.prototype.handleSourceLoad_ = function() {
|
||||
this.dispatchLoadEvent();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Is ready.
|
||||
*/
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
goog.provide('ol.layer.MapQuestOSM');
|
||||
goog.provide('ol.layer.MapQuestOpenAerial');
|
||||
|
||||
goog.require('ol.Attribution');
|
||||
goog.require('ol.TileUrlFunction');
|
||||
goog.require('ol.layer.XYZ');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.layer.XYZ}
|
||||
* @param {Object.<string, *>=} opt_values Values.
|
||||
*/
|
||||
ol.layer.MapQuestOSM = function(opt_values) {
|
||||
|
||||
var tileUrlFunction = ol.TileUrlFunction.createFromTemplate(
|
||||
'http://otile{1-4}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.jpg');
|
||||
|
||||
var attributions = [
|
||||
new ol.Attribution(
|
||||
'Tiles Courtesy of ' +
|
||||
'<a href="http://www.mapquest.com/" target="_blank">MapQuest</a> ' +
|
||||
'<img src="http://developer.mapquest.com/content/osm/mq_logo.png">'),
|
||||
new ol.Attribution(
|
||||
'Data © ' +
|
||||
'<a href="http://www.openstreetmap.org">OpenStreetMap</a> ' +
|
||||
'contributors, ' +
|
||||
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC BY-SA</a>')
|
||||
];
|
||||
|
||||
goog.base(this, 18, tileUrlFunction, attributions);
|
||||
|
||||
};
|
||||
goog.inherits(ol.layer.MapQuestOSM, ol.layer.XYZ);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.layer.XYZ}
|
||||
* @param {Object.<string, *>=} opt_values Values.
|
||||
*/
|
||||
ol.layer.MapQuestOpenAerial = function(opt_values) {
|
||||
|
||||
var tileUrlFunction = ol.TileUrlFunction.createFromTemplate(
|
||||
'http://oatile{1-4}.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.jpg');
|
||||
|
||||
var attributions = [
|
||||
new ol.Attribution(
|
||||
'Tiles Courtesy of ' +
|
||||
'<a href="http://www.mapquest.com/" target="_blank">MapQuest</a> ' +
|
||||
'<img src="http://developer.mapquest.com/content/osm/mq_logo.png">'),
|
||||
new ol.Attribution(
|
||||
'Portions Courtesy NASA/JPL-Caltech and ' +
|
||||
'U.S. Depart. of Agriculture, Farm Service Agency')
|
||||
];
|
||||
|
||||
goog.base(this, 18, tileUrlFunction, attributions);
|
||||
|
||||
};
|
||||
goog.inherits(ol.layer.MapQuestOpenAerial, ol.layer.XYZ);
|
||||
@@ -1,40 +0,0 @@
|
||||
goog.provide('ol.layer.OpenStreetMap');
|
||||
goog.provide('ol.source.OpenStreetMap');
|
||||
|
||||
goog.require('ol.TileUrlFunction');
|
||||
goog.require('ol.layer.TileLayer');
|
||||
goog.require('ol.source.XYZ');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.layer.TileLayer}
|
||||
* @param {Object.<string, *>=} opt_values Values.
|
||||
*/
|
||||
ol.layer.OpenStreetMap = function(opt_values) {
|
||||
var tileSource = new ol.source.OpenStreetMap();
|
||||
goog.base(this, tileSource, opt_values);
|
||||
};
|
||||
goog.inherits(ol.layer.OpenStreetMap, ol.layer.TileLayer);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.source.XYZ}
|
||||
*/
|
||||
ol.source.OpenStreetMap = function() {
|
||||
|
||||
var tileUrlFunction = ol.TileUrlFunction.createFromTemplate(
|
||||
'http://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png');
|
||||
|
||||
var attribution = new ol.Attribution(
|
||||
'© <a href="http://www.openstreetmap.org">OpenStreetMap</a> ' +
|
||||
'contributors, ' +
|
||||
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC BY-SA</a>');
|
||||
|
||||
goog.base(this, 18, tileUrlFunction, [attribution]);
|
||||
|
||||
};
|
||||
goog.inherits(ol.source.OpenStreetMap, ol.source.XYZ);
|
||||
@@ -1,92 +0,0 @@
|
||||
// FIXME Configure minZoom when supported by TileGrid
|
||||
|
||||
goog.provide('ol.layer.Stamen');
|
||||
goog.provide('ol.source.Stamen');
|
||||
|
||||
goog.require('ol.TileUrlFunction');
|
||||
goog.require('ol.layer.XYZ');
|
||||
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
*/
|
||||
ol.StamenProvider = {
|
||||
TERRAIN: 'terrain',
|
||||
TONER: 'toner',
|
||||
WATERCOLOR: 'watercolor'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
*/
|
||||
ol.StamenFlavor = {
|
||||
TERRAIN_BACKGROUND: 'background',
|
||||
TERRAIN_LABELS: 'labels',
|
||||
TERRAIN_LINES: 'lines',
|
||||
TONER_2010: '2010',
|
||||
TONER_2011: '2011',
|
||||
TONER_2011_LABELS: '2011-labels',
|
||||
TONER_2011_LINES: '2011-lines',
|
||||
TONER_2011_LITE: '2011-lite',
|
||||
TONER_BACKGROUND: 'background',
|
||||
TONER_HYBRID: 'hybrid',
|
||||
TONER_LABELS: 'labels',
|
||||
TONER_LINES: 'lines',
|
||||
TONER_LITE: 'lite'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @type {Object.<ol.StamenProvider,
|
||||
* {type: string, minZoom: number, maxZoom: number}>}
|
||||
*/
|
||||
ol.StamenProviderConfig = {};
|
||||
ol.StamenProviderConfig[ol.StamenProvider.TERRAIN] = {
|
||||
type: 'jpg',
|
||||
minZoom: 4,
|
||||
maxZoom: 18
|
||||
};
|
||||
ol.StamenProviderConfig[ol.StamenProvider.TONER] = {
|
||||
type: 'png',
|
||||
minZoom: 0,
|
||||
maxZoom: 20
|
||||
};
|
||||
ol.StamenProviderConfig[ol.StamenProvider.WATERCOLOR] = {
|
||||
type: 'jpg',
|
||||
minZoom: 3,
|
||||
maxZoom: 16
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.layer.XYZ}
|
||||
* @param {ol.StamenProvider} provider Provider.
|
||||
* @param {ol.StamenFlavor=} opt_flavor Flavor.
|
||||
* @param {Object.<string, *>=} opt_values Values.
|
||||
*/
|
||||
ol.layer.Stamen = function(provider, opt_flavor, opt_values) {
|
||||
|
||||
var config = ol.StamenProviderConfig[provider];
|
||||
|
||||
var layer = provider;
|
||||
if (goog.isDef(opt_flavor)) {
|
||||
layer += '-' + opt_flavor;
|
||||
}
|
||||
var tileUrlFunction = ol.TileUrlFunction.createFromTemplate(
|
||||
'http://{a-d}.tile.stamen.com/' + layer + '/{z}/{x}/{y}.' + config.type);
|
||||
|
||||
var attribution = new ol.Attribution(
|
||||
'Map tiles by <a href="http://stamen.com">Stamen Design</a>, ' +
|
||||
'under ' +
|
||||
'<a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. ' +
|
||||
'Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, ' +
|
||||
'under ' +
|
||||
'<a href="http://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>.');
|
||||
|
||||
goog.base(this, config.maxZoom, tileUrlFunction, [attribution]);
|
||||
|
||||
};
|
||||
goog.inherits(ol.layer.Stamen, ol.layer.XYZ);
|
||||
@@ -1,181 +0,0 @@
|
||||
// FIXME add some error checking
|
||||
// FIXME check order of async callbacks
|
||||
// FIXME use minzoom when supported by ol.TileGrid
|
||||
|
||||
/**
|
||||
* @see http://mapbox.com/developers/api/
|
||||
*/
|
||||
|
||||
goog.provide('ol.layer.TileJSON');
|
||||
goog.provide('ol.source.TileJSON');
|
||||
goog.provide('ol.tilejson');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('goog.net.jsloader');
|
||||
goog.require('goog.string');
|
||||
goog.require('ol.TileCoverageArea');
|
||||
goog.require('ol.TileSource');
|
||||
goog.require('ol.TileUrlFunction');
|
||||
goog.require('ol.layer.TileLayer');
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<TileJSON>}
|
||||
*/
|
||||
ol.tilejson.grids_ = [];
|
||||
|
||||
|
||||
/**
|
||||
* @param {TileJSON} tileJSON Tile JSON.
|
||||
*/
|
||||
var grid = function(tileJSON) {
|
||||
ol.tilejson.grids_.push(tileJSON);
|
||||
};
|
||||
goog.exportSymbol('grid', grid);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.layer.TileLayer}
|
||||
* @param {string} url URL.
|
||||
* @param {Object.<string, *>=} opt_values Values.
|
||||
*/
|
||||
ol.layer.TileJSON = function(url, opt_values) {
|
||||
goog.asserts.assert(goog.string.endsWith(url, '.jsonp'));
|
||||
var tileSource = new ol.source.TileJSON(url, function(tileSource) {
|
||||
this.dispatchEvent(goog.events.EventType.LOAD);
|
||||
}, this);
|
||||
goog.base(this, tileSource, opt_values);
|
||||
};
|
||||
goog.inherits(ol.layer.TileJSON, ol.layer.TileLayer);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.TileSource}
|
||||
* @param {string} uri URI.
|
||||
* @param {?function(ol.source.TileJSON)=} opt_callback Callback.
|
||||
* @param {*=} opt_obj Object.
|
||||
*/
|
||||
ol.source.TileJSON = function(uri, opt_callback, opt_obj) {
|
||||
|
||||
var projection = ol.Projection.getFromCode('EPSG:3857');
|
||||
|
||||
goog.base(
|
||||
this, projection, null, ol.TileUrlFunction.nullTileUrlFunction, null);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {?function(ol.source.TileJSON)}
|
||||
*/
|
||||
this.callback_ = opt_callback || null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {*}
|
||||
*/
|
||||
this.object_ = opt_obj;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.ready_ = false;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {!goog.async.Deferred}
|
||||
*/
|
||||
this.deferred_ = goog.net.jsloader.load(uri, {cleanupWhenDone: true});
|
||||
this.deferred_.addCallback(this.handleTileJSONResponse, this);
|
||||
|
||||
};
|
||||
goog.inherits(ol.source.TileJSON, ol.TileSource);
|
||||
|
||||
|
||||
/**
|
||||
* @protected
|
||||
*/
|
||||
ol.source.TileJSON.prototype.handleTileJSONResponse = function() {
|
||||
|
||||
var tileJSON = ol.tilejson.grids_.pop();
|
||||
|
||||
var epsg4326Projection = ol.Projection.getFromCode('EPSG:4326');
|
||||
|
||||
var epsg4326Extent, extent;
|
||||
if (goog.isDef(tileJSON.bounds)) {
|
||||
var bounds = tileJSON.bounds;
|
||||
epsg4326Extent = new ol.Extent(
|
||||
bounds[0], bounds[1], bounds[2], bounds[3]);
|
||||
extent = epsg4326Extent.transform(
|
||||
ol.Projection.getTransform(epsg4326Projection, this.getProjection()));
|
||||
this.setExtent(extent);
|
||||
} else {
|
||||
epsg4326Extent = null;
|
||||
extent = null;
|
||||
}
|
||||
|
||||
var scheme = goog.isDef(tileJSON.scheme) || 'xyz';
|
||||
if (goog.isDef(tileJSON.scheme)) {
|
||||
goog.asserts.assert(tileJSON.scheme == 'xyz');
|
||||
}
|
||||
var minzoom = tileJSON.minzoom || 0;
|
||||
goog.asserts.assert(minzoom === 0); // FIXME
|
||||
var maxzoom = tileJSON.maxzoom || 22;
|
||||
var tileGrid = new ol.tilegrid.XYZ(maxzoom);
|
||||
this.tileGrid = tileGrid;
|
||||
|
||||
this.tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
|
||||
function(tileCoord) {
|
||||
if (tileCoord.z < minzoom || maxzoom < tileCoord.z) {
|
||||
return null;
|
||||
}
|
||||
var n = 1 << tileCoord.z;
|
||||
var y = -tileCoord.y - 1;
|
||||
if (y < 0 || n <= y) {
|
||||
return null;
|
||||
}
|
||||
var x = goog.math.modulo(tileCoord.x, n);
|
||||
if (!goog.isNull(extent)) {
|
||||
var tileExtent = tileGrid.getTileCoordExtent(
|
||||
new ol.TileCoord(tileCoord.z, x, tileCoord.y));
|
||||
if (!tileExtent.intersects(extent)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return new ol.TileCoord(tileCoord.z, x, y);
|
||||
},
|
||||
ol.TileUrlFunction.createFromTemplates(tileJSON.tiles));
|
||||
|
||||
if (goog.isDef(tileJSON.attribution)) {
|
||||
var coverageAreas = [
|
||||
new ol.TileCoverageArea(tileGrid, epsg4326Extent, minzoom, maxzoom)
|
||||
];
|
||||
var coverageAreaProjection = epsg4326Projection;
|
||||
this.setAttributions([
|
||||
new ol.Attribution(
|
||||
tileJSON.attribution, coverageAreas, coverageAreaProjection)
|
||||
]);
|
||||
}
|
||||
|
||||
this.ready_ = true;
|
||||
|
||||
if (!goog.isNull(this.callback_)) {
|
||||
this.callback_.call(this.object_, this);
|
||||
this.callback_ = null;
|
||||
this.object_ = null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.source.TileJSON.prototype.isReady = function() {
|
||||
return this.ready_;
|
||||
};
|
||||
@@ -1,25 +1,25 @@
|
||||
goog.provide('ol.layer.TileLayer');
|
||||
|
||||
goog.require('ol.TileSource');
|
||||
goog.require('ol.layer.Layer');
|
||||
goog.require('ol.layer.LayerOptions');
|
||||
goog.require('ol.source.TileSource');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.layer.Layer}
|
||||
* @param {ol.TileSource} tileSource Tile source.
|
||||
* @param {Object.<string, *>=} opt_values Values.
|
||||
* @param {ol.layer.LayerOptions} layerOptions Layer options.
|
||||
*/
|
||||
ol.layer.TileLayer = function(tileSource, opt_values) {
|
||||
goog.base(this, tileSource, opt_values);
|
||||
ol.layer.TileLayer = function(layerOptions) {
|
||||
goog.base(this, layerOptions);
|
||||
};
|
||||
goog.inherits(ol.layer.TileLayer, ol.layer.Layer);
|
||||
|
||||
|
||||
/**
|
||||
* @return {ol.TileSource} Source.
|
||||
* @return {ol.source.TileSource} Source.
|
||||
*/
|
||||
ol.layer.TileLayer.prototype.getTileSource = function() {
|
||||
return /** @type {ol.TileSource} */ this.getSource();
|
||||
return /** @type {ol.source.TileSource} */ this.getSource();
|
||||
};
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
goog.provide('ol.layer.XYZ');
|
||||
goog.provide('ol.source.XYZ');
|
||||
goog.provide('ol.tilegrid.XYZ');
|
||||
|
||||
goog.require('goog.math');
|
||||
goog.require('ol.Attribution');
|
||||
goog.require('ol.Coordinate');
|
||||
goog.require('ol.Projection');
|
||||
goog.require('ol.Size');
|
||||
goog.require('ol.TileCoord');
|
||||
goog.require('ol.TileGrid');
|
||||
goog.require('ol.TileSource');
|
||||
goog.require('ol.TileUrlFunction');
|
||||
goog.require('ol.layer.Layer');
|
||||
goog.require('ol.layer.TileLayer');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.TileGrid}
|
||||
* @param {number} maxZoom Maximum zoom.
|
||||
* @param {ol.Size=} opt_tileSize Tile size.
|
||||
*/
|
||||
ol.tilegrid.XYZ = function(maxZoom, opt_tileSize) {
|
||||
|
||||
var resolutions = new Array(maxZoom + 1);
|
||||
var z;
|
||||
for (z = 0; z <= maxZoom; ++z) {
|
||||
resolutions[z] = ol.Projection.EPSG_3857_HALF_SIZE / (128 << z);
|
||||
}
|
||||
|
||||
var extent = ol.Projection.EPSG_3857_EXTENT;
|
||||
var origin = new ol.Coordinate(
|
||||
-ol.Projection.EPSG_3857_HALF_SIZE, ol.Projection.EPSG_3857_HALF_SIZE);
|
||||
|
||||
goog.base(this, resolutions, extent, origin, opt_tileSize);
|
||||
|
||||
};
|
||||
goog.inherits(ol.tilegrid.XYZ, ol.TileGrid);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.tilegrid.XYZ.prototype.forEachTileCoordParentTileRange =
|
||||
function(tileCoord, callback, opt_obj) {
|
||||
var x = tileCoord.x;
|
||||
var y = tileCoord.y;
|
||||
var z = tileCoord.z;
|
||||
var tileRange;
|
||||
while (true) {
|
||||
z -= 1;
|
||||
if (z < 0) {
|
||||
break;
|
||||
}
|
||||
x = Math.floor(x / 2);
|
||||
y = Math.floor(y / 2);
|
||||
tileRange = new ol.TileRange(x, y, x, y);
|
||||
if (callback.call(opt_obj, z, tileRange)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.layer.TileLayer}
|
||||
* @param {number} maxZoom Maximum zoom.
|
||||
* @param {ol.TileUrlFunctionType} tileUrlFunction Tile URL function.
|
||||
* @param {Array.<ol.Attribution>=} opt_attributions Attributions.
|
||||
* @param {string=} opt_crossOrigin Cross origin.
|
||||
* @param {Object.<string, *>=} opt_values Values.
|
||||
*/
|
||||
ol.layer.XYZ = function(
|
||||
maxZoom, tileUrlFunction, opt_attributions, opt_crossOrigin, opt_values) {
|
||||
var tileSource = new ol.source.XYZ(
|
||||
maxZoom, tileUrlFunction, opt_attributions, opt_crossOrigin);
|
||||
goog.base(this, tileSource, opt_values);
|
||||
};
|
||||
goog.inherits(ol.layer.XYZ, ol.layer.TileLayer);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.TileSource}
|
||||
* @param {number} maxZoom Maximum zoom.
|
||||
* @param {ol.TileUrlFunctionType} tileUrlFunction Tile URL function.
|
||||
* @param {Array.<ol.Attribution>=} opt_attributions Attributions.
|
||||
* @param {string=} opt_crossOrigin Cross origin.
|
||||
*/
|
||||
ol.source.XYZ =
|
||||
function(maxZoom, tileUrlFunction, opt_attributions, opt_crossOrigin) {
|
||||
|
||||
var projection = ol.Projection.getFromCode('EPSG:3857');
|
||||
var tileGrid = new ol.tilegrid.XYZ(maxZoom);
|
||||
var tileUrlFunction2 = ol.TileUrlFunction.withTileCoordTransform(
|
||||
function(tileCoord) {
|
||||
var n = 1 << tileCoord.z;
|
||||
var y = -tileCoord.y - 1;
|
||||
if (y < 0 || n <= y) {
|
||||
return null;
|
||||
} else {
|
||||
var x = goog.math.modulo(tileCoord.x, n);
|
||||
return new ol.TileCoord(tileCoord.z, x, y);
|
||||
}
|
||||
},
|
||||
tileUrlFunction);
|
||||
var extent = projection.getExtent();
|
||||
|
||||
goog.base(this, projection, tileGrid, tileUrlFunction2, extent,
|
||||
opt_attributions, opt_crossOrigin);
|
||||
|
||||
};
|
||||
goog.inherits(ol.source.XYZ, ol.TileSource);
|
||||
Reference in New Issue
Block a user