Select to view content in your preferred language

Why my graphics are not added to the map?

2660
12
12-04-2012 08:01 AM
YvanBérard
Regular Contributor
Hi all,

I'm following this example (but programmatically) http://help.arcgis.com/EN/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/find_map_datag...

and I don't know why my graphic are not showing up...

Thank's for your help.

//display the location results on the map 
function showResultsLocator(results) 
{
    map = getMap();
    //find results return an array of findResult.
    console.dir(map); // my map object is fully working here
    map.graphics.clear();
    var dataForGrid = [];
    //Build an array of attribute information and add each found graphic to the map
    var cpt = 0;
    //console.log(results);
    
    
    dojo.forEach(results, function(result) 
    {
     cpt++;
     var graphic = result.feature;
              
     //console.log(graphic.attributes.NAD83+","+ graphic.attributes.CIVIQUE+","+ graphic.attributes.VOIE);
  dataForGrid.push([result.layerName,graphic.attributes.NAD83, graphic.attributes.CIVIQUE, graphic.attributes.VOIE]);
  
        var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 2), new dojo.Color([255,255,0,0.5]));
        graphic.setSymbol(symbol);
  map.graphics.add(graphic);  // the graphics are not added to the map. Why?
 });
 //console.log(dataForGrid);
 generateTableSearch(dataForGrid);
 //console.log("cpt search = "+cpt);
 $('#nb_res_search').empty();
 $('#nb_res_search').text('Nb. résultat(s): '+cpt);
}
0 Kudos
12 Replies
YvanBérard
Regular Contributor
Even this doesn't work....

I can see in my DOM object that my created layer( var mySearchLayer = new esri.layers.GraphicsLayer({ id: 'search_result' }); ) have all of my search result and their geometry, but they are still not showing.

What's wrong with that????
0 Kudos
BenFousek
Deactivated User
I'm not sure. Zip up you app and post it or send it via a private message and I'll take a look.
0 Kudos
YvanBérard
Regular Contributor
I'm not sure. Zip up you app and post it or send it via a private message and I'll take a look.


After digging up my problem with Mr. Fousek (btfou), he found that my graphic are added to the map but with a totally wrong extent.

This is my original extent:
var initialExtent = new esri.geometry.Extent({ 'xmin': -8034661, 'ymin': 5652797, 'xmax': -8004182, 'ymax': 5670187, 'spatialReference': new esri.SpatialReference({ wkid: 102100 }) });


But, when the event add(graphic) is fired, the graphic are added in the middle of the mediterannean sea (?!?!?!???). How could this happen? I've never seen that bug.

var graphic = new esri.Graphic(result.feature.geometry, sym); //create graphic with geometry (result.feature.geometry) and symbol (sym)
        console.dir(map);
        map._layers.search_result.add(graphic); //add graphic to graphics layer created above
0 Kudos