AnsweredAssumed Answered

Simple add graphics question

Question asked by bensca on Jan 15, 2014
Latest reply on Jan 16, 2014 by kenbuja
I am new to javascript and the api and experimenting with the various samples on this site as a starting point.  One thing I have tried is adding a graphic to a map using map.graphics.add.

I am finding that when I contain the map.graphics.add part in the dojo connect statement (as per example 1 below) my script works - it plots a single point on the map at the specified coordinates.

If, however I try a more functionally decomposed script as is presented in https://developers.arcgis.com/en/javascript/jsapi/map.html I get a blank map (see example 2.).  I am sure this is something simple, but can't figure out what's wrong.

Any ideas?

Cheers,
Ben

Example 1.
  <script>     dojo.require("esri.map");        function init(){       var map = new esri.Map("mapDiv", {         center: [150, -33],         zoom: 3,         basemap: "streets"       });       dojo.connect(map, 'onLoad', function() {        var point = new esri.geometry.Point(150, -33, new esri.SpatialReference({wkid:4326}));       map.graphics.add(new esri.Graphic(point,new esri.symbol.SimpleMarkerSymbol()));       });     }     dojo.ready(init);   </script>  


Example 2.
  <script>     dojo.require("esri.map");          function init(){       var map = new esri.Map("mapDiv", {         center: [150, -33],         zoom: 7,         basemap: "streets"       });       dojo.connect(map, "onLoad", function() { ShowLocation(150, -33); });          }      function ShowLocation(x, y)      {       var point = new esri.geometry.Point(x, y, new esri.SpatialReference({wkid:4326}));       map.graphics.add(new esri.Graphic(point,new esri.symbol.SimpleMarkerSymbol()));     }                  dojo.ready(init);   </script>

Outcomes