Geomap: Add default svg size (#43246) (#43250)

* add default svg size

(cherry picked from commit 625c5e0e09)

Co-authored-by: nikki-kiga <42276368+nikki-kiga@users.noreply.github.com>
This commit is contained in:
Grot (@grafanabot)
2021-12-17 01:31:18 +01:00
committed by GitHub
co-authored by nikki-kiga
parent 02daac26b0
commit 5549070a82
@@ -216,7 +216,7 @@ const makers: SymbolMaker[] = [
},
];
async function prepareSVG(url: string): Promise<string> {
async function prepareSVG(url: string, size?: number): Promise<string> {
return fetch(url, { method: 'GET' })
.then((res) => {
return res.text();
@@ -228,8 +228,15 @@ async function prepareSVG(url: string): Promise<string> {
if (!svg) {
return '';
}
const svgSize = size ?? 100;
const width = svg.getAttribute('width') ?? svgSize;
const height = svg.getAttribute('height') ?? svgSize;
// open layers requires a white fill becaues it uses tint to set color
svg.setAttribute('fill', '#fff');
svg.setAttribute('width', `${width}px`);
svg.setAttribute('height', `${height}px`);
const svgString = new XMLSerializer().serializeToString(svg);
const svgURI = encodeURIComponent(svgString);
return `data:image/svg+xml,${svgURI}`;