Select to view content in your preferred language

ScreenToMap() retuning wrong values

782
3
08-31-2010 09:45 AM
JaskiratAnand
Emerging Contributor
Hi,
I am facing a issue with the ScreenToMap() method of the API. Whenever a user clicks on the map I'm capturing that event and performing a ScreeToMap() conversion on that point. Most of the time the conversion is correct, however, sometimes the returned value is wrong. I have confirmed the wrong values by running a mouse hover event on the map which gives me the current x,y co-ordinates corresponding to the current mouse location on the map. The map is in WGS1984.
If anybody else has ever faced the same issue or a relative issue please share your experience.

thanks
Jaskirat
0 Kudos
3 Replies
dotMorten_esri
Esri Notable Contributor
Make sure you give it coordinates that are relative to the upper left corner of the map.
You can transform them using the TransformToVisual command. Ex:
Point relativeToMap = uiElementThatInputPointAreRelativeTo.TransformToVisual(MyMap).Transform(inputPoint);
0 Kudos
LakshmananVenkatesan
Frequent Contributor
Make sure you give it coordinates that are relative to the upper left corner of the map.
You can transform them using the TransformToVisual command. Ex:
Point relativeToMap = uiElementThatInputPointAreRelativeTo.TransformToVisual(MyMap).Transform(inputPoint);


Hello

I have tried TransformToVisualMethod but still values are wrong. How to give relative to upper left corner of the Map?. I am using ESRI SL 1.2 API. Can you please elobrate on this issue.
0 Kudos
ShenglinXu
Deactivated User
I have tested the following code, works fine. Basically, I added a polygon drawing points to a point collection and draw them again. If I use a UI element, a textbox for example, the polygon will shift to right to some extent. However, I found this works great.

var ps = e.GetPosition(null);
Point aPnt = this.TransformToVisual(Map).Transform(ps);
ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = Map.ScreenToMap(aPnt);
_measurPntCol.Add(mapPoint);
0 Kudos