How to toggle/change selectability of a Feature layer?

3623
28
Jump to solution
11-02-2017 07:51 AM
JohnAdams
New Contributor III

Hello,

I'm creating a web map in which I will need to change/toggle the selectability of a Feature layer. Is there any way to do this? I've looked through the API for the FeatureLayer class but don't see anything like what I'm looking for:

FeatureLayer | API Reference | ArcGIS API for JavaScript 3.22 

I would expect to see something like "IsSelectable" or "Seletable" but don't see anything like it. In Server Manager there is also nothing to change the selectability of my service. Is it not possible to do this at all, or am I missing something?

Thanks

0 Kudos
1 Solution

Accepted Solutions
JohnAdams
New Contributor III

Thanks. I seem to have come across a solution that does what I want it to do. I have:

measurement.on("tool-change", disablepopup);
function disablepopup()
{
     handler.pause();
}

And ...

measurement.on("measure-end", enablepopup);
function enablepopup()
{
     measurement.setTool(measurement.activeTool, false);
     handler.resume();
}

This makes it so that when the user clicks on one of the tools, the handler is paused. Then - and this is important - once they're done drawing the measurement, the tool is re-set and the handler is resumed. The reason I want this is because I'm assuming the typical user might want to immediately start selecting parcels again after they've made a measurement without having to press any other buttons. So the flow would be:

1. Click measure tool

2. Make measurment

3. OK to click on parcel

If they want to make another measurement right after they made the first one, *then* they'll have to press one of the measure buttons again, but I don't consider that to be a big deal. Once the user sees the measure tool button not depressed anymore, they'll automatically go and re-press it if they want to. So the flow would be:

1. Click measure tool

2. Make measurement

3. Click measure tool

4. Make measurement

5. Etc., or OK to click on parcel, too

The Clear Graphics button is basically the same thing as the "measure-end" handler, except that it also clears the graphics. I figured out you need to put ClearResult() before you re-set the tool, otherwise the ClearResult() doesn't work:

function cleargraphics()
{
    measurement.clearResult();
    measurement.setTool(measurement.activeTool, false);
    handler.resume();
}

I'm using IE 11.

Your implementation worked on your host there, I don't know why it doesn't work on my computer, but I've been dealing with that sort of thing ever since I started this job, so I'm used to it. As I said, I think it might be a network security issue. This would explain why it worked when you hosted it but not when I tried to run your code on my local machine. I think our network folks have things set up in everybody's localhost pretty restrictively, or something.

One thing that doesn't work with anything above 3.15 are my navigation tools and bookmarks. However, I like them the way I've got them there so I don't mind. There have been other things that don't work but I forget which ones off the top of my head.

View solution in original post

0 Kudos
28 Replies
RobertScheitlin__GISP
MVP Emeritus

John,

   The ArcMap concept of selectability is not something that exists in JS API. What exactly are you wanting to prevent in your app?

0 Kudos
JohnAdams
New Contributor III

I have a Measurement tool that is also selecting the underlying parcel layer when the user clicks on the map to make a measurement. When that happens I have a popup with some features from that parcel layer that also pops up. That is, when the user tries to make a measurement they also get this annoying popup from the parcel they happened to click on. If I could temporarily disable the parcel layer's selectability I could have them make a measurement without having this other annoying popup come up.

In ArcGIS Online somehow they manage to make the measurement tool not select the underlying layers when you're clicking on the map to make a measurement. But I don't know how they achieve that. That's what I'm trying to replicate.

In general the whole selectability issue is a bit annoying, because even when I set my parcel layer to "not visible" or turn it off, it's *still* selectable.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

John,

   OK, I understand your use of "selectablity" now. To disable the layer popup you just set the map.setInfoWindowOnClick method to false:

https://developers.arcgis.com/javascript/3/jsapi/map-amd.html#setinfowindowonclick 

0 Kudos
JohnAdams
New Contributor III

Doesn't work. I need a way to have the user disable the popup when they click on a measurement tool. I tried this:

measurement.on("tool-change", disablepopup);
function disablepopup()
{  map.setInfoWindowOnClick(false);  }

This would make it so that when the user clicked on one of the measurement tools to make a measurement, the popup would be disabled. Then, I would do something like this:

measurement.on("measure-end", enablepopup);
function enablepopup()
{  map.setInfoWindowOnClick(true);  }

Unfortunately, the first one (disable) does nothing. I know the function is getting invoked because when I put an alert box in there it does pop up, but it doesn't disable my info window.

I think maybe the setInfoWindowOnClick event only lasts the duration of the function I've put it in. I tried writing it like: measurement.on("tool-change", map.setInfoWindowOnClick(false));

...but it just hangs.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

John,

   Is your map coming from a WebMap?

0 Kudos
JohnAdams
New Contributor III

I have a basemap and a parcel layer, which is a feature layer. Pretty standard stuff.

Another thing I just tried is to set the activation of the IdentityTask info window on a double click instead of a single click. That way when the user selects a measure tool they only click once to get the measurement started and the popup doesn't pop up. Unfortunately, they need to double-click to complete the measurement, at which point the info window still pops up anyway. So all I did was reduce the # of popups from two to one.

0 Kudos
JohnAdams
New Contributor III

Also, having them double-click on a parcel to get the info window to pop up makes the map zoom in, which is a bit annoying and is something I don't want.

As I said before, in ArcGIS Online when you use the measure tool it doesn't select any underlying features, so it must be possible to do what I want to do ... somehow.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

John,

  It absolutely is the issue is that I need more info to help. So back to my last question are you using a WebMap coming from AGOL/Portal or are you adding Layers in your code to the Map class? Are you using an IdentifyTask or just a standard PopupTemplate for your parcel layer?

0 Kudos
JohnAdams
New Contributor III

I'm adding layers to code in my web map. This is a javascript map not an ArcGIS Online map.

I'm using an IdentifyTask, not a standard popup template.

0 Kudos