I am adding a GraphicsLayer with markers on the map and need to know which marker was clicked. How do I get a value of an attribute when I click on the marker? Thank you
const Layer1 = new GraphicsLayer({id: 'Layer1ID'});
map.add(Layer1);
const point = {
type: "point",
longitude: -80,
latitude: 25
};
const attributes = { "MarkerType": "Type1" }
const pointGraphic = new Graphic({
geometry: point,
symbol: simpleMarkerSymbol,
attributes: attributes
});
Layer1.add(pointGraphic);
view.on(""click"", e => {
alert(need to access the above attribute MarkerType);
});
Solved! Go to Solution.
You can use this code to get your Markertype
view.on('click',(event) =>{
view.hitTest(event)
.then((response) =>{
console.log(response.results[0].graphic.attributes.MarkerType); //or attributes['MarkerType'];
});
});
hitTest() will return features from an intersecting GraphicsLayer, from which you can getAttribute() or browse with the attributes property.
Here are some hitTest() samples to check out.
You can use this code to get your Markertype
view.on('click',(event) =>{
view.hitTest(event)
.then((response) =>{
console.log(response.results[0].graphic.attributes.MarkerType); //or attributes['MarkerType'];
});
});
Thank you Ken.