如何创建2个SVG并使用jquery.extend()来组合它们?

时间:2017-11-02 02:18:24

标签: javascript jquery html svg

我有两个返回SVG对象的方法。第一个返回SVG,第二个返回SVG矩形。在第二种方法中,我想使用jquery.extend(true,...,..)来组合对象。我希望返回对象是矩形SVG(来自第二种方法)。我没有在第一种方法中创建形状的原因是因为我只需要属性。我使用第二种方法(矩形)的形状。

方法1:

RedlineElement.prototype.exportSVG = function() {
    var svg = document.createElement('SVG');

    svg.setAttribute("stroke-opacity",  this.getOpacity());
    svg.setAttribute("stroke",this.getStrokeColor());
    svg.setAttribute('stroke-width', this.getStrokeWidth());
    svg.setAttribute("x", this.getOriginX());
    svg.setAttribute("y", this.getOriginY());

    return svg;
};


RedlineElementRectangle.prototype.exportSVG = function() {
        var svgRect = "`http://www.w3.org/2000/svg`";
        var rect = document.createElementNS(svgRect, 'rect');
        rect.setAttributeNS(null, 'height', this.getHeight());
        rect.setAttributeNS(null, 'width', this.getWidth());
        rect.setAttributeNS(null, 'fillColor', this.getFillColor());

        //custom SVG attributes
        rect.setAttributeNS(null, 'version', 1);
        rect.setAttributeNS(null, 'elementType', sap.ui.vk.Redline.ElementType.Rectangle)

    return jQuery.extend(true, RedlineElement.prototype.exportSVG, rect);

};

但是这会随机返回一个非SVG矩形元素。

Console Image here

0 个答案:

没有答案
相关问题