Select to view content in your preferred language

Return graphics from mulitiple layers

288
1
Jump to solution
12-23-2024 11:19 AM
Mr_Kirkwood
Regular Contributor

I have an onclick function, but it is tied to one layer. How can i make it so that i can use multiple layers? 

 

view.on ("click", function (event)
            {
                // Handle feature selection here
                console.log ("Get Selected Features Data")
                $ ('#customWindow').jqxWindow ('close');
                 $ ('#assignedEmployeesTable').jqxGrid ('clear')        
                view.hitTest (event).then (function (response)
                {
                    if (response.results.length > 0) {
                        const features = response.results.filter (function (result)
                        {
                            return result.graphic.layer === roomsUseLayer;// Filter for your specific layer
                        });

                        // Extract attributes from the selected features
                        features.forEach (function (feature)
                        {
                            attributes = feature.graphic.attributes;
                            console.log (attributes.SPACEID);
                            
                        });
                        getSpaceObjectID ();
                    }
                });
            });

 

Thanks for your help. 

0 Kudos
1 Solution

Accepted Solutions
Mr_Kirkwood
Regular Contributor

The code below works as a solution:

 

view.on("click", function (event) {
    // Handle feature selection here
    console.log("Get Selected Features Data")
    view.hitTest(event).then(function (response) {
        for (let i = 0; i < response.results.length; i++) {
            const result = response.results[i];
            const graphic = result.graphic;
            attributes = graphic.attributes;
            const layer = result.layer;
            console.log("Layer:", layer.title);
            console.log("Attributes:", attributes);
            console.log(attributes.OBJECTID)
            getObjectID();
        }
    });
});

 

 

View solution in original post

0 Kudos
1 Reply
Mr_Kirkwood
Regular Contributor

The code below works as a solution:

 

view.on("click", function (event) {
    // Handle feature selection here
    console.log("Get Selected Features Data")
    view.hitTest(event).then(function (response) {
        for (let i = 0; i < response.results.length; i++) {
            const result = response.results[i];
            const graphic = result.graphic;
            attributes = graphic.attributes;
            const layer = result.layer;
            console.log("Layer:", layer.title);
            console.log("Attributes:", attributes);
            console.log(attributes.OBJECTID)
            getObjectID();
        }
    });
});

 

 

0 Kudos