Skip to content
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

added support for Bing Maps' AerialWithLabelsOnDemand imagery set, as… #41

Merged
merged 5 commits into from
May 2, 2019

Conversation

KeyboardSounds
Copy link

@KeyboardSounds KeyboardSounds commented Apr 28, 2019

… requested in TerriaJS/terriajs#3113

@KeyboardSounds KeyboardSounds requested a review from kring April 28, 2019 22:26
// The version of the Bing maps API that we hit if we're using `BingMapsStyle.AERIAL_WITH_LABELS_ON_DEMAND` does this
// instead of returning a "This image is missing" image.
// Since this isn't really an error, we want to supress the one that just got thrown.
if (error.name === 'InvalidStateError' && error.message === 'The source image could not be decoded.') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test isn't great, because there are other reasons that image decoding could fail. I think the best solution is to change Resource.prototype.fetchImage to attach the generatedBlob to the error object in the otherwise block. Then you can check for it on the error and check if its size is zero.

var promise = ImageryProvider.loadImage(this, buildImageResource(this, x, y, level, request));

if(defined(promise)) {
return promise.then(() => promise, (error) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use promise.otherwise instead of two-parameter then.

// Since this isn't really an error, we want to supress the one that just got thrown.
if (error.name === 'InvalidStateError' && error.message === 'The source image could not be decoded.') {
return {};
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're not handling the error, you need to re-throw it. Otherwise it acts like a successful result yielding undefined.

// instead of returning a "This image is missing" image.
// Since this isn't really an error, we want to supress the one that just got thrown.
if (error.name === 'InvalidStateError' && error.message === 'The source image could not be decoded.') {
return {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declare a module-scope missingImage field, intiailized to {}, and return that here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better yet, declare the field on DiscardEmptyTileImagePolicy. Then in the discard policy you can just check for a missingImage rather than looking at the blob at all.

* @type {String}
* @constant
*/
AERIAL_WITH_LABELS_ON_DEMAND : 'AerialWithLabelsOnDemand',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add the other new styles, too: https://docs.microsoft.com/en-us/bingmaps/rest-services/imagery/get-imagery-metadata
It doesn't make sense to add the BirdsEye or Streetside ones, but the others should be added.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a couple still missing (unless there's some reason I'm not aware of that they can't be used):
CanvasDark, CanvasLight, CanvasGray, and OrdnanceSurvey

Incorporates PR suggestions from #41
if (defined(error.blob) && error.blob.size === 0) {

// If our tile discard policy tells us how to represent an empty image, we return that.
if (defined(this._tileDiscardPolicy.emptyImage)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool but probably unnecessary complexity. Just returning DiscardEmptyTilePolicy.DEFAULT_EMPTY_IMAGE is fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And at that point just rename it to DiscardEmptyTilePolicy.EMPTY_IMAGE.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if someone wanted to reuse the DiscardEmptyTilePolicy for another imagery provider though, where the behaviour for an empty tile was different? It seems silly to make them either implement a brand new discard policy or update the code for the existing one, and then you'd have to update this existing code to respect the setting.

@kring
Copy link
Member

kring commented May 2, 2019

Thanks @KeyboardSounds! I made one small tweak to swap a regular function for an arrow function, because Cesium sadly still targets ES5. Doesn't matter for TerriaJS, but it will make it easier to merge upstream.

@kring kring merged commit 9672f40 into terriajs May 2, 2019
@kring kring deleted the bing-aerial-with-labels-on-demand branch May 2, 2019 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants