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>
<style>
#viewDiv {
width: 800px;
height: 600px;
border: solid 1px black;
}
</style>
</head>
<body>
<script>
require(["esri/Map",
"esri/views/MapView",
"esri/layers/FeatureLayer",
"esri/widgets/Editor",
"dojo/domReady!"
],
function(Map, MapView, FeatureLayer, , 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.4917691, 14.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-size: 20px;
font-weight: bold;
font-family: sans-serif;
color: white
}
</style>
</body>
</html>