如何使用loadImage在svg中添加svg作为标记?

时间:2020-07-14 07:03:38

标签: mapbox mapbox-gl-js

我想在地图上放置自己的标记,但MyImage应该为png。如果我希望它成为svg,怎么办?

map.loadImage(MyImage, function(error, image) {
      if (error) throw error;
      map.addImage("custom-marker", image);
    });

1 个答案:

答案 0 :(得分:1)

mapbox不支持SVG,您需要光栅化SVG

import mySVG from 'foo.svg'
let img = new Image(20,20)
img.onload = ()=>map.addImage('bus', img)
img.src = mySVG

来源:https://github.com/mapbox/mapbox-gl-js/issues/5529#issuecomment-340011876