Refactor attribution control
This commit is contained in:
@@ -5,7 +5,7 @@ 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.TileRange');
|
||||
goog.require('ol.source.ImageTileSource');
|
||||
goog.require('ol.tilegrid.XYZ');
|
||||
|
||||
@@ -118,21 +118,35 @@ ol.source.BingMaps.prototype.handleImageryMetadataResponse =
|
||||
};
|
||||
})));
|
||||
|
||||
var projection = ol.Projection.getFromCode('EPSG:4326');
|
||||
var transform = ol.Projection.getTransform(
|
||||
ol.Projection.getFromCode('EPSG:4326'), this.getProjection());
|
||||
var attributions = goog.array.map(
|
||||
resource.imageryProviders,
|
||||
function(imageryProvider) {
|
||||
var html = imageryProvider.attribution;
|
||||
var coverageAreas = goog.array.map(
|
||||
/** @type {Object.<string, Array.<ol.TileRange>>} */
|
||||
var tileRanges = {};
|
||||
goog.array.forEach(
|
||||
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);
|
||||
var bbox = coverageArea.bbox;
|
||||
var epsg4326Extent =
|
||||
new ol.Extent(bbox[1], bbox[0], bbox[3], bbox[2]);
|
||||
var extent = epsg4326Extent.transform(transform);
|
||||
var tileRange, z, zKey;
|
||||
for (z = minZ; z <= maxZ; ++z) {
|
||||
zKey = z.toString();
|
||||
tileRange = tileGrid.getTileRangeForExtentAndZ(extent, z);
|
||||
if (zKey in tileRanges) {
|
||||
tileRanges[zKey].push(tileRange);
|
||||
} else {
|
||||
tileRanges[zKey] = [tileRange];
|
||||
}
|
||||
}
|
||||
});
|
||||
return new ol.Attribution(html, coverageAreas, projection);
|
||||
return new ol.Attribution(html, tileRanges);
|
||||
});
|
||||
this.setAttributions(attributions);
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ goog.require('goog.events.EventType');
|
||||
goog.require('goog.net.jsloader');
|
||||
goog.require('goog.string');
|
||||
goog.require('ol.Projection');
|
||||
goog.require('ol.TileCoverageArea');
|
||||
goog.require('ol.TileUrlFunction');
|
||||
goog.require('ol.source.ImageTileSource');
|
||||
goog.require('ol.tilegrid.XYZ');
|
||||
@@ -98,17 +97,17 @@ ol.source.TileJSON.prototype.handleTileJSONResponse = function() {
|
||||
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 minZoom = tileJSON.minzoom || 0;
|
||||
goog.asserts.assert(minZoom === 0); // FIXME
|
||||
var maxZoom = tileJSON.maxzoom || 22;
|
||||
var tileGrid = new ol.tilegrid.XYZ({
|
||||
maxZoom: maxzoom
|
||||
maxZoom: maxZoom
|
||||
});
|
||||
this.tileGrid = tileGrid;
|
||||
|
||||
this.tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
|
||||
function(tileCoord) {
|
||||
if (tileCoord.z < minzoom || maxzoom < tileCoord.z) {
|
||||
if (tileCoord.z < minZoom || maxZoom < tileCoord.z) {
|
||||
return null;
|
||||
}
|
||||
var n = 1 << tileCoord.z;
|
||||
@@ -129,13 +128,18 @@ ol.source.TileJSON.prototype.handleTileJSONResponse = function() {
|
||||
ol.TileUrlFunction.createFromTemplates(tileJSON.tiles));
|
||||
|
||||
if (goog.isDef(tileJSON.attribution)) {
|
||||
var coverageAreas = [
|
||||
new ol.TileCoverageArea(tileGrid, epsg4326Extent, minzoom, maxzoom)
|
||||
];
|
||||
var coverageAreaProjection = epsg4326Projection;
|
||||
var attributionExtent = goog.isNull(extent) ?
|
||||
epsg4326Projection.getExtent() : extent;
|
||||
/** @type {Object.<string, Array.<ol.TileRange>>} */
|
||||
var tileRanges = {};
|
||||
var z, zKey;
|
||||
for (z = minZoom; z <= maxZoom; ++z) {
|
||||
zKey = z.toString();
|
||||
tileRanges[zKey] =
|
||||
[tileGrid.getTileRangeForExtentAndZ(attributionExtent, z)];
|
||||
}
|
||||
this.setAttributions([
|
||||
new ol.Attribution(
|
||||
tileJSON.attribution, coverageAreas, coverageAreaProjection)
|
||||
new ol.Attribution(tileJSON.attribution, tileRanges)
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user