Skip to main content
1 of 2

Adding markers to a layer at runtime

I would like to use two layers (units, calls) over the streets base map.

I have a timer loop that runs every 30 seconds and i would like to clear the units layer, then add the new unit markers to the unit layer.

  var units = new Graphic();  // graphic with units
  var calls = new Graphic();  // graphic with calls


  map = new Map({
    basemap: "streets-navigation-vector"
  });

  view = new MapView({
    container: "viewDiv",
    map: map,
    zoom: 12,
    center: {
      latitude: 38.8935,
      longitude: -77.0487
    }
  });


  var unitsLayer = new GraphicsLayer({
    graphics: [units]
  });

  var callsLayer = new GraphicsLayer({
    graphics: [calls]
  });


  map.add(unitsLayer);
  map.add(callsLayer);
  • Question 1) How do i clear a layer of markers without effecting the other layers?
  • Question 2) How do i add a marker to the units layer at run time?