Hi
When zoomed in and the streets feature layer is available we are able to drop a graphic marker anywhere on the map.
I'd like to limit the graphic marker to be only able to drop it onto the feature (street) and not just anywhere on the map.
How can I do that?
This map will be used for reporting potholes on a street and the graphic will serve no other service other than visually showing (along with the popup that appears when you click on the feature) where someone has clicked to report the location of the pothole.
Thanks
Solved! Go to Solution.
That's excellent and working well, thank you. I did try taking the top line out but I'd missed taking out the } right at the bottom and that clearly now was my error!
thank you so much for your patience, help and advice.
Hi Rene,
This has been working great, I hope you don't mind but I now have a further query with regards to this.
I've been asked to add another layer to the map (the boundary layer) see this pen https://codepen.io/RFletERYC/full/mdKbQEo . When I add this layer the check on the graphics no longer works and I can drop a marker anywhere on the map again, rather than it being restricted to the streets layer.
I note further up the comments you mention further checks such as layer id or title. This sounds like something I now need. How would I add one of those checks in please?
Thanks in advance. Ricky
You have a second hitTest in your code there, but aren't passing the options with the target layer in the include.
https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#hitTest
You do it the first hitTest.
I tested that in your codepen and it works just like before when you do that.
This sample does something similar.
https://developers.arcgis.com/javascript/latest/sample-code/view-hittest/
For your example, this works ok. But note that hitTest was updated at 4.24.
https://developers.arcgis.com/javascript/latest/release-notes/#mapview-and-sceneview-hittest-updates
So depending on how you are using the hitTest results, you may need to check the type like the snippet in the docs.