If your shapefile can be converted to GeoJSON, in other words you were able to create a proper Leaflet layer out of it in Mapbox, you can use TurfJS's Inside operator like here:
If you really don't want any dependency you can go back to secondary school calc. :) My algorithm is like this:
- Iterate over the polygon's sides in one direction taking the 2 endpoint of the given polygon side.
- Let's call the endpoints p0(x0,y0) and p1(x1,y1). Your address point to check is P(x,y)
- Calculate signed distance from the line defined by the 2 polygon points:
d=((y0-y1)x+(x1-x0)y+(x0y1-x1y0))/sqrt((x1-x0)^2+(y1-y0)^2) (reasoning here)
- If the point IS WITHIN your polygons then the distances calculated from the polygon sides will have the same sign (depending on the direction of the rings all positive or all negative)
- If your polygon has holes you need to iterate over all the rings inside and your point has to be NOT WITHIN the inside rings but WITHIN the outer ring.
Hope this helps. This will not work for erroneous polygons like "bowties" (sides crossing themselves).
I'm sure there can be tons of other algo's for this tasks. This just came off the top of my head as something that can be coded simply in JS.