Skip to content

Commit 05a3a54

Browse files
committedOct 19, 2016
Allow retina Mapbox imagery and other formats to be specified
This just allows `format` to be anything, rather than forcing it to start with a `.` which provides the flexibility for specifying `@2x.png`. Replaces #3899.
1 parent d02bdd2 commit 05a3a54

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed
 

‎CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Change Log
1414
* Fixed a bug with rotated, textured rectangles. [#4430](https://github.com/AnalyticalGraphicsInc/cesium/pull/4430)
1515
* Fixed a bug when morphing from 2D to 3D. [#4388](https://github.com/AnalyticalGraphicsInc/cesium/pull/4388)
1616
* Added `Rectangle.simpleIntersection`.
17+
* Added the ability to specify retina options, such as `@2x.png`, via the `MapboxImageryProvider` `format` option.
1718
* 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.
1819

1920
### 1.26 - 2016-10-03

‎Source/Scene/MapboxImageryProvider.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,16 @@ define([
6666
this._mapId = mapId;
6767
this._accessToken = MapboxApi.getAccessToken(options.accessToken);
6868
var format = defaultValue(options.format, 'png');
69-
this._format = format.replace('.', '');
69+
if (!/\./.test(format)) {
70+
format = '.' + format;
71+
}
72+
this._format = format;
7073

7174
var templateUrl = url;
7275
if (!trailingSlashRegex.test(url)) {
7376
templateUrl += '/';
7477
}
75-
templateUrl += mapId + '/{z}/{x}/{y}.' + this._format;
78+
templateUrl += mapId + '/{z}/{x}/{y}' + this._format;
7679
if (defined(this._accessToken)) {
7780
templateUrl += '?access_token=' + this._accessToken;
7881
}

‎Specs/Scene/MapboxImageryProviderSpec.js

+46
Original file line numberDiff line numberDiff line change
@@ -280,4 +280,50 @@ defineSuite([
280280
});
281281
});
282282
});
283+
284+
it('appends specified format', function() {
285+
var provider = new MapboxImageryProvider({
286+
url : 'made/up/mapbox/server/',
287+
mapId: 'test-id',
288+
format: '@2x.png'
289+
});
290+
291+
return pollToPromise(function() {
292+
return provider.ready;
293+
}).then(function() {
294+
spyOn(loadImage, 'createImage').and.callFake(function(url, crossOrigin, deferred) {
295+
expect(/made\/up\/mapbox\/server\/test-id\/0\/0\/0@2x\.png\?access_token=/.test(url)).toBe(true);
296+
297+
// Just return any old image.
298+
loadImage.defaultCreateImage('Data/Images/Red16x16.png', crossOrigin, deferred);
299+
});
300+
301+
return provider.requestImage(0, 0, 0).then(function(image) {
302+
expect(loadImage.createImage).toHaveBeenCalled();
303+
});
304+
});
305+
});
306+
307+
it('adds missing period for format', function() {
308+
var provider = new MapboxImageryProvider({
309+
url : 'made/up/mapbox/server/',
310+
mapId: 'test-id',
311+
format: 'png'
312+
});
313+
314+
return pollToPromise(function() {
315+
return provider.ready;
316+
}).then(function() {
317+
spyOn(loadImage, 'createImage').and.callFake(function(url, crossOrigin, deferred) {
318+
expect(/made\/up\/mapbox\/server\/test-id\/0\/0\/0\.png\?access_token=/.test(url)).toBe(true);
319+
320+
// Just return any old image.
321+
loadImage.defaultCreateImage('Data/Images/Red16x16.png', crossOrigin, deferred);
322+
});
323+
324+
return provider.requestImage(0, 0, 0).then(function(image) {
325+
expect(loadImage.createImage).toHaveBeenCalled();
326+
});
327+
});
328+
});
283329
});

0 commit comments

Comments
 (0)