From f419fabf65787ba3d60e2b49dba9400c4cb1a2d9 Mon Sep 17 00:00:00 2001 From: hisham waleed karam Date: Sun, 2 Jun 2019 12:29:29 +0200 Subject: [PATCH 1/2] raster support --- src/plots/mapbox/layers.js | 27 ++++++++++++++++++++------- src/plots/mapbox/layout_attributes.js | 4 ++-- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/plots/mapbox/layers.js b/src/plots/mapbox/layers.js index 914b30ea3a6..51ad5335860 100644 --- a/src/plots/mapbox/layers.js +++ b/src/plots/mapbox/layers.js @@ -131,7 +131,7 @@ function isVisible(opts) { return opts.visible && ( Lib.isPlainObject(source) || - (typeof source === 'string' && source.length > 0) + ((typeof source === 'string' || Array.isArray(source)) && source.length > 0) ); } @@ -193,22 +193,35 @@ function convertOpts(opts) { break; } - return { layout: layout, paint: paint }; + return { + layout: layout, + paint: paint + }; } function convertSourceOpts(opts) { var sourceType = opts.sourcetype; var source = opts.source; - var sourceOpts = {type: sourceType}; + var sourceOpts = { + type: sourceType + }; var field; - - if(sourceType === 'geojson') { + if (sourceType === 'geojson') { field = 'data'; - } else if(sourceType === 'vector') { + } else if (sourceType === 'vector') { field = typeof source === 'string' ? 'url' : 'tiles'; + } else if (sourceType === 'raster') { + field = 'tiles'; + sourceOpts['tileSize'] = 256; + for (let index = 0; index < source.length; index++) { + const url = source[index]; + source[index] = decodeURIComponent(url); + + } } sourceOpts[field] = source; + return sourceOpts; } @@ -216,6 +229,6 @@ module.exports = function createMapboxLayer(mapbox, index, opts) { var mapboxLayer = new MapboxLayer(mapbox, index); mapboxLayer.update(opts); - + return mapboxLayer; }; diff --git a/src/plots/mapbox/layout_attributes.js b/src/plots/mapbox/layout_attributes.js index 259d3d3cd33..33fc73e5ce7 100644 --- a/src/plots/mapbox/layout_attributes.js +++ b/src/plots/mapbox/layout_attributes.js @@ -100,7 +100,7 @@ var attrs = module.exports = overrideAll({ }, sourcetype: { valType: 'enumerated', - values: ['geojson', 'vector'], + values: ['geojson', 'vector', 'raster'], dflt: 'geojson', role: 'info', description: [ @@ -132,7 +132,7 @@ var attrs = module.exports = overrideAll({ type: { valType: 'enumerated', - values: ['circle', 'line', 'fill', 'symbol'], + values: ['circle', 'line', 'fill', 'symbol', 'raster'], dflt: 'circle', role: 'info', description: [ From d57e8a3ee19ec0e5da6fcc28780ed85f726bdb4e Mon Sep 17 00:00:00 2001 From: hisham waleed karam Date: Sun, 2 Jun 2019 12:56:44 +0200 Subject: [PATCH 2/2] fix syntax test --- src/plots/mapbox/layers.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/plots/mapbox/layers.js b/src/plots/mapbox/layers.js index 51ad5335860..c8f3816b386 100644 --- a/src/plots/mapbox/layers.js +++ b/src/plots/mapbox/layers.js @@ -206,17 +206,16 @@ function convertSourceOpts(opts) { type: sourceType }; var field; - if (sourceType === 'geojson') { + if(sourceType === 'geojson') { field = 'data'; - } else if (sourceType === 'vector') { + } else if(sourceType === 'vector') { field = typeof source === 'string' ? 'url' : 'tiles'; - } else if (sourceType === 'raster') { + } else if(sourceType === 'raster') { field = 'tiles'; - sourceOpts['tileSize'] = 256; - for (let index = 0; index < source.length; index++) { - const url = source[index]; + sourceOpts.tileSize = 256; + for(var index = 0; index < source.length; index++) { + var url = source[index]; source[index] = decodeURIComponent(url); - } } @@ -229,6 +228,6 @@ module.exports = function createMapboxLayer(mapbox, index, opts) { var mapboxLayer = new MapboxLayer(mapbox, index); mapboxLayer.update(opts); - + return mapboxLayer; };