Openlayers ScaleLine component has a way to convert from resolution to scale, but what about the other way around?
Our customers are choosing a scale for each layer, indicating the scale where the layer should be visible. That's why I have to convert from scale to resolution.
I have tried the following, where the ScaleLine is showing "50m" Expected result would be for the two resolutions to be the same. Output:
Expected: 0.5964957884324376
Resolution: 0.013229166680160416
Code
const scale = 50; // 50 meters
const view = this.map.getView();
const center = view.getCenter();
const projection = view.getProjection();
const inchesPrMeter = 39.3700787;
const dpi = 96; // What about ol.has.DEVICE_PIXEL_RATIO ?
const expectedResolution = view.getResolution();
const resolution = scale / (projection.getMetersPerUnit() * inchesPrMeter * dpi);
console.log('Expected:', expectedResolution);
console.log('Resolution:', resolution);
I also don't like the hardcoded DPI.