Skip to content

Commit 030e176

Browse files
committed
[Maps] do not show border color for icon in legend when border width is zero
1 parent 3da8a76 commit 030e176

File tree

6 files changed

+36
-68
lines changed

6 files changed

+36
-68
lines changed

x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/symbol_icon.js

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,62 +12,30 @@ import { getMakiSymbolSvg, styleSvg, buildSrcUrl } from '../../symbol_utils';
1212
export class SymbolIcon extends Component {
1313
state = {
1414
imgDataUrl: undefined,
15-
prevSymbolId: undefined,
16-
prevFill: undefined,
17-
prevStroke: undefined,
18-
prevStrokeWidth: undefined,
1915
};
2016

2117
componentDidMount() {
2218
this._isMounted = true;
23-
this._loadSymbol(
24-
this.props.symbolId,
25-
this.props.fill,
26-
this.props.stroke,
27-
this.props.strokeWidth
28-
);
29-
}
30-
31-
componentDidUpdate() {
32-
this._loadSymbol(
33-
this.props.symbolId,
34-
this.props.fill,
35-
this.props.stroke,
36-
this.props.strokeWidth
37-
);
19+
this._loadSymbol();
3820
}
3921

4022
componentWillUnmount() {
4123
this._isMounted = false;
4224
}
4325

44-
async _loadSymbol(nextSymbolId, nextFill, nextStroke, nextStrokeWidth) {
45-
if (
46-
nextSymbolId === this.state.prevSymbolId &&
47-
nextFill === this.state.prevFill &&
48-
nextStroke === this.state.prevStroke &&
49-
nextStrokeWidth === this.state.prevStrokeWidth
50-
) {
51-
return;
52-
}
53-
26+
async _loadSymbol() {
5427
let imgDataUrl;
5528
try {
56-
const svg = getMakiSymbolSvg(nextSymbolId);
57-
const styledSvg = await styleSvg(svg, nextFill, nextStroke, nextStrokeWidth);
29+
const svg = getMakiSymbolSvg(this.props.symbolId);
30+
const styledSvg = await styleSvg(svg, this.props.fill, this.props.stroke);
5831
imgDataUrl = buildSrcUrl(styledSvg);
5932
} catch (error) {
6033
// ignore failures - component will just not display an icon
34+
return;
6135
}
6236

6337
if (this._isMounted) {
64-
this.setState({
65-
imgDataUrl,
66-
prevSymbolId: nextSymbolId,
67-
prevFill: nextFill,
68-
prevStroke: nextStroke,
69-
prevStrokeWidth: nextStrokeWidth,
70-
});
38+
this.setState({ imgDataUrl });
7139
}
7240
}
7341

@@ -80,7 +48,6 @@ export class SymbolIcon extends Component {
8048
symbolId, // eslint-disable-line no-unused-vars
8149
fill, // eslint-disable-line no-unused-vars
8250
stroke, // eslint-disable-line no-unused-vars
83-
strokeWidth, // eslint-disable-line no-unused-vars
8451
...rest
8552
} = this.props;
8653

@@ -98,7 +65,6 @@ export class SymbolIcon extends Component {
9865

9966
SymbolIcon.propTypes = {
10067
symbolId: PropTypes.string.isRequired,
101-
fill: PropTypes.string.isRequired,
102-
stroke: PropTypes.string.isRequired,
103-
strokeWidth: PropTypes.string.isRequired,
68+
fill: PropTypes.string,
69+
stroke: PropTypes.string,
10470
};

x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_icon.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ export function VectorIcon({ fillColor, isPointsOnly, isLinesOnly, strokeColor,
3737

3838
return (
3939
<SymbolIcon
40+
key={`${symbolId}${fillColor}${strokeColor}`}
4041
symbolId={symbolId}
41-
fill={style.fill}
42-
stroke={style.stroke}
43-
strokeWidth={style.strokeWidth}
42+
fill={fillColor}
43+
stroke={strokeColor}
4444
/>
4545
);
4646
}
@@ -49,6 +49,6 @@ VectorIcon.propTypes = {
4949
fillColor: PropTypes.string,
5050
isPointsOnly: PropTypes.bool.isRequired,
5151
isLinesOnly: PropTypes.bool.isRequired,
52-
strokeColor: PropTypes.string.isRequired,
52+
strokeColor: PropTypes.string,
5353
symbolId: PropTypes.string,
5454
};

x-pack/legacy/plugins/maps/public/layers/styles/vector/components/symbol/icon_select.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,10 @@ export class IconSelect extends Component {
8080
fullWidth
8181
prepend={
8282
<SymbolIcon
83+
key={value}
8384
className="mapIconSelectSymbol__inputButton"
8485
symbolId={value}
8586
fill={isDarkMode ? 'rgb(223, 229, 239)' : 'rgb(52, 55, 65)'}
86-
stroke={isDarkMode ? 'rgb(255, 255, 255)' : 'rgb(0, 0, 0)'}
87-
strokeWidth={'1px'}
8887
/>
8988
}
9089
/>
@@ -100,10 +99,9 @@ export class IconSelect extends Component {
10099
label,
101100
prepend: (
102101
<SymbolIcon
102+
key={value}
103103
symbolId={value}
104104
fill={isDarkMode ? 'rgb(223, 229, 239)' : 'rgb(52, 55, 65)'}
105-
stroke={isDarkMode ? 'rgb(255, 255, 255)' : 'rgb(0, 0, 0)'}
106-
strokeWidth={'1px'}
107105
/>
108106
),
109107
};

x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,6 @@ export class VectorStyleEditor extends Component {
146146
this.props.handlePropertyChange(propertyName, styleDescriptor);
147147
};
148148

149-
_hasBorder() {
150-
const width = this.props.styleProperties[VECTOR_STYLES.LINE_WIDTH];
151-
return width.isDynamic() ? width.isComplete() : width.getOptions().size !== 0;
152-
}
153-
154149
_hasMarkerOrIcon() {
155150
const iconSize = this.props.styleProperties[VECTOR_STYLES.ICON_SIZE];
156151
return iconSize.isDynamic() || iconSize.getOptions().size > 0;
@@ -192,7 +187,7 @@ export class VectorStyleEditor extends Component {
192187
const disabledByIconSize = isPointBorderColor && !this._hasMarkerOrIcon();
193188
return (
194189
<VectorStyleColorEditor
195-
disabled={disabledByIconSize || !this._hasBorder()}
190+
disabled={disabledByIconSize || !this.props.hasBorder}
196191
disabledBy={disabledByIconSize ? VECTOR_STYLES.ICON_SIZE : VECTOR_STYLES.LINE_WIDTH}
197192
swatches={DEFAULT_LINE_COLORS}
198193
onStaticStyleChange={this._onStaticStyleChange}

x-pack/legacy/plugins/maps/public/layers/styles/vector/symbol_utils.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,15 @@ export function buildSrcUrl(svgString) {
6969
return domUrl.createObjectURL(svg);
7070
}
7171

72-
export async function styleSvg(svgString, fill, stroke, strokeWidth) {
72+
export async function styleSvg(svgString, fill, stroke) {
7373
const svgXml = await parseXmlString(svgString);
7474
let style = '';
7575
if (fill) {
7676
style += `fill:${fill};`;
7777
}
7878
if (stroke) {
7979
style += `stroke:${stroke};`;
80-
}
81-
if (strokeWidth) {
82-
style += `stroke-width:${strokeWidth};`;
80+
style += `stroke-width:1;`;
8381
}
8482
if (style) svgXml.svg.$.style = style;
8583
const builder = new xml2js.Builder();
@@ -119,8 +117,6 @@ export function getIconPaletteOptions(isDarkMode) {
119117
className="mapIcon"
120118
symbolId={iconId}
121119
fill={isDarkMode ? 'rgb(223, 229, 239)' : 'rgb(52, 55, 65)'}
122-
stroke={isDarkMode ? 'rgb(255, 255, 255)' : 'rgb(0, 0, 0)'}
123-
strokeWidth={'1px'}
124120
/>
125121
</div>
126122
);

x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ export class VectorStyle extends AbstractStyle {
138138
];
139139
}
140140

141+
_hasBorder() {
142+
return this._lineWidthStyleProperty.isDynamic()
143+
? this._lineWidthStyleProperty.isComplete()
144+
: this._lineWidthStyleProperty.getOptions().size !== 0;
145+
}
146+
141147
renderEditor({ layer, onStyleDescriptorChange }) {
142148
const rawProperties = this.getRawProperties();
143149
const handlePropertyChange = (propertyName, settings) => {
@@ -170,6 +176,7 @@ export class VectorStyle extends AbstractStyle {
170176
onIsTimeAwareChange={onIsTimeAwareChange}
171177
isTimeAware={this.isTimeAware()}
172178
showIsTimeAware={propertiesWithFieldMeta.length > 0}
179+
hasBorder={this._hasBorder()}
173180
/>
174181
);
175182
}
@@ -423,12 +430,18 @@ export class VectorStyle extends AbstractStyle {
423430

424431
getIcon = () => {
425432
const isLinesOnly = this._getIsLinesOnly();
426-
const strokeColor = isLinesOnly
427-
? extractColorFromStyleProperty(this._descriptor.properties[VECTOR_STYLES.LINE_COLOR], 'grey')
428-
: extractColorFromStyleProperty(
429-
this._descriptor.properties[VECTOR_STYLES.LINE_COLOR],
430-
'none'
431-
);
433+
let strokeColor;
434+
if (isLinesOnly) {
435+
strokeColor = extractColorFromStyleProperty(
436+
this._descriptor.properties[VECTOR_STYLES.LINE_COLOR],
437+
'grey'
438+
);
439+
} else if (this._hasBorder()) {
440+
strokeColor = extractColorFromStyleProperty(
441+
this._descriptor.properties[VECTOR_STYLES.LINE_COLOR],
442+
'none'
443+
);
444+
}
432445
const fillColor = isLinesOnly
433446
? null
434447
: extractColorFromStyleProperty(

0 commit comments

Comments
 (0)