Scale and draw on images

I would like to be able to upload a map (jpeg or pdf) and do the following

  1. Scale the map in the software, so if I measure any 2 points in the map, the app calculates the distance automatically.

  2. Warp the map, so that if someone takes a photo of a map and uploads it, the app can correct for perspective and flatten the image.

  3. Draw lines on the map that let’s me save distances in the map in my database. This should be automatically calculated since the map has been scaled

  4. Draw rectangles that let’s me calculate area. Similar to #3.

Does anyone know what is the best way to achieve this?