Skip to content

Commit 6d7929c

Browse files
committed
Merge branch 'mapbox-v1' into choroplethmapbox-pr
2 parents ca48461 + f5bc2e4 commit 6d7929c

File tree

8 files changed

+78
-26
lines changed

8 files changed

+78
-26
lines changed

package-lock.json

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
},
5858
"dependencies": {
5959
"@plotly/d3-sankey": "0.7.2",
60+
"@plotly/d3-sankey-circular": "0.33.1",
6061
"@turf/area": "^6.0.1",
6162
"@turf/centroid": "^6.0.2",
6263
"alpha-shape": "^1.0.0",
@@ -68,7 +69,6 @@
6869
"d3-force": "^1.0.6",
6970
"d3-hierarchy": "^1.1.8",
7071
"d3-interpolate": "1",
71-
"@plotly/d3-sankey-circular": "0.33.1",
7272
"delaunay-triangulate": "^1.1.6",
7373
"es6-promise": "^3.0.2",
7474
"fast-isnumeric": "^1.1.3",
@@ -91,7 +91,7 @@
9191
"glslify": "^7.0.0",
9292
"has-hover": "^1.0.1",
9393
"has-passive-events": "^1.0.0",
94-
"mapbox-gl": "1.0.0",
94+
"mapbox-gl": "1.1.0",
9595
"matrix-camera-controller": "^2.1.3",
9696
"mouse-change": "^1.4.0",
9797
"mouse-event-offset": "^3.0.2",

src/plots/mapbox/constants.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,40 @@
88

99
'use strict';
1010

11-
var requiredVersion = '1.0.0';
11+
var requiredVersion = '1.1.0';
1212

1313
module.exports = {
1414
requiredVersion: requiredVersion,
1515

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: [

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 {

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

src/plots/mapbox/mapbox.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ var dragElement = require('../../components/dragelement');
2121
var prepSelect = require('../cartesian/select').prepSelect;
2222
var selectOnClick = require('../cartesian/select').selectOnClick;
2323
var constants = require('./constants');
24-
var layoutAttributes = require('./layout_attributes');
2524
var createMapboxLayer = require('./layers');
2625

2726
function Mapbox(gd, id) {
@@ -632,21 +631,24 @@ proto.getViewEdits = function(cont) {
632631
};
633632

634633
function getStyleObj(val) {
635-
var styleValues = layoutAttributes.style.values;
636-
var styleDflt = layoutAttributes.style.dflt;
637634
var styleObj = {};
638635

639636
if(Lib.isPlainObject(val)) {
640637
styleObj.id = val.id;
641638
styleObj.style = val;
642639
} else if(typeof val === 'string') {
643640
styleObj.id = val;
644-
styleObj.style = (styleValues.indexOf(val) !== -1) ?
645-
convertStyleVal(val) :
646-
val;
641+
642+
if(constants.styleValuesMapbox.indexOf(val) !== -1) {
643+
styleObj.style = convertStyleVal(val);
644+
} else if(val === constants.styleValueOSM) {
645+
styleObj.style = constants.styleOSM;
646+
} else {
647+
styleObj.style = val;
648+
}
647649
} else {
648-
styleObj.id = styleDflt;
649-
styleObj.style = convertStyleVal(styleDflt);
650+
styleObj.id = constants.styleValueDflt;
651+
styleObj.style = convertStyleVal(constants.styleValueDflt);
650652
}
651653

652654
styleObj.transition = {duration: 0, delay: 0};
22.1 KB
Loading

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)