我在这里搜索fabricJS-circle,但没有找到一种方法来添加数字1或2或3 ...在画布上的圆内吗?

这是我在画布上的圆对象:

function makeStaion(left, top, stationID) {
    var c = new fabric.Circle({
        left: left,
        top: top,
        radius: 2,
        fill: '#5afffa',
        stroke: '#666',
        selectable: true,
        centeredScaling:true,
        padding:2,
        hasRotatingPoint: false,
        borderColor: 'black',
        cornerColor: 'black'

    });
    c.hasControls = true;
    c.station = true;

    c.stationID = stationID;
    c.stationName = stations[stationID].name;
    c.description = stations[stationID].desc;
    c.image = stations[stationID].image;

    return c;
}

最佳答案

我认为您正在寻找的是面料集团。

此处的教程:http://fabricjs.com/fabric-intro-part-3#groups

此处的文档:http://fabricjs.com/docs/fabric.Group.html

尝试这样的事情:

var c = new fabric.Circle({
        left: left,
        top: top,
        radius: 2,
        fill: '#5afffa',
        stroke: '#666',
        selectable: true,
        centeredScaling:true,
        padding:2,
        hasRotatingPoint: false,
        borderColor: 'black',
        cornerColor: 'black'
    });

var t = new fabric.Text(stationID, {
        fontFamily: 'Calibri',
        fontSize: 1.2,
        textAlign: 'center',
        originX: 'center',
        originY: 'center',
        left: LayoutCoordX(STA),
        top: LayoutCoordY(BL-BLOffset)-radius-.4
    });

var g = new fabric.Group([c, t],{
        // any group attributes here
    });


    g.hasControls = true;
    g.station = true;

    g.stationID = stationID;
    g.stationName = stations[stationID].name;
    g.description = stations[stationID].desc;
    g.image = stations[stationID].image;

    return g;

关于jquery - 如何在fabricJS中向圆形对象添加文本?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36552544/

10-09 02:59