Coordinates problem.

Topics: SharpMap Project, SharpMap v0.9 / v1.x
Mar 12, 2009 at 6:33 PM

I have an implementation of sharpmap that goes to the sql server and gets some points.

With that points I create a layer, the points are represented by icons

When I click in the map over the icon that represents the coordinates that are returned is different of the original.

This is the javascript that i use

//Fired when query is selected and map is clicked




function MapClicked(event, obj) {




var mousePos = SharpMap_GetRelativePosition(event.clientX, event.clientY, obj.container);



var pnt = SharpMap_PixelToMap(mousePos.x, mousePos.y, obj);






true, "Please wait while retrieving Shapefile data...");



MapService.GetPlaceInformation( pnt.x, pnt.y, QueryData_success, onFailed);



What’s my problem?

One thing that I realize was that exists an offset  over the x point of the mouse.


Mar 13, 2009 at 10:18 AM
Hi stonas, can you give us an idea of the expected vs actual result cheers jd
Mar 13, 2009 at 11:54 AM
Edited Mar 13, 2009 at 11:59 AM
In my data base the are two tipes of coordenates UTM and Lat/Long

What i do is create a layer with points represented  by icons. That points are stored in the DataBase like longitude and latitude
After i show de map, if i click over a icon and get the coordenates and converted them to UTM and shearch in the database if there is any coordenate like that (whith a offset) it didn't show any one.
But if i give a ofsset(ex. +250 or -250 ) to the x mouse position  it works. But the offset changes whith de zoom that i am using

For example is i am using a zoom of 0.027 and give a offset of +250 it finds the coordents in the database, if i don't use the offset when i click over the icon  the given coordent haven't any correspondent in the database.
If i use a diferent zoom i have to use a diferent offset to work.

My idea is to show a map where are points of interests and we can click it and show a pop-up width some relavant information.
Can you show-me some working example tha helps me?
I am doing this in

Mar 13, 2009 at 12:17 PM
If you take the original screen click coordinate then create new points in screen space by offsetting the original point first by (-1,-1)px then by (+1,+1)px before converting the new points to 'real world' coordinates.
You can then construct a bounding box from the two new points and use that in your queries. This has the avantage that the buffering will be proportional to the actual scale of the map hth jd
Mar 13, 2009 at 12:28 PM
i am new using the Sharpmap. So i'm not understanding  what you are sugesting.

If you send me a simple working example was greate.
Mar 13, 2009 at 3:14 PM
Hi stonas, maybe this explains it better.. note I changed the signature of GetPlaceInformation

function MapClicked(event, obj) {
 //get the actual clicked point
 var mousePos = SharpMap_GetRelativePosition(event.clientX, event.clientY, obj.container);

 //here we create two points in realworld coordinates corrseponding to screen points offset by +/- (1,1) from the actual clicked point
 //in effect we describe a small square around the clicked point.
 var min = SharpMap_PixelToMap(mousePos.x - 1, mousePos.y - 1, obj); //bottom left coordinate of the square
 var max = SharpMap_PixelToMap(mousePos.x + 1, mousePos.y + 1, obj); //top right coordinate of the square 
 //now we query using the square instead of the point so we get all features in a range not all features exactly at the point
 MapService.GetPlaceInformation( min.x, min.y, max.x, max.y, QueryData_success, onFailed);


hth jd
Mar 13, 2009 at 4:23 PM
I have tried to do that but it doesn't work. it continues with the offeset.
Mar 13, 2009 at 7:48 PM
Can any one send me a working example of a map that when we click over a icon show a pop-up window.
The icon was placed by me.