get and put graphic attribute on mouseclick of a particular overlay

503
1
Jump to solution
01-28-2021 11:00 PM
rsharma
Occasional Contributor III

Hi i am trying to get graphic attribute on mouse click , below is my code. Kindly help.

Hi @ErwinSoekianto 

i want to show username like the picture below it do not come from any feature layer but i have 

to get it from private server to show, here on click

Screenshot 2021-01-27 at 11.23.22 AM.png

so i tried like this and trying to get graphic- attribute or geometry, but it always come undefined, as i have to identify the graphic clicked and then get the username .

// *** declare mapview***//
    MapView {
        id:mapView
        property real initialMapRotation: 0
        Component.onCompleted: {
                mmpk.load();
            }
        anchors {
            left: parent.left
            right: parent.right
            top: parent.top
            bottom: parent.bottom
        }

        
        GraphicsOverlay{
            id:hunterfreindPathOverlay
        }
        //! [show callout qml api snippet]
        // initialize Callout
        calloutData {
            location: calloutLocation
            detail: "LINZ USER"
        }

        Callout {
            id: callout
            calloutData: parent.calloutData
            leaderPosition: leaderPositionEnum.Automatic
        }
        //! [show callout qml api snippet]

        // display callout on mouseClicked
        onMouseClicked: {
            const tolerance = 22;
            const returnPopupsOnly = false;
            const maximumResults = 1;

            if (callout.calloutVisible)
                callout.dismiss()
            else
            {             
       mapView.identifyGraphicsOverlayWithMaxResults(hunterfreindPathOverlay, mouse.x, mouse.y, tolerance, returnPopupsOnly, maximumResults);
                calloutLocation = mouse.mapPoint;
            }
        }
        // Signal handler for identify graphics overlay
            onIdentifyGraphicsOverlayStatusChanged: {
                if (identifyGraphicsOverlayStatus === Enums.TaskStatusCompleted) {
                    if (identifyGraphicsOverlayResult.graphics.length > 0) {
console.log("===>"+identifyGraphicsOverlayResult.graphics.geometry);
console.log("===>"+identifyGraphicsOverlayResult.graphics.attribute);
                        callout.accessoryButtonHidden = true;
                        callout.showCallout();
                    }
                } else if (identifyGraphicsOverlayStatus === Enums.TaskStatusErrored) {
                    console.log("error");
                }
            }
                //! [identify graphics api snippet]
    }//End Mapview

So i tried to add attribute like this and trying to fetch it, but unsuccessful

     // *** Create  graphic for boundaries and markers ***//
    function createGraphic(geometry, symbol) {
        var graphic = ArcGISRuntimeEnvironment.createObject("Graphic");
        graphic.geometry = geometry;
        graphic.symbol = symbol;
        graphic.attributes.insertAttribute("username", "LINZs");

        return graphic;
    }//end createGraphic

 

0 Kudos
1 Solution

Accepted Solutions
rsharma
Occasional Contributor III
     // *** Create  graphic for boundaries and markers ***//
    function createGraphic(geometry, symbol, uname) {
        var graphic = ArcGISRuntimeEnvironment.createObject("Graphic");
        graphic.geometry = geometry;
        graphic.symbol = symbol;
        graphic.attributes.attributesJson = {name: uname};
        return graphic;
    }//end createGraphic

 

 // Signal handler for identify graphics overlay
            onIdentifyGraphicsOverlayStatusChanged: {
                if (identifyGraphicsOverlayStatus === Enums.TaskStatusCompleted) {
                    if (identifyGraphicsOverlayResult.graphics.length > 0) {
                        console.log(JSON.stringify(identifyGraphicsOverlayResult.graphics[0].attributes.attributeValue("name")));
                       calloutData.detail=identifyGraphicsOverlayResult.graphics[0].attributes.attributeValue("name");
                       callout.accessoryButtonHidden = true;
                       callout.showCallout();
                    }
                } else if (identifyGraphicsOverlayStatus === Enums.TaskStatusErrored) {
                    console.log("error");
                }
            }

View solution in original post

0 Kudos
1 Reply
rsharma
Occasional Contributor III
     // *** Create  graphic for boundaries and markers ***//
    function createGraphic(geometry, symbol, uname) {
        var graphic = ArcGISRuntimeEnvironment.createObject("Graphic");
        graphic.geometry = geometry;
        graphic.symbol = symbol;
        graphic.attributes.attributesJson = {name: uname};
        return graphic;
    }//end createGraphic

 

 // Signal handler for identify graphics overlay
            onIdentifyGraphicsOverlayStatusChanged: {
                if (identifyGraphicsOverlayStatus === Enums.TaskStatusCompleted) {
                    if (identifyGraphicsOverlayResult.graphics.length > 0) {
                        console.log(JSON.stringify(identifyGraphicsOverlayResult.graphics[0].attributes.attributeValue("name")));
                       calloutData.detail=identifyGraphicsOverlayResult.graphics[0].attributes.attributeValue("name");
                       callout.accessoryButtonHidden = true;
                       callout.showCallout();
                    }
                } else if (identifyGraphicsOverlayStatus === Enums.TaskStatusErrored) {
                    console.log("error");
                }
            }
0 Kudos