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

Allow retina Mapbox imagery and other formats to be specified #4453

Merged
merged 1 commit into from
Oct 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Change Log
* Fixed a bug with rotated, textured rectangles. [#4430](https://github.com/AnalyticalGraphicsInc/cesium/pull/4430)
* Fixed a bug when morphing from 2D to 3D. [#4388](https://github.com/AnalyticalGraphicsInc/cesium/pull/4388)
* Added `Rectangle.simpleIntersection`.
* Added the ability to specify retina options, such as `@2x.png`, via the `MapboxImageryProvider` `format` option.
* Removed an unnecessary reprojection of Web Mercator imagery tiles to the Geographic projection on load. This should improve both visual quality and load performance slightly.

### 1.26 - 2016-10-03
Expand Down
7 changes: 5 additions & 2 deletions Source/Scene/MapboxImageryProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@ define([
this._mapId = mapId;
this._accessToken = MapboxApi.getAccessToken(options.accessToken);
var format = defaultValue(options.format, 'png');
this._format = format.replace('.', '');
if (!/\./.test(format)) {
format = '.' + format;
}
this._format = format;

var templateUrl = url;
if (!trailingSlashRegex.test(url)) {
templateUrl += '/';
}
templateUrl += mapId + '/{z}/{x}/{y}.' + this._format;
templateUrl += mapId + '/{z}/{x}/{y}' + this._format;
if (defined(this._accessToken)) {
templateUrl += '?access_token=' + this._accessToken;
}
Expand Down
46 changes: 46 additions & 0 deletions Specs/Scene/MapboxImageryProviderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,50 @@ defineSuite([
});
});
});

it('appends specified format', function() {
var provider = new MapboxImageryProvider({
url : 'made/up/mapbox/server/',
mapId: 'test-id',
format: '@2x.png'
});

return pollToPromise(function() {
return provider.ready;
}).then(function() {
spyOn(loadImage, 'createImage').and.callFake(function(url, crossOrigin, deferred) {
expect(/made\/up\/mapbox\/server\/test-id\/0\/0\/0@2x\.png\?access_token=/.test(url)).toBe(true);

// Just return any old image.
loadImage.defaultCreateImage('Data/Images/Red16x16.png', crossOrigin, deferred);
});

return provider.requestImage(0, 0, 0).then(function(image) {
expect(loadImage.createImage).toHaveBeenCalled();
});
});
});

it('adds missing period for format', function() {
var provider = new MapboxImageryProvider({
url : 'made/up/mapbox/server/',
mapId: 'test-id',
format: 'png'
});

return pollToPromise(function() {
return provider.ready;
}).then(function() {
spyOn(loadImage, 'createImage').and.callFake(function(url, crossOrigin, deferred) {
expect(/made\/up\/mapbox\/server\/test-id\/0\/0\/0\.png\?access_token=/.test(url)).toBe(true);

// Just return any old image.
loadImage.defaultCreateImage('Data/Images/Red16x16.png', crossOrigin, deferred);
});

return provider.requestImage(0, 0, 0).then(function(image) {
expect(loadImage.createImage).toHaveBeenCalled();
});
});
});
});