AnsweredAssumed Answered

Zoom to feature from Datagrid after spatial query

Question asked by rcsellman on Sep 11, 2014
Latest reply on Sep 12, 2014 by zj_zou

I am trying to set up a section in my app where you can search for features within a layer and select features within that same layer.  The results of each of these need to feed to one datagrid, from which users can click rows and zoom to the feature.  As it stands now, both the findtask and spatial query execute properly and feed to one datagrid.  However zooming to a selected feature from the datagrid only works for data that has been supplied by the find task.  When I do the spatial query, the graphics draw, the datagrid populates but I get the following error when I click on a row:

 

"Uncaught TypeError: Cannot read property 'geometry' of undefined"

 

Here's the findtask:

 

findManholesTask = new FindTask("http://summitgis.summitoh.net:6080/arcgis/rest/services/DOES/MapServer/");

 

 

                map.on("load", function() {

                    findManholesParams = new FindParameters();

                    findManholesParams.returnGeometry = true;

                    findManholesParams.layerIds = [2];

                    findManholesParams.searchFields = ["UNAME"];

                    findManholesParams.outSpatialReference = map.spatialReference;

                });

 

 

                function doDoesManholeFind() {

                    findManholesParams.searchText = dom.byId("doesManholeText").value;

  dojo.byId('manhole-result-count').innerHTML = "Searching...";

                    findManholesTask.execute(findManholesParams, showManholesResults);

                }

 

 

 

 

                function showManholesResults(results) {

  dojo.byId('manhole-result-count').innerHTML = "Results: " + results.length;

                    if (results.length > 0) {

                        map.graphics.clear();

                        var markerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_SQUARE, 10, new SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 1), new dojo.Color([0, 255, 0, 0.25]));

                        var lineSymbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASH, new dojo.Color([255, 0, 0]), 1);

                        var polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_NONE, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color([255, 0, 0]), 2), new dojo.Color([255, 255, 0, 0.25]));

 

 

                        var items5 = arrayUtils.map(results, function(result) {

                            var graphic = result.feature;

 

 

                            switch (graphic.geometry.type) {

                                case "point":

                                    graphic.setSymbol(markerSymbol);

                                    break;

                                case "polyline":

                                    graphic.setSymbol(lineSymbol);

                                    break;

                                case "polygon":

                                    graphic.setSymbol(polygonSymbol);

                                    break;

                            }

                            map.graphics.add(graphic);

                            return result.feature.attributes;

                        });

                        var data5 = {

                            identifier: "OBJECTID",

                            label: "OBJECTID",

                            items: items5

                        };

                        var store5 = new ItemFileReadStore({

                            data: data5

                        });

 

 

                        var grid = registry.byId("manholeGrid");

 

 

                        grid.setStore(store5);

                        grid.on("rowclick", onRowClickHandler);

 

 

                        //map.centerAndZoom(centerPoint, zoom);

                    } else {

                        alert("No Utility Feature or Parcel found!  Please enter a valid PARID, UNAME, PIPEID, Plant ID, PUMPID or Name.");

                    }

                }

 

 

 

The query:

 

dojo.connect(map, "onLoad", function(map) {

    //initialize the toolbar

    toolBar2 = new esri.toolbars.Draw(map);

    dojo.connect(toolBar2, "onDrawEnd", onDrawEnd);

});

 

 

var featureLayerUrl = "http://summitgis.summitoh.net:6080/arcgis/rest/services/DOES/MapServer/2";

featureLayer = new esri.layers.FeatureLayer(featureLayerUrl, {

    mode: esri.layers.FeatureLayer.MODE_ONDEMAND

});

featureLayer.setSelectionSymbol(new esri.symbol.SimpleMarkerSymbol().setSize(8).setColor(new dojo.Color([160, 214, 238])));

map.addLayer(featureLayer);

 

 

function onDrawEnd(extent) {

    toolBar2.deactivate();

 

 

    var query = new esri.tasks.Query();

    query.geometry = extent;

    featureLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW, function(features, selectionMethod) {

 

 

        var items30 = dojo.map(features, function(feature) {

            return feature.attributes;

        });

        var data30 = {

            identifier: "OBJECTID",

            items: items30

        };

        var store30 = new dojo.data.ItemFileReadStore({

            data: data30

        });

 

 

        var manholeGrid = registry.byId("manholeGrid");

 

 

        manholeGrid.on("rowclick", onRowClickHandler);

 

 

        manholeGrid.setStore(store30);

    });

}

 

 

 

 

My row click handler function:

 

function onRowClickHandler(evt) {

                    var clickedObjectf = evt.grid.getItem(evt.rowIndex).OBJECTID;

                    var selectedObjectf;

                    var distance = 50;

                    dojo.forEach(map.graphics.graphics, function(graphicf) {

                        if ((graphicf.attributes) && graphicf.attributes.OBJECTID === clickedObjectf) {

                            selectedObjectf = graphicf;

                            return;

                        }

                    });

                    if (selectedObjectf.geometry.declaredClass == 'esri.geometry.Point') {

                        var PointExtent = new esri.geometry.Extent({

                            "xmin": selectedObjectf.geometry.x - distance,

                            "ymin": selectedObjectf.geometry.y - distance,

                            "xmax": selectedObjectf.geometry.x + distance,

                            "ymax": selectedObjectf.geometry.y + distance,

                            "spatialReference": {

                                "wkid": 3728

                            }

                        });

                        map.setExtent(PointExtent);

                    } else if (selectedObjectf.geometry.declaredClass == 'esri.geometry.Polygon') {

                        var selectedParcel = selectedObjectf.geometry.getExtent();

                        map.setExtent(selectedParcel.expand(3));

                    } else if (selectedObjectf.geometry.declaredClass == 'esri.geometry.Polyline') {

                        var selectedStreetl = selectedObjectf.geometry.getExtent();

                        map.setExtent(selectedStreetl.expand(3));

                    }

                }

 

 

 

Does anyone have an idea why the row click will not work after the spatial query is performed??

 

Thanks for any help in advance!!

 

Ryan

Outcomes