Select to view content in your preferred language

Restricitng Feature Creation Area

473
1
Jump to solution
11-14-2023 04:13 AM
MQPublic
New Contributor

Hi all,
I have been trying to limit the area in which users are able to create new features using the editor, as I want to prevent the reporting of new features outside of an actionable distance. Preferably this would not allow the user to 'drop' the graphic under the cursor after selecting 'New Feature', unless the cursor is within the allowed area. I have looked at hitTest() for implementing this functionality but haven’t found a suitable solution. I was wondering if this functionality exists natively, and if not, could anyone point me in the right direction?

I am currently using the Javascript Maps SDK version 4.27, but can upgrade if needed.

Any help with this is greatly appreciated!

0 Kudos
1 Solution

Accepted Solutions
MQPublic
New Contributor
Seeing as this never got any replies, I'm revisiting having implemented a working solution.

I ended up using a GeoJsonLayer as the visual for the boundary, and utilized a hitTest() to decide whether to continue to submission handling.


const bounds = view.on("click", (event) => {
  const opts = {
    include: geoJsonBoundaryLayer
  }

  view.hitTest(event, opts).then((response) => {
    if (response.results.length) {  
      bounds.remove();
      /**
      * Handle submission or other required behaviour.
      * I ended up building my own submission function rather than using
      * the included editor.
       */
    } else {
      alert("Message to user, you are outside the boundary")
    }
  }
}

View solution in original post

0 Kudos
1 Reply
MQPublic
New Contributor
Seeing as this never got any replies, I'm revisiting having implemented a working solution.

I ended up using a GeoJsonLayer as the visual for the boundary, and utilized a hitTest() to decide whether to continue to submission handling.


const bounds = view.on("click", (event) => {
  const opts = {
    include: geoJsonBoundaryLayer
  }

  view.hitTest(event, opts).then((response) => {
    if (response.results.length) {  
      bounds.remove();
      /**
      * Handle submission or other required behaviour.
      * I ended up building my own submission function rather than using
      * the included editor.
       */
    } else {
      alert("Message to user, you are outside the boundary")
    }
  }
}
0 Kudos