<?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 Re: How to select multiple features from one layer? in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-select-multiple-features-from-one-layer/m-p/1583977#M86510</link>
    <description>&lt;P&gt;I got thgis to work using a thread here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/ctrl-mouse-click/td-p/425312" target="_blank"&gt;https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/ctrl-mouse-click/td-p/425312&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;meta 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;Select by Point&amp;lt;/title&amp;gt;

    &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.30/esri/themes/light/main.css" /&amp;gt;
    &amp;lt;script src="https://js.arcgis.com/4.30/"&amp;gt;&amp;lt;/script&amp;gt;

    &amp;lt;style&amp;gt;
        html,
        body,
        #viewDiv {
            padding: 0;
            margin: 0;
            height: 100%;
            width: 100%;
        }
    &amp;lt;/style&amp;gt;
    &amp;lt;script&amp;gt;
        require([
            "esri/views/draw/Draw",
            "esri/Map",
            "esri/Graphic",
            "esri/layers/GraphicsLayer",
            "esri/layers/FeatureLayer",
            "esri/geometry/Point",
            "esri/geometry/Multipoint",
            "esri/views/MapView"

        ], function (Draw, Map, Graphic, GraphicsLayer, FeatureLayer, Point, Multipoint, MapView) {
            const pntGraphics = new GraphicsLayer();
            let viewClickEvtHandler = null, viewMouseMoveEvtHandler = null;
            var renderer = {
                type: "simple", // autocasts as new SimpleRenderer()
                symbol: {
                    type: "simple-fill", // autocasts as new SimpleFillSymbol()
                    color: [255, 255, 255, 0.5],
                    style: "none",
                    outline: {  // autocasts as new SimpleLineSymbol()
                        color: "black",
                        width: 2
                    }
                }
            };
            const statesLyr = new FeatureLayer({
                url: 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/2',
                // renderer: renderer,
                outFields: ['*']
            });

            let drawPnt, graphic, ctrlKey = false, highlight, statesLyrView;

            const map = new Map({
                basemap: "topo-vector",
                layers: [pntGraphics, statesLyr]
            });

            const view = new MapView({
                container: "viewDiv",
                map: map,
                center: [-105.570, 41.313193],
                zoom: 15.5
            });

            statesLyr.when(function () {
                view.whenLayerView(statesLyr).then(function (layerView) {
                    statesLyrView = layerView;
                });
            })

            const draw = new Draw({
                view: view
            });

            var sym = {
                type: "simple-marker",
                style: "circle",
                color: [0, 255, 255, 0.6],
                size: "8px",
                outline: {
                    color: [0, 255, 255, 1],
                    width: 1
                }
            };

            view.ui.add("point-button", "top-left");

            document.getElementById("point-button").onclick = drawPoint;

            function drawPoint() {
                if (viewMouseMoveEvtHandler) {
                    viewMouseMoveEvtHandler.remove()
                    viewMouseMoveEvtHandler = null
                }
                if (viewClickEvtHandler) {
                    viewClickEvtHandler.remove()
                    viewClickEvtHandler = null
                }
                const action = draw.create("point");
                viewMouseMoveEvtHandler = view.on('pointer-move', (evt) =&amp;gt; {
                    if (evt.native.ctrlKey) {
                        moveCtrlKey = true;
                    } else {
                        moveCtrlKey = false;
                    }
                })
                viewClickEvtHandler = view.on('pointer-down', (evt) =&amp;gt; {
                    if (evt.native.ctrlKey) {
                        ctrlKey = true;
                    } else {
                        ctrlKey = false;
                    }
                })
                if (highlight) {
                    highlight.remove();
                }

                // Give a visual feedback to users as they move the pointer over the view
                action.on("cursor-update", function (evt) {
                    view.graphics.removeAll();
                    drawPnt = new Point({
                        x: evt.coordinates[0],
                        y: evt.coordinates[1],
                        spatialReference: view.spatialReference
                    });
                    graphic = new Graphic({
                        geometry: drawPnt,
                        symbol: sym
                    });
                    view.graphics.add(graphic);
                    if (ctrlKey &amp;amp;&amp;amp; !moveCtrlKey) {
                        draw.reset();
                        view.graphics.removeAll();
                        selectStates();
                    }
                });

                action.on("draw-complete", function (evt) {
                    drawPnt = new Point({
                        x: evt.coordinates[0],
                        y: evt.coordinates[1],
                        spatialReference: view.spatialReference
                    });

                    graphic = new Graphic({
                        geometry: drawPnt,
                        symbol: sym
                    });
                    pntGraphics.add(graphic);
                    if (ctrlKey) {
                        drawPoint();
                    } else {
                        view.graphics.removeAll();
                        selectStates();
                    }
                });
                view.focus();
            };

            function selectStates() {
                ctrlKey = false
                moveCtrlKey = false
                if (viewMouseMoveEvtHandler) {
                    viewMouseMoveEvtHandler.remove()
                    viewMouseMoveEvtHandler = null
                }
                if (viewClickEvtHandler) {
                    viewClickEvtHandler.remove()
                    viewClickEvtHandler = null
                }
                let mp = new Multipoint({
                    spatialReference: view.spatialReference
                });
                let pntArray = pntGraphics.graphics.map(function (gra) {
                    mp.addPoint(gra.geometry);
                });

                const query = {
                    geometry: mp,
                    outFields: ["*"],
                    outSpatialReference: view.spatialReference,
                    returnGeometry: true
                };

                statesLyr.queryFeatures(query)
                    .then(function (results) {
                        const graphics = results.features;

                        var employeeEditData = [
                            { name: "", id: "" },
                            { name: "", id: "" }
                        ];
                        employeeEditData = [];
                        for (var i = 0; i &amp;lt; results.features.length; i++) {
                            if (results.features[i].attributes.BUILDINGID) {
                                employeeEditData.push({
                                    name: results.features[i].attributes.BUILDINGID,
                                    id: results.features[i].attributes.OBJECTID,
                                    OBJECTID: results.features[i].attributes.OBJECTID,
                                    LONGNAME: results.features[i].attributes.LONGNAME,


                                });
                                console.log(results.features[i].attributes.OBJECTID)
                            }

                        }

                        var floorRoomAvailable = [];
                        for (var k = 0; k &amp;lt; employeeEditData.length; k++) {
                            //                                console.log (myRoomAvailableData[k].OBJECTID)
                            floorRoomAvailable.push(
                                employeeEditData[k].OBJECTID
                            );

                        }
                        console.log(floorRoomAvailable)

                        console.log(employeeEditData)

                        console.log(graphics)

                        // remove existing highlighted features
                        if (highlight) {
                            highlight.remove();
                        }

                        // highlight query results
                        highlight = statesLyrView.highlight(graphics);
                        console.log("Test")
                        pntGraphics.removeAll();
                    }).catch(function (err) {
                        console.error(err);
                    })
            }
        });
    &amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
    &amp;lt;div id="viewDiv"&amp;gt;
        &amp;lt;div id="point-button" class="esri-widget esri-widget--button esri-interactive" title="Select Countries"&amp;gt;
            &amp;lt;span class="esri-icon-map-pin"&amp;gt;&amp;lt;/span&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;

