Skip to content

Commit

Permalink
Merge branch 'mapbox-v1' into choroplethmapbox-pr
Browse files Browse the repository at this point in the history
  • Loading branch information
etpinard committed Jul 3, 2019
2 parents ca48461 + f5bc2e4 commit 6d7929c
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 26 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
},
"dependencies": {
"@plotly/d3-sankey": "0.7.2",
"@plotly/d3-sankey-circular": "0.33.1",
"@turf/area": "^6.0.1",
"@turf/centroid": "^6.0.2",
"alpha-shape": "^1.0.0",
Expand All @@ -68,7 +69,6 @@
"d3-force": "^1.0.6",
"d3-hierarchy": "^1.1.8",
"d3-interpolate": "1",
"@plotly/d3-sankey-circular": "0.33.1",
"delaunay-triangulate": "^1.1.6",
"es6-promise": "^3.0.2",
"fast-isnumeric": "^1.1.3",
Expand All @@ -91,7 +91,7 @@
"glslify": "^7.0.0",
"has-hover": "^1.0.1",
"has-passive-events": "^1.0.0",
"mapbox-gl": "1.0.0",
"mapbox-gl": "1.1.0",
"matrix-camera-controller": "^2.1.3",
"mouse-change": "^1.4.0",
"mouse-event-offset": "^3.0.2",
Expand Down
28 changes: 27 additions & 1 deletion src/plots/mapbox/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,40 @@

'use strict';

var requiredVersion = '1.0.0';
var requiredVersion = '1.1.0';

module.exports = {
requiredVersion: requiredVersion,

styleUrlPrefix: 'mapbox://styles/mapbox/',
styleUrlSuffix: 'v9',

styleValuesMapbox: ['basic', 'streets', 'outdoors', 'light', 'dark', 'satellite', 'satellite-streets'],
styleValueOSM: 'open-street-map',
styleValueDflt: 'basic',

styleOSM: {
id: 'osm',
version: 8,
sources: {
'plotly-osm-tiles': {
type: 'raster',
tiles: [
'https://a.tile.openstreetmap.org/{z}/{x}/{y}.png',
'https://b.tile.openstreetmap.org/{z}/{x}/{y}.png'
],
tileSize: 256
}
},
layers: [{
id: 'plotly-osm-tiles',
type: 'raster',
source: 'plotly-osm-tiles',
minzoom: 0,
maxzoom: 22
}]
},

controlContainerClassName: 'mapboxgl-control-container',

wrongVersionErrorMsg: [
Expand Down
4 changes: 2 additions & 2 deletions src/plots/mapbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ exports.attributes = {
}
};

var layoutAttrs = exports.layoutAttributes = require('./layout_attributes');
exports.layoutAttributes = require('./layout_attributes');

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

Expand Down Expand Up @@ -142,7 +142,7 @@ function findAccessToken(gd, mapboxIds) {
var style = opts.style;
var token = opts.accesstoken;

if(typeof style === 'string' && layoutAttrs.style.values.indexOf(style) !== -1) {
if(typeof style === 'string' && constants.styleValuesMapbox.indexOf(style) !== -1) {
if(token) {
Lib.pushUnique(tokensUseful, token);
} else {
Expand Down
10 changes: 6 additions & 4 deletions src/plots/mapbox/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* LICENSE file in the root directory of this source tree.
*/


'use strict';

var Lib = require('../../lib');
Expand All @@ -17,6 +16,8 @@ var textposition = require('../../traces/scatter/attributes').textposition;
var overrideAll = require('../../plot_api/edit_types').overrideAll;
var templatedArray = require('../../plot_api/plot_template').templatedArray;

var constants = require('./constants');

var fontAttr = fontAttrs({
description: [
'Sets the icon text font (color=mapbox.layer.paint.text-color, size=mapbox.layer.layout.text-size).',
Expand All @@ -43,13 +44,14 @@ var attrs = module.exports = overrideAll({
},
style: {
valType: 'any',
values: ['basic', 'streets', 'outdoors', 'light', 'dark', 'satellite', 'satellite-streets'],
dflt: 'basic',
values: constants.styleValuesMapbox.concat(constants.styleValueOSM),
dflt: constants.styleValueDflt,
role: 'style',
description: [
'Sets the Mapbox map style.',
'Either input one of the default Mapbox style names or the URL to a custom style',
'or a valid Mapbox style JSON.'
'or a valid Mapbox style JSON.',
'From OpenStreetMap raster tiles, use *open-street-map*.'
].join(' ')
},

Expand Down
18 changes: 10 additions & 8 deletions src/plots/mapbox/mapbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ var dragElement = require('../../components/dragelement');
var prepSelect = require('../cartesian/select').prepSelect;
var selectOnClick = require('../cartesian/select').selectOnClick;
var constants = require('./constants');
var layoutAttributes = require('./layout_attributes');
var createMapboxLayer = require('./layers');

function Mapbox(gd, id) {
Expand Down Expand Up @@ -632,21 +631,24 @@ proto.getViewEdits = function(cont) {
};

function getStyleObj(val) {
var styleValues = layoutAttributes.style.values;
var styleDflt = layoutAttributes.style.dflt;
var styleObj = {};

if(Lib.isPlainObject(val)) {
styleObj.id = val.id;
styleObj.style = val;
} else if(typeof val === 'string') {
styleObj.id = val;
styleObj.style = (styleValues.indexOf(val) !== -1) ?
convertStyleVal(val) :
val;

if(constants.styleValuesMapbox.indexOf(val) !== -1) {
styleObj.style = convertStyleVal(val);
} else if(val === constants.styleValueOSM) {
styleObj.style = constants.styleOSM;
} else {
styleObj.style = val;
}
} else {
styleObj.id = styleDflt;
styleObj.style = convertStyleVal(styleDflt);
styleObj.id = constants.styleValueDflt;
styleObj.style = convertStyleVal(constants.styleValueDflt);
}

styleObj.transition = {duration: 0, delay: 0};
Expand Down
Binary file modified test/image/baselines/mapbox_osm-style.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions test/image/mocks/mapbox_osm-style.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,29 @@
"data": [
{
"type": "scattermapbox",
"name": "on custom style pointing to OSM",
"lon": [ 10, 20 ],
"lat": [ 20, 10 ]
},
{
"type": "scattermapbox",
"name": "using style:open-street-map",
"lon": [ 10, 20 ],
"lat": [ 20, 10 ],
"subplot": "mapbox2"
}
],
"layout": {
"grid": {"rows": 2, "columns": 1},

"legend": {
"x": 0,
"y": 1, "yanchor": "bottom"
},

"mapbox": {
"domain": {"row": 0, "column": 0},

"style": {
"id": "osm",
"version": 8,
Expand All @@ -31,6 +48,11 @@
}
]
}
},
"mapbox2": {
"domain": {"row": 1, "column": 0},

"style": "open-street-map"
}
}
}

0 comments on commit 6d7929c

Please sign in to comment.