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.
Solved! Go to Solution.
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();
}
});
});
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();
}
});
});