Openlayers 3 ol.Style.Icon和内联SVG

Openlayers 3 ol.Style.Icon和内联SVG,openlayers-3,Openlayers 3,有没有办法在图标中使用内嵌SVG var iconStyle=new ol.style.style({ 图片:新ol.style.Icon(({ src:'img/svg.svg' })) }); 工作正常,但我在代码中生成内联SVG var icon = "<svg width=34 height=34 ><polyline points='17,17 17,0 13,5 17,0 21,5' fill='none' stroke='blue' stroke-width='

有没有办法在图标中使用内嵌SVG

var iconStyle=new ol.style.style({
图片:新ol.style.Icon(({
src:'img/svg.svg'
}))
});

工作正常,但我在代码中生成内联SVG

var icon = "<svg width=34 height=34 ><polyline  points='17,17 17,0 13,5 17,0 21,5' fill='none' stroke='blue' stroke-width='2' transform='rotate(263,17,17)'></polyline><circle cx=17 cy=17 r=11 style='fill:rgba(51,153,102,1);' /><circle cx=17 cy=17 r=6.5 style='fill:rgba(150,150,150,1);' /></svg>";
var图标=”;

我可以将此字符串用作图标的源吗?或者有任何可能的方法吗?

您可以显示包含内联SVG的覆盖

var icon = "<svg width=34 height=34 ><polyline  points='17,17 17,0 13,5 17,0 21,5' fill='none' stroke='blue' stroke-width='2' transform='rotate(263,17,17)'></polyline><circle cx=17 cy=17 r=11 style='fill:rgba(51,153,102,1);' /><circle cx=17 cy=17 r=6.5 style='fill:rgba(150,150,150,1);' /></svg>";

var overlayContent = document.createElement('div');
overlayContent.innerHTML = icon;

var overlay = new ol.Overlay({
    element: overlayContent,
    position: [0, 0],
    positioning: 'center-center'
});

map.addOverlay(overlay);
我尝试使用一个图标,并将字符串放在“data:image/svg+xml;utf8”中,但当我移动地图时,IE11中的OL3出现了一些异常。(Chrome显示一切正常)

无论如何,对我来说,使用覆盖效果更好,我可以修改图标的内容(大小、颜色等),而无需每次重新创建图标

如果您只需要旋转它,ol.Style.Icon可以动态地进行旋转;但您只需要看看是否没有更多的bug:)

overlay.getElement().style.cssText = 'transform: rotate(' + degrees + 'deg)';