Geomap: Add default svg size (#43246)

* add default svg size
This commit is contained in:
nikki-kiga
2021-12-17 01:10:52 +01:00
committed by GitHub
parent 8fdbc6cc20
commit 625c5e0e09
@@ -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}`;