0

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?

1 Answer 1

0

To remove all the graphics from a GraphicsLayer, call removeAll():

unitsLayer.removeAll();

To add a marker to a Graphics Layer, first create a Graphic. Then call:

unitsLayer.add(g); // (where "g" is that graphic you just created

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.