Skip to content

Commit e82c14c

Browse files
committed
adding support for icon-rotate and icon-allow-overlap in mapbox
added to angles example
1 parent acc9c21 commit e82c14c

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

src/traces/scattermapbox/attributes.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,24 @@ module.exports = overrideAll({
8787
'are only available for *circle* symbols.'
8888
].join(' ')
8989
},
90+
angle: {
91+
valType: 'number',
92+
dflt: null,
93+
role: 'style',
94+
arrayOk: true,
95+
description: [
96+
'Sets the marker angle.'
97+
].join(' ')
98+
},
99+
allowoverlap: {
100+
valType: 'boolean',
101+
dflt: false,
102+
role: 'style',
103+
arrayOk: false,
104+
description: [
105+
'Flag to allow symbols to overlap'
106+
].join(' ')
107+
},
90108
opacity: markerAttrs.opacity,
91109
size: markerAttrs.size,
92110
sizeref: markerAttrs.sizeref,

src/traces/scattermapbox/convert.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,22 @@ module.exports = function convert(gd, calcTrace) {
104104
'icon-size': trace.marker.size / 10
105105
});
106106

107+
if('angle' in trace.marker) {
108+
Lib.extendFlat(symbol.layout,{
109+
'icon-rotation-alignment': 'map',
110+
'icon-rotate': {
111+
type: 'identity', property: 'angle'
112+
// unfortunately cant use {angle} do to this issue:
113+
// https://github.com/mapbox/mapbox-gl-js/issues/873
114+
}})
115+
}
116+
117+
if('allowoverlap' in trace.marker) {
118+
Lib.extendFlat(symbol.layout,
119+
{'icon-allow-overlap': trace.marker.allowoverlap})
120+
}
121+
122+
107123
Lib.extendFlat(symbol.paint, {
108124
'icon-opacity': trace.opacity * trace.marker.opacity,
109125

@@ -239,15 +255,21 @@ function makeSymbolGeoJSON(calcTrace, gd) {
239255

240256
var marker = trace.marker || {};
241257
var symbol = marker.symbol;
258+
var angle = marker.angle;
242259

243260
var fillSymbol = (symbol !== 'circle') ?
244261
getFillFunc(symbol) :
245262
blankFillFunc;
246263

264+
var fillAngle = (angle) ?
265+
getFillFunc(angle):
266+
blankFillFunc;
267+
247268
var fillText = subTypes.hasText(trace) ?
248269
getFillFunc(trace.text) :
249270
blankFillFunc;
250271

272+
251273
var features = [];
252274

253275
for(var i = 0; i < calcTrace.length; i++) {
@@ -266,7 +288,7 @@ function makeSymbolGeoJSON(calcTrace, gd) {
266288
var meta = trace._meta || {};
267289
text = Lib.texttemplateString(tt, labels, fullLayout._d3locale, pointValues, calcPt, meta);
268290
} else {
269-
text = fillText(calcPt.tx);
291+
text = fillText(i);
270292
}
271293

272294
if(text) {
@@ -280,7 +302,8 @@ function makeSymbolGeoJSON(calcTrace, gd) {
280302
coordinates: calcPt.lonlat
281303
},
282304
properties: {
283-
symbol: fillSymbol(calcPt.mx),
305+
symbol: fillSymbol(i),
306+
angle: fillAngle(i),
284307
text: text
285308
}
286309
});
@@ -294,9 +317,9 @@ function makeSymbolGeoJSON(calcTrace, gd) {
294317

295318
function getFillFunc(attr) {
296319
if(Lib.isArrayOrTypedArray(attr)) {
297-
return function(v) { return v; };
320+
return function(i) { return attr[i]; };
298321
} else if(attr) {
299-
return function() { return attr; };
322+
return function(i) { return attr; };
300323
} else {
301324
return blankFillFunc;
302325
}

src/traces/scattermapbox/defaults.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
4343
if(subTypes.hasMarkers(traceOut)) {
4444
handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce, {noLine: true});
4545

46+
coerce('marker.allowoverlap');
47+
coerce('marker.angle');
48+
4649
// array marker.size and marker.color are only supported with circles
4750
var marker = traceOut.marker;
4851
if(marker.symbol !== 'circle') {

test/image/mocks/mapbox_angles.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
"monument",
4242
"harbor",
4343
"music"
44-
]
44+
],
45+
"angle": [-45, 45, 0],
46+
"allowoverlap":true
4547
},
4648
"subplot": "mapbox2"
4749
}

0 commit comments

Comments
 (0)