Skip to content

Commit 54efdad

Browse files
committed
add some layer sourcetype -> type logic
1 parent 153c6b4 commit 54efdad

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

src/plots/mapbox/layout_defaults.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
109
'use strict';
1110

1211
var Lib = require('../../lib');
@@ -52,6 +51,8 @@ function handleLayerDefaults(layerIn, layerOut) {
5251
var visible = coerce('visible');
5352
if(visible) {
5453
var sourceType = coerce('sourcetype');
54+
var mustBeRasterLayer = sourceType === 'raster' || sourceType === 'image';
55+
5556
coerce('source');
5657

5758
if(sourceType === 'vector') {
@@ -62,8 +63,15 @@ function handleLayerDefaults(layerIn, layerOut) {
6263
coerce('coordinates');
6364
}
6465

65-
// maybe add smart default based off GeoJSON geometry?
66-
var type = coerce('type');
66+
var typeDflt;
67+
if(mustBeRasterLayer) typeDflt = 'raster';
68+
69+
var type = coerce('type', typeDflt);
70+
71+
if(mustBeRasterLayer && type !== 'raster') {
72+
type = layerOut.type = 'raster';
73+
Lib.log('Source types *raster* and *image* must drawn *raster* layer type.');
74+
}
6775

6876
coerce('below');
6977
coerce('color');

test/jasmine/tests/mapbox_test.js

+46
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,52 @@ describe('mapbox defaults', function() {
184184
expect(layoutOut.mapbox.layers[3].circle).toBeUndefined();
185185
});
186186

187+
it('should not allow to set layer type other than *raster* for sourcetype value *raster* and *image*', function() {
188+
spyOn(Lib, 'log');
189+
190+
layoutIn = {
191+
mapbox: {
192+
layers: [{
193+
sourcetype: 'raster',
194+
source: 'url',
195+
type: 'circle'
196+
}, {
197+
sourcetype: 'image',
198+
source: 'url',
199+
type: 'fill'
200+
}]
201+
}
202+
};
203+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
204+
205+
expect(Lib.log).toHaveBeenCalledTimes(2);
206+
expect(Lib.log).toHaveBeenCalledWith('Source types *raster* and *image* must drawn *raster* layer type.');
207+
208+
expect(layoutOut.mapbox.layers[0].type).toBe('raster');
209+
expect(layoutOut.mapbox.layers[1].type).toBe('raster');
210+
});
211+
212+
it('should default layer with sourcetype *raster* and *image* to type *raster', function() {
213+
spyOn(Lib, 'log');
214+
215+
layoutIn = {
216+
mapbox: {
217+
layers: [{
218+
sourcetype: 'raster',
219+
source: 'url'
220+
}, {
221+
sourcetype: 'image',
222+
source: 'url'
223+
}]
224+
}
225+
};
226+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
227+
228+
expect(Lib.log).toHaveBeenCalledTimes(0);
229+
expect(layoutOut.mapbox.layers[0].type).toBe('raster');
230+
expect(layoutOut.mapbox.layers[1].type).toBe('raster');
231+
});
232+
187233
it('should set *layout.dragmode* to pan while zoom is not available', function() {
188234
var gd = {
189235
data: fullData,

0 commit comments

Comments
 (0)