Accidents near a junction - points in circle

points in circle radius (m):  

Most urban road accidents take place near road junctions. This tool allows you to count the number of accidents within x metres of a road junction.

The Leaflet map on click event is used to determine the lat/long of the centre of the cirle. The radius of the circle is determined by the value in the text box and the cirle is drawn using the Leaflet circle class.

A point is deemed to be in the circle simply by comparing its distance from the centre of the circle to the circle radius. This distance is calculated using the distanceTo method of the LatLng object. This method uses the Haversine formula which calculates the great-circle (i.e. shortest) distance between two points on a sphere.

The points found are added, one by one, to a new Leaflet LayerGroup, which is added to the map as the original layer is removed.

To use the tool, make sure the check box is checked, specify a radius and then click on the map.