ready(function(){ parser.parse(); // create the dgrid window.grid = new (declare([Grid, Selection]))({ columns: { "OBJECTID": "OBJECTID", "NAME": "Name", "OWNER": "Owner", "COUNTY": "County", "LATITUDE": "Latitude", "LONGITUDE": "Longitude" //"median": { "label": "Median Net Worth", "formatter": dojoNum.format }, //"over1m": { "label": "Households Net Worth > $1M", "formatter": dojoNum.format } } }, "grid"); // add a click listener on the ID column grid.on(".field-OBJECTID:click", selectState); var bounds = new Extent({ "xmin": 1292510.8077427894, "ymin": 60762.840879261494, "xmax": 2759293.81036745, "ymax": 1233497.6866797954, "spatialReference": { "wkid": 3361 } }); window.map = new Map("map", { extent: bounds, logo:false }); var tiledMapServiceLayer = new esri.layers.ArcGISTiledMapServiceLayer(""); map.addLayer(tiledMapServiceLayer var content = "<b>Name</b>: ${NAME}" + "<br /><b>Owner</b>: ${OWNER}" + "<br /><b>County</b>: ${COUNTY}" + "<br /><b>Acres</b>: ${ACRES}" + "<br /><b>Game Zone</b>: ${GAMEZONE}" + "<br /><b>DNR Region</b>: ${DNRREGION}" + "<br /><b>Latitude</b>: ${LATITUDE}" + "<br /><b>Longitude</b>: ${LONGITUDE}"; var infoTemplate = new InfoTemplate("Dove Field", content); window.statesUrl = ""; window.outFields = ["OBJECTID", "NAME", "OWNER", "COUNTY", "LATITUDE", "LONGITUDE"];//NEED TO ADD IN URL AFTER ADDING FIELD var fl = new FeatureLayer(window.statesUrl, { id:"states", mode: esri.layers.FeatureLayer.MODE_ONDEMAND, outFields: ["OBJECTID", "NAME", "OWNER", "COUNTY", "LATITUDE", "LONGITUDE"],//NEED TO ADD IN URL AFTER ADDING FIELD infoTemplate: infoTemplate, }); fl.on("load", function () { fl.maxScale = 0; // show the states layer at all scales fl.setSelectionSymbol(new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_SQUARE, 20).setColor('#700000')); }); // fl.on("click", selectGrid); var scalebar = new Scalebar({ map: map, scalebarUnit: "dual", attachTo:"bottom-center" }); fl.on("mouse-over", function () { map.setMapCursor("pointer"); }); fl.on("mouse-out", function () { map.setMapCursor("default"); }); map.addLayers([fl]); map.on("load", function (evt) { domStyle.set(registry.byId("mainWindow").domNode, "visibility", "visible"); populateGrid(Memory); // pass a reference to the MemoryStore constructor }); map.on("layers-add-result", function (evt) { var layerInfo = arrayUtils.map(evt.layers, function (layer, index) { return { layer: layer.layer, title: layer.layer.name }; }); if (layerInfo.length >= 0) { var legendDijit = new Legend({ map: map, layerInfos: layerInfo }, "legendDiv"); legendDijit.startup(); } }); function populateGrid(Memory) { var qt = new QueryTask(window.statesUrl); var query = new Query(); query.where = "1=1"; query.returnGeometry = false; query.outFields = window.outFields; qt.execute(query, function (results) { var data = array.map(results.features, function (feature) { return { "OBJECTID": feature.attributes[window.outFields[0]], "NAME": feature.attributes[window.outFields[1]], "OWNER": feature.attributes[window.outFields[2]], "COUNTY": feature.attributes[window.outFields[3]], "LATITUDE": feature.attributes[window.outFields[4]], "LONGITUDE": feature.attributes[window.outFields[5]] } }); window.grid.renderArray(data) }); } // fires when a row in the dgrid is clicked function selectState(e) { // select the feature var fl = map.getLayer("states"); var query = new Query(); query.objectIds = [parseInt(e.target.textContent)]; //query.objectIds = [parseInt(e.target.innerHTML)]; fl.selectFeatures(query, FeatureLayer.SELECTION_NEW, function (result) { if (result.length) { // re-center the map to the selected feature //window.map.centerAt(result[0].geometry.getExtent().getCenter()); window.map.centerAt(result[0].geometry); } else { console.log("Feature Layer query returned no features... ", result); } }); } // fires when a feature on the map is clicked - ORIGINAL CODE function selectGrid(e) { var id = e.graphic.attributes.OBJECTID; // select the feature that was clicked var query = new Query(); query.objectIds = [id]; var states = map.getLayer("states"); states.selectFeatures(query, FeatureLayer.SELECTION_NEW); // select the corresponding row in the grid // and make sure it is in view grid.clearSelection(); grid.select(id); grid.row(id).element.scrollIntoView(); } }); });
Solved! Go to Solution.
require([ "dojo/data/ObjectStore", "esri/symbols/SimpleFillSymbol", "esri/tasks/QueryTask", "esri/tasks/query", "dojo/_base/declare", "dojo/number", "dijit/registry", "dojo/store/Memory", "dgrid/OnDemandGrid", "dgrid/Selection", "esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleMarkerSymbol", "dojo/dom-construct", "esri/map", "esri/layers/FeatureLayer", "esri/geometry/Extent", "esri/InfoTemplate", "dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dijit/layout/TabContainer", "esri/dijit/Legend", "dojo/_base/array", "dojo/parser", "dijit/form/ToggleButton", "dojo/dom-style", "dojo/dom", "esri/dijit/Scalebar", "dojo/ready", "dojo/on", "dijit/form/DropDownButton", "dojo/domReady!" ], function ( ObjectStore, SimpleFillSymbol, QueryTask, Query, declare, dojoNum, registry, Memory, Grid, Selection, SimpleLineSymbol, SimpleMarkerSymbol, domConstruct, Map, FeatureLayer, Extent, InfoTemplate, BorderContainer, ContentPane, TabContainer, Legend, arrayUtils, parser, ToggleButton, domStyle, dom, Scalebar, ready, on, DropDownButton )
var data = array.map(results.features, function (feature) { return { "OBJECTID": feature.attributes[window.outFields[0]], "NAME": feature.attributes[window.outFields[1]], "OWNER": feature.attributes[window.outFields[2]], "COUNTY": feature.attributes[window.outFields[3]], "LATITUDE": feature.attributes[window.outFields[4]], "LONGITUDE": feature.attributes[window.outFields[5]] } });
var data = array.map(results.features, function (feature) {
var data = arrayUtils.map(results.features, function (feature) {