Select to view content in your preferred language

disable geometryUpdatesEnabled

423
2
Jump to solution
12-05-2023 04:25 PM
LefterisKoumis
Frequent Contributor

I tried to modify this example to disable the editing of geometry of existing features, but it doesn't work. Bug?

https://codepen.io/lkoumis1/pen/MWLZPyJ?editors=1000

 

const editor = new Editor({
            view: view,
            // Pass in the configurations created above
            layerInfos: [{
              layer:editConfigCrimeLayer,
              geometryUpdatesEnabled: false
            },
            {layer:editConfigPoliceLayer,
            geometryUpdatesEnabled: false
            }],

 

Reference: https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Editor.html#layerInfos 

0 Kudos
1 Solution

Accepted Solutions
JoelBennett
MVP Regular Contributor

No, the problem here is that those properties have been added in the wrong location.  Instead, see lines 74, 88, and 125 below:

<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
    <title>Editor widget with configurations | Sample | ArcGIS Maps SDK for JavaScript 4.28</title>
    <link rel="stylesheet" href="https://js.arcgis.com/4.28/esri/themes/light/main.css" />
    <script src="https://js.arcgis.com/4.28/"></script>

    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }

    </style>

    <script>
      require(["esri/WebMap", "esri/views/MapView", "esri/widgets/Editor"], function (
        WebMap,
        MapView,
        Editor
      ) {
          let editConfigCrimeLayer, editConfigPoliceLayer;

          // Create a map from the referenced webmap item id
          let webmap = new WebMap({
            portalItem: {
              id: "154ba34201774bb29f7c3b68adf52b6a"
            }
          });

          let view = new MapView({
            container: "viewDiv",
            map: webmap
          });

        view.when(() => {
          // Create a custom group to separate the different areas of crime.
          // This function takes a 'grouping' object which contains a feature template and a feature layer.

          function customGroup(grouping) {
            // If the layer is 'Police routes', do not group.
            let groupHeading = "Police Routes";
            if (grouping.layer.title.toLowerCase() === "crime map") {
              switch (grouping.template.name) {
                case "Criminal Homicide":
                case "Rape":
                case "Robbery":
                case "Aggravated Assault":
                  groupHeading = "Violent Crime";
                  break;
                case "Arson":
                case "Burglary":
                case "Larceny":
                case "Motor Vehicle Theft":
                  groupHeading = "Property Crime";
                  break;
                default:
                  groupHeading = "Quality of Life";
              }
            }
            return groupHeading;
          }

          // Loop through the webmap's layers and set an edit configuration
          view.map.layers.forEach((layer) => {
            if (layer.title === "Police routes") {
              editConfigPoliceLayer = {
                layer: layer,
                geometryUpdatesEnabled: false,
                formTemplate: { //autocastable to FormTemplate
                // Set it so that only one field displays within the form
                  elements: [{ // autocastable to FieldElement
                    type: "field",
                    fieldName: "PatrolType",
                    label: "Patrol Type"
                  }]
                }
              };
            } else {
              // Specify a few of the fields to edit within the form
              editConfigCrimeLayer = {
                layer: layer,
                geometryUpdatesEnabled: false,
                formTemplate: { // autocastable to FormTemplate
                  elements: [{ // autocastable to FieldElement
                      type: "field",
                      fieldName: "fulladdr",
                      label: "Full Address"
                    },
                    {
                      type: "field",
                      fieldName: "neighborhood",
                      label: "Neighborhood"
                    },
                    {
                      type: "field",
                      fieldName: "ucrdesc",
                      label: "UCR Description"
                    },
                    {
                      type: "field",
                      fieldName: "crimecategory",
                      label: "Category"
                    },
                    {
                      type: "field",
                      fieldName: "casestatus",
                      label: "Status"
                    }
                  ]
                }
              };
            }
          });

          // Create the Editor
          const editor = new Editor({
            view: view,
            // Pass in the configurations created above
            layerInfos: [editConfigCrimeLayer, editConfigPoliceLayer],
            // Override the default template behavior of the Editor widget
            supportingWidgetDefaults: {
              featureTemplates: {
                groupBy: customGroup
              }
            }
          });

          // Add widget to the view
          view.ui.add(editor, "top-right");
      });
    });
  </script>
</head>

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

</html>

 

View solution in original post

0 Kudos
2 Replies
JoelBennett
MVP Regular Contributor

No, the problem here is that those properties have been added in the wrong location.  Instead, see lines 74, 88, and 125 below:

<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
    <title>Editor widget with configurations | Sample | ArcGIS Maps SDK for JavaScript 4.28</title>
    <link rel="stylesheet" href="https://js.arcgis.com/4.28/esri/themes/light/main.css" />
    <script src="https://js.arcgis.com/4.28/"></script>

    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }

    </style>

    <script>
      require(["esri/WebMap", "esri/views/MapView", "esri/widgets/Editor"], function (
        WebMap,
        MapView,
        Editor
      ) {
          let editConfigCrimeLayer, editConfigPoliceLayer;

          // Create a map from the referenced webmap item id
          let webmap = new WebMap({
            portalItem: {
              id: "154ba34201774bb29f7c3b68adf52b6a"
            }
          });

          let view = new MapView({
            container: "viewDiv",
            map: webmap
          });

        view.when(() => {
          // Create a custom group to separate the different areas of crime.
          // This function takes a 'grouping' object which contains a feature template and a feature layer.

          function customGroup(grouping) {
            // If the layer is 'Police routes', do not group.
            let groupHeading = "Police Routes";
            if (grouping.layer.title.toLowerCase() === "crime map") {
              switch (grouping.template.name) {
                case "Criminal Homicide":
                case "Rape":
                case "Robbery":
                case "Aggravated Assault":
                  groupHeading = "Violent Crime";
                  break;
                case "Arson":
                case "Burglary":
                case "Larceny":
                case "Motor Vehicle Theft":
                  groupHeading = "Property Crime";
                  break;
                default:
                  groupHeading = "Quality of Life";
              }
            }
            return groupHeading;
          }

          // Loop through the webmap's layers and set an edit configuration
          view.map.layers.forEach((layer) => {
            if (layer.title === "Police routes") {
              editConfigPoliceLayer = {
                layer: layer,
                geometryUpdatesEnabled: false,
                formTemplate: { //autocastable to FormTemplate
                // Set it so that only one field displays within the form
                  elements: [{ // autocastable to FieldElement
                    type: "field",
                    fieldName: "PatrolType",
                    label: "Patrol Type"
                  }]
                }
              };
            } else {
              // Specify a few of the fields to edit within the form
              editConfigCrimeLayer = {
                layer: layer,
                geometryUpdatesEnabled: false,
                formTemplate: { // autocastable to FormTemplate
                  elements: [{ // autocastable to FieldElement
                      type: "field",
                      fieldName: "fulladdr",
                      label: "Full Address"
                    },
                    {
                      type: "field",
                      fieldName: "neighborhood",
                      label: "Neighborhood"
                    },
                    {
                      type: "field",
                      fieldName: "ucrdesc",
                      label: "UCR Description"
                    },
                    {
                      type: "field",
                      fieldName: "crimecategory",
                      label: "Category"
                    },
                    {
                      type: "field",
                      fieldName: "casestatus",
                      label: "Status"
                    }
                  ]
                }
              };
            }
          });

          // Create the Editor
          const editor = new Editor({
            view: view,
            // Pass in the configurations created above
            layerInfos: [editConfigCrimeLayer, editConfigPoliceLayer],
            // Override the default template behavior of the Editor widget
            supportingWidgetDefaults: {
              featureTemplates: {
                groupBy: customGroup
              }
            }
          });

          // Add widget to the view
          view.ui.add(editor, "top-right");
      });
    });
  </script>
</head>

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

</html>

 

0 Kudos
LefterisKoumis
Frequent Contributor

THank you. It works. I thought it was a bug based on the ESRI's example. But actually the code posted is missing some commas and it breaks the code.

LefterisKoumis_0-1701889388182.png