How to use esri/widgets/Editor with all FeatureLayers in my map? it doesn't work !

351
1
07-14-2021 07:47 AM
AbirELTAIEF1
New Contributor II

I have featurelayers and I need to loop through all my featurelayers (in my map), to apply the Editor widget "esri/widgets/Editor", to the layers in my map (uploaded from Arcgis server online), because I need to add (edit, delete, update capibilities to my featurelayers in the same document) : could you please guide me, here you find my code, I have this error message, when I run it

"Uncaught (in promise) TypeError: view.map.loadAll is not a function at code.html: 410 "

I understand now that this method loadAll is for a WebMap), but how to do with my featurelayers (I only have featurelayers) and thanks. I tried to delete :( view1.map.loadAll().then(() => )   and replace (view1.map.forEach(layer)=>)  by (view1.map.layers(layer) => ), but it gives me also another message error: 

Uncaught TypeError: r.load is not a 4.20:1879 function
at w.B._createLayerView (4.20:1879)
at E.A.z._doWork [as callback] (4.20:1875)
at u (4.20:168)
at 4.20:172
here my all the code

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ArcGis_API_JS</title>
    <link rel="stylesheet" href="https://js.arcgis.com/4.20/esri/themes/light/main.css">
    <script src="https://js.arcgis.com/4.20/"></script>
    <style>
        #viewDiv {
            width800px;
            height600px;
            bordersolid 1px black;
        }
    </style>

</head>

<body>
    <script>
        require(["esri/Map",
                "esri/views/MapView",
                "esri/layers/FeatureLayer",
                "esri/widgets/Editor",
                "dojo/domReady!"
            ],
            function(MapMapViewFeatureLayer, , Editor) {
                let pointLayer;
                let polygonLayer;



                let mypopup = {
                    title: "{Loc_Eng}",
                    content: [{
                        type: "fields",
                        fieldInfos: [{
                            fieldName: "Total_Pop",
                            label: "Population"
                        }, {
                            fieldName: "Total_M",
                            label: "Male"
                        }, {
                            fieldName: "Total_Fe",
                            label: "Female"
                        }]
                    }]
                };



                //Localities
                let featureLayer1 = new FeatureLayer({
                    popupTemplate: mypopup,

                });

                //Rivers
                let featureLayer2 = new FeatureLayer({
                    minScale: 100000000

                });


                let map1 = new Map({
                    basemap: "satellite",
                    ground: "world-elevation",

                });
                map1.add(featureLayer1)
                map1.add(featureLayer2)

                let view1 = new MapView({
                    map: map1,
                    container: "viewDiv",
                    center: [29.491769114.5844444],
                    zoom: 4
                });

                view1.when(() => {
                    view1.map.loadAll().then(() => {
                        view1.map.forEach((layer=> {
                            if (layer.type === "feature") {
                                switch (layer.geometryType) {
                                    case "polygon":
                                        polygonLayer = layer;
                                        break;
                                    case "point":
                                        pointLayer = layer;
                                        break;
                                }
                            }
                        });

                        // Create layerInfos for layers in Editor. This
                        // sets the fields for editing.

                        const pointInfos = {
                            layer: pointLayer,
                            fieldConfig: [{
                                name: "LOCALITY",
                                label: "Locality"
                            }, {
                                name: "SETTLEMENT",
                                label: "SETTLEMENT"
                            }]
                        };

                        const polyInfos = {
                            layer: polygonLayer,
                            fieldConfig: [{
                                name: "DATE_ ",
                                label: "DATE"
                            }, {
                                name: "NAME",
                                label: "NAME"
                            }]
                        };

                        const editor = new Editor({
                            view: view,

                            layerInfos: [{
                                layer: pointLayer,
                                fieldConfig: [pointInfos]
                            }, {
                                layer: polygonLayer,
                                fieldConfig: [polyInfos]
                            }],
                            // Set the snapping options for the Editor. By default, snapping is enabled. This can be toggled on/off using the CTRL key.
                            snappingOptions: {
                                enabled: true,
                                selfEnabled: true,
                                featureEnabled: true,
                                featureSources: [{
                                    layer: pointLayer
                                }, {
                                    layer: polygonLayer
                                }]
                            }
                        });
                        // Add widget to top-right of the view
                        view1.ui.add(editor"top-right");
                    });
                });



            });
    </script>

    <div id="viewDiv"></div>

    <span id="help-window"></span>
    <style>
        #help-window {
            font-size20px;
            font-weightbold;
            font-familysans-serif;
            colorwhite
        }
    </style>
</body>

</html>

 

 

 

Tags (1)
0 Kudos
1 Reply
KenBuja
MVP Honored Contributor

You can use this syntax to cycle through all the layers in your map

view.when(() => {
  view.map.layers.forEach((layer) => {
    //your code
  });
});
0 Kudos