Skip to content

Mapbox raster #3928

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

Closed
wants to merge 3 commits into from
Closed
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
20 changes: 16 additions & 4 deletions src/plots/mapbox/layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, this means both:

Plotly.newPlot('graph', [{type: 'scattermapbox'}], {
  mapbox: {
    layers: [{
      sourcetype: 'raster',
      source: 'mapbox://mapbox.satellite',
      type: 'raster'
    }]
  }
})

and

Plotly.newPlot('graph', [{type: 'scattermapbox'}], {
  mapbox: {
    layers: [{
      sourcetype: 'raster',
      source: [
        'https://a.tile.openstreetmap.org/{z}/{x}/{y}.png',
        'https://b.tile.openstreetmap.org/{z}/{x}/{y}.png'
      ],
      type: 'raster'
    }]
  }
})

will work

);
}

Expand Down Expand Up @@ -193,22 +193,34 @@ 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') {
field = 'data';
} else if(sourceType === 'vector') {
field = typeof source === 'string' ? 'url' : 'tiles';
} else if(sourceType === 'raster') {
field = 'tiles';
sourceOpts.tileSize = 256;
for(var index = 0; index < source.length; index++) {
var url = source[index];
source[index] = decodeURIComponent(url);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this necessary? I would expect the URLs in the mapbox.layers[i] setting to already be decoded.

}
}

sourceOpts[field] = source;

return sourceOpts;
}

Expand Down
4 changes: 2 additions & 2 deletions src/plots/mapbox/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ var attrs = module.exports = overrideAll({
},
sourcetype: {
valType: 'enumerated',
values: ['geojson', 'vector'],
values: ['geojson', 'vector', 'raster'],
Copy link
Contributor

@etpinard etpinard Jun 28, 2019

Choose a reason for hiding this comment

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

dflt: 'geojson',
role: 'info',
description: [
Expand Down Expand Up @@ -132,7 +132,7 @@ var attrs = module.exports = overrideAll({

type: {
valType: 'enumerated',
values: ['circle', 'line', 'fill', 'symbol'],
values: ['circle', 'line', 'fill', 'symbol', 'raster'],
Copy link
Contributor

@etpinard etpinard Jun 28, 2019

Choose a reason for hiding this comment

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

As type: 'raster' is the only value that "makes sense" for sourcetype: 'raster', we should probably override (wrong) user settings during the defaults step:

if(visible) {
var sourceType = coerce('sourcetype');
coerce('source');
if(sourceType === 'vector') coerce('sourcelayer');
// maybe add smart default based off GeoJSON geometry?
var type = coerce('type');
coerce('below');
coerce('color');
coerce('opacity');
coerce('minzoom');
coerce('maxzoom');
if(type === 'circle') {
coerce('circle.radius');
}
if(type === 'line') {
coerce('line.width');
coerce('line.dash');
}
if(type === 'fill') {
coerce('fill.outlinecolor');
}
if(type === 'symbol') {
coerce('symbol.icon');
coerce('symbol.iconsize');
coerce('symbol.text');
Lib.coerceFont(coerce, 'symbol.textfont');
coerce('symbol.textposition');
coerce('symbol.placement');
}
}

Down the road, it might be nice to expose some of mapbox-gl's raster style settings:

https://docs.mapbox.com/mapbox-gl-js/style-spec/#layers-raster

dflt: 'circle',
role: 'info',
description: [
Expand Down