Using Icon Fonts as Markers in Google Maps V3

前端 未结 7 1980
醉梦人生
醉梦人生 2020-11-28 23:43

I was wondering whether it is possible to use icon font icons (e.g. Font Awesome) as markers in Google Maps V3 to replace the default marker. To show/insert them in a HTML o

7条回答
  •  执念已碎
    2020-11-29 00:05

    In a modern browser one can use the canvas in order to render the font to png, and then use the data URI scheme:

    
      function getIcon(glyph, color) {
        var canvas, ctx;
        canvas = document.createElement('canvas');
        canvas.width = canvas.height = 20;
        ctx = canvas.getContext('2d');
        if (color) {
          ctx.strokeStyle = color;
        }
        ctx.font = '20px FontAwesome';
        ctx.fillText(glyph, 0, 16);
        return canvas.toDataURL();
      }
    

    For example: getIcon("\uf001") for the music note.

提交回复
热议问题