Select to view content in your preferred language

Edit one layer when there's multiple layers on the app

619
1
12-26-2022 06:14 AM
KARIMLABIDI
Frequent Contributor

Hello, 

i would like to know if there is a way to edit one feature on the layer visible on the app whre there's n layers? I have 3 layers , i put the edit widget on the pop up and i would like to edit for each layer. My script works for one layer, I don't know how to do when there's n layers on the app.

I 'm trying with a function with an IF on the visibility of the layer but i doesn't work.

Here's my code:

 

 

view.when(() => {
            function test(){
              if (fl_proj1.visible=true) {

          // Create the Editor with the specified layer and a list of field configurations
          editor = new Editor({
            view: view,
            // Hide the snapping controls as it is not needed for this specific workflow
            visibleElements: { snappingControls: false },
            container: document.createElement("div"),

            layerInfos: [
              {
                layer: fl_proj1,
                formTemplate: {
                  // autocasts to FormTemplate
                  elements: [
                    // autocasts to FieldElement
                    {
                      type: "field",
                      fieldName: "IDARRET",
                      label: "IDAP",
                      editable: false
                    }
                  ]
                }
              }
            ]
          });
        }
        }

          // Execute each time the "Edit feature" action is clicked
          function editThis() {
            // If the Editor's activeWorkflow is null, make the popup not visible
            if (!editor.activeWorkFlow) {
              view.popup.visible = false;
              // Call the Editor update feature edit workflow

              editor.startUpdateWorkflowAtFeatureEdit(
                view.popup.selectedFeature
              );
              view.ui.add(editor, "top-right");
            }

            // Remove the editor widget from the display when the state of the editor's viewModel is "ready" and re-add the popup. Ready state indicates that the initial editor panel displays and is ready for editing.

            // The editor displays a panel to select a feature to update if the user "backs" out of the current edit workflow. This is not needed in this specific workflow as the feature is already selected from the popup. The "ready" state indicates that this initial editor panel is active and was activated via the "back" button. In this example, we remove the editor from the view and replace it with the popup.

            reactiveUtils.when(
              () => editor.viewModel.state === "ready",
              () => {
                // Remove the editor and open the popup again
                view.ui.remove(editor);
                view.popup.open({
                  fetchFeatures: true,
                  shouldFocus: true
                });
              }
            );
          }

          // Event handler that fires each time an action is clicked
          view.popup.on("trigger-action", (event) => {
            if (event.action.id === "edit-this") {
              editThis();
            }
          });
        });

        // Watch when the popup is visible
        view.popup.watch("visible", (event) => {
          // Check the Editor's viewModel state, if it is currently open and editing existing features, disable popups
          if (editor.viewModel.state === "editing-existing-feature") {
            view.popup.close();
          } else {
            // Grab the features of the popup
            features = view.popup.features;
          }
        });

        featureLayer.on("apply-edits", () => {
          // Once edits are applied to the layer, remove the Editor from the UI
          view.ui.remove(editor);

          // Iterate through the features
          features.forEach((feature) => {
            // Reset the template for the feature if it was edited
            feature.popupTemplate = template;
          });

          // Open the popup again and reset its content after updates were made on the feature
          if (features) {
            view.popup.open({
              features: features
            });
          }

          // Cancel the workflow so that once edits are applied, a new popup can be displayed
          editor.viewModel.cancelWorkflow();
        });

 

Here's a capture a the widget and the 3 layers with the visibility.

KARIMLABIDI_0-1672064296732.png

 

 I don't know if it's clear !

 

Thank you for your help.

0 Kudos
1 Reply
KARIMLABIDI
Frequent Contributor

Pleeaaaase 🙂

0 Kudos