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; }
That will be great if you can post your complete source code. Thanks for your time.
let me know if need the complete source code i can share it with you,i never used jsfiddle.
Can you post the entire code in JSFiddle? Thanks.
<script> $("#search").bind( "click", function() { map.graphics.clear(); //var stnum = registry.byId("addnum").get("value"); var stname = $("#streetName").val(); //var stcity = registry.byId("addcity").get("value"); AddressSearchTask("", stname, ""); }); //Zoom to the parcel when the user clicks a row function featureZoom(feature) { map.graphics.clear(); ftype = feature.geometry.type; console.log(ftype); if(ftype == "point") { var pt = feature.geometry; var factor = 1; //some factor for converting point to extent var extent = new esri.geometry.Extent(pt.x - factor, pt.y - factor, pt.x + factor, pt.y + factor, pt.spatialReference); map.setExtent(extent.expand(60)); showFeature(feature); } else { var fExtent = feature.geometry.getExtent().expand(3); map.setExtent(fExtent); showFeature(feature); } } function showFeature (feature) { console.log('showFeature'); map.graphics.clear(); ftype = feature.geometry.type; if(ftype == "point") { feature.setSymbol(psymbol) setTimeout(function(){map.graphics.clear()}, 3000); // 3000 is a timeout to show the feature then clear it. change to liking } else { feature.setSymbol(symbol); setTimeout(function(){map.graphics.clear()}, 3000); // 3000 is a timeout to show the feature then clear it. change to liking } map.graphics.add(feature); } </script>
registry.byId("AddressSearch").on("click", function () { map.graphics.clear(); var stnum = registry.byId("addnum").get("value"); var stname = registry.byId("addname").get("value"); var stcity = registry.byId("addcity").get("value"); AddressSearchTask(stnum, stname, stcity); } );
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; var scount = AddrFeatures.length; switch(scount) { // if no address found show the message in div case 0: showMessage("asmessages", "Address not found"); break; // if only one message found just zoom directly to it case 1: zoomToStreet(results); break; // if multiple addresses found default: // create the variable for the address results AddrResults = {displayFieldName: null, features:[]}; // loop through the features found and add them for the AddrResults variable for (var i = 0; i < scount; i++) { var aResult = AddrFeatures; if (!AddrResults.displayFieldName){ AddrResults.displayFieldName = aResult.displayFieldName } AddrResults.features.push(aResult); } // pass the results to the function to format the results var stlist = addrList(AddrResults); // put the results into the addrlist div $("#addrlist").html(stlist); // show the div $("#addrlist").show("slow"); break; } }
function addrList(results) { var template = ""; var addr = results.features; //alert(sn.length); 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 featureZoom(feature) { map.graphics.clear(); ftype = feature.geometry.type; //console.log(result); if(ftype == "point") { var pt = feature.geometry; var factor = 1; //some factor for converting point to extent var extent = new esri.geometry.Extent(pt.x - factor, pt.y - factor, pt.x + factor, pt.y + factor, pt.spatialReference); map.setExtent(extent.expand(60)); showFeature(feature); } else { var fExtent = feature.geometry.getExtent().expand(3); map.setExtent(fExtent); showFeature(feature); } }
function showFeature (feature) { map.graphics.clear(); ftype = feature.geometry.type; if(ftype == "point") { feature.setSymbol(psymbol) setTimeout(function(){map.graphics.clear()}, 3000); } else { feature.setSymbol(symbol); setTimeout(function(){map.graphics.clear()}, 3000); } map.graphics.add(feature); }
function featureZoom(feature) { map.graphics.clear(); ftype = feature.geometry.type; //console.log(result); if(ftype == "point") { var pt = feature.geometry; var factor = 1; //some factor for converting point to extent var extent = new esri.geometry.Extent(pt.x - factor, pt.y - factor, pt.x + factor, pt.y + factor, pt.spatialReference); map.setExtent(extent.expand(60)); showFeature(feature); } else { var fExtent = feature.geometry.getExtent().expand(3); map.setExtent(fExtent); showFeature(feature); } } function showFeature (feature) { map.graphics.clear(); ftype = feature.geometry.type; if(ftype == "point") { feature.setSymbol(psymbol) setTimeout(function(){map.graphics.clear()}, 3000); // 3000 is a timeout to show the feature then clear it. change to liking } else { feature.setSymbol(symbol); setTimeout(function(){map.graphics.clear()}, 3000); // 3000 is a timeout to show the feature then clear it. change to liking } map.graphics.add(feature); }
symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([0, 255, 255]), 5), new Color([255, 255, 0, 0.25]) ); psymbol = new SimpleMarkerSymbol( SimpleMarkerSymbol.STYLE_CIRCLE, 8, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([0, 255, 255]), 8), new Color([255, 255, 0, 0.25]) );
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 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 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 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
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.