diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/__snapshots__/vector_icon.test.js.snap b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/__snapshots__/vector_icon.test.js.snap index 5837a80ec3083..f7dea92a8a0b7 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/__snapshots__/vector_icon.test.js.snap +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/__snapshots__/vector_icon.test.js.snap @@ -38,8 +38,8 @@ exports[`Renders PolygonIcon 1`] = ` exports[`Renders SymbolIcon 1`] = ` `; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/symbol_icon.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/symbol_icon.js index 301d64e676703..ea3886c600be9 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/symbol_icon.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/symbol_icon.js @@ -12,62 +12,30 @@ import { getMakiSymbolSvg, styleSvg, buildSrcUrl } from '../../symbol_utils'; export class SymbolIcon extends Component { state = { imgDataUrl: undefined, - prevSymbolId: undefined, - prevFill: undefined, - prevStroke: undefined, - prevStrokeWidth: undefined, }; componentDidMount() { this._isMounted = true; - this._loadSymbol( - this.props.symbolId, - this.props.fill, - this.props.stroke, - this.props.strokeWidth - ); - } - - componentDidUpdate() { - this._loadSymbol( - this.props.symbolId, - this.props.fill, - this.props.stroke, - this.props.strokeWidth - ); + this._loadSymbol(); } componentWillUnmount() { this._isMounted = false; } - async _loadSymbol(nextSymbolId, nextFill, nextStroke, nextStrokeWidth) { - if ( - nextSymbolId === this.state.prevSymbolId && - nextFill === this.state.prevFill && - nextStroke === this.state.prevStroke && - nextStrokeWidth === this.state.prevStrokeWidth - ) { - return; - } - + async _loadSymbol() { let imgDataUrl; try { - const svg = getMakiSymbolSvg(nextSymbolId); - const styledSvg = await styleSvg(svg, nextFill, nextStroke, nextStrokeWidth); + const svg = getMakiSymbolSvg(this.props.symbolId); + const styledSvg = await styleSvg(svg, this.props.fill, this.props.stroke); imgDataUrl = buildSrcUrl(styledSvg); } catch (error) { // ignore failures - component will just not display an icon + return; } if (this._isMounted) { - this.setState({ - imgDataUrl, - prevSymbolId: nextSymbolId, - prevFill: nextFill, - prevStroke: nextStroke, - prevStrokeWidth: nextStrokeWidth, - }); + this.setState({ imgDataUrl }); } } @@ -80,7 +48,6 @@ export class SymbolIcon extends Component { symbolId, // eslint-disable-line no-unused-vars fill, // eslint-disable-line no-unused-vars stroke, // eslint-disable-line no-unused-vars - strokeWidth, // eslint-disable-line no-unused-vars ...rest } = this.props; @@ -98,7 +65,6 @@ export class SymbolIcon extends Component { SymbolIcon.propTypes = { symbolId: PropTypes.string.isRequired, - fill: PropTypes.string.isRequired, - stroke: PropTypes.string.isRequired, - strokeWidth: PropTypes.string.isRequired, + fill: PropTypes.string, + stroke: PropTypes.string, }; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_icon.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_icon.js index 29429b5b29aff..e255dceda856e 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_icon.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_icon.js @@ -37,10 +37,10 @@ export function VectorIcon({ fillColor, isPointsOnly, isLinesOnly, strokeColor, return ( ); } @@ -49,6 +49,6 @@ VectorIcon.propTypes = { fillColor: PropTypes.string, isPointsOnly: PropTypes.bool.isRequired, isLinesOnly: PropTypes.bool.isRequired, - strokeColor: PropTypes.string.isRequired, + strokeColor: PropTypes.string, symbolId: PropTypes.string, }; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/symbol/__snapshots__/icon_select.test.js.snap b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/symbol/__snapshots__/icon_select.test.js.snap index b4b7a3fcf28fa..706dc0763b7ca 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/symbol/__snapshots__/icon_select.test.js.snap +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/symbol/__snapshots__/icon_select.test.js.snap @@ -25,8 +25,6 @@ exports[`Should render icon select 1`] = ` } @@ -53,8 +51,6 @@ exports[`Should render icon select 1`] = ` "label": "symbol1", "prepend": , "value": "symbol1", @@ -63,8 +59,6 @@ exports[`Should render icon select 1`] = ` "label": "symbol2", "prepend": , "value": "symbol2", diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/symbol/icon_select.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/symbol/icon_select.js index 03cd1ac14a013..68f7a30b22862 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/symbol/icon_select.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/symbol/icon_select.js @@ -80,11 +80,10 @@ export class IconSelect extends Component { fullWidth prepend={ } /> @@ -100,10 +99,9 @@ export class IconSelect extends Component { label, prepend: ( ), }; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js index 9636dab406a44..7daf85b68dd8e 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js @@ -146,11 +146,6 @@ export class VectorStyleEditor extends Component { this.props.handlePropertyChange(propertyName, styleDescriptor); }; - _hasBorder() { - const width = this.props.styleProperties[VECTOR_STYLES.LINE_WIDTH]; - return width.isDynamic() ? width.isComplete() : width.getOptions().size !== 0; - } - _hasMarkerOrIcon() { const iconSize = this.props.styleProperties[VECTOR_STYLES.ICON_SIZE]; return iconSize.isDynamic() || iconSize.getOptions().size > 0; @@ -192,7 +187,7 @@ export class VectorStyleEditor extends Component { const disabledByIconSize = isPointBorderColor && !this._hasMarkerOrIcon(); return ( ); diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/symbol_utils.test.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/symbol_utils.test.js index ed59b1d5513a0..1d3b3608cb2d9 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/symbol_utils.test.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/symbol_utils.test.js @@ -32,21 +32,12 @@ describe('styleSvg', () => { ); }); - it('Should add stroke style property to svg element', async () => { + it('Should add stroke and stroke-wdth style properties to svg element', async () => { const unstyledSvgString = ''; const styledSvg = await styleSvg(unstyledSvgString, 'red', 'white'); expect(styledSvg.split('\n')[1]).toBe( - '' - ); - }); - - it('Should add stroke-width style property to svg element', async () => { - const unstyledSvgString = - ''; - const styledSvg = await styleSvg(unstyledSvgString, 'red', 'white', '2px'); - expect(styledSvg.split('\n')[1]).toBe( - '' + '' ); }); }); diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index 1f96c37c9d286..62651fdd702d6 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -138,6 +138,12 @@ export class VectorStyle extends AbstractStyle { ]; } + _hasBorder() { + return this._lineWidthStyleProperty.isDynamic() + ? this._lineWidthStyleProperty.isComplete() + : this._lineWidthStyleProperty.getOptions().size !== 0; + } + renderEditor({ layer, onStyleDescriptorChange }) { const rawProperties = this.getRawProperties(); const handlePropertyChange = (propertyName, settings) => { @@ -170,6 +176,7 @@ export class VectorStyle extends AbstractStyle { onIsTimeAwareChange={onIsTimeAwareChange} isTimeAware={this.isTimeAware()} showIsTimeAware={propertiesWithFieldMeta.length > 0} + hasBorder={this._hasBorder()} /> ); } @@ -423,12 +430,18 @@ export class VectorStyle extends AbstractStyle { getIcon = () => { const isLinesOnly = this._getIsLinesOnly(); - const strokeColor = isLinesOnly - ? extractColorFromStyleProperty(this._descriptor.properties[VECTOR_STYLES.LINE_COLOR], 'grey') - : extractColorFromStyleProperty( - this._descriptor.properties[VECTOR_STYLES.LINE_COLOR], - 'none' - ); + let strokeColor; + if (isLinesOnly) { + strokeColor = extractColorFromStyleProperty( + this._descriptor.properties[VECTOR_STYLES.LINE_COLOR], + 'grey' + ); + } else if (this._hasBorder()) { + strokeColor = extractColorFromStyleProperty( + this._descriptor.properties[VECTOR_STYLES.LINE_COLOR], + 'none' + ); + } const fillColor = isLinesOnly ? null : extractColorFromStyleProperty(