Tuesday, October 14, 2008

Fine tuning of the GeoMedia MapWindow object's height and width

Sometimes I need to define the exact width and height of the GeoMedia map in pixels to control the dimensions of the map view image created by the snap shot function. To do this, a developer can create a custom program to access the MapWindow object and set the width and height properties, as follows:


mapWnd.Width = 512;
mapWnd.Height = 512;


However, this is not entirely correct because the width and height of the MapWindow object include the Windows border and title bar as shown in the example screen shot below.



When you do a snap shot of the map window by selecting Edit > Snapshot, an image of the map view is created in the Windows clipboard. The map view image would have a width and height a little less than the width and height you set earlier e.g. 504 pixels by 489 pixels.

To get a map view image with the exact dimensions you want, you will have to add the border width and title bar height to the MapWindow object's width and height properties. An example code listing is shown below.
MapviewLib.GMMapView mview = null;
double xlo = 0, ylo = 0, zlo = 0, xhi = 0, yhi = 0, zhi = 0; //world
int pixelXlo = 0, pixelYlo = 0, pixelXhi = 0, pixelYhi = 0; //pixels
int mviewWidth, mviewHeight; //map view dimensions

//Set an initial desired width and height, e.g. 512x512
mapWnd.Width = 512;
mapWnd.Height = 512;

//Get the mapview object in the map window
mview = (MapviewLib.GMMapView)mapWnd.MapView;

//Get the map view object's MBR in real world coordinates
mview.GetRange(ref xlo, ref ylo, ref zlo, ref xhi, ref yhi, ref zhi);

//Convert the real world coordinates to screen pixels
mview.WorldToWindow(xlo, ylo, zlo, ref pixelXlo, ref pixelYlo);
mview.WorldToWindow(xhi, yhi, zhi, ref pixelXhi, ref pixelYhi);

//Calculate the map view objects width and height
mviewWidth = Math.Abs(pixelXhi - pixelXlo);
mviewHeight = Math.Abs(pixelYhi - pixelYlo);

//Adjust the map window object's dimensions by adding
//in the border and title bar's dimensions
mapWnd.Width = (mapWnd.Width - mviewWidth) + mapWnd.Width;
mapWnd.Height = (mapWnd.Height - mviewHeight) + mapWnd.Height;

After this adjustment, the snap shot image will have the correct desired dimensions.

1 comment:

Edson Cunha said...

god bless you. intergraph information on the internet is absolutely rare, unhappyly

Related Posts with Thumbnails