Last active
May 13, 2019 16:38
-
-
Save skoch/72ec40669c561b7e16a9f11f313d93c1 to your computer and use it in GitHub Desktop.
An example for using SVG string in Javascript
This file contains hidden or 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
const markerSvg = { | |
url: 'data:image/svg+xml,%3Csvg width="39" height="49" xmlns="http://www.w3.org/2000/svg"%3E%3Cg fill="none" fill-rule="evenodd"%3E%3Cpath d="M19.5 2C29.165 2 37 9.835 37 19.5c0 13.933-15.267 26.984-17.5 26.984C16.982 46.484 2 33.433 2 19.5 2 9.835 9.835 2 19.5 2zm.126 25.18a6.715 6.715 0 1 0 0-13.43 6.715 6.715 0 0 0 0 13.43z" fill="%23000" fill-rule="nonzero"/%3E%3Cpath d="M19.5 1C29.717 1 38 9.283 38 19.5c0 6.465-3.099 13.192-8.139 19.35-3.85 4.706-8.608 8.634-10.361 8.634-1.878 0-6.608-3.876-10.47-8.637C4.06 32.723 1 25.977 1 19.5 1 9.283 9.283 1 19.5 1zm.126 25.18a5.715 5.715 0 1 0 0-11.43 5.715 5.715 0 0 0 0 11.43z" stroke="%23FFF" stroke-width="2" fill="%231D5FE2"/%3E%3C/g%3E%3C/svg%3E', | |
}; | |
const markerSvgOver = { | |
url: 'data:image/svg+xml,%3Csvg width="39" height="49" xmlns="http://www.w3.org/2000/svg"%3E%3Cg fill="none" fill-rule="evenodd"%3E%3Cpath d="M19.5 2C29.165 2 37 9.835 37 19.5c0 13.933-15.267 26.984-17.5 26.984C16.982 46.484 2 33.433 2 19.5 2 9.835 9.835 2 19.5 2zm.126 25.18a6.715 6.715 0 1 0 0-13.43 6.715 6.715 0 0 0 0 13.43z" fill="%23000" fill-rule="nonzero"/%3E%3Cpath d="M19.5 1C29.717 1 38 9.283 38 19.5c0 6.465-3.099 13.192-8.139 19.35-3.85 4.706-8.608 8.634-10.361 8.634-1.878 0-6.608-3.876-10.47-8.637C4.06 32.723 1 25.977 1 19.5 1 9.283 9.283 1 19.5 1zm.126 25.18a5.715 5.715 0 1 0 0-11.43 5.715 5.715 0 0 0 0 11.43z" stroke="%23FFF" stroke-width="2" fill="%23173E8D"/%3E%3C/g%3E%3C/svg%3E', | |
}; | |
// creating the marker with our custom icon: | |
const marker = new google.maps.Marker({ | |
// ... | |
icon: this.markerSvg, | |
// ... | |
}); | |
// Adding the handlers to change the icon | |
google.maps.event.addListener(marker, 'mouseover', () => { | |
// ... | |
marker.setIcon(markerSvgOver); | |
}); | |
google.maps.event.addListener(marker, 'mouseout', () => { | |
// ... | |
marker.setIcon(markerSvg); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment