I am new with OpenLayers 3. I'm working with the projection EPSG:4326.
I can get current resolution from view.getResolution(), but I am having trouble to get current scale of map. Please, give me a solution as soon as possible.
I am new with OpenLayers 3. I'm working with the projection EPSG:4326.
I can get current resolution from view.getResolution(), but I am having trouble to get current scale of map. Please, give me a solution as soon as possible.
Below is a function to get the resolution from scale, you should be able to transform the other way round using the same logic:
getResolutionForScale(scale, units) {
var dpi = 25.4 / 0.28;
var mpu = ol.proj.METERS_PER_UNIT[units];
var inchesPerMeter = 39.37;
return parseFloat(scale) / (mpu * inchesPerMeter * dpi);
}
I think scale is not that useful for screen devices, you can obtain the scale by getting the resolution and multiplying it for the amount of pixels in your desired unit. The first answer to this question, Getting the physical screen dimensions / dpi / pixel density in Chrome on Android , explains with great detail how reference pixels correspond to real units, so 96 pixels should be equal to an inch and your scale would be 1:(resolution*96). I think a better approach is to draw a scale line as most sites do, and OpenLayers 3 has ol.control.ScaleLine for that.