&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 11 Feb 2025 13:32:26 GMT</pubDate>
    <dc:creator>RobertKirkwood</dc:creator>
    <dc:date>2025-02-11T13:32:26Z</dc:date>
    <item>
      <title>How to select multiple features from one layer?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-select-multiple-features-from-one-layer/m-p/1583249#M86495</link>
      <description>&lt;P&gt;I would like to be able to select multiple polygons from a service feature layer using JavaScript. I see this example but have not been able to get it to work with JS 4.30:&lt;/P&gt;&lt;P&gt;&lt;A title="select multiple features by mouse clicks" href="https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/select-multiple-features-by-mouse-clicks/td-p/588560" target="_self"&gt;https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/select-multiple-features-by-mouse-clicks/td-p/588560&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2025 18:54:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-select-multiple-features-from-one-layer/m-p/1583249#M86495</guid>
      <dc:creator>RobertKirkwood</dc:creator>
      <dc:date>2025-02-07T18:54:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to select multiple features from one layer?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-select-multiple-features-from-one-layer/m-p/1583977#M86510</link>
      <description>&lt;P&gt;I got thgis to work using a thread here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/ctrl-mouse-click/td-p/425312" target="_blank"&gt;https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/ctrl-mouse-click/td-p/425312&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;meta 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;Select by Point&amp;lt;/title&amp;gt;

    &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.30/esri/themes/light/main.css" /&amp;gt;
    &amp;lt;script src="https://js.arcgis.com/4.30/"&amp;gt;&amp;lt;/script&amp;gt;

    &amp;lt;style&amp;gt;
        html,
        body,
        #viewDiv {
            padding: 0;
            margin: 0;
            height: 100%;
            width: 100%;
        }
    &amp;lt;/style&amp;gt;
    &amp;lt;script&amp;gt;
        require([
            "esri/views/draw/Draw",
            "esri/Map",
            "esri/Graphic",
            "esri/layers/GraphicsLayer",
            "esri/layers/FeatureLayer",
            "esri/geometry/Point",
            "esri/geometry/Multipoint",
            "esri/views/MapView"

        ], function (Draw, Map, Graphic, GraphicsLayer, FeatureLayer, Point, Multipoint, MapView) {
            const pntGraphics = new GraphicsLayer();
            let viewClickEvtHandler = null, viewMouseMoveEvtHandler = null;
            var renderer = {
                type: "simple", // autocasts as new SimpleRenderer()
                symbol: {
                    type: "simple-fill", // autocasts as new SimpleFillSymbol()
                    color: [255, 255, 255, 0.5],
                    style: "none",
                    outline: {  // autocasts as new SimpleLineSymbol()
                        color: "black",
                        width: 2
                    }
                }
            };
            const statesLyr = new FeatureLayer({
                url: 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/2',
                // renderer: renderer,
                outFields: ['*']
            });

            let drawPnt, graphic, ctrlKey = false, highlight, statesLyrView;

            const map = new Map({
                basemap: "topo-vector",
                layers: [pntGraphics, statesLyr]
            });

            const view = new MapView({
                container: "viewDiv",
                map: map,
                center: [-105.570, 41.313193],
                zoom: 15.5
            });

            statesLyr.when(function () {
                view.whenLayerView(statesLyr).then(function (layerView) {
                    statesLyrView = layerView;
                });
            })

            const draw = new Draw({
                view: view
            });

            var sym = {
                type: "simple-marker",
                style: "circle",
                color: [0, 255, 255, 0.6],
                size: "8px",
                outline: {
                    color: [0, 255, 255, 1],
                    width: 1
                }
            };

            view.ui.add("point-button", "top-left");

            document.getElementById("point-button").onclick = drawPoint;

            function drawPoint() {
                if (viewMouseMoveEvtHandler) {
                    viewMouseMoveEvtHandler.remove()
                    viewMouseMoveEvtHandler = null
                }
                if (viewClickEvtHandler) {
                    viewClickEvtHandler.remove()
                    viewClickEvtHandler = null
                }
                const action = draw.create("point");
                viewMouseMoveEvtHandler = view.on('pointer-move', (evt) =&amp;gt; {
                    if (evt.native.ctrlKey) {
                        moveCtrlKey = true;
                    } else {
                        moveCtrlKey = false;
                    }
                })
                viewClickEvtHandler = view.on('pointer-down', (evt) =&amp;gt; {
                    if (evt.native.ctrlKey) {
                        ctrlKey = true;
                    } else {
                        ctrlKey = false;
                    }
                })
                if (highlight) {
                    highlight.remove();
                }

                // Give a visual feedback to users as they move the pointer over the view
                action.on("cursor-update", function (evt) {
                    view.graphics.removeAll();
                    drawPnt = new Point({
                        x: evt.coordinates[0],
                        y: evt.coordinates[1],
                        spatialReference: view.spatialReference
                    });
                    graphic = new Graphic({
                        geometry: drawPnt,
                        symbol: sym
                    });
                    view.graphics.add(graphic);
                    if (ctrlKey &amp;amp;&amp;amp; !moveCtrlKey) {
                        draw.reset();
                        view.graphics.removeAll();
                        selectStates();
                    }
                });

                action.on("draw-complete", function (evt) {
                    drawPnt = new Point({
                        x: evt.coordinates[0],
                        y: evt.coordinates[1],
                        spatialReference: view.spatialReference
                    });

                    graphic = new Graphic({
                        geometry: drawPnt,
                        symbol: sym
                    });
                    pntGraphics.add(graphic);
                    if (ctrlKey) {
                        drawPoint();
                    } else {
                        view.graphics.removeAll();
                        selectStates();
                    }
                });
                view.focus();
            };

            function selectStates() {
                ctrlKey = false
                moveCtrlKey = false
                if (viewMouseMoveEvtHandler) {
                    viewMouseMoveEvtHandler.remove()
                    viewMouseMoveEvtHandler = null
                }
                if (viewClickEvtHandler) {
                    viewClickEvtHandler.remove()
                    viewClickEvtHandler = null
                }
                let mp = new Multipoint({
                    spatialReference: view.spatialReference
                });
                let pntArray = pntGraphics.graphics.map(function (gra) {
                    mp.addPoint(gra.geometry);
                });

                const query = {
                    geometry: mp,
                    outFields: ["*"],
                    outSpatialReference: view.spatialReference,
                    returnGeometry: true
                };

                statesLyr.queryFeatures(query)
                    .then(function (results) {
                        const graphics = results.features;

                        var employeeEditData = [
                            { name: "", id: "" },
                            { name: "", id: "" }
                        ];
                        employeeEditData = [];
                        for (var i = 0; i &amp;lt; results.features.length; i++) {
                            if (results.features[i].attributes.BUILDINGID) {
                                employeeEditData.push({
                                    name: results.features[i].attributes.BUILDINGID,
                                    id: results.features[i].attributes.OBJECTID,
                                    OBJECTID: results.features[i].attributes.OBJECTID,
                                    LONGNAME: results.features[i].attributes.LONGNAME,


                                });
                                console.log(results.features[i].attributes.OBJECTID)
                            }

                        }

                        var floorRoomAvailable = [];
                        for (var k = 0; k &amp;lt; employeeEditData.length; k++) {
                            //                                console.log (myRoomAvailableData[k].OBJECTID)
                            floorRoomAvailable.push(
                                employeeEditData[k].OBJECTID
                            );

                        }
                        console.log(floorRoomAvailable)

                        console.log(employeeEditData)

                        console.log(graphics)

                        // remove existing highlighted features
                        if (highlight) {
                            highlight.remove();
                        }

                        // highlight query results
                        highlight = statesLyrView.highlight(graphics);
                        console.log("Test")
                        pntGraphics.removeAll();
                    }).catch(function (err) {
                        console.error(err);
                    })
            }
        });
    &amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
    &amp;lt;div id="viewDiv"&amp;gt;
        &amp;lt;div id="point-button" class="esri-widget esri-widget--button esri-interactive" title="Select Countries"&amp;gt;
            &amp;lt;span class="esri-icon-map-pin"&amp;gt;&amp;lt;/span&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;

&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 11 Feb 2025 13:32:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-select-multiple-features-from-one-layer/m-p/1583977#M86510</guid>
      <dc:creator>RobertKirkwood</dc:creator>
      <dc:date>2025-02-11T13:32:26Z</dc:date>
    </item>
  </channel>
</rss>

