Select features with buffer not working properly

1439
8
Jump to solution
10-03-2014 10:25 AM
RyanSellman
Occasional Contributor II

I'm trying to incorporate an esri sample in my app, where the user clicks on the map, which creates a buffer and selects features within that buffer.  I can get the the buffer to work correctly and the selected features are drawing ok, however I'm trying to push the selected results to an enhanced datagrid and keep getting this error: "ReferenceError: array is not defined".  I feel like I'm missing something really small but can't figure it out.  Can anyone help??

Here's the code I am using:

var gridNF = new EnhancedGrid({

  structure : [

  {name: "UNAME", field : "UNAME"}

  ],

  plugins: {

  exporter: true,

  printer: true

  }

  }, "divGrid");

  gridNF.startup();

  var outFieldsNF = ["UNAME"];

  var doesFeatureLayer = new FeatureLayer("http://summitgis.summitoh.net:6080/arcgis/rest/services/DOES_Mercator/MapServer/1",{

  outFields: ["*"],

  mode: FeatureLayer.MODE_ONDEMAND

  });

  var symbol = new SimpleMarkerSymbol( 

  SimpleMarkerSymbol.STYLE_CIRCLE, 

  12, 

  new SimpleLineSymbol( 

  SimpleLineSymbol.STYLE_NULL, 

  new Color([247, 34, 101, 0.9]), 

  1 

  ), 

  new Color([207, 34, 171, 0.5]) 

  );

  doesFeatureLayer.setSelectionSymbol(symbol); 

 

  map.addLayer(doesFeatureLayer);

  var circleSymb = new SimpleFillSymbol( 

  SimpleFillSymbol.STYLE_NULL, 

  new SimpleLineSymbol( 

  SimpleLineSymbol.STYLE_SHORTDASHDOTDOT, 

  new Color([105, 105, 105]), 

  2 

  ), new Color([255, 255, 0, 0.25]) 

  ); 

 

  var circle; 

  var radius = parseInt(dom.byId("bufferDistance").value);

  map.on("click", function(evt){ 

  var radius = parseInt(dom.byId("bufferDistance").value); 

  circle = new Circle({ 

  center: evt.mapPoint, 

  geodesic: true, 

  radius: radius, 

  radiusUnit: "esriFeet" 

  });  ; 

 

  map.graphics.clear(); 

  //map.infoWindow.show(); 

           

  var graphic = new Graphic(circle, circleSymb); 

  map.graphics.add(graphic);

  var query = new Query(); 

  query.geometry = circle.getExtent(); 

  doesFeatureLayer.queryFeatures(query, selectInBuffer); 

  });

  function selectInBuffer(response){ 

  var feature; 

  var features = response.features; 

  var inBuffer = []; 

 

        

  for (var i = 0; i < features.length; i++) { 

  feature = features

  if(circle.contains(feature.geometry)){ 

  inBuffer.push(feature.attributes[doesFeatureLayer.objectIdField]); 

  } 

  } 

 

  var query = new Query(); 

  query.objectIds = inBuffer; 

         

  doesFeatureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(results){                         

           

  }); 

  

  populateGrid(response);

  } 

  function populateGrid(results) {

  var gridData;

  dataNF = array.map(results.features, function(feature) {

  return {

         

  "UNAME" : feature.attributes[outFieldsNF[1]],

  }

  });

  

  var memStore = new ItemFileWriteStore({

  data : {

  identifier: 'OBJECTID',

  items: dataNF

  }

  });

  

  gridNF.setStore(memStore);

  }

0 Kudos
1 Solution

Accepted Solutions
RyanSellman
Occasional Contributor II

Ok, I think I have it figured out, with your help of course.  In response to your last inquiry, I included the field "OBJECTID" (along with a few others) in the outFieldsNF variable:

var outFieldsNF = ["OBJECTID", "UNAME", "DRAWINGNUM", "INVERT", "STREET"]

and also, I included, "OBJECTID" here:

dataNF = arrayUtils.map(results.features, function(feature) {

  return {

  "OBJECTID" : feature.attributes[outFieldsNF[0]],

  "UNAME" : feature.attributes[outFieldsNF[1]],

  "DRAWINGNUM" : feature.attributes[outFieldsNF[2]],

  "INVERT" : feature.attributes[outFieldsNF[3]],

  "STREET" : feature.attributes[outFieldsNF[4]]

  }

  });

along with those few extra fields.  These changes seem to have it fixed!

I really appreciate your help!

View solution in original post

0 Kudos
8 Replies
KenBuja
MVP Esteemed Contributor

Did you add the array module in your require? You'll need something like

require(["dojo/_base/array"], function (array) {}

0 Kudos
RyanSellman
Occasional Contributor II

Yep!  Here's what I have in my require:

require([

                "dojo/parser",

                "esri/geometry/Extent",

                 "esri/geometry/Circle",

                 "dojo/store/Memory",

                 "dojo/data/ItemFileWriteStore",

                 "dgrid/OnDemandGrid",

                 "dojox/grid/EnhancedGrid",

                 "dojox/grid/enhanced/plugins/exporter/CSVWriter",

                 "dojox/grid/enhanced/plugins/Printer",

                 "dgrid/Selection",

                "esri/graphicsUtils",

                "esri/SpatialReference",

                "dojo/on", "dojo/dom",

                "dijit/registry",

                "esri/tasks/FindTask",

                "esri/tasks/FindParameters",

                "esri/map",

                "esri/layers/ArcGISDynamicMapServiceLayer",

                "esri/InfoTemplate",

                "dojo/dom-construct",

                "esri/dijit/Popup",

                "esri/tasks/IdentifyTask",

                "esri/tasks/IdentifyResult",

                "esri/tasks/IdentifyParameters",

                "esri/dijit/InfoWindow",

                "esri/dijit/HomeButton",

                "esri/layers/FeatureLayer",

                 "esri/toolbars/navigation",

                "esri/dijit/Legend",

                "esri/dijit/Print",

                "esri/dijit/BasemapToggle",

                "dojo/_base/array",

                "dijit/form/CheckBox",

                "dijit/form/NumberTextBox",

                "esri/dijit/BasemapGallery",

                "esri/dijit/Geocoder",

                "dojo/_base/Color",

                "esri/graphic",

                "esri/tasks/Geoprocessor",

                "esri/symbols/SimpleMarkerSymbol",

                "esri/geometry/screenUtils",

                "esri/dijit/Measurement",

                "esri/dijit/OverviewMap",

                "esri/dijit/Bookmarks",

                "esri/dijit/BasemapLayer",

                "esri/dijit/Basemap",

                "esri/dijit/BookmarkItem",

                "esri/units",

                "esri/geometry/Geometry",

                "esri/geometry/Point",

                "esri/geometry/Polyline",

                "esri/geometry/Polygon",

                "esri/dijit/Scalebar",

                "esri/dijit/AttributeInspector",

                "esri/symbols/SimpleLineSymbol",

                "dojo/query",

                "esri/symbols/SimpleFillSymbol",

                "esri/layers/ArcGISTiledMapServiceLayer",

                "esri/layers/ImageParameters",

                "esri/config",

                "esri/tasks/query",

                "esri/symbols/TextSymbol",

                "esri/renderers/SimpleRenderer",

                "esri/layers/LabelLayer",

                "dijit/form/Button",

                "dijit/form/ComboBox",

                "dijit/Dialog",

                "esri/toolbars/draw",

                "dijit/layout/BorderContainer",

                "esri/tasks/GeometryService",

                "dijit/layout/ContentPane",

                "dijit/layout/AccordionContainer",

                "dijit/layout/TabContainer",

                "dijit/layout/SplitContainer",

                "dojox/layout/ExpandoPane",

                "dojox/grid/DataGrid",

                "dojo/data/ItemFileReadStore",

                "agsjs/dijit/TOC",

                "dojo/domReady!"

            ],

            function(

                parser,

                Extent,

                 Circle,

                 Memory,

                 ItemFileWriteStore,

                 Grid,

                 EnhancedGrid,

                 CSVWriter,

                 Printer,

                 Selection,

                graphicsUtils,

                SpatialReference,

                on,

                dom,

                registry,

                FindTask,

                FindParameters,

                Map,

                ArcGISDynamicMapServiceLayer,

                InfoTemplate,

                domConstruct,

                Popup,

                IdentifyTask,

                IdentifyResult,

                IdentifyParameters,

                InfoWindow,

                HomeButton,

                FeatureLayer,

                Navigation,

                Legend,

                Print,

                BasemapToggle,

                arrayUtils,

                CheckBox,

                NumberTextBox,

                BasemapGallery,

                Geocoder,

                Color,

                Graphic,

                Geoprocessor,

                SimpleMarkerSymbol,

                screenUtils,

                Measurement,

                OverviewMap,

                Bookmarks,

                BasemapLayer,

                Basemap,

                BookmarkItem,

                Units,

                Geometry,

                Point,

                Polyline,

                Polygon,

                Scalebar,

                AttributeInspector,

                SimpleLineSymbol,

                query,

                SimpleFillSymbol,

                ArcGISTiledMapServiceLayer,

                ImageParameters,

                esriConfig,

                Query,

                TextSymbol,

                SimpleRenderer,

                LabelLayer,

                Button,

                ComboBox,

                Dialog,

                Draw,

                BorderContainer,

                GeometryService,

                ContentPane,

                AccordionContainer,

                TabContainer,

                SplitContainer,

                ExpandoPane,

                DataGrid,

                ItemFileReadStore,

                TOC

            ) {

0 Kudos
KenBuja
MVP Esteemed Contributor

Since you're passing the parameter "arrayUtils" in the function, you have to use

dataNF = arrayUtils.map(results.features, function(feature) {

RyanSellman
Occasional Contributor II

I made the change, but now get an error message saying "Cannot read property '0' if undefined". 

0 Kudos
KenBuja
MVP Esteemed Contributor

Which line are you getting this error?

0 Kudos
RyanSellman
Occasional Contributor II

In chrome dev tools its saying at line 10 of DataGrid.js...not sure if that helps much.

0 Kudos
KenBuja
MVP Esteemed Contributor

Are you sure this line is correct?


"UNAME" : feature.attributes[outFieldsNF[1]],  



You've declared that variable with only one item


var outFieldsNF = ["UNAME"];

RyanSellman
Occasional Contributor II

Ok, I think I have it figured out, with your help of course.  In response to your last inquiry, I included the field "OBJECTID" (along with a few others) in the outFieldsNF variable:

var outFieldsNF = ["OBJECTID", "UNAME", "DRAWINGNUM", "INVERT", "STREET"]

and also, I included, "OBJECTID" here:

dataNF = arrayUtils.map(results.features, function(feature) {

  return {

  "OBJECTID" : feature.attributes[outFieldsNF[0]],

  "UNAME" : feature.attributes[outFieldsNF[1]],

  "DRAWINGNUM" : feature.attributes[outFieldsNF[2]],

  "INVERT" : feature.attributes[outFieldsNF[3]],

  "STREET" : feature.attributes[outFieldsNF[4]]

  }

  });

along with those few extra fields.  These changes seem to have it fixed!

I really appreciate your help!

0 Kudos