Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.41 KB | None | 0 0
  1. define([
  2. "esri/tasks/FindTask",
  3. "esri/tasks/FindParameters",
  4. "esri/symbols/SimpleLineSymbol",
  5. "esri/symbols/SimpleFillSymbol",
  6. "esri/Color",
  7.  
  8. "dgrid/Grid",
  9. "dgrid/Selection",
  10. 'dojo/_base/declare',
  11. "dojo/on",
  12. "dojo/dom",
  13. "dijit/registry",
  14. "dojo/_base/array",
  15. "dijit/form/Button",
  16. "dojo/parser",
  17. "esri/symbols/SimpleMarkerSymbol","dojo/data/ItemFileReadStore","dojox/grid/EnhancedGrid","dojo/data/ItemFileWriteStore",
  18. "dojox/grid/enhanced/plugins/Pagination","dojox/grid/enhanced/plugins/Selector","dojox/grid/enhanced/plugins/Filter","dojox/grid/enhanced/plugins/exporter/CSVWriter","dojo/io/iframe",
  19. "dojo/domReady!"],function ( FindTask, FindParameters, SimpleLineSymbol, SimpleFillSymbol, Color,
  20. Grid, Selection, declare, on, dom, registry, arrayUtils, Button, parser,SimpleMarkerSymbol,ItemFileReadStore,EnhancedGrid,ItemFileWriteStore) {
  21. return{
  22.  
  23. Find: function (map) {
  24.  
  25. var findTask, findParams;
  26.  
  27. var grid, store;
  28.  
  29.  
  30.  
  31.  
  32. parser.parse();
  33.  
  34. registry.byId("searchfind").on("click", doFind);
  35.  
  36. //Create Find Task using the URL of the map service to search
  37. findTask = new FindTask("http://...:6080/arcgis/rest/services/layers2/MapServer/");
  38.  
  39. map.on("load", function () {
  40. //Create the find parameters
  41. findParams = new FindParameters();
  42. findParams.returnGeometry = true;
  43. findParams.layerIds = [0];
  44. findParams.searchFields = ["Name"];
  45. findParams.outSpatialReference = map.spatialReference;
  46. console.log("find sr: ", findParams.outSpatialReference);
  47. });
  48.  
  49. function doFind() {
  50. //Set the search text to the value in the box
  51. var ownerNameBox = dom.byId("findName");
  52. findParams.searchText = dom.byId("findName").value;
  53. findTask.execute(findParams, showResults);
  54. }
  55. function showFilterBar(){
  56. dijit.byId('grid').showFilterBar(true);
  57. }
  58.  
  59. function showResults(results) {
  60.  
  61. //This function works with an array of FindResult that the task returns
  62. map.graphics.clear();
  63. var symbol = new SimpleMarkerSymbol();
  64. symbol.setColor(new Color([0,255,255]));
  65.  
  66. //create array of attributes
  67. var items = dojo.map(results, function (result) {
  68. var graphic = result.feature;
  69. graphic.setSymbol(symbol);
  70. map.graphics.add(graphic);
  71. return result.feature.attributes;
  72. });
  73. var data = {
  74. identifier: 'OBJECTID',
  75. label:'OBJECID',
  76. items: items
  77. };
  78.  
  79.  
  80.  
  81.  
  82. store = new dojo.data.ItemFileReadStore({data: data});
  83.  
  84. /*set up layout*/
  85. var layout = [[
  86. {'name': 'OBJECTID', 'field': 'OBJECTID', 'width':'9em',datatype:"number"},
  87. {'name': 'Name', 'field': 'Name','width':'16em',datatype:"string",autocomplete:true},
  88. {'name':'Address','field':'Address','width':'18em',datatype:"string",autocomplete:true}
  89.  
  90. ]];
  91.  
  92. /*create a new grid:*/
  93. var grid = new dojox.grid.EnhancedGrid({
  94.  
  95. id: 'grid',
  96. store:store,
  97. structure: layout, rowSelector: '1px',
  98. plugins: {
  99. // pagination: {
  100. // pageSizes: ["5", "10", "All"],
  101. // description: true,
  102. // sizeSwitch: false,
  103. // pageStepper: true,
  104. // gotoButton: true,
  105. // /*page step to be displayed*/
  106. // maxPageStep: 3,
  107. // /*position of the pagination bar*/
  108. // position: "bottom"
  109. // },
  110. filter: {
  111. // Show the closeFilterbarButton at the filter bar
  112. closeFilterbarButton: true
  113. // Set the maximum rule count to 5
  114. // ruleCount: 5,
  115. // Set the name of the items
  116. // itemsName: "songs",
  117.  
  118. }
  119.  
  120. }
  121.  
  122. },
  123.  
  124. document.createElement('div'));
  125.  
  126. /*append the new grid to the div*/
  127.  
  128. dojo.byId("grid").appendChild(grid.domNode);
  129.  
  130.  
  131.  
  132. /*Call startup() to render the grid*/
  133.  
  134. grid.startup();
  135. grid.setStore(store);
  136. grid.refresh()
  137.  
  138.  
  139.  
  140.  
  141.  
  142. }
  143. //Zoom to the parcel when the user clicks a row
  144.  
  145.  
  146.  
  147.  
  148. //display the results in the grid
  149.  
  150.  
  151.  
  152. //Zoom back to the initial map extent
  153. // map.centerAndZoom(center, zoom);
  154.  
  155.  
  156. // //Zoom to the parcel when the user clicks a row
  157. function onRowClickHandler(evt) {
  158. var clickedTaxLotId = event.rows[0].data.BRTID;
  159. var selectedTaxLot = arrayUtils.filter(map.graphics.graphics, function (graphic) {
  160. return ((graphic.attributes) && graphic.attributes.BRTID === clickedTaxLotId);
  161. });
  162. if ( selectedTaxLot.length ) {
  163. map.setExtent(selectedTaxLot[0].geometry.getExtent(), true);
  164. }
  165. }
  166.  
  167. }
  168.  
  169.  
  170. }
  171.  
  172.  
  173.  
  174. }
  175.  
  176.  
  177. )
  178.  
  179. <body class="claro" role="main">
  180. <div id="appLayout" style="width:100%; height:100%;" >
  181. </div>
  182. <!--<div id="rightpane">-->
  183. <!--</div>-->
  184.  
  185. <div id="center">
  186.  
  187. <!-->
  188. some divs
  189. <!-->
  190. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement