Select to view content in your preferred language

Type error: Graphis is null

936
6
10-23-2012 05:56 PM
SK
by
Emerging Contributor
I added a base layer with spatial reference 102100. When I try to add a point and a symbol to it, it throws an error at
map.graphics.add - graphics is null. Here is my code

var pt= new esri.geometry.Point(x,y,sr);
var sms= new esri.symbol.SimpleMarkerSymbol(...);
var label = new esri.Graphic(pt,sms);
map.graphics.add(label);

Firebug shows label holds the pt and sms values. What could be causing the issue?
0 Kudos
6 Replies
StephenLead
Honored Contributor
Note that the help file for graphicsLayer says:

The graphics object is available to use after the Map.onLoad event.


So you should place your code below inside an event which runs once the map has loaded:

dojo.connect(map, "onLoad", function() {
  var pt= new esri.geometry.Point(x,y,sr);
  var sms= new esri.symbol.SimpleMarkerSymbol(...);
  var label = new esri.Graphic(pt,sms);
  map.graphics.add(label);
});   

0 Kudos
SK
by
Emerging Contributor
Thanks Stevel. I tried that as well, still it was giving me the same error. Any thoughts?
0 Kudos
StephenLead
Honored Contributor
Thanks Stevel. I tried that as well, still it was giving me the same error. Any thoughts?


Can you post your whole code (or at least enough to reproduce the problem)?

Cheers,
Steve
0 Kudos
__Rich_
Deactivated User
Don't forget the map cannot function without a non-Graphics layer:

http://forums.arcgis.com/threads/65475-Graphics-without-a-base-map
0 Kudos
SK
by
Emerging Contributor
Thanks.  Now, I can get the points show up. I am wondering if a text (textsymbol) can be added as below. Text is not showing up. I am not sure if am doing it right. Please help

dojo.connect(map, "onLoad", function(){

      var xy = new esri.geometry.Point ([-13074275.960 , 4015990.240], new esri.SpatialReference({wkid:102100}));

   //var xy =  new esri.geometry.Point([-117.440 , 33.905]  , new esri.SpatialReference({wkid:102100}));

   var sms = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 10,
   new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,
   new dojo.Color([47,85,89]), 1),
   new dojo.Color([112,15,70]));
   
   var text =  new esri.symbol.TextSymbol("Hello World").setColor(
    new dojo.Color([128,0,0])).setAlign(esri.symbol.Font.ALIGN_START).setAngle(45).setFont(
    new esri.symbol.Font("12pt").setWeight(esri.symbol.Font.WEIGHT_BOLD)) ;

   var ptlabel= new esri.Graphic(xy,sms,text);

          map.graphics.add(ptlabel);
   });
0 Kudos
__Rich_
Deactivated User
Could you start a new thread for this separate issue?  (and close off this one by marking the relevant post as the answer)
0 Kudos