problem with map.graphics.add(graphic);

6100
14
04-29-2014 11:20 AM
GyeyoungChoi
New Contributor II
Hi all,

function getLocRes(results) {
 //map.graphics.clear();
 var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([80, 0, 0]), 2), new dojo.Color([80, 0, 0, 0.5]));
 var combinedExtent = new esri.geometry.Extent();
 console.log("er",results.features.length);
 for (var i = 0;i < results.features.length; i++) {console.log("i=",i);
  var polyGraphic = new esri.Graphic(results.features, symbol);
  console.log("i=",polyGraphic);
  polyGraphic.setSymbol(symbol);
  //map.graphics.add(graphic);
 }
 combinedExtent = esri.graphicsExtent(results.features);
 map.setExtent(combinedExtent, true);
}


this function is working sort of  but when I enable either
map.graphics.clear();
or
map.graphics.add(graphic);
it stops where the code is
console.log("i=",i);
this shows
only 0 when map.graphics.add(graphic); is on
if not it doesn't add graphic but shows console.log("i=",i); result until the end

Am I missing something here that map.graphics.add(graphic); shouldn't work?

dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.ContentPane");
dojo.require("esri.map");
dojo.require("esri.dijit.Popup");
dojo.require("esri.dijit.Legend");
dojo.require("esri.layers.agsdynamic");

dojo.require("esri.layers.ArcGISTiledMapServiceLayer");
dojo.require("dijit.dijit");
dojo.require("esri.tasks.find");//search     

dojo.require("esri.arcgis.utils");
dojo.require("esri.dijit.Print");
dojo.require("dojox.grid.DataGrid");

dojo.require("dojo.data.ItemFileReadStore");
dojo.require("dijit.form.Button");
dojo.require("esri.tasks.query");
dojo.require("esri.dijit.Scalebar");
dojo.require("esri.graphic");
dojo.require("esri.symbol");
0 Kudos
14 Replies
JonathanUihlein
Esri Regular Contributor
You are trying to add an object that does not exist. You want to add 'polyGraphic' to the map.

map.graphics.add(polyGraphic);


Also, make sure you have access to your map object within that functional scope.
0 Kudos
GyeyoungChoi
New Contributor II
You are trying to add an object that does not exist. You want to add 'polyGraphic' to the map.

map.graphics.add(polyGraphic);


Also, make sure you have access to your map object within that functional scope.


oops, but anyways that wasn't problem still does same thing
and I have full access to the map as well

any suggestions?

I've tried
function getLocRes(results) {
 //map.graphics.clear();
 var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([80, 0, 0]), 2), new dojo.Color([80, 0, 0, 0.5]));
 var combinedExtent = new esri.geometry.Extent();
 for (var i = 0;i < results.features.length; i++) {console.log("i=",i);
  var polyGraphic = new esri.Graphic(results.features, symbol);
  map.graphics.add(polyGraphic);
  console.log("i=",i);
 }
 combinedExtent = esri.graphicsExtent(results.features);
 map.setExtent(combinedExtent, true);
}

function getLocRes(results) {
 //map.graphics.clear();
 var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([80, 0, 0]), 2), new dojo.Color([80, 0, 0, 0.5]));
 var combinedExtent = new esri.geometry.Extent();
 for (var i = 0;i < results.features.length; i++) {console.log("i=",i);
  var polyGraphic = results.features;
  polyGraphic.setSymbol(symbol);
  map.graphics.add(polyGraphic);
  console.log("i=",i);
 }
 combinedExtent = esri.graphicsExtent(results.features);
 map.setExtent(combinedExtent, true);
}

both stop at either map.graphics.add(polyGraphic); or  map.graphics.clear();
Thanks Jon
0 Kudos
JonathanUihlein
Esri Regular Contributor
Could you recreate the issue using jsfiddle.net so I can take a closer look? Thanks!
0 Kudos
GyeyoungChoi
New Contributor II
Could you recreate the issue using jsfiddle.net so I can take a closer look? Thanks!


I tried using jsfiddle but here is url
0 Kudos
JonathanUihlein
Esri Regular Contributor
Unfortunately, this doesn't help because your application is simply too big for me to spend time digging through.

I really need you to strip out all the unnecessary code and create a sample that highlights your specific issue using jsfiddle.net.

Sometimes, when doing this, the issue presents itself, so I suggest giving it a try!

Sorry and thank you!
0 Kudos
GyeyoungChoi
New Contributor II
Unfortunately, this doesn't help because your application is simply too big for me to spend time digging through.

I really need you to strip out all the unnecessary code and create a sample that highlights your specific issue using jsfiddle.net.

Sometimes, when doing this, the issue presents itself, so I suggest giving it a try!

Sorry and thank you!


thanks Jon
I'll try to put my code on jsfiddle soon
0 Kudos
GyeyoungChoi
New Contributor II
here is how it works and problems:

url looks like http://my.com/test.htm?bldgabbrv=msc,sup3,gsc,rudd,cen
query.where = Abbrev = 'MSC' OR Abbrev = 'SUP3' OR Abbrev = 'GSC' OR Abbrev = 'RUDD' OR Abbrev = 'CEN'
then queryTask.execute(query, getLocRes);

if you look at getLocRes
script stops where map.whatever without them script just goes (tested with bunch of console.log)
tried for and while but they were not a problem.

The Funny thing is when I add alert(); right before queryTask.execute the function works perfect.


Does anyone knows what I did wrong?

Thanks!

*update on jsfiddle when u click run it should select 4 polygons in maroon color
0 Kudos
GyeyoungChoi
New Contributor II
So the problem with this is

error: Cannot read property 'add' of null

[ATTACH=CONFIG]33536[/ATTACH]

I am not sure what this means... does anyone knows about this?
0 Kudos
GyeyoungChoi
New Contributor II
on firebug says

error: map.graphics is null

still doesn't make any sense
0 Kudos