Skip to content

Commit 3952050

Browse files
committed
mapbox: rm mapbox.createGeoJSONSource calls
- which were removed from the API on 0.22.0 - replace with map.addSource and map.getSource().setData()
1 parent 03289bc commit 3952050

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

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/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
};

0 commit comments

Comments
 (0)