Skip to content

Commit adb1f8d

Browse files
committed
mapbox: use MultiPolygon for 'fill' trace with nulls
- as recommend in mapbox/mapbox-gl-js#3032
1 parent 0b38d85 commit adb1f8d

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

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

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)