<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic JS API 3.x - Select multiple features by mouse click event in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-3-x-select-multiple-features-by-mouse-click/m-p/1012836#M71233</link>
    <description>&lt;P&gt;I am trying to select multiple features in a feature layer by using "hold 'ctrl' button and mouse click event". I am using ArcGIS JS API 3.x.&lt;/P&gt;&lt;P&gt;I am creating the US State boundary by using FeatureCollection, [Able to display the boundary on map] I have to select multiple states by mouse click while holding 'ctrl' or 'alt' key.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var featureLayer = new esri.layers.FeatureLayer(featureCollection, {
    id: stateLayer,
    opacity: 0.30,
    visible: true,
    infoTemplate: infoTemplate
});
g_esri.map.addLayer(featureLayer);
featureLayer.on("click", onBoundaryClick);

function onBoundaryClick(evt) {
    var g = evt.graphic;
    g_esri.map.infoWindow.setContent(g.getContent());
    g_esri.map.infoWindow.show(evt.screenPoint, g_esri.map.getInfoWindowAnchor(evt.screenPoint));
    formatInfotemplate(false, g);
}&lt;/LI-CODE&gt;&lt;P&gt;I tried to follow some of the below links,&amp;nbsp;&lt;/P&gt;&lt;P&gt;a.&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-api-for-javascript/selecting-multiple-features-with-graphics/m-p/562210#M52481" target="_blank"&gt;https://community.esri.com/t5/arcgis-api-for-javascript/selecting-multiple-features-with-graphics/m-p/562210#M52481&lt;/A&gt;&lt;/P&gt;&lt;P&gt;b.&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-api-for-javascript/select-multiple-features-by-mouse-clicks/td-p/588560" target="_blank"&gt;https://community.esri.com/t5/arcgis-api-for-javascript/select-multiple-features-by-mouse-clicks/td-p/588560&lt;/A&gt;&lt;/P&gt;&lt;P&gt;But couldn't able to get through,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help welcome&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Kishor&lt;/P&gt;</description>
    <pubDate>Wed, 30 Dec 2020 08:54:22 GMT</pubDate>
    <dc:creator>Valgenmap</dc:creator>
    <dc:date>2020-12-30T08:54:22Z</dc:date>
    <item>
      <title>JS API 3.x - Select multiple features by mouse click event</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-3-x-select-multiple-features-by-mouse-click/m-p/1012836#M71233</link>
      <description>&lt;P&gt;I am trying to select multiple features in a feature layer by using "hold 'ctrl' button and mouse click event". I am using ArcGIS JS API 3.x.&lt;/P&gt;&lt;P&gt;I am creating the US State boundary by using FeatureCollection, [Able to display the boundary on map] I have to select multiple states by mouse click while holding 'ctrl' or 'alt' key.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var featureLayer = new esri.layers.FeatureLayer(featureCollection, {
    id: stateLayer,
    opacity: 0.30,
    visible: true,
    infoTemplate: infoTemplate
});
g_esri.map.addLayer(featureLayer);
featureLayer.on("click", onBoundaryClick);

function onBoundaryClick(evt) {
    var g = evt.graphic;
    g_esri.map.infoWindow.setContent(g.getContent());
    g_esri.map.infoWindow.show(evt.screenPoint, g_esri.map.getInfoWindowAnchor(evt.screenPoint));
    formatInfotemplate(false, g);
}&lt;/LI-CODE&gt;&lt;P&gt;I tried to follow some of the below links,&amp;nbsp;&lt;/P&gt;&lt;P&gt;a.&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-api-for-javascript/selecting-multiple-features-with-graphics/m-p/562210#M52481" target="_blank"&gt;https://community.esri.com/t5/arcgis-api-for-javascript/selecting-multiple-features-with-graphics/m-p/562210#M52481&lt;/A&gt;&lt;/P&gt;&lt;P&gt;b.&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-api-for-javascript/select-multiple-features-by-mouse-clicks/td-p/588560" target="_blank"&gt;https://community.esri.com/t5/arcgis-api-for-javascript/select-multiple-features-by-mouse-clicks/td-p/588560&lt;/A&gt;&lt;/P&gt;&lt;P&gt;But couldn't able to get through,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help welcome&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Kishor&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2020 08:54:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-3-x-select-multiple-features-by-mouse-click/m-p/1012836#M71233</guid>
      <dc:creator>Valgenmap</dc:creator>
      <dc:date>2020-12-30T08:54:22Z</dc:date>
    </item>
    <item>
      <title>Re: JS API 3.x - Select multiple features by mouse click event</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-3-x-select-multiple-features-by-mouse-click/m-p/1047494#M72553</link>
      <description>&lt;P&gt;Follow the example below.,&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;When adding just check if the desire keys are pressed.&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&amp;gt;
    &amp;lt;meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no"&amp;gt;
    &amp;lt;title&amp;gt;Labeling features client-side&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/3.35/esri/css/esri.css"&amp;gt;
    &amp;lt;style&amp;gt;
      html, body, #map {
        height: 100%; width: 100%; margin: 0; padding: 0; 
      }
    &amp;lt;/style&amp;gt;

   &amp;lt;script src="https://js.arcgis.com/3.35/"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script&amp;gt;
      var map;
    
      require([
        "esri/map", 
        "esri/geometry/Extent",
        "esri/layers/FeatureLayer",
        "esri/layers/GraphicsLayer",
        "esri/symbols/SimpleLineSymbol",
        "esri/symbols/SimpleFillSymbol",
        "esri/renderers/SimpleRenderer",
        "esri/Color",
         
        "dojo/domReady!"
      ], function(Map, Extent, FeatureLayer, GraphicsLayer,
                  SimpleLineSymbol, SimpleFillSymbol, 
                  SimpleRenderer, Color) 
      {
        const bbox = new Extent({"xmin": -1940058, "ymin": -814715, "xmax": 1683105, "ymax": 1446096, "spatialReference": {"wkid": 102003}});
      
        const map = new Map("map", {
          extent: bbox   
        });


        const statesUrl = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3";
        const states = new FeatureLayer(statesUrl, {
          id: "states",
          outFields: ["*"]
        });

        map.addLayer(states);

        const color = new Color("#00ffff");
        const line = new SimpleLineSymbol("solid", color, 1.5);
        const symbol = new SimpleFillSymbol("solid", line, null);
        const renderer = new SimpleRenderer(symbol);
        const selected = new GraphicsLayer();
        selected.setRenderer(renderer);
        map.addLayer(selected);

        let ctrl = false;
        let shift = false;

        map.on("key-down", function (evt) {
          if (evt.key === "Control") {
            ctrl = true;
          } else if (evt.key === "Shift") {
            shift = true;
          }
        });

        map.on("key-up", function (evt) {
          if (evt.key === "Control") {
            ctrl = false;
          } else if (evt.key === "Shift") {
            shift = false;
          }
        });

        states.on("click", function (evt) {
          if (!ctrl &amp;amp;&amp;amp; !shift) {
            selected.clear();
          }
          selected.add(evt.graphic.clone());
          console.log(`Selected: ${selected.graphics.length}`);
        });
    
      });
    &amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;div id="map"&amp;gt;&amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Apr 2021 11:23:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-3-x-select-multiple-features-by-mouse-click/m-p/1047494#M72553</guid>
      <dc:creator>NandaKishor</dc:creator>
      <dc:date>2021-04-15T11:23:35Z</dc:date>
    </item>
  </channel>
</rss>

