My Graphics objects get plotted on very strange places

788
4
Jump to solution
08-07-2012 12:10 PM
by Anonymous User
Not applicable
Original User: clindholm

Hi,

I have a simple code that should add one graphic point to a basic world street map. I cannot find out why my graphic point gets plotted at very strange coordinates. What is wrong in my code below when the testGraphic object gets plotted at the equator and not inside Finland.
The map extent gets correctly set (see attachment 1), but as can bee seen in the second attachment the point gets plotted near coordinates 0N 0E.

dojo.require("esri.map");  function init(){     var map = new esri.Map("map",{   wrapAround180:true,   extent: esri.geometry.geographicToWebMercator(new esri.geometry.Extent(19.5, 59, 31.7, 70.5 , new esri.SpatialReference(4326)))  });    dojo.connect(window,'resize',map,map.resize);    var tiledMapServiceLayer = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");  map.addLayer(tiledMapServiceLayer);    dojo.connect(map, "onLoad", function() {     var Point = new esri.geometry.Point(20, 60, new esri.SpatialReference(4326));       var testGraphic =    new esri.Graphic(     Point,     new esri.symbol.SimpleMarkerSymbol().setColor(new dojo.Color([0,0,255])),     {"Point":"1"},     new esri.InfoTemplate()    );   map.graphics.add(testGraphic);  });   }   dojo.addOnLoad(init);



Thanks in advance,
-Christian
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable
Original User: Kelly

The graphic is added in the incorrect location because the input point is in gcs  and the basemap is Web Mercator. You can resolve this by converting the point to web mercator before adding it to the map using esri.geometry.geographicToWebMercator.

  var Point = esri.geometry.geographicToWebMercator(new esri.geometry.Point(20, 60, new esri.SpatialReference(4326))); 

View solution in original post

0 Kudos
4 Replies
by Anonymous User
Not applicable
Original User: Kelly

The graphic is added in the incorrect location because the input point is in gcs  and the basemap is Web Mercator. You can resolve this by converting the point to web mercator before adding it to the map using esri.geometry.geographicToWebMercator.

  var Point = esri.geometry.geographicToWebMercator(new esri.geometry.Point(20, 60, new esri.SpatialReference(4326))); 
0 Kudos
JohnGravois
Frequent Contributor
in your code, when you pass your latitude and longitude values to set the extent of the map you are taking advantage of the utility method "geographicToWebMercator" to reproject the coordinates to web mercator values (to match the coordinate system of the map.)

geometry objects can't reproject on the fly either, so if you want your graphics to draw in the right location they also have to be created with a coordinate system that matches the projection of your map or explicitly reprojected.
0 Kudos
by Anonymous User
Not applicable
Original User: clindholm

Thanks guys, I got it working now.

-Christian
0 Kudos
ChristianLindholm
New Contributor
One more question on this theme:

If my data points are in the Finnish KKJ2 projection (i.e. Finland_Zone_2), wkid 2392. How would I go about creating the data point and converting it to webmercator?

I tried with the code
esri.geometry.geographicToWebMercator(new esri.geometry.Point(east, north, new esri.SpatialReference(2392)))

but it seems like it will always assume that the spatial reference is WSG84 (or whatever the default is). It does not matter what wkid i put in my code, my points end up on the exact same location on the map regardless of the wkid.

Where should I start looking for a solution?

BR
-Christian
0 Kudos