Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AndreiTelteu/34c12d01683b12fb6bc589b1aa1d78ba to your computer and use it in GitHub Desktop.
Save AndreiTelteu/34c12d01683b12fb6bc589b1aa1d78ba to your computer and use it in GitHub Desktop.
I extracted the svg icon of the markers shown by Google Maps directions display, and i use it as a directive. Demo: https://codepen.io/AndreiTelteu/pen/GxLdKK
<div ng-app="GoogleMapsMarkerDemo">
<!-- Usage -->
<div ng-repeat="marker in ['marker1', 'marker2', 'marker3']">
<google-marker label="$index | indexToAlphabet"></google-marker>
</div>
<!-- You can have this svg as a separate file -->
<script type="text/ng-template" id="google-marker-template">
<svg version="1.1" width="27px" height="43px" viewBox="0 0 27 43" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<path id="a" d="m12.5 0c-6.9039 0-12.5 5.5961-12.5 12.5 0 1.8859 0.54297 3.7461 1.4414 5.4617 3.425 6.6156 10.216 13.566 10.216 22.195 0 0.46562 0.37734 0.84297 0.84297 0.84297s0.84297-0.37734 0.84297-0.84297c0-8.6289 6.7906-15.58 10.216-22.195 0.89844-1.7156 1.4414-3.5758 1.4414-5.4617 0-6.9039-5.5961-12.5-12.5-12.5z"/>
</defs>
<g fill="none" fill-rule="evenodd">
<g transform="translate(1 1)">
<use fill="#EA4335" fill-rule="evenodd" xlink:href="#a"/>
<path d="m12.5-0.5c7.18 0 13 5.82 13 13 0 1.8995-0.52398 3.8328-1.4974 5.6916-0.91575 1.7688-1.0177 1.9307-4.169 6.7789-4.2579 6.5508-5.9907 10.447-5.9907 15.187 0 0.74177-0.6012 1.343-1.343 1.343s-1.343-0.6012-1.343-1.343c0-4.7396-1.7327-8.6358-5.9907-15.187-3.1512-4.8482-3.2532-5.01-4.1679-6.7768-0.97449-1.8608-1.4985-3.7942-1.4985-5.6937 0-7.18 5.82-13 13-13z" stroke="#fff"/>
</g>
<text text-anchor="middle" dy="0.3em" x="14" y="15" font-family="Roboto, Arial, sans-serif" font-size="16px" fill="#FFF">{{ label }}</text>
</g>
</svg>
</script>
</div>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/angular@1.6.9/angular.js"></script>
<script>
var App = angular.module('GoogleMapsMarkerDemo', []);
App.directive('googleMarker', function () {
return {
restrict: 'E',
templateUrl: 'google-marker-template',
scope: {
label: '=',
},
}
});
App.filter('indexToAlphabet', function () {
return function (input) {
return String.fromCharCode(65 + input);
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment