简体   繁体   中英

how to get vertices in mxGraph javascript

I'm trying to add a new icon in my existing vertex/vertices programmatically using mxCellOverlay and addCellOverlay . How do I get all my vertices I have in my workeditor xml so I can pass it in addCellOverlay parameter, like the example below.

var overlay = new mxCellOverlay(new mxImage('editors/images/overlays/check.png',
16, 16), 'Overlay tooltip');
graph.addCellOverlay(allMyVertices, overlay);

reference: http://jgraph.github.io/mxgraph/javascript/examples/fixedicon.html

If I add this code in the fixedIcon.html (line 72) afer var v1 it gives me a new tick/check icon.

var overlay = new mxCellOverlay(new mxImage('editors/images/overlays/check.png',
16, 16), 'Overlay tooltip');

graph.addCellOverlay(v1, overlay);

If you only want to get the vertices (not edges) of one level, I would suggest mxGraph.getChildVertices instead of mxgraph.getCells . But you have to pass the parent mxCell to the function. You will then get all child vertices of this cell. E. g.if you want to add an overlay to all vertices of the default parent you could do something like this:

var overlay = new mxCellOverlay(new mxImage('editors/images/overlays/check.png', 16, 16), 'Overlay tooltip');
var parent = graph.getDefaultParent();
var vertices = graph.getChildVertices(parent);
graph.addCellOverlay(vertices, overlay);

Of course, a recursive implementation would be possible, if you want all vertices of every level.

For further informations: https://jgraph.github.io/mxgraph/docs/js-api/files/view/mxGraph-js.html#mxGraph.getChildVertices

这是:

mxGraph.prototype.getCells = function(x,y,width,height,parent,result);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM