Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery OpenLayers为SVG图标着色_Jquery_Svg_Openlayers - Fatal编程技术网

Jquery OpenLayers为SVG图标着色

Jquery OpenLayers为SVG图标着色,jquery,svg,openlayers,Jquery,Svg,Openlayers,我一直在遵循OpenLayers网站上的图标颜色示例 这对我处理png和jpg图像效果很好,但是当我切换到使用svg图像时,颜色根本不会改变。没有错误。颜色就是不变 以下是发生颜色更改的代码片段: /*set the colour*/ var style = new ol.style.Style({ image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({ anchor

我一直在遵循OpenLayers网站上的图标颜色示例

这对我处理png和jpg图像效果很好,但是当我切换到使用svg图像时,颜色根本不会改变。没有错误。颜色就是不变

以下是发生颜色更改的代码片段:

    /*set the colour*/
    var style = new ol.style.Style({
        image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
            anchor: [0.5, 0.5],
            src : 'img/icons/example.svg',
            color: '#8959A8'
        }))
    }); 

任何建议都将不胜感激

显然,SVG的
fill
属性需要为白色(
#fff
)。文档没有对此做任何说明,但我的结论是,任何白色(
#fff
)都将使用传递给
color
属性的值进行着色,与图像的类型无关。

在Plunckr中发布整个代码。我检查了自己的SVG工作情况。还有一件事,图像是否正在加载?嗨@Sumanth,谢谢回复。我已经将问题缩小到svg本身。例如,这个svg可以工作:'',但我用''等的svg不能工作。文档现在提到,颜色为原始标记添加了“色调”。我相信这是因为它也适用于PNG、JPEG等。我还没有找到一种方法来保持SVG的一部分为白色,而改变其余部分的颜色。