To make that map, they used a special class of Red Giant stars with known physical properties, 22 million of them which lets you calculate the distance to them precisely from their brightness
We can measure the distances to clusters and star forming regions and denser parts of the nearby galaxy, and several spiral arms have been mapped out that way, though of course we see them best in the region closest to the Earth. So that helps us to fill in the details, like this:
(for some reason they have it the other way up, with the sun at the top. It shows more information, for the individual arms, see e.g. Norma Arm)
The ESA Gaia mission will make this more precise. It aims to find out the precise distance to a billion stars. It can find the distance to stars at the centre of the galaxy, 30,000 light years away to an accuracy of 20%, and for stars close to the solar system to an accuracy of 0.001%. Gaia overview
It will be able to create a much more detailed 3D map of the galaxy.
In future maybe with some "super Gaia" we can map the exact positions of all the stars we can see, both visible, also infra red, x-ray sources etc, right out to the edge of the galaxy. After all Gaia can already go 30,000 light years, and the galaxy is only 100,000 light years across, doesn't seem too impossible that some day we can do an exact map of the whole thing.