ThinkGeo.com    |     Documentation    |     Premium Support

Translating screen point to map point using GdiPlusRasterLayer initialized with rectangle shape

Hi,
I use a GdiPlusRasterLayer with a path and an image extent (without world file).
i am using the following code to get the map coordinates where the mouse is located on on each mouse move:
Point screenPoint = args.GetPosition(_view);
mapControl.PointFromScreen(screenPoint);

The image layer was created like this:
RectangleShape imageLayerBBOX = new RectangleShape(0, imageSize.Height, imageSize.Width, 0);
GdiPlusRasterLayer gdiPlusRasterLayer = new GdiPlusRasterLayer(imagePath, imageLayerBBOX);
gdiPlusRasterLayer.Name = coreLayer.LayerID.ToString();

and on initialization of the map iam setting:
mapControl.MapUnit = GeographyUnit.Meter;
mapControl.ZoomLevelSet = new PrinterZoomLevelSet(mapControl.MapUnit, PrinterHelper.GetPointsPerGeographyUnit(mapControl.MapUnit));

my problem is that i am expecting to get 0,0 on the map coordinates on the upper left of the image (Red circle)
what i do get is where in the green circle.
also i see that the actual location changes according to my current extent.

i am trying to get the location in order to place one of our features on that location, can’t seem to do that.
am i doing some thing wrong here?
Thanks.

Hi Gal,

Are you using our MVC edition for that?

I think your imageLayerBBOX shouldn’t be the screen coordinates but should be world coordinates.

If you want to make the image keep on the left upper corner, you need get current extent when you pan the map, then calculate the upper left point coordinate and build your image extent.

Regards,

Don

No i am using WPF Edition.
my current map is blank, the first layer i try to add is this GDI raster one.
i am doing this steps according to a sample i got from Think geo support.
Thanks.

Hi Gal,

Please share your sample project in this post, so we can get more information about your question.

From the code you mentioned, I think the incorrect extent you are using caused this issue.

Regards,

Don

i am getting a message

when i try to upload attachment.

Hi Gal,

Thanks to let us know that, I have contact the forum administrator and it looks you can try to upload that now.

Regards,

Don

Here is the sample,
I Had to remove the MapSuiteCore dll and xml file from the dependencies folder and also 2 Cad file the app is using
in order to make the zip file small enough so i can upload.
I am guessing that the dll and xml file you already have and the CAD files you don’t need as we are talking about the image sample.

Thanks.

DisplayCadFileSample-2015-Aug-07.zip (1.3 MB)Uploading…

HI Gal,

Thanks for your code share.

The mainly problem of your code is, you keep use screen points to assign to our extent. Our extent only accept the world extent.

So I did small change to your code:

  1. Add color as back ground to make sure the image whether put in correct position
    map.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.StandardColors.Red);

  2. Directly use current extent for image extent
    GdiPlusRasterLayer gdiPlusRasterLayer = new GdiPlusRasterLayer(@"…\App_Data\Jpg\MIA_Miami_International_Airport_FAA_diagram.jpg", map.CurrentExtent);

  3. When refresh, assign the world coordinates to current extent instead of your screen points
    LayerItem imageLayerItem = new LayerItem(“ImageLayer”, map.CurrentExtent);
    RefreshSelectedLayer(imageLayerItem);

The map locate on upper-left corner now.

Regards,

Don

This does not seem to make sense to me, this image is without any world file.
I am tring to load it to the map in a way that the upper left point will be 0,0 and the lower right corner will be image.Width, Image.Height

I don’t see how you can achieve this without opening the layer file and checking what is its size?
i tried adding your 3 lines and after refresh i get a black page.

Hi Gal,

Please see my attached zip file, replace them into your sample and see whether that works for you.

8055.zip (3.3 KB)

Regards,

Don

What about the rest of my question?

Hi Gal,

I think the modified sample can render the image just like what you want.

Do you means “I don’t see how you can achieve this without opening the layer file and checking what is its size?” this question?

We don’t need to know what’s its size, we will render it into the extent we passed in.

Regards,

Don

and what will be the coordinates i will get when clicking on the top left and on the bottom right of the image?
will they be depended on the extent i am in when i open them? will they be the same every time i load the image in different extents?

in my use case the users have multiple maps he can switch between them, each map has its own image layer and the user can place entities on the layer. to place the entities i get the point the user clicks on and save that value to my DB so every time the user loads this map his entities will be there at the same location.

The extent of the map can be different each time i come to load my layer.

so what i need to know if in they way you said will i get the same point if i click on the same part of the image every time i load the map regardless of the extent i am in when i open the layer?

what will be the coordinates i get, how are they calculated for a map without world file?

Thanks.

Hi Gal,

When you click on the upper-left corner of the image, the coordinate will be the upper-left corner of the extent you passed into. (The current extent in my code)

If you load different extent, in my code the coordinates will be different, that’s for make sure they “dock” in current extent.

If you don’t have world file and don’t passed in an extent, we cannot draw the image, because our map don’t know where to draw it.

About your latest question, I have some confused about it. Why you have to save a screen coordinate and what’s the relationship between user’s extent? If you want to draw the image in a special coordinate of current extent, I think you can convert it to world coordinate after the map loaded, then draw it with world coordinate. But if you want to make the image “dock” map, you need to use current extent for it.

Regards,

Don