Skip to content

Commit 36e3f06

Browse files
committed
add *open-street-map* mapbox.style value
... which is an alias to a mapbox style object pointing to the OpenStreetMap raster tiles
1 parent 23ffe4f commit 36e3f06

File tree

6 files changed

+66
-14
lines changed

6 files changed

+66
-14
lines changed

Diff for: src/plots/mapbox/constants.js

+26
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,32 @@ module.exports = {
1616
styleUrlPrefix: 'mapbox://styles/mapbox/',
1717
styleUrlSuffix: 'v9',
1818

19+
styleValuesMapbox: ['basic', 'streets', 'outdoors', 'light', 'dark', 'satellite', 'satellite-streets'],
20+
styleValueOSM: 'open-street-map',
21+
styleValueDflt: 'basic',
22+
23+
styleOSM: {
24+
id: 'osm',
25+
version: 8,
26+
sources: {
27+
'plotly-osm-tiles': {
28+
type: 'raster',
29+
tiles: [
30+
'https://a.tile.openstreetmap.org/{z}/{x}/{y}.png',
31+
'https://b.tile.openstreetmap.org/{z}/{x}/{y}.png'
32+
],
33+
tileSize: 256
34+
}
35+
},
36+
layers: [{
37+
id: 'plotly-osm-tiles',
38+
type: 'raster',
39+
source: 'plotly-osm-tiles',
40+
minzoom: 0,
41+
maxzoom: 22
42+
}]
43+
},
44+
1945
controlContainerClassName: 'mapboxgl-control-container',
2046

2147
wrongVersionErrorMsg: [

Diff for: src/plots/mapbox/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ exports.attributes = {
4343
}
4444
};
4545

46-
var layoutAttrs = exports.layoutAttributes = require('./layout_attributes');
46+
exports.layoutAttributes = require('./layout_attributes');
4747

4848
exports.supplyLayoutDefaults = require('./layout_defaults');
4949

@@ -142,7 +142,7 @@ function findAccessToken(gd, mapboxIds) {
142142
var style = opts.style;
143143
var token = opts.accesstoken;
144144

145-
if(typeof style === 'string' && layoutAttrs.style.values.indexOf(style) !== -1) {
145+
if(typeof style === 'string' && constants.styleValuesMapbox.indexOf(style) !== -1) {
146146
if(token) {
147147
Lib.pushUnique(tokensUseful, token);
148148
} else {

Diff for: src/plots/mapbox/layout_attributes.js

+6-4
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');
@@ -17,6 +16,8 @@ var textposition = require('../../traces/scatter/attributes').textposition;
1716
var overrideAll = require('../../plot_api/edit_types').overrideAll;
1817
var templatedArray = require('../../plot_api/plot_template').templatedArray;
1918

19+
var constants = require('./constants');
20+
2021
var fontAttr = fontAttrs({
2122
description: [
2223
'Sets the icon text font (color=mapbox.layer.paint.text-color, size=mapbox.layer.layout.text-size).',
@@ -43,13 +44,14 @@ var attrs = module.exports = overrideAll({
4344
},
4445
style: {
4546
valType: 'any',
46-
values: ['basic', 'streets', 'outdoors', 'light', 'dark', 'satellite', 'satellite-streets'],
47-
dflt: 'basic',
47+
values: constants.styleValuesMapbox.concat(constants.styleValueOSM),
48+
dflt: constants.styleValueDflt,
4849
role: 'style',
4950
description: [
5051
'Sets the Mapbox map style.',
5152
'Either input one of the default Mapbox style names or the URL to a custom style',
52-
'or a valid Mapbox style JSON.'
53+
'or a valid Mapbox style JSON.',
54+
'From OpenStreetMap raster tiles, use *open-street-map*.'
5355
].join(' ')
5456
},
5557

Diff for: src/plots/mapbox/mapbox.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ var dragElement = require('../../components/dragelement');
1717
var prepSelect = require('../cartesian/select').prepSelect;
1818
var selectOnClick = require('../cartesian/select').selectOnClick;
1919
var constants = require('./constants');
20-
var layoutAttributes = require('./layout_attributes');
2120
var createMapboxLayer = require('./layers');
2221

2322
function Mapbox(gd, id) {
@@ -538,21 +537,24 @@ proto.getViewEdits = function(cont) {
538537
};
539538

540539
function getStyleObj(val) {
541-
var styleValues = layoutAttributes.style.values;
542-
var styleDflt = layoutAttributes.style.dflt;
543540
var styleObj = {};
544541

545542
if(Lib.isPlainObject(val)) {
546543
styleObj.id = val.id;
547544
styleObj.style = val;
548545
} else if(typeof val === 'string') {
549546
styleObj.id = val;
550-
styleObj.style = (styleValues.indexOf(val) !== -1) ?
551-
convertStyleVal(val) :
552-
val;
547+
548+
if(constants.styleValuesMapbox.indexOf(val) !== -1) {
549+
styleObj.style = convertStyleVal(val);
550+
} else if(val === constants.styleValueOSM) {
551+
styleObj.style = constants.styleOSM;
552+
} else {
553+
styleObj.style = val;
554+
}
553555
} else {
554-
styleObj.id = styleDflt;
555-
styleObj.style = convertStyleVal(styleDflt);
556+
styleObj.id = constants.styleValueDflt;
557+
styleObj.style = convertStyleVal(constants.styleValueDflt);
556558
}
557559

558560
styleObj.transition = {duration: 0, delay: 0};

Diff for: test/image/baselines/mapbox_osm-style.png

22.1 KB
Loading

Diff for: test/image/mocks/mapbox_osm-style.json

+22
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,29 @@
22
"data": [
33
{
44
"type": "scattermapbox",
5+
"name": "on custom style pointing to OSM",
56
"lon": [ 10, 20 ],
67
"lat": [ 20, 10 ]
8+
},
9+
{
10+
"type": "scattermapbox",
11+
"name": "using style:open-street-map",
12+
"lon": [ 10, 20 ],
13+
"lat": [ 20, 10 ],
14+
"subplot": "mapbox2"
715
}
816
],
917
"layout": {
18+
"grid": {"rows": 2, "columns": 1},
19+
20+
"legend": {
21+
"x": 0,
22+
"y": 1, "yanchor": "bottom"
23+
},
24+
1025
"mapbox": {
26+
"domain": {"row": 0, "column": 0},
27+
1128
"style": {
1229
"id": "osm",
1330
"version": 8,
@@ -31,6 +48,11 @@
3148
}
3249
]
3350
}
51+
},
52+
"mapbox2": {
53+
"domain": {"row": 1, "column": 0},
54+
55+
"style": "open-street-map"
3456
}
3557
}
3658
}

0 commit comments

Comments
 (0)