Skip to content

Commit 94107bc

Browse files
authored
Merge pull request #867 from plotly/bump-mapbox
Bump mapbox-gl to v0.22.0
2 parents ee2a7d5 + adb1f8d commit 94107bc

File tree

8 files changed

+43
-31
lines changed

8 files changed

+43
-31
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"gl-select-box": "^1.0.1",
7373
"gl-spikes2d": "^1.0.1",
7474
"gl-surface3d": "^1.2.3",
75-
"mapbox-gl": "^0.18.0",
75+
"mapbox-gl": "^0.22.0",
7676
"mouse-change": "^1.1.1",
7777
"mouse-wheel": "^1.0.2",
7878
"ndarray": "^1.0.16",

src/plots/mapbox/mapbox.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -358,16 +358,24 @@ proto.toImage = function() {
358358

359359
// convenience wrapper to create blank GeoJSON sources
360360
// and avoid 'invalid GeoJSON' errors
361-
proto.createGeoJSONSource = function() {
361+
proto.initSource = function(idSource) {
362362
var blank = {
363-
type: 'Feature',
364-
geometry: {
365-
type: 'Point',
366-
coordinates: []
363+
type: 'geojson',
364+
data: {
365+
type: 'Feature',
366+
geometry: {
367+
type: 'Point',
368+
coordinates: []
369+
}
367370
}
368371
};
369372

370-
return new mapboxgl.GeoJSONSource({data: blank});
373+
return this.map.addSource(idSource, blank);
374+
};
375+
376+
// convenience wrapper to set data of GeoJSON sources
377+
proto.setSourceData = function(idSource, data) {
378+
this.map.getSource(idSource).setData(data);
371379
};
372380

373381
// convenience wrapper to create set multiple layer

src/traces/scattermapbox/convert.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,21 @@ function makeBlankGeoJSON() {
147147
}
148148

149149
function makeFillGeoJSON(_, coords) {
150+
if(coords.length === 1) {
151+
return {
152+
type: 'Polygon',
153+
coordinates: coords
154+
};
155+
}
156+
157+
var _coords = new Array(coords.length);
158+
for(var i = 0; i < coords.length; i++) {
159+
_coords[i] = [coords[i]];
160+
}
161+
150162
return {
151-
type: 'Polygon',
152-
coordinates: coords
163+
type: 'MultiPolygon',
164+
coordinates: _coords
153165
};
154166
}
155167

src/traces/scattermapbox/plot.js

+8-16
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,10 @@ function ScatterMapbox(mapbox, uid) {
2828
this.idLayerCircle = uid + '-layer-circle';
2929
this.idLayerSymbol = uid + '-layer-symbol';
3030

31-
this.sourceFill = mapbox.createGeoJSONSource();
32-
this.map.addSource(this.idSourceFill, this.sourceFill);
33-
34-
this.sourceLine = mapbox.createGeoJSONSource();
35-
this.map.addSource(this.idSourceLine, this.sourceLine);
36-
37-
this.sourceCircle = mapbox.createGeoJSONSource();
38-
this.map.addSource(this.idSourceCircle, this.sourceCircle);
39-
40-
this.sourceSymbol = mapbox.createGeoJSONSource();
41-
this.map.addSource(this.idSourceSymbol, this.sourceSymbol);
31+
this.mapbox.initSource(this.idSourceFill);
32+
this.mapbox.initSource(this.idSourceLine);
33+
this.mapbox.initSource(this.idSourceCircle);
34+
this.mapbox.initSource(this.idSourceSymbol);
4235

4336
this.map.addLayer({
4437
id: this.idLayerFill,
@@ -73,7 +66,6 @@ var proto = ScatterMapbox.prototype;
7366

7467
proto.update = function update(calcTrace) {
7568
var mapbox = this.mapbox;
76-
7769
var opts = convert(calcTrace);
7870

7971
mapbox.setOptions(this.idLayerFill, 'setLayoutProperty', opts.fill.layout);
@@ -82,22 +74,22 @@ proto.update = function update(calcTrace) {
8274
mapbox.setOptions(this.idLayerSymbol, 'setLayoutProperty', opts.symbol.layout);
8375

8476
if(isVisible(opts.fill)) {
85-
this.sourceFill.setData(opts.fill.geojson);
77+
mapbox.setSourceData(this.idSourceFill, opts.fill.geojson);
8678
mapbox.setOptions(this.idLayerFill, 'setPaintProperty', opts.fill.paint);
8779
}
8880

8981
if(isVisible(opts.line)) {
90-
this.sourceLine.setData(opts.line.geojson);
82+
mapbox.setSourceData(this.idSourceLine, opts.line.geojson);
9183
mapbox.setOptions(this.idLayerLine, 'setPaintProperty', opts.line.paint);
9284
}
9385

9486
if(isVisible(opts.circle)) {
95-
this.sourceCircle.setData(opts.circle.geojson);
87+
mapbox.setSourceData(this.idSourceCircle, opts.circle.geojson);
9688
mapbox.setOptions(this.idLayerCircle, 'setPaintProperty', opts.circle.paint);
9789
}
9890

9991
if(isVisible(opts.symbol)) {
100-
this.sourceSymbol.setData(opts.symbol.geojson);
92+
mapbox.setSourceData(this.idSourceSymbol, opts.symbol.geojson);
10193
mapbox.setOptions(this.idLayerSymbol, 'setPaintProperty', opts.symbol.paint);
10294
}
10395
};
-1.06 KB
Loading
6.88 KB
Loading
700 Bytes
Loading

test/jasmine/tests/scattermapbox_test.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -307,14 +307,14 @@ describe('scattermapbox convert', function() {
307307

308308
assertVisibility(opts, ['visible', 'visible', 'visible', 'none']);
309309

310-
var lineCoords = [[
311-
[10, 20], [20, 20], [30, 10]
312-
], [
313-
[20, 10], [10, 20]
314-
]];
310+
var segment1 = [[10, 20], [20, 20], [30, 10]],
311+
segment2 = [[20, 10], [10, 20]];
312+
313+
var lineCoords = [segment1, segment2],
314+
fillCoords = [[segment1], [segment2]];
315315

316-
expect(opts.fill.geojson.coordinates).toEqual(lineCoords, 'have correct fill coords');
317316
expect(opts.line.geojson.coordinates).toEqual(lineCoords, 'have correct line coords');
317+
expect(opts.fill.geojson.coordinates).toEqual(fillCoords, 'have correct fill coords');
318318

319319
var circleCoords = opts.circle.geojson.features.map(function(f) {
320320
return f.geometry.coordinates;

0 commit comments

Comments
 (0)