Closed raghavshivi94 closed 3 years ago
You have to get the pixel size at the center point for the map projection, then compute the scale:
// Pixel resolution 1px = res meter
var res = ol.proj.getPointResolution(map.getView().getProjection(), 1, imageCenter);
// Get image scale
var imageScale = widthInMeters / (widthInPixel * res)
For this formula, how can I calculate 'widthInPixel'? And is the height of the image not required while calculating the scale?
The widthInPixel is the number of pixel columns in your image... The imageScale argument is an ol/size~Size: an array [scaleX,scaleY]. You have to calculate the scaleY if not the same as scaleX using the number of pixel lines in your image and its height in meter (and the projection resolution at center)...
You can also try Map-georeferencer (https://github.com/Viglino/Map-georeferencer) to calculate the params (http://viglino.github.io/Map-georeferencer/)
I have got height and width of the image in meters and its center geo coordinates.
const source = new GeoImage({ url: src, projection: olProj.get('EPSG:3857'), imageCenter: olProj.fromLonLat(centerPoint), imageRotate: Number(45*Math.PI/180), imageScale:
?
});How can I dynamically calculate imageScale based on height and width of the image and center coordinates