Select to view content in your preferred language

WAB feature actions code ???

8886
42
Jump to solution
01-02-2018 11:41 AM
CharlesBailey
Occasional Contributor

Where does the feature actions code go in the select widget manifest? What's wrong with this? Can someone please show me a correct sample? Thanks, cob

{
"name": "Select2",
"platform": "HTML",
"version": "2.6",
"wabVersion": "2.6",
"author": "Esri R&D Center Beijing",
"description": "",
"copyright": "",
"license": "http://www.apache.org/licenses/LICENSE-2.0",
"properties": {
"supportMultiInstance": false,

"featureActions": [{
"name": "ShowVertex",
"uri": "ShowVertexFeatureAction"
}]
}

}

0 Kudos
42 Replies
CharlesBailey
Occasional Contributor

?OK, finally got that error to disappear - back to the 'not a constructor error'- Here's the edited code too. Thanks-cob

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Charles,

   Your onExecute is not a function in your code the way you have your code setup... all those requires you have there need to be combined with the initial require array list and your onExecute need to be an actual function.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Cob,

  This is what I would expect the code to look like:

 define([
   'dojo/_base/declare',
   'jimu/BaseFeatureAction',
   'jimu/WidgetManager',
   "dojo/dom",
   "dojo/_base/lang",
   "dojo/json",
   "esri/tasks/GeometryService",
   "esri/tasks/AreasAndLengthsParameters"
 ], function(declare, BaseFeatureAction, WidgetManager, dom, lang, json, GeometryService, AreasAndLengthsParameters) {
   var clazz = declare(BaseFeatureAction, {

     iconFormat: 'png',

     isFeatureSupported: function(featureSet) {
       return featureSet.features.length > 0 && featureSet.features[0].geometry.type !== 'point';
     },

     onExecute: function(featureSet){
       var geometry = featureSet.features[0].geometry;
       var geometryService = new GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
       geometryService.on("areas-and-lengths-complete", lang.hitch(this, function(evtObj){
         var result = evtObj.result;
         console.log(json.stringify(result));
         dom.byId("area").innerHTML = result.areas[0].toFixed(3) + " acres";
         dom.byId("length").innerHTML = result.lengths[0].toFixed(3) + " feet";
       }));

       //setup the parameters for the areas and lengths operation
       var areasAndLengthParams = new AreasAndLengthsParameters();
       areasAndLengthParams.lengthUnit = GeometryService.UNIT_FOOT;
       areasAndLengthParams.areaUnit = GeometryService.UNIT_ACRES;
       geometryService.simplify([geometry], lang.hitch(this, function(simplifiedGeometries) {
         areasAndLengthParams.polygons = simplifiedGeometries;
         geometryService.areasAndLengths(areasAndLengthParams);
       }));
     }
   });
   return clazz;
 });‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I am not convinced that you will get access to your area and length dom objects the way you are doing it though.

0 Kudos
CharlesBailey
Occasional Contributor

Just changed computers and had to start over(again) – it doesn’t seem to like the simplify method in line 33…but when I comment out that part of the line is says unexpected token in line 36 (with the })):)). If I do anything to that line the whole thing blows up and won’t show my feature action in the ellipse dropdown (which has happened like a thousand times).

I had a ? about the DOM but need to get the code working first. Thanks Robert - cob

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Charles,

   OK, then change this line:

var geometry = featureSet.features[0].geometry;
0 Kudos
CharlesBailey
Occasional Contributor

Now it has the Access-Control-Allow-Origin error – I’ve seen this before but have never been able to fix it – is it something in the index.html? Thanks, cob

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

cob,

  try replacing the GeomertyService url with your own GeometryService url then.

0 Kudos
CharlesBailey
Occasional Contributor

You mean, like the one on our arcgis server?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

yep

0 Kudos
CharlesBailey
Occasional Contributor

Ok that sort of works, but has to be on the network and most of our users are just in AGOL via internet. Is there any way to do it using the esri public service?

0 Kudos