Use ol.Attribution
This commit is contained in:
@@ -63,12 +63,6 @@ ol.tilestore.BingMaps =
|
||||
*/
|
||||
this.culture_ = goog.isDef(opt_culture) ? opt_culture : 'en-us';
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<BingMapsImageryProvider>}
|
||||
*/
|
||||
this.imageryProviders_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
@@ -98,13 +92,6 @@ ol.tilestore.BingMaps =
|
||||
var projection = ol.Projection.getFromCode('EPSG:3857');
|
||||
var extent = projection.getExtent();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.TransformFunction}
|
||||
*/
|
||||
this.attributionTransform_ = ol.Projection.getTransform(
|
||||
ol.Projection.getFromCode('EPSG:4326'), projection);
|
||||
|
||||
goog.base(
|
||||
this, projection, null, ol.TileUrlFunction.nullTileUrlFunction, extent);
|
||||
|
||||
@@ -112,34 +99,6 @@ ol.tilestore.BingMaps =
|
||||
goog.inherits(ol.tilestore.BingMaps, ol.TileStore);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.tilestore.BingMaps.prototype.getAttributions = function(extent, resolution) {
|
||||
if (this.isReady()) {
|
||||
var attributions = [];
|
||||
goog.array.forEach(this.imageryProviders_, function(imageryProvider) {
|
||||
var include = goog.array.some(
|
||||
imageryProvider.coverageAreas,
|
||||
function(coverageArea) {
|
||||
var epsg4326CoverageAreaExtent = new ol.Extent(
|
||||
coverageArea.bbox[0], coverageArea.bbox[1],
|
||||
coverageArea.bbox[2], coverageArea.bbox[3]);
|
||||
var coverageAreaExtent = epsg4326CoverageAreaExtent.transform(
|
||||
this.attributionTransform_);
|
||||
return coverageAreaExtent.intersects(extent);
|
||||
});
|
||||
if (include) {
|
||||
attributions.push(imageryProvider.attribution);
|
||||
}
|
||||
});
|
||||
return attributions;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {BingMapsImageryMetadataResponse} response Response.
|
||||
*/
|
||||
@@ -194,7 +153,23 @@ ol.tilestore.BingMaps.prototype.handleImageryMetadataResponse =
|
||||
};
|
||||
})));
|
||||
|
||||
this.imageryProviders_ = resource.imageryProviders;
|
||||
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 minZ = coverageArea.zoomMin;
|
||||
var maxZ = coverageArea.zoomMax;
|
||||
return new ol.CoverageArea(
|
||||
bbox[0], bbox[1], bbox[2], bbox[3], minZ, maxZ);
|
||||
});
|
||||
return new ol.Attribution(html, coverageAreas, projection);
|
||||
});
|
||||
this.setAttributions(attributions);
|
||||
|
||||
this.ready_ = true;
|
||||
|
||||
@@ -26,15 +26,16 @@ goog.inherits(ol.layer.OpenStreetMap, ol.TileLayer);
|
||||
*/
|
||||
ol.store.OpenStreetMap = function() {
|
||||
|
||||
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, ol.TileUrlFunction.createFromTemplates([
|
||||
'http://a.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||
'http://b.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||
'http://c.tile.openstreetmap.org/{z}/{x}/{y}.png'
|
||||
]), [
|
||||
'© <a href="http://www.openstreetmap.org">OpenStreetMap</a> ' +
|
||||
'contributors, ' +
|
||||
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC BY-SA</a>'
|
||||
]);
|
||||
]), [attribution]);
|
||||
|
||||
};
|
||||
goog.inherits(ol.store.OpenStreetMap, ol.tilestore.XYZ);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
goog.provide('ol.TileStore');
|
||||
|
||||
goog.require('ol.Attribution');
|
||||
goog.require('ol.Store');
|
||||
goog.require('ol.Tile');
|
||||
goog.require('ol.TileCoord');
|
||||
@@ -15,12 +16,13 @@ goog.require('ol.TileUrlFunctionType');
|
||||
* @param {ol.TileGrid} tileGrid Tile grid.
|
||||
* @param {ol.TileUrlFunctionType} tileUrlFunction Tile URL.
|
||||
* @param {ol.Extent=} opt_extent Extent.
|
||||
* @param {Array.<string>=} opt_attributions Attributions.
|
||||
* @param {?string=} opt_crossOrigin Cross origin.
|
||||
*/
|
||||
ol.TileStore = function(
|
||||
projection, tileGrid, tileUrlFunction, opt_extent, opt_crossOrigin) {
|
||||
ol.TileStore = function(projection, tileGrid, tileUrlFunction, opt_extent,
|
||||
opt_attributions, opt_crossOrigin) {
|
||||
|
||||
goog.base(this, projection, opt_extent);
|
||||
goog.base(this, projection, opt_extent, opt_attributions);
|
||||
|
||||
/**
|
||||
* @protected
|
||||
|
||||
@@ -3,6 +3,7 @@ goog.provide('ol.tilegrid.XYZ');
|
||||
goog.provide('ol.tilestore.XYZ');
|
||||
|
||||
goog.require('goog.math');
|
||||
goog.require('ol.Attribution');
|
||||
goog.require('ol.Coordinate');
|
||||
goog.require('ol.Layer');
|
||||
goog.require('ol.Projection');
|
||||
@@ -45,12 +46,14 @@ goog.inherits(ol.tilegrid.XYZ, ol.TileGrid);
|
||||
* @extends {ol.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_crossOrigin, opt_values) {
|
||||
ol.layer.XYZ = function(
|
||||
maxZoom, tileUrlFunction, opt_attributions, opt_crossOrigin, opt_values) {
|
||||
var tileStore = new ol.tilestore.XYZ(
|
||||
maxZoom, tileUrlFunction, undefined, opt_crossOrigin);
|
||||
maxZoom, tileUrlFunction, opt_attributions, opt_crossOrigin);
|
||||
goog.base(this, tileStore, opt_values);
|
||||
};
|
||||
goog.inherits(ol.layer.XYZ, ol.TileLayer);
|
||||
@@ -62,7 +65,7 @@ goog.inherits(ol.layer.XYZ, ol.TileLayer);
|
||||
* @extends {ol.TileStore}
|
||||
* @param {number} maxZoom Maximum zoom.
|
||||
* @param {ol.TileUrlFunctionType} tileUrlFunction Tile URL function.
|
||||
* @param {Array.<string>=} opt_attributions Attributions.
|
||||
* @param {Array.<ol.Attribution>=} opt_attributions Attributions.
|
||||
* @param {string=} opt_crossOrigin Cross origin.
|
||||
*/
|
||||
ol.tilestore.XYZ =
|
||||
@@ -84,23 +87,8 @@ ol.tilestore.XYZ =
|
||||
tileUrlFunction);
|
||||
var extent = projection.getExtent();
|
||||
|
||||
goog.base(
|
||||
this, projection, tileGrid, tileUrlFunction2, extent, opt_crossOrigin);
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<string>}
|
||||
*/
|
||||
this.attributions_ = goog.isDef(opt_attributions) ? opt_attributions : [];
|
||||
goog.base(this, projection, tileGrid, tileUrlFunction2, extent,
|
||||
opt_attributions, opt_crossOrigin);
|
||||
|
||||
};
|
||||
goog.inherits(ol.tilestore.XYZ, ol.TileStore);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.tilestore.XYZ.prototype.getAttributions = function(extent, resolution) {
|
||||
return this.attributions_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user