Robert, I have task where I need to select a predefined value from a drop down, and based on that value it queries the underlying layers. Your widget works great if I have to query a single layer. Can anyone of you suggest a sample or a widget that I could use?
Thanks
Sonia
Solved! Go to Solution.
Sonia,
The issue is that the "this.info.innerHTML = resultItems.join("");" is inside a function that has a different scope then you want, so "this" does not know what "info" is.
You need to use lang.hitch
featureLayer1.selectFeatures(query1, FeatureLayer.SELECTION_ADD, lang.hitch(this, function(features) {
Sonia,
Sounds like you want the identify widget then.
Robert, sorry I should have elaborated my question. So the scenario is to select a unique value from a layer first. Based on the value selected from the second drop down it would populate the results tab with the underlying layers. The task is a combination of By Value & By Shape. I am not sure what would be the best method to approach this task.
Appreciate your help on this!
Sonia,
So you are wanting to search by a value (which means that you are searching based on the value of a field) and then click on the map (by shape) and have it search all layers in the map (meaning that all the layers in the map would have that exact field to be searched by)?... This is not something that has been developed. The eSearch uses the JS API's QueryTask which is for a single layer of a map service. The FindTask can search multiple layers but not by geometry only by attribute. So what you are asking for is more like an IdentifyTask but you want to limit results by attribute. Like I said this has not been developed and I have never had the need to look into this so I don't have any code for it.
Robert, I wrote some code that does gives me the desired output (county and City fields) However I cannot get the results to show up in a results tab. I am using the showresults function but it doesn't seem to work. Could you please take a look and see what I am doing wrong? I have attached the zip file for your reference. Would really appreciate your help on this....
showresults: function (results) {
var resultItems = [];
var resultCount = features.length;
for (var i = 0; i < resultCount; i++) {
var featureAttributes = features.attributes;
for (var attr in featureAttributes) {
"<b>" + attr + ":</b> " + featureAttributes[attr] + "<br>");
"<br>");
this.info.innerHTML = resultItems.join("");
Sonia,
The returned var for your function is "results" yet you never use it in your code you start using "features" but there is nothing in your code to define what features is.
Thanks Robert! Getting closer..I do see the featureattributes part working, but I don't see anything being pushed out. The console shows that this.info is undefined even though I have it in widget.html
Please advise...
var field1 = this.uniqueValuesSelect.get('value');
var queryField1 = this.mySelect.get('value');
var query1 = new Query();
query1.where = queryField1 +"='" + field1 + "'";
query1.returnGeometry = true;
query1.outFields = "SORT_TEXT","City", "County"];
featureLayer1.selectFeatures(query1, FeatureLayer.SELECTION_ADD, function(features) {
featureLayer1.setSelectionSymbol(lineSymbol);
var resultItems = [];
var resultCount = features.length;
for (var i = 0; i < resultCount; i++) {
featureAttributes = features.attributes;
(var attr in featureAttributes) {
resultItems.push("
" + attr + ":
" + featureAttributes[attr] + "}
this.info.innerHTML = resultItems.join("");
Sonia,
The issue is that the "this.info.innerHTML = resultItems.join("");" is inside a function that has a different scope then you want, so "this" does not know what "info" is.
You need to use lang.hitch
featureLayer1.selectFeatures(query1, FeatureLayer.SELECTION_ADD, lang.hitch(this, function(features) {
That works....Thanks so much Robert!
Robert,
I am having a couple of issues with the code. I am trying to specify the outFields: ["OBJECTID, SORT_TEXT, COUNTY, CITY"] but it doesn't work. It works if I put ["*"]
The other issue is it's caching the featurelayer, and not removing the selected features if I use the Reset function. I tried using the
disableClientCaching : true. Any ideas on this?