Select to view content in your preferred language

Executing a feature action in a widget: what get passed?

1684
6
Jump to solution
03-01-2017 04:08 PM
StahlyEngineering
Occasional Contributor

I have a handful of general questions about what happens when a feature action is executed.

I am attempting to do a query returning all features from Layer2 intersecting a selected feature from Layer1.

The feature action gets called from a popup that comes up after selecting a feature from Layer1.

Whenever I attempt to get specific values from the featureSet or featureLayer object I get undefined results, which makes me feel that the widget doesn't get the actual selected feature as an input.

Additionally when I refer to Layer2 via a QuaryTask or a FeatureLayer, I am unable to display any information about Layer2. 

Below is a code snippet. How am I using featureLayer and quarytask constructors wrong?

onExecute: function(featureSet, featureLayer){
WidgetManager.getInstance().triggerWidgetOpen(this.widgetId)
.then(function(myWidget) {
//Widget Action
var fName = []; //useless temp array
fName[0] = featureSet.spatialReference.wkid;
fName[1] = featureSet.displayFieldName;
console.log('log: step 0 '+featureLayer.name);

SecDiv_FL = new FeatureLayer("http://services6.arcgis.com/3aTanasiPG0rbYg4/arcgis/rest/services/PLSS_Sanders_2ndDiv/FeatureServer/...");
slct = featureLayer.getSelectedFeatures();
//var queryTask = new QueryTask("http://services6.arcgis.com/3aTanasiPG0rbYg4/arcgis/rest/services/PLSS_Sanders_2ndDiv/FeatureServer/...");

console.log('log: step 0.1 '+featureSet.features[0].attributes['FID']);
Q = new Query();
Q.returnGeometry = true;
Q.outSpatialReference = new SpatialReference({wkid:102100});
Q.geometry = featureSet.features[0].geometry;
Q.spatialRelationship = Query.SPATIAL_REL_INTERSECTS;

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

So are you getting any of your console.log statements in your console?

Since this is a widget, are there other files where I need to require those classes?

No just in the FeatureAction.

SecDiv.queryFeatures(Q,function(fset){
  console.log(fSet.features[0].attributes.SECDIVID); //should be a function of a featureset returned by queryFeatures
});

in line 1 of the above code you have fset and in line 2 you use fSet.

console.log('log: step 0.1 '+SecDiv.name); //doesn't work

Because you have not given SecDiv a name property value.

return clazz; //what does this do?

It returns the BaseFeatureAction declare 

View solution in original post

6 Replies
RobertScheitlin__GISP
MVP Emeritus

Stahly,

  Did you add the requires to your FeatureAction code for FeatureLayer, QueryTask and Query?

Also I do not see anywhere in your code posted where you actually use the Query (i.e. no queryTask.execute or SecDiv_FL.queryFeatures)

0 Kudos
StahlyEngineering
Occasional Contributor

I think I added the correct require for Query and FeatureLayer (checking the spelling/ case according to the javascript API). I've included the complete code in a reply to the original post.

Since this is a widget, are there other files where I need to require those classes?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

So are you getting any of your console.log statements in your console?

Since this is a widget, are there other files where I need to require those classes?

No just in the FeatureAction.

SecDiv.queryFeatures(Q,function(fset){
  console.log(fSet.features[0].attributes.SECDIVID); //should be a function of a featureset returned by queryFeatures
});

in line 1 of the above code you have fset and in line 2 you use fSet.

console.log('log: step 0.1 '+SecDiv.name); //doesn't work

Because you have not given SecDiv a name property value.

return clazz; //what does this do?

It returns the BaseFeatureAction declare 

StahlyEngineering
Occasional Contributor

-console.log statements:

Yes, those all work and show the correct values in the console. 

- fSet, fset:

That appeared to be the problem (I'll learn to check letter cases one of these days)

-SecDiv.name:

So to make sure, featurelayer.name is a property that I must set when constructing the object, it's not the layer's name as it is defined in the feature layer?

I've marked the question answered.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Stahly,

So to make sure, featurelayer.name is a property that I must set when constructing the object, it's not the layer's name as it is defined in the feature layer?

   You are correct the documentation states: 

The name of the layer as defined in the map service.

It is likely because the FeatureLayer was not loaded before you had the console.log line. You would need to wait for the layer to fire it's load event before checking that property.

StahlyEngineering
Occasional Contributor

Here is the entire feature action code:

define([
"dojo/_base/declare",
"jimu/BaseFeatureAction",
"jimu/WidgetManager",
"esri/tasks/FeatureSet",
"esri/tasks/query",
"esri/layers/FeatureLayer",
], function(declare, BaseFeatureAction, WidgetManager, FeatureSet, Query, FeatureLayer){
var clazz = declare(BaseFeatureAction, {
iconFormat: 'png',
isFeatureSupported: function(featureSet){
return featureSet.displayFieldName == 'OwnerName';
},

onExecute: function(featureSet, featureLayer){
WidgetManager.getInstance().triggerWidgetOpen(this.widgetId)
.then(function(myWidget) {
//Widget Action
var fName = []; //useless temp array
fName[0] = featureSet.spatialReference.wkid;
fName[1] = featureSet.displayFieldName;
console.log('log: step 0 '+featureLayer.name);

SecDiv = new FeatureLayer("http://services6.arcgis.com/3aTanasiPG0rbYg4/arcgis/rest/services/PLSS_Sanders_2ndDiv/FeatureServer/..."); //likely broken
console.log('log: step 0.1 '+featureSet.features[0].attributes.PARCELID); //works
console.log('log: step 0.1 '+SecDiv.name); //doesn't work
Q = new Query();
Q.geometry = featureSet.features[0].geometry;
Q.outFields = [ "*" ];
Q.spatialRelationship = Query.SPATIAL_REL_INTERSECTS;
Q.returnGeometry = true;
console.log('log: step 0.2 '+Q.geometry.type);
console.log('log: step 0.3 '+featureLayer.displayField);
SecDiv.queryFeatures(Q,function(fset){
console.log(fSet.features[0].attributes.SECDIVID); //should be a function of a featureset returned by queryFeatures
});
myWidget.SelectParcels(fName); //useless temp output
});
}
});
return clazz; //what does this do?
});

0 Kudos