Solved! Go to Solution.
function addrList(results) { var template = ""; var addr = results.features; template = "<i>Streets Found: " + addr.length + "</i>"; template += "<table border='1'>"; template += "<tr>" template += "</tr>"; for (var i = 0, il = addr.length; i < il; i++) { template += "<tr>"; template += "<td>"+ addr.attributes["PRIMARYADD"] +" "+ addr.attributes["ZN"] +"</td>"; template += '<td><a href="#" onclick="featureZoom(AddrResults.features['+ i +']); return false;">(Zoom To)</a></td>'; template += "</tr>"; } template += "</table>"; return template; }
function AddressSearchTask(stnum, stname, stcity) { streetname = stname.toUpperCase(); queryTask = new QueryTask("http://192.168.20.14:6080/arcgis/rest/services/emap12/MapServer/17"); query = new Query(); query.returnGeometry = true; query.outFields = ["PRIMARYADD", "ZN"]; query.where = "HOUSENUMBE = '" + stnum + "' AND PRIMARYNAM LIKE '%" + streetname + "%'"; if(stcity != 0) { query.where = "HOUSENUMBE = '" + stnum + "' AND PRIMARYNAM LIKE '%" + streetname + "%' AND ZN = '" + stcity + "'"; } queryTask.execute(query, pickAddress); }
function pickAddress(results) { AddrFeatures = results.features; console.log(results); var scount = AddrFeatures.length; switch(scount) { case 0: showMessage("asmessages", "Address not found"); break; case 1: zoomToStreet(results); break; default: AddrResults = {displayFieldName: null, features:[]}; for (var i = 0; i < scount; i++) { var aResult = AddrFeatures; if (!AddrResults.displayFieldName){ AddrResults.displayFieldName = aResult.displayFieldName } AddrResults.features.push(aResult); } var stlist = addrList(AddrResults); $("#addrlist").html(stlist); $("#addrlist").show("slow"); break; } }
If you are querying just a single layer, you could use a query task and write a more specific "where" clause like "street_name = 'SOUTH' and owner_name = 'katz'".
https://developers.arcgis.com/javascript/jsapi/query-amd.html#where
I use a query task instead of find task here is a sample.function AddressSearchTask(stnum, stname, stcity) { streetname = stname.toUpperCase(); queryTask = new QueryTask("http://192.168.20.14:6080/arcgis/rest/services/emap12/MapServer/17"); query = new Query(); query.returnGeometry = true; query.outFields = ["PRIMARYADD", "ZN"]; query.where = "HOUSENUMBE = '" + stnum + "' AND PRIMARYNAM LIKE '%" + streetname + "%'"; if(stcity != 0) { query.where = "HOUSENUMBE = '" + stnum + "' AND PRIMARYNAM LIKE '%" + streetname + "%' AND ZN = '" + stcity + "'"; } queryTask.execute(query, pickAddress); }
The 17 is the layer id from your service. You should be able to modify it to use your fields.
query.where uses Standard Query Language(SQL) so you can use LIKE, IN, ect..
This returns the results to another function called pickAddressfunction pickAddress(results) { AddrFeatures = results.features; console.log(results); var scount = AddrFeatures.length; switch(scount) { case 0: showMessage("asmessages", "Address not found"); break; case 1: zoomToStreet(results); break; default: AddrResults = {displayFieldName: null, features:[]}; for (var i = 0; i < scount; i++) { var aResult = AddrFeatures; if (!AddrResults.displayFieldName){ AddrResults.displayFieldName = aResult.displayFieldName } AddrResults.features.push(aResult); } var stlist = addrList(AddrResults); $("#addrlist").html(stlist); $("#addrlist").show("slow"); break; } }
If more than one result is found it will create a pick list if only one result is found it will zoom to the point. Some of this code requires other functions and variable in order to function correctly which I have not included.
BTW I have enclosed these function in jQuery in order to populate divs and tables. You can use the stardard ArcGIS JSAPI functions to do this if you like.
Ray
function addrList(results) { var template = ""; var addr = results.features; template = "<i>Streets Found: " + addr.length + "</i>"; template += "<table border='1'>"; template += "<tr>" template += "</tr>"; for (var i = 0, il = addr.length; i < il; i++) { template += "<tr>"; template += "<td>"+ addr.attributes["PRIMARYADD"] +" "+ addr.attributes["ZN"] +"</td>"; template += '<td><a href="#" onclick="featureZoom(AddrResults.features['+ i +']); return false;">(Zoom To)</a></td>'; template += "</tr>"; } template += "</table>"; return template; }