01-29-2017 01:34 PM - edited 01-29-2017 01:48 PM
I have to programmatically calculate the width and height in pixels required to display a map when given a range at a given scale. I'm using a map window to validate my efforts, but ultimately need to know how to do this without a map window.
So, for testing I take a range and scale from the mapView, and after performing my scaling and conversion logic expect to have the same width and height in pixels as the map window's map area.
I am using the USSampleData with storage type projected for debug purposes. The range is in meters.
Here's my approach.
I've noticed the results differ if I change the monitor's screen resolution. The GeoMedia window remains the same size on screen yet the scale indicated differs. At 1920x1096 my calculations are about 63% of the map view area. At 1280x1024 they are close but not correct.
I use a third party sdk to convert from inches to pixels, but the thing is the inches calculated with my approach as outlined are incorrect to begin with.
Anyone know the trick to do this correctly?
Solved! Go to Solution.
01-29-2017 01:45 PM
I suggest you to look at the Windows API function GetDeviceCaps. You should query various capabilities of your display device such as HORZSIZE, HORZRES, VERTSIZE, VERTRES to get the correct ratio for your transformations. And note that the physical dimension of your screen may not be correct, especially if you have an old monitor with improper driver installed, or if you use some virtualization environment. But calculation based on those values should at least give you consistent results when you change the screen resolution.
01-29-2017 03:33 PM
Thanks for your reply, I'll check that out.
In the meantime, can you tell me at least if my approach is correct, steps 1-3.
01-29-2017 05:30 PM
I think I have a solution.
First I figure out a width and height adjustment ratio by doing the following:
Then after I have obtained this ratio, I take the end-user provided range and scale and perform the scaling as described previously. Then multiply the results by the width and height adjustment ratios.
This way I always get a pixel size that matches GeoMedia. Question is, if I create a mapView with those values will they work together?