AnsweredAssumed Answered

List Existing Graphics Points Based On Closest Distance To a Click Event

Question asked by behClevest on Sep 28, 2017
Latest reply on Sep 29, 2017 by EternalDOOM

Can you please take a look at this Demo and code and let me know how I can get a list of point graphics based on the closest distance to the click event position?

require([
          "esri/map",
          "esri/SpatialReference",
          "esri/graphic",
          "esri/layers/GraphicsLayer",
          "esri/geometry/Point",
          "esri/symbols/SimpleMarkerSymbol",
          "esri/symbols/SimpleFillSymbol",
          "dojo/domReady!"
  ],
  function(
          Map,
          SpatialReference,
          Graphic,
          GraphicsLayer,
          Point,
          SimpleMarkerSymbol,
          SimpleFillSymbol
  ) {
      var map = new Map("map", {
          basemap: "streets",
          center: [-122.4, 37.785],
          zoom: 14,
    });

    var graphicsLayer = new GraphicsLayer();
    var Symbol = new SimpleMarkerSymbol();

    graphicsLayer.add(new Graphic(new Point(-122.4, 37.777, new SpatialReference({ wkid: 4326 })), Symbol));
    graphicsLayer.add(new Graphic(new Point(-122.4, 37.785, new SpatialReference({ wkid: 4326 })), Symbol));
    graphicsLayer.add(new Graphic(new Point(-122.39,37.785, new SpatialReference({ wkid: 4326 })), Symbol));
    graphicsLayer.add(new Graphic(new Point(-122.41,37.785, new SpatialReference({ wkid: 4326 })), Symbol));
    graphicsLayer.add(new Graphic(new Point(-122.4, 37.793, new SpatialReference({ wkid: 4326 })), Symbol));

    map.addLayer(graphicsLayer);

    map.on("click", function(evt){    });

  });

Outcomes