//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);
}
t.execute(p, function (results) {
if (results[0] != undefined) {
var r = results[0].feature;
var atts = r.attributes;
var sym = app.sym.SimpleFillSymbol('solid', new esri.symbol.SimpleLineSymbol('solid', new dojo.Color([255, 0, 0]), 2), new dojo.Color([255, 255, 0, 0.2]));
var it = new esri.InfoTemplate('My Info Title', 'My Info Content')
var graphic = new esri.Graphic(r.geometry, sym, atts, it);
map._layers.MY_GRAPHICS_LAYER.add(graphic);
}
})
What does the graphic object look like in the DOM @ map.graphics; is it even present?
Also, create your own graphics layer. I had trouble in the past with map.graphics and quit using it some time ago.
var plotGraphics = new esri.layers.GraphicsLayer({ id: 'plot_gl' });
app.map.addLayer(plotGraphics);var myGraphicsLayer = new esri.layers.GraphicsLayer({ id: 'my_graphics_layer' });
map.addLayer(myGraphicsLayer);function addResultsToMap(results) {
dojo.forEach(results, function(result) {
var sym = esri.symbol.SimpleFillSymbol('solid', new esri.symbol.SimpleLineSymbol('solid', new dojo.Color([255, 0, 0]), 2), new dojo.Color([255, 255, 0, 0.2]));
var graphic = new esri.Graphic(result.feature.geometry, sym); //create graphic with geometry (result.feature.geometry) and symbol (sym)
map._layers.my_graphics_layer.add(graphic); //add graphic to graphics layer created above
//OR
//map.graphics.add(graphic); //add to map.graphics
});
}