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
Solved! Go to Solution.
John,
So you say "in my web map" do you mean you are using code like this?
var webMapItemID = "c41d5f3b4e304806a047702fbfc2759e"; deferred = arcgisUtils.createMap(webMapItemID, "ui-map", createMapOptions);
Then you say you are using IdentifyTask so the code I was providing will have no impact as you are seeing (these are the type of details you should lead with). Normally developers fire the IdentifyTask from a map.on('click', dosomething); event is that your case? If so then you just need to use a pauseable event listener or remove the map on click event and then re-add it after the measure is done.
No, this is a javascript web map. I'm making it in Visual Studio, with some C# code-behind (the latter of which is irrelevant to this particular issue).
Yes, I'm doing a map.on('click', dosomething);
Not sure what you mean by a pausable event listener??
John,
Sorry you keep using terminology that has specific meaning to developer using the JS API (web map is an AGOL/Portal item that is a map that can be referenced by item id). So when using Dojo "on" you can create a pausable event listener.
https://dojotoolkit.org/reference-guide/1.9/dojo/on.html#pausable
Using on.pausable is my recomendation for your use case.
OK thanks for the link. Didn't know there were pausable listeners.
So if I have:
map.on("click", executeIdentifyTask);
How would I change that to a pausible one? Would it be:
var handler = on.pausible(map, "click", executeIdentifyTask);
Not sure if I can use "map" where the code in your link says "button"??
Nevermind that worked. Thanks for the help!
Actually, I just figured out it doesn't really work after all. To clear a measurements graphic after you're done drawing it, you have to click on one of the measurement tools . Unfortunately, doing so pauses the pausable listener that I just created to prevent the popup from popping up. So, if you want to resume clicking on parcels and getting the popup, you're not allowed to clear the measurement graphic first. That's unrealistic to expect users to figure out.
Basically I solved one problem but created another.
John,
The measurement tools are toggle buttons so when there is no tool toggled on then you unpause the map click event listener.
Unfortunately, as far as I can tell there is no way to un-toggle one of the measurement buttons via code.
Measurement | API Reference | ArcGIS API for JavaScript 3.22
Clicking on the buttons creates the problem I described above. Once the measurement is done drawing, I'd need to write some code like: distanceButton.Clicked = false in the "measure-end" handler. However I don't see anything like that in the API.
In the code for my "tool-change" handler I tried:
if(handler.pause()) handler.resume();
else handler.pause();
Unfortunately, pause and resume don't seem to return anything. Would be nice if they returned a boolean.
Not making layers selectable and unselectable seems to be a major shortfall in the API.
John,
It is just a matter of your coded workflow. The API is fully capable of handling your desired work flow with out issue. Can you share your code on how you are adding the click handler and how you are pausing it using which measure dijit event?
The way I handle this situation in my code is:
aspect.after(measurement, 'setTool', lang.hitch(this, function() {
if (measurement.activeTool) {
disableWebMapPopup();
} else {
enableWebMapPopup();
}
}));