Freigeben über


Vwa.ShapeCollection.getItemByName Method

Letzte Änderung: Samstag, 6. August 2011

Gilt für: apps for SharePoint | SharePoint Server 2013

Gibt das Shape, das dem angegebenen Namen zurück.

var value = ShapeCollection.getItemByName(string ShapeName)

Parameter

ShapeName Eine Zeichenfolge, die den Namen der zurückzugebenden Form angibt.

Rückgabewert

Vwa.Shape Das Shape, das dem angegebenen Namen ab.

Hinweise

Die Vwa.Shape.getName -Methode können Sie den Namen eines Shapes ermitteln.

Wenn die Methode eine Form mit dem angegebenen Namen nicht finden kann, wird nullzurückgegeben.

Weitere Informationen zum Hinzufügen eines Visio Web Access-Webparts zu einer SharePoint-Webparts-Seite finden Sie unter Customizing Visio Web Drawings in the Visio Web Access Web Part.

Beispiel

Das folgende Beispiel erstellt ein HTML-Textfeld und Schaltfläche im Inhalts-Editor-Webpart. Wenn auf die Schaltfläche geklickt wird, überprüft das Beispiel die aktuell angezeigte Seite in der Webzeichnung für ein Shape in das Textfeld bereitgestellte Zeichenfolge entsprechen. Wenn ein Shape übereinstimmenden gefunden wird, die Form wird hervorgehoben, und das Webpart wird auf dem Shape zentriert.

<script type="text/javascript">

// Create the HTML input controls.
document.write("<div> Shape to search for: " +
               "<input type='text' id='shapename' />" + 
               "<input type='button' id='search' value='Search' style='width:100px;height:22px' onclick='searchPage()' />" +
               "&nbsp;<span id='output' style='color:#FF0000'></span></div>");

// Declare global variables.
var vwaControl;
var vwaPage;
var vwaShapes;
var vwaShape;
var shapeBounds;
var searchOutput;

// Hook into the AJAX Sys.Application.load event.
Sys.Application.add_load(onApplicationLoad)

// Capture a reference to the current session of the Visio Web Access Web Part.
function onApplicationLoad() {
    try{
        vwaControl= new Vwa.VwaControl(getVWAWebPartID());
        vwaControl.addHandler("diagramcomplete", onDiagramComplete);
    }
    catch(err){
        alert(err);
    }
}

// Search the SharePoint page to get the WebPartID# for the Visio Web Access Web Part.
function getVWAWebPartID() {
    
    // Get a NodesList of all the div tags on the page. 
    var divArray = document.getElementsByTagName("div");
    var webPartElementID;
    
    // Iterate through the NodesList to get the node with the class attribute "VisioWebAccess."
    for (var i = 0; i < divArray.length; i++) {
        var node = divArray[i];
        
        // Return the first instance of the Visio Web Access Web Part.
        if (node.className == "VisioWebAccess") {
            webPartElementID = node.parentNode.parentNode.id;
            break;
        }
    }
    return webPartElementID;
}

// Capture references to global variables.
function onDiagramComplete(){
    try{
        vwaPage = vwaControl.getActivePage();
        vwaShapes = vwaPage.getShapes();
        searchOutput = document.getElementById('output');
    }
    catch(err){
        alert(err);
    }
}

// Search the displayed page for the shape specified by the user.
function searchPage() {
    try {
        
        // Remove any highlights currently displayed in the drawing.
        if (vwaShape) {vwaShape.removeHighlight()}
        
        // Get the user's input and get the shape object from the page.
        shapeName = document.getElementById('shapename').value;
        vwaShape = vwaShapes.getItemByName(shapeName);
        
        // Focus drawing on the shape if it is found.
        if (vwaShape) {
            focusOnShape();
        }
        // Provide feedback to the user if the shape is not found.
        else {
           searchOutput.innerHTML = " Shape not found.";
        }
    }
    catch (err) {
        alert(err);
    }
}

// Focus the displayed Web Drawing page on and highlight the shape sought by the user.
function focusOnShape()
{
    var isInView;
    var shapeId = vwaShape.getId();
    var shapeX, shapeY;

    // Get the location of the shape on the page.
    shapeBounds = vwaShape.getBounds();
    shapeX = shapeBounds.x;
    shapeY = shapeBounds.y;
    searchOutput.innerHTML = " Shape at: x = " + shapeX + "px, y = " + shapeY + "px";
    
    // Select the shape the user searched for and highlight it.
    vwaPage.setSelectedShape(shapeId);
    vwaShape.addHighlight(5, "#FF0000");

    // Check whether the shape is currently in view; if not, zoom out of the Web Drawing page.
    isInView = vwaPage.isShapeInView(shapeId);
    if (!isInView){
       vwaPage.setZoom(-1);
    }
}

</script>

Siehe auch

Referenz

Vwa.ShapeCollection Class

Vwa.Page Class Methods