Last active
May 23, 2020 22:04
-
-
Save david-mart/5c38586f045b7823ba6de0a513b5a8fe to your computer and use it in GitHub Desktop.
icon-url-generator.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
import Vue from 'vue' | |
import LocationIcon from './LocationIcon' | |
// create a constructor from a Vue component | |
const LocationIconConstructor = Vue.extend(LocationIcon) | |
export const getColoredIconUrl = (fillColor, strokeColor) => { | |
// create a Vue element with required props | |
const iconComponent = new LocationIconConstructor({ propsData: { fillColor, strokeColor } }) | |
// mount the component shadow DOM | |
iconComponent.$mount() | |
// get icon DOM element | |
const iconDom = iconComponent.$el | |
// generate an html string from an element | |
const iconString = new XMLSerializer().serializeToString(iconComponent.$el) | |
// finally, generate a data url from a string | |
return 'data:image/svg+xml;charset=UTF-8;base64,' + btoa(iconString) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment