Origin points
Snapped points
Basic snap to road logic
This sample shows how to snap individual points to the rendered roads on the map. Click on any point to find out how far it moved in order to snap to the nearest road. This sample calculates the nearest rendered road every time the map moves within certain distance thresholds since only roads in view and at certain zoom levels are rendered. This is a cheap way to snap real-time GPS coordinates to the road network on the map. Similar logic can be used for snapping to other line featurs on the map. Simply change the names in the source layer to the layers you want to snap to. A full list of source layers available in the base road map vector tiles is documented
here