Select to view content in your preferred language

Newbie: graphic is always at map center (projection problem?)

2220
4
09-15-2010 06:44 AM
ClaudioCaspani
Emerging Contributor
Hi,

I'm starting a small project that basically is a map that should show up some POI but I'm already on a dead end.

I've created the map using:

      
function init() {
        map = new esri.Map("map", {spatialReference:{wkid: 4326}});
        dojo.connect(map, "onLoad", loadHQDataSample);
        var tiledMapServiceLayer = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");
        map.addLayer(tiledMapServiceLayer);
       }


The map show up perfectly showing the world; then I'm trying to add a single POI via JSON using:

var myPoint1 = {
      "geometry":
      {
       "spatialReference":
       {
        "wkid": 4326
       },
       "x": -115.199,
       "y": 32.0207
      },
      "symbol":
      {
       "angle": 0,
       "color":[0,0,0,255],
       "height": 30,
       "size": 9,
       "style":"esriPMS",
       "type":"esriPMS",
       "url":"images/bluedot.png",
       "width": 30,
       "xoffset": 0,
       "yoffset": 0
      },
      "infoTemplate":
      {
       "title":"5 - 48.0 mi SSE of Calexico, CA",
       "content":"<img src=\"http://earthquake.usgs.gov/eqcenter/shakemap/thumbs/shakemap_sc_10798005.jpg\" width=\"100\" align=\"left\" hspace=\"10\"/><p>Date: Tue, 14 Sep 2010 10:52:17 UTC<br/>Lat/Lon: 32.0207/-115.199<br/>Depth: 10</p>"
      }      
       };
 var graphic1 = new esri.Graphic(myPoint1);
 map.graphics.add(graphic1);


What is happening is that the graphics is always put in the center of the map. I think that may be is a problem with projection but... no idea.
Looking at other sample seems that this should work... 

Anyone could shed some light on me?

Thank you in advance.

Regards Claudio
0 Kudos
4 Replies
AlexGray
Deactivated User
Claudio,

Looking at the second code window.. it looks like your symbol has xoffset and yoffset set to zero.
I am not sure if this is the problem or not but it looks like it would make sense to me if you were to change that to something other than zero and see if that changes the location of you symbol on the screen..

Sorry, I can't be of much help but maybe that is it..

Alex
0 Kudos
ClaudioCaspani
Emerging Contributor
Hi Alex,

I've gave a try but this is not changing the result... The graphic object is always placed in the center of map. 😞
I should miss something basic but I can see what is...

Cheers Claudio
0 Kudos
derekswingley1
Deactivated User
The map service you're using is in web mercator. Use esri.geometry.geographicToWebMercator() to convert your point to web mercator so it will be plotted correctly on your map.
0 Kudos
ClaudioCaspani
Emerging Contributor
The map service you're using is in web mercator. Use esri.geometry.geographicToWebMercator() to convert your point to web mercator so it will be plotted correctly on your map.


Yep 🙂
Checking carefully code of my other flex project I realized that I was using

http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer

instead of

http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer

As soon as I've switched to first one everything start to work as expected 🙂

Thank you.

Regards claudio
0 Kudos