1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214 | 1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
3×
3×
3×
3×
3×
3×
3×
3×
1×
1×
1×
1×
1×
1×
1×
3×
3×
3×
3×
3×
3×
3×
3×
3×
3×
3×
3×
3×
3×
12×
12×
12×
6×
6×
6×
6×
6×
3×
3×
3×
84×
84×
84×
528×
528×
528×
528×
528×
528×
528×
4143×
4143×
4143×
3291×
852×
84×
3×
3×
3×
3×
| goog.provide('ol.source.BingMaps');
goog.require('ol');
goog.require('ol.Attribution');
goog.require('ol.TileUrlFunction');
goog.require('ol.extent');
goog.require('ol.net');
goog.require('ol.proj');
goog.require('ol.source.State');
goog.require('ol.source.TileImage');
goog.require('ol.tilecoord');
goog.require('ol.tilegrid');
/**
* @classdesc
* Layer source for Bing Maps tile data.
*
* @constructor
* @extends {ol.source.TileImage}
* @param {olx.source.BingMapsOptions} options Bing Maps options.
* @api
*/
ol.source.BingMaps = function(options) {
/**
* @private
* @type {boolean}
*/
this.hidpi_ = options.hidpi !== undefined ? options.hidpi : false;
ol.source.TileImage.call(this, {
cacheSize: options.cacheSize,
crossOrigin: 'anonymous',
opaque: true,
projection: ol.proj.get('EPSG:3857'),
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
state: ol.source.State.LOADING,
tileLoadFunction: options.tileLoadFunction,
tilePixelRatio: this.hidpi_ ? 2 : 1,
wrapX: options.wrapX !== undefined ? options.wrapX : true
});
/**
* @private
* @type {string}
*/
this.culture_ = options.culture !== undefined ? options.culture : 'en-us';
/**
* @private
* @type {number}
*/
this.maxZoom_ = options.maxZoom !== undefined ? options.maxZoom : -1;
/**
* @private
* @type {string}
*/
this.apiKey_ = options.key;
/**
* @private
* @type {string}
*/
this.imagerySet_ = options.imagerySet;
var url = 'https://dev.virtualearth.net/REST/v1/Imagery/Metadata/' +
this.imagerySet_ +
'?uriScheme=https&include=ImageryProviders&key=' + this.apiKey_;
ol.net.jsonp(url, this.handleImageryMetadataResponse.bind(this), undefined,
'jsonp');
};
ol.inherits(ol.source.BingMaps, ol.source.TileImage);
/**
* The attribution containing a link to the Microsoft® Bing™ Maps Platform APIs’
* Terms Of Use.
* @const
* @type {ol.Attribution}
* @api
*/
ol.source.BingMaps.TOS_ATTRIBUTION = new ol.Attribution({
html: '<a class="ol-attribution-bing-tos" ' +
'href="https://www.microsoft.com/maps/product/terms.html">' +
'Terms of Use</a>'
});
/**
* Get the api key used for this source.
*
* @return {string} The api key.
* @api
*/
ol.source.BingMaps.prototype.getApiKey = function() {
return this.apiKey_;
};
/**
* Get the imagery set associated with this source.
*
* @return {string} The imagery set.
* @api
*/
ol.source.BingMaps.prototype.getImagerySet = function() {
return this.imagerySet_;
};
/**
* @param {BingMapsImageryMetadataResponse} response Response.
*/
ol.source.BingMaps.prototype.handleImageryMetadataResponse = function(response) {
Iif (response.statusCode != 200 ||
response.statusDescription != 'OK' ||
response.authenticationResultCode != 'ValidCredentials' ||
response.resourceSets.length != 1 ||
response.resourceSets[0].resources.length != 1) {
this.setState(ol.source.State.ERROR);
return;
}
var brandLogoUri = response.brandLogoUri;
Eif (brandLogoUri.indexOf('https') == -1) {
brandLogoUri = brandLogoUri.replace('http', 'https');
}
//var copyright = response.copyright; // FIXME do we need to display this?
var resource = response.resourceSets[0].resources[0];
var maxZoom = this.maxZoom_ == -1 ? resource.zoomMax : this.maxZoom_;
var sourceProjection = this.getProjection();
var extent = ol.tilegrid.extentFromProjection(sourceProjection);
var tileSize = resource.imageWidth == resource.imageHeight ?
resource.imageWidth : [resource.imageWidth, resource.imageHeight];
var tileGrid = ol.tilegrid.createXYZ({
extent: extent,
minZoom: resource.zoomMin,
maxZoom: maxZoom,
tileSize: tileSize / (this.hidpi_ ? 2 : 1)
});
this.tileGrid = tileGrid;
var culture = this.culture_;
var hidpi = this.hidpi_;
this.tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(
resource.imageUrlSubdomains.map(function(subdomain) {
var quadKeyTileCoord = [0, 0, 0];
var imageUrl = resource.imageUrl
.replace('{subdomain}', subdomain)
.replace('{culture}', culture);
return (
/**
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {number} pixelRatio Pixel ratio.
* @param {ol.proj.Projection} projection Projection.
* @return {string|undefined} Tile URL.
*/
function(tileCoord, pixelRatio, projection) {
Iif (!tileCoord) {
return undefined;
} else {
ol.tilecoord.createOrUpdate(tileCoord[0], tileCoord[1],
-tileCoord[2] - 1, quadKeyTileCoord);
var url = imageUrl;
Iif (hidpi) {
url += '&dpi=d1&device=mobile';
}
return url.replace('{quadkey}', ol.tilecoord.quadKey(
quadKeyTileCoord));
}
});
}));
Eif (resource.imageryProviders) {
var transform = ol.proj.getTransformFromProjections(
ol.proj.get('EPSG:4326'), this.getProjection());
var attributions = resource.imageryProviders.map(function(imageryProvider) {
var html = imageryProvider.attribution;
/** @type {Object.<string, Array.<ol.TileRange>>} */
var tileRanges = {};
imageryProvider.coverageAreas.forEach(function(coverageArea) {
var minZ = coverageArea.zoomMin;
var maxZ = Math.min(coverageArea.zoomMax, maxZoom);
var bbox = coverageArea.bbox;
var epsg4326Extent = [bbox[1], bbox[0], bbox[3], bbox[2]];
var extent = ol.extent.applyTransform(epsg4326Extent, 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: html, tileRanges: tileRanges});
});
attributions.push(ol.source.BingMaps.TOS_ATTRIBUTION);
this.setAttributions(attributions);
}
this.setLogo(brandLogoUri);
this.setState(ol.source.State.READY);
};
|