Solved! Go to Solution.
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]) );
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); }
<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>