forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Maps] symbolize points with maki icons (elastic#37822)
* [Maps] sybmolize points with maki icons * add from for selecting symbol * add from for selecting symbol * get icons working for static colors * static icon sizing * refacto symbol_utils * timing issue * use SDF icons * dynamic iconSize * set icon-anchor * display symbol icon in map legend * add unit tests for VectorIcon * set icon fill based on dark mode * remove unused file * fix jest tests * set icon-opacity * use size style to configure icon-image small or large * fix queryRadius error by just hiding other point layer instead of removing * remove console statement on error * use maki icon size constants * add retry around opening set view popover for flaky test
- Loading branch information
Showing
33 changed files
with
7,019 additions
and
53 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "@kbn/maki", | ||
"version": "6.1.0", | ||
"description": "browser friendly version of @mapbox/maki", | ||
"license": "Apache-2.0", | ||
"main": "index.js", | ||
"devDependencies": {}, | ||
"dependencies": {}, | ||
"peerDependencies": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# @kbn/maki | ||
|
||
[@mapbox/maki](https://www.npmjs.com/package/@mapbox/maki) only works in node.js. | ||
See https://github.com/mapbox/maki/issues/462 for details. | ||
|
||
@kbn/maki is a browser friendly version of @mapbox/maki |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { parseString } from 'xml2js'; | ||
|
||
// promise based wrapper around parseString | ||
export async function parseXmlString(xmlString) { | ||
const parsePromise = new Promise((resolve, reject) => { | ||
parseString(xmlString, (error, result) => { | ||
if (error) { | ||
reject(error); | ||
} else { | ||
resolve(result); | ||
} | ||
}); | ||
}); | ||
|
||
return await parsePromise; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { parseXmlString } from './parse_xml_string'; | ||
|
||
describe('parseXmlString', () => { | ||
it('Should parse xml string into JS object', async () => { | ||
const xmlAsObject = await parseXmlString('<foo>bar</foo>'); | ||
expect(xmlAsObject).toEqual({ | ||
foo: 'bar' | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...red/layers/styles/components/vector/__snapshots__/vector_style_symbol_editor.test.js.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
...blic/shared/layers/styles/components/vector/legend/__snapshots__/vector_icon.test.js.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
x-pack/plugins/maps/public/shared/layers/styles/components/vector/legend/symbol_icon.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { getMakiSymbolSvg, styleSvg, buildSrcUrl } from '../../../symbol_utils'; | ||
|
||
export class SymbolIcon extends Component { | ||
|
||
state = { | ||
imgDataUrl: undefined, | ||
prevSymbolId: undefined, | ||
prevFill: undefined, | ||
} | ||
|
||
componentDidMount() { | ||
this._isMounted = true; | ||
this._loadSymbol(this.props.symbolId, this.props.fill); | ||
} | ||
|
||
componentDidUpdate() { | ||
this._loadSymbol(this.props.symbolId, this.props.fill); | ||
} | ||
|
||
componentWillUnmount() { | ||
this._isMounted = false; | ||
} | ||
|
||
async _loadSymbol(nextSymbolId, nextFill) { | ||
if (nextSymbolId === this.state.prevSymbolId | ||
&& nextFill === this.state.prevFill) { | ||
return; | ||
} | ||
|
||
let imgDataUrl; | ||
try { | ||
const svg = getMakiSymbolSvg(nextSymbolId); | ||
const styledSvg = await styleSvg(svg, nextFill); | ||
imgDataUrl = buildSrcUrl(styledSvg); | ||
} catch (error) { | ||
// ignore failures - component will just not display an icon | ||
} | ||
|
||
if (this._isMounted) { | ||
this.setState({ | ||
imgDataUrl, | ||
prevSymbolId: nextSymbolId, | ||
prevFill: nextFill | ||
}); | ||
} | ||
} | ||
|
||
render() { | ||
if (!this.state.imgDataUrl) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<img width="16px" src={this.state.imgDataUrl} alt={this.props.symbolId} /> | ||
); | ||
} | ||
} | ||
|
||
SymbolIcon.propTypes = { | ||
symbolId: PropTypes.string.isRequired, | ||
fill: PropTypes.string.isRequired, | ||
}; |
Oops, something went wrong.