-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Add Azure 2D imagery provider #13001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lukemckinstry
wants to merge
10
commits into
main
Choose a base branch
from
azure-2d-tiles
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+137
−41
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
043d87e
add attribution for azure
lukemckinstry 93fa6df
update imagery tutorial sandcastle
lukemckinstry 8a96309
docs typo
lukemckinstry ad1944c
make Azure class public
lukemckinstry e2e7245
move azure sandcastles out of development folder
lukemckinstry c5d2c31
add azure maps to default options in imagery layer picker
lukemckinstry a060483
use derived resources for attribution calls
lukemckinstry 46ac4e6
remove labels only layers from base layer picker defaults
lukemckinstry e7bcd7d
update specs
lukemckinstry fe54e66
remove labels thumbnails
lukemckinstry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
File renamed without changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import Check from "../Core/Check.js"; | ||
| import Frozen from "../Core/Frozen.js"; | ||
| import Credit from "../Core/Credit.js"; | ||
| import defined from "../Core/defined.js"; | ||
| import Resource from "../Core/Resource.js"; | ||
|
|
@@ -29,7 +30,6 @@ const trailingSlashRegex = /\/$/; | |
| * | ||
| * @alias Azure2DImageryProvider | ||
| * @constructor | ||
| * @private | ||
| * @param {Azure2DImageryProvider.ConstructorOptions} options Object describing initialization options | ||
| * | ||
| * @example | ||
|
|
@@ -41,16 +41,18 @@ const trailingSlashRegex = /\/$/; | |
| */ | ||
| function Azure2DImageryProvider(options) { | ||
| options = options ?? {}; | ||
| const maximumLevel = options.maximumLevel ?? 22; | ||
| const minimumLevel = options.minimumLevel ?? 0; | ||
| const tilesetId = options.tilesetId ?? "microsoft.imagery"; | ||
| this._maximumLevel = options.maximumLevel ?? 22; | ||
| this._minimumLevel = options.minimumLevel ?? 0; | ||
|
|
||
| const subscriptionKey = | ||
| this._subscriptionKey = | ||
| options.subscriptionKey ?? options["subscription-key"]; | ||
| //>>includeStart('debug', pragmas.debug); | ||
| Check.defined("options.subscriptionKey", subscriptionKey); | ||
| Check.defined("options.subscriptionKey", this._subscriptionKey); | ||
| //>>includeEnd('debug'); | ||
|
|
||
| this._tilesetId = options.tilesetId; | ||
|
|
||
| const resource = | ||
| options.url instanceof IonResource | ||
| ? options.url | ||
|
|
@@ -60,19 +62,23 @@ function Azure2DImageryProvider(options) { | |
| if (!trailingSlashRegex.test(templateUrl)) { | ||
| templateUrl += "/"; | ||
| } | ||
| templateUrl += `map/tile`; | ||
|
|
||
| resource.url = templateUrl; | ||
| const tilesUrl = `${templateUrl}map/tile`; | ||
| this._viewportUrl = `${templateUrl}map/attribution`; | ||
|
|
||
| resource.url = tilesUrl; | ||
|
|
||
| resource.setQueryParameters({ | ||
| "api-version": "2024-04-01", | ||
| tilesetId: tilesetId, | ||
| "subscription-key": this._subscriptionKey, | ||
| zoom: `{z}`, | ||
| x: `{x}`, | ||
| y: `{y}`, | ||
| "subscription-key": subscriptionKey, | ||
| }); | ||
|
|
||
| this._resource = resource; | ||
|
|
||
| let credit; | ||
| if (defined(options.credit)) { | ||
| credit = options.credit; | ||
|
|
@@ -83,8 +89,8 @@ function Azure2DImageryProvider(options) { | |
|
|
||
| const provider = new UrlTemplateImageryProvider({ | ||
| ...options, | ||
| maximumLevel, | ||
| minimumLevel, | ||
| maximumLevel: this._maximumLevel, | ||
| minimumLevel: this._minimumLevel, | ||
| url: resource, | ||
| credit: credit, | ||
| }); | ||
|
|
@@ -93,6 +99,7 @@ function Azure2DImageryProvider(options) { | |
|
|
||
| // This will be defined for ion resources | ||
| this._tileCredits = resource.credits; | ||
| this._attributionsByLevel = undefined; | ||
| } | ||
|
|
||
| Object.defineProperties(Azure2DImageryProvider.prototype, { | ||
|
|
@@ -263,7 +270,18 @@ Object.defineProperties(Azure2DImageryProvider.prototype, { | |
| * @returns {Credit[]|undefined} The credits to be displayed when the tile is displayed. | ||
| */ | ||
| Azure2DImageryProvider.prototype.getTileCredits = function (x, y, level) { | ||
| return this._imageryProvider.getTileCredits(x, y, level); | ||
| const hasAttributions = defined(this._attributionsByLevel); | ||
|
|
||
| if (!hasAttributions || !defined(this._tileCredits)) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const innerCredits = this._attributionsByLevel.get(level); | ||
| if (!defined(this._tileCredits)) { | ||
| return innerCredits; | ||
| } | ||
|
|
||
| return this._tileCredits.concat(innerCredits); | ||
| }; | ||
|
|
||
| /** | ||
|
|
@@ -282,7 +300,21 @@ Azure2DImageryProvider.prototype.requestImage = function ( | |
| level, | ||
| request, | ||
| ) { | ||
| return this._imageryProvider.requestImage(x, y, level, request); | ||
| const promise = this._imageryProvider.requestImage(x, y, level, request); | ||
|
|
||
| // If the requestImage call returns undefined, it couldn't be scheduled this frame. Make sure to return undefined so this can be handled upstream. | ||
| if (!defined(promise)) { | ||
| return undefined; | ||
| } | ||
|
|
||
| // Asynchronously request and populate _attributionsByLevel if it hasn't been already. We do this here so that the promise can be properly awaited. | ||
| if (promise && !defined(this._attributionsByLevel)) { | ||
| return Promise.all([promise, this.getViewportCredits()]).then( | ||
| (results) => results[0], | ||
| ); | ||
| } | ||
|
|
||
| return promise; | ||
| }; | ||
|
|
||
| /** | ||
|
|
@@ -306,5 +338,57 @@ Azure2DImageryProvider.prototype.pickFeatures = function ( | |
| return undefined; | ||
| }; | ||
|
|
||
| /** | ||
| * Get attribution for imagery from Azure Maps to display in the credits | ||
| * @private | ||
| * @return {Promise<Map<Credit[]>>} The list of attribution sources to display in the credits. | ||
| */ | ||
| Azure2DImageryProvider.prototype.getViewportCredits = async function () { | ||
| const maximumLevel = this._maximumLevel; | ||
|
|
||
| const promises = []; | ||
| for (let level = 0; level < maximumLevel + 1; level++) { | ||
| promises.push( | ||
| fetchViewportAttribution( | ||
| this._resource, | ||
| this._viewportUrl, | ||
| this._subscriptionKey, | ||
| this._tilesetId, | ||
| level, | ||
| ), | ||
| ); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not strictly required to merge this PR, but I wonder if we can more lazily request tile credits as needed based on the current zoom level, and potentially extents, alongside the image requests in This would also potentially apply to |
||
| const results = await Promise.all(promises); | ||
|
|
||
| const attributionsByLevel = new Map(); | ||
| for (let level = 0; level < maximumLevel + 1; level++) { | ||
| const credits = []; | ||
| const attributions = results[level].join(","); | ||
| if (attributions) { | ||
| const levelCredits = new Credit(attributions); | ||
| credits.push(levelCredits); | ||
| } | ||
| attributionsByLevel.set(level, credits); | ||
| } | ||
|
|
||
| this._attributionsByLevel = attributionsByLevel; | ||
|
|
||
| return attributionsByLevel; | ||
| }; | ||
|
|
||
| async function fetchViewportAttribution(resource, url, key, tilesetId, level) { | ||
| const viewportResource = resource.getDerivedResource({ | ||
| url, | ||
| queryParameters: { | ||
| zoom: level, | ||
| bounds: "-180,-90,180,90", | ||
| }, | ||
| data: JSON.stringify(Frozen.EMPTY_OBJECT), | ||
| }); | ||
|
|
||
| const viewportJson = await viewportResource.fetchJson(); | ||
| return viewportJson.copyrights; | ||
| } | ||
|
|
||
| // Exposed for tests | ||
| export default Azure2DImageryProvider; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the motivation for changing this away from Bing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was missed in the last release for Google imagery. This sandcastle corresponds to and is linked from the imagery tutorial https://cesium.com/learn/cesiumjs-learn/cesiumjs-imagery/ We updated the tutorial and sample code to use Google but forgot to update the sandcastle.