Hi. I have two feature service layers representing same data . One layer is of a simple point symbology(layer1) and another a picture marker symbology(layer2). Two layers are overlayed one over the other
I would like to view the picture marker symbolgy (Layer2) on clicking the point symbology (Layer1).
I read the "Hit Test" content in the developer resources guide. I was unable to find any examples of how to accomplish this. Can anyone offer assistance?
Are you looking to show the entire layer2 when clicking any point on layer1 ? or just the feature from layer2 that matches with the clicked feature of layer1?
When loading layer2, you could pass inn a definitionexpression (filter) which will always return 0 entries in the beginning. And by clicking on a feature in layer1, you could update that filter based on fields that would match 1-to-1 with the result of the hitTest, making layer2 only show what is returned by the updated filter.
Sample:
layer2 = new FeatureLayer({...., definitionExpression: 'Id = -1'})
const eventRef = view.on('immediate-click', (event) => {
const options = {
include: layer1,
};
view.hitTest(event, options).then((response) => {
if (!response.results.length) return; // no hit
const result = response.results[0] as __esri.GraphicHit;
const primaryKey = result.graphic.attributes['Id'];
layer2.definitionExpression = $`Id={primaryKey}`
});
});
Something in the lines of the above i think would work. A bit of pseudo code, so you need to ofcourse adapt it.
Thanks Christer for your response. I would like to show the feature from layer2 that matches with the clicked feature of layer 1. I will try with the logic mentioned and work with it.