A problem on moving cursor to get points' information

843
6
10-16-2013 05:23 AM
sailiTang
New Contributor III
Hi,

I am using the code to read a database to get some points xy coordinates and using the following code to put these points to the map. Stpointcoord is xy coordinates array. I used vb.net to get the coordinate from the database and transfer these coordinate string to javascript.

var srLatLon = new SpatialReference({ wkid: 4326 });
for (var i = 0; i < stpointcoord.length; i = i + 2) {
     var x = stpointcoord;
     var y = stpointcoord[i + 1];
     stpoint = new Point(x, y, srLatLon);
     arrayUtils.forEach([stpoint], function (result) {
     //add point to the map

      graphic = new Graphic(result, createSymbol(initColor, "6"));
      map.graphics.add(graphic);
                                   };    

The map is attached. Now I would like users to move the cursor over a point and then the point information is shown by infowindow. But the problem is that the xy coordinates I am using evt.mapPoint to get are not accurate and there is at most 500000 difference. For example, St.Paul???s xy coordinate in the database is 2617213,7485938, but I get the coordinate which is 3070882, 7012354 when I move my cursor over the point. So the information window shows wrong information. Could you tell me why the coordinates have big difference and how I can fix it. Thanks.

Saili
0 Kudos
6 Replies
ManishkumarPatel
Occasional Contributor II
Hi Saili,

It seems the coordinates might be either displayed in a different coordinate system or it might be returning some different value. Have you tried using attaching a click handler instead to verify if you are able to get the correct coordinates. Also if possible could you put up a jsfiddle with a some reproducible code so its easier to troubleshoot.

Regards,
Manish
0 Kudos
sailiTang
New Contributor III
Thank you for your answer, Manish. To show the map, I am using the spatial Reference: { "wkid": 2953} and to populate the points, I define var stpoint = new Point(x, y, new SpatialReference({wkid: 2953})). I also change the point spatial reference from 2953 to 4326 and the coordinates difference  is the same. Any idea? What spatial reference I need to set?

Saili
0 Kudos
sailiTang
New Contributor III
And also I am using map.on("mouse-move", showStationName); to realize my purpose.
0 Kudos
JohnGravois
Frequent Contributor
i'm a little unclear how you are getting latitude and longitude coordinates from your database to display in the correct location in a projected map without projecting them, but in general, you might consider adding the X and Y values as graphic attributes and displaying the attributes when people click on the popup instead of digging into the geometry.

https://developers.arcgis.com/en/javascript/jshelp/inside_graphics.html
https://developers.arcgis.com/en/javascript/jssamples/graphics_multiple_layers.html
0 Kudos
sailiTang
New Contributor III
I have projected these points before I put them to the map. The project spatial reference is the same as map's.
0 Kudos
JohnGravois
Frequent Contributor
that makes my suggestion perfect 🙂
0 Kudos