How can I use an SVG image as a map marker in OpenLayers-3?

前端 未结 6 1389
醉话见心
醉话见心 2020-12-31 13:57

I am trying to create map \"pin-drops\" (ie. map markers) in OpenLayers-3 (OL3) using SVG images.

Currently, I am using PNG images as the pindrops that reference the

6条回答
  •  既然无缘
    2020-12-31 15:05

    Convert the SVG to Base 64 . This (Link) helped me.

    copied the base 64 and used it as a string in javascript .

    Eg : var svg = "convertedBase64";

    Then

    var icon = new ol.style.Icon({
            src:'data:image/svg+xml;base64,'+svg ,
            other props
    });
    

    And you are done, may be a few Kbs more than SVG but this did work perfect for me .

提交回复
热议问题