Select to view content in your preferred language

Search by Parcel and Address

710
2
10-04-2012 04:31 AM
CraigMcDade
Deactivated User
I'd like to duplicate the search feature in the Parks Finder app, where there is a radio button to choose the type of search. I'd like to be able to search by parcel # or address. It looks like the applicable code is spread between a few of the files (utils.js, config, default) so that makes it a little tough for me to decipher how to put it together in one file (still a novice) to make it work. As my app stands now, I have a functional search feature (by address only), so I don't necessarily need to blow that up to create an exact duplicate, but I'm not sure how to go about adding the parcel search to what I have either.

For what its worth, here is the search code in my app currently:
//Create Search Function
   function locate() {
        map.graphics.clear();
        var address = {"SingleLine":dojo.byId("address").value};
        locator.outSpatialReference= map.spatialReference;
        var options = {
          address:address,
          outFields:["Loc_name"]
        }
        locator.addressToLocations(options);
      }

      function showResults(candidates) {
        var candidate;
        var symbol = new esri.symbol.SimpleMarkerSymbol();
        var infoTemplate = new esri.InfoTemplate("Location", "Address: ${address}<br />Score: ${score}<br />Source locator: ${locatorName}");

        symbol.setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_ROUND);
        symbol.setColor(new dojo.Color([153,0,51,0.75]));

        var geom;
        
        dojo.every(candidates,function(candidate){
          console.log(candidate.score);
          if (candidate.score > 80) {
            console.log(candidate.location);
            var attributes = { address: candidate.address, score:candidate.score, locatorName:candidate.attributes.Loc_name };   
            geom = candidate.location;
            var graphic = new esri.Graphic(geom, symbol, attributes, infoTemplate);
    //add a graphic to the map at the geocoded location
            map.graphics.add(graphic);
    //add a text symbol to the map listing the location of the matched address.
            var displayText = candidate.address;
            var font = new esri.symbol.Font("16pt",esri.symbol.Font.STYLE_NORMAL, esri.symbol.Font.VARIANT_NORMAL,esri.symbol.Font.WEIGHT_BOLD,"Helvetica");
           
            var textSymbol = new esri.symbol.TextSymbol(displayText,font,new dojo.Color("#610B0B"));
            textSymbol.setOffset(0,8);
            map.graphics.add(new esri.Graphic(geom, textSymbol));
            return false; //break out of loop after one candidate with score greater  than 80 is found.
          }
        });
        if(geom !== undefined){
          map.centerAndZoom(geom,15);
        }
      }
0 Kudos
2 Replies
JohnGravois
Deactivated User
i took a look at this and all you have to do is add the additional field to the config.txt file

//Fields used for searching the features through find task.  (don't forget the trailing comma!)
'SearchFields':"FacilitySitePoint.NAME,FacilitySitePoint.OBJECTID",
0 Kudos
JohnGravois
Deactivated User
if you're trying to rewrite that funcationality in a new single page application, thats a whole nother can of worms. 

in general you'll have to think about maintaining two seperate functions and use one to define parameters for the find task and another to geocode.  in the parks and rec sample, they use a function called locate() to run the find task.  Inside that function, if txtAddress is disabled, it fires the function GeoCodeAddress() instead.
0 Kudos