Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(maps): fix inline svg urls #1324

Merged
merged 3 commits into from
Feb 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silent-horses-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@baloise/design-system-components': patch
---

**maps**: fix image inline svg urls for the legacy marker api.
71 changes: 71 additions & 0 deletions packages/components/src/test/maps.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<!doctype html>
<html dir="ltr" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<style>
#map {
height: 100%;
}
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
<script>
var exports = {}
</script>
<script src="https://unpkg.com/@googlemaps/js-api-loader@1.x/dist/index.min.js"></script>
<script module src="/assets/maps.js"></script>
</head>

<body>
<div id="map"></div>
<script>
const position = { lat: -25.344, lng: 131.031 }

const mapOptions = {
mapId: 'DEMO_MAP_ID',
center: position,
zoom: 4,
styles: exports.balMapTypeStyles,
}

const loader = new google.maps.plugins.loader.Loader({
apiKey: '--your-api-key--',
version: 'weekly',
libraries: ['places'],
})

let map
loader.importLibrary('maps').then(({ Map }) => {
map = new Map(document.getElementById('map'), mapOptions)

loader.importLibrary('marker').then(({ AdvancedMarkerElement, Marker }) => {
// Legacy
new Marker({
map,
position: { lat: -33.8688, lng: 151.2093 },
title: 'Sydney',
icon: {
url: exports.balMapMarkerDefault,
},
})

const parser = new DOMParser()
const pinSvgString = exports.balMapMarkerDefault.replace('data:image/svg+xml;utf-8, ', '')
const pinSvg = parser.parseFromString(pinSvgString, 'image/svg+xml').documentElement
new AdvancedMarkerElement({
map,
position,
title: 'Uluru',
content: pinSvg,
})
})
})
</script>
</body>
</html>
4 changes: 4 additions & 0 deletions packages/components/stencil.config.ts
Original file line number Diff line number Diff line change
@@ -93,6 +93,10 @@ export const config: Config = {
src: '../../css/css/theme-compact.css',
dest: 'assets/theme-compact.css',
},
{
src: '../../maps/dist/index.js',
dest: 'assets/maps.js',
},
{ src: '../../css/css/baloise-design-system.css', dest: 'assets/baloise-design-system.css', warn: true },
{ src: '../../fonts/lib', dest: 'assets/fonts', warn: true },
],
7 changes: 1 addition & 6 deletions packages/maps/scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -62,12 +62,7 @@ async function optimizeSvg() {

async function optimizeIcon(input) {
const svg = await svgo.optimize(input, {
plugins: [
{
name: 'preset-default',
active: false,
},
],
plugins: [],
})
return svg.data
}
Loading