AnsweredAssumed Answered

Having Issue On Removing Layer on ArcGIS API For JavaScript

Question asked by BEHSEINI on Sep 15, 2015
Latest reply on Oct 15, 2015 by rakeshmodi1585

I am adding a markers layer called `layer1` like this to map



 function drawPoints(mapInfo) {
      layer1 = new esri.layers.GraphicsLayer();
        for (var i = 0; i < mapInfo.length; i++) {
               var projects = mapInfo[i];
               var project = new esri.geometry.Point(projects.Longitude, projects.Latitude);
               project = esri.geometry.geographicToWebMercator(project);
               var symbol = new esri.symbol.PictureMarkerSymbol("img/map/marker.png", 18, 18);
               projectInfoTemplate = new InfoTemplate();
               projectInfoTemplate.setTitle("Project Details");
               projectInfoTemplate.setContent('<div class="row"></div> ');
               var projectsG = new esri.Graphic(project, symbol).setInfoTemplate(projectInfoTemplate);


now in next request I need to clear map so I used the






but this is causing error because the `layer1` still not created at first request. Now I need to check `IF` the map has a layer called `layer1` then removeit. Here is a pseudo code of what I need to do:





can you please let me know how to do that?