Mxgraph locates the blind zone image to the center of the drawing Area

Source: Internet
Author: User

There are often many images in a drawing area. It is annoying to right-drag the canvas or use a scroll bar to find them. Next I will provide a solution to this problem.

The premise is that there is a tree or DataGrid in the entire drawing area. We need to select the graphic cell to be located directly.

First, we need a global object of mxgraph, which is now defined as yleditor. ylcanvas.

Next, we need to define a method to search for the graphic cell. Only through this method can we find the cell we want in the canvas.

ylCommon.findCellById=function(id){    ylEditor.ylCanvas.selectAll();    var cells=ylEditor.ylCanvas.getSelectionCells();    ylEditor.ylCanvas.clearSelection();    for(var i=0;i<cells.length;i++){        if(cells[i].id==id){            return cells[i];        }        if(cells[i].children.length>0){            for(var j=0;j<cells[i].children.length;j++){                var child=cells[i].children[j];                if(child.id==id){                    return child;                }            }        }    }    return null;}

Then, locate the Cell Method of the graph and directly give the Cell ID to the graph. Find the graph first, select the graph, calculate the coordinates, and locate it.

Ylcommon. selectcell = function (ID) {var cell = ylcommon. findcellbyid ('cell-'+ id); If (cell) {yleditor. ylcanvas. setselectioncell (cell); var x =-cell. geometry. X + ($ ('# canvas '). width ()-cell. geometry. width)/2; var y =-cell. geometry. Y + ($ ('# canvas '). height ()-cell. geometry. height)/2; yleditor. ylcanvas. getview (). settranslate (x, y);} else {alert ('the image you selected is not in the canvas! ');}}

In the tree or DataGrid, select the object to be located and pass the Object ID to the selectcell method, provided that the ID matches the image ID in the canvas.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.