-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
adding support for icon-rotate and icon-allow-overlap in mapbox #4575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e82c14c
3a12803
093f507
5285343
684df71
2242b28
6943d7a
f9eb48b
243680b
f725425
1e1458b
cd91905
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,6 +104,19 @@ module.exports = function convert(gd, calcTrace) { | |
'icon-size': trace.marker.size / 10 | ||
}); | ||
|
||
if('angle' in trace.marker) { | ||
Lib.extendFlat(symbol.layout, { | ||
// unfortunately cant use {angle} do to this issue: | ||
// https://github.com/mapbox/mapbox-gl-js/issues/873 | ||
'icon-rotate': { | ||
type: 'identity', property: 'angle' | ||
}, | ||
'icon-rotation-alignment': 'map' | ||
}); | ||
} | ||
|
||
symbol.layout['icon-allow-overlap'] = trace.marker.allowoverlap; | ||
|
||
Lib.extendFlat(symbol.paint, { | ||
'icon-opacity': trace.opacity * trace.marker.opacity, | ||
|
||
|
@@ -239,15 +252,21 @@ function makeSymbolGeoJSON(calcTrace, gd) { | |
|
||
var marker = trace.marker || {}; | ||
var symbol = marker.symbol; | ||
var angle = marker.angle; | ||
|
||
var fillSymbol = (symbol !== 'circle') ? | ||
getFillFunc(symbol) : | ||
blankFillFunc; | ||
|
||
var fillAngle = (angle) ? | ||
getFillFunc(angle, true) : | ||
blankFillFunc; | ||
|
||
var fillText = subTypes.hasText(trace) ? | ||
getFillFunc(trace.text) : | ||
blankFillFunc; | ||
|
||
|
||
var features = []; | ||
|
||
for(var i = 0; i < calcTrace.length; i++) { | ||
|
@@ -266,7 +285,7 @@ function makeSymbolGeoJSON(calcTrace, gd) { | |
var meta = trace._meta || {}; | ||
text = Lib.texttemplateString(tt, labels, fullLayout._d3locale, pointValues, calcPt, meta); | ||
} else { | ||
text = fillText(calcPt.tx); | ||
text = fillText(i); | ||
} | ||
|
||
if(text) { | ||
|
@@ -280,7 +299,8 @@ function makeSymbolGeoJSON(calcTrace, gd) { | |
coordinates: calcPt.lonlat | ||
}, | ||
properties: { | ||
symbol: fillSymbol(calcPt.mx), | ||
symbol: fillSymbol(i), | ||
angle: fillAngle(i), | ||
text: text | ||
} | ||
}); | ||
|
@@ -292,9 +312,12 @@ function makeSymbolGeoJSON(calcTrace, gd) { | |
}; | ||
} | ||
|
||
function getFillFunc(attr) { | ||
function getFillFunc(attr, numeric) { | ||
if(Lib.isArrayOrTypedArray(attr)) { | ||
return function(v) { return v; }; | ||
if(numeric) { | ||
return function(i) { return isNumeric(attr[i]) ? +attr[i] : 0; }; | ||
} | ||
return function(i) { return attr[i]; }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This actually seems just fine for symbol and text, since those are both strings / string arrays. But what happens for angles if the user provides an array of numbers-as-strings? A single number as a string will get converted to an actual number by It may be that this is just fine - assuming mapbox casts this angle to a number consistently, and treats non-numbers as 0. Can you confirm that this works? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok so I tested this, and yes basically coerce seems to turn a string into an actual number which means it gets interpreted as an acceptable angle, but if provided as an array, then string values get passed on to mapbox which treats non-numbers as 0. I'm not sure whether that's an acceptable behavior, and honestly I don't think I know enough about the code to figure out how to make it work the way it should without having to have a few back and forths and me diving deeper into other functions. So if you don't mind if this is not acceptable, it'd be great if you could suggest a fix. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think 1e1458b should do it 🙏 |
||
} else if(attr) { | ||
return function() { return attr; }; | ||
} else { | ||
|
Uh oh!
There was an error while loading. Please reload this page.