Select to view content in your preferred language

centerAndZoom stopped working after changed link in findTask

907
2
07-31-2013 05:40 AM
RyanWhiley
Emerging Contributor
Hello all,

I had to update the links for the application I was working on and ever since I have updated my findTask link, the centerAndZoom has stopped working.  When I change the link back to the old link it works again though.
Here is the findTask in my init
 //create find task with url to map service
        findTask = new esri.tasks.FindTask("../GeoWeb/BasiskaartCuracaov3/MapServer");

        //create find parameters and define known values
        findParams = new esri.tasks.FindParameters();
        findParams.returnGeometry = true;
        findParams.layerIds = [0];
        findParams.searchFields = ["Adres", "Straatnaam", "Huisnummer", "Shape"];
  findParams.autoComplete = true;


And here is my execute and show results functions
function execute(searchText) {
  
        //set the search text to find parameters
  
        findParams.searchText = searchText;
        findTask.execute(findParams, showResults);
  
      }

function showResults(results) {
        //symbology for graphics
  
        var markerSymbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 15, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 1), new dojo.Color([0, 255, 0, 0.25]));
        var lineSymbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASH, new dojo.Color([255, 0, 0]), 1);
        var polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_NONE, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color([255, 0, 0]), 2), new dojo.Color([255, 255, 0, 0.25]));
  console.log("7");
  console.log(findParams.searchText);
  console.log(results);
  
        //find results return an array of findResult.
        map.graphics.clear();
        var dataForGrid = [];
        var geom;
  //Build an array of attribute information and add each found graphic to the map
        dojo.forEach(results, function(result) {
          var graphic = result.feature;
    console.log(result.feature);
    geom = results[0].feature.geometry;
          dataForGrid.push(["${Huisnummer}", result.foundFieldName, result.value]);
    console.log(result.foundFieldName + result.value);
          switch (graphic.geometry.type) {
          case "point":
            graphic.setSymbol(markerSymbol);
            break;
          case "polyline":
            graphic.setSymbol(lineSymbol);
            break;
          case "polygon":
            graphic.setSymbol(polygonSymbol);
            break;
          }
          map.graphics.add(graphic);
    console.log(graphic);
        });
        if(geom !== undefined){
   console.log(geom);
          map.centerAndZoom(geom,17);
        }
  else {
   alert("No matching addresses could be found.");
   }
  var data = {
          items: dataForGrid
        };
        var store = new dojo.data.ItemFileReadStore({
          data: data
        });
        grid.setStore(store);
  }


As you can see, i have console.logs that log the information and all the information is coming up properly in my console.  The geom variable has the right coordinates attached to it after I enter a search, but the application simply won't zoom to the location.  And the graphics for the searched points will not show up either.  I've updated all the searchFields as well and it's still not working.  I'm pretty stumped right now as to why this won't work with the new link, so if anyone could offer me any assistance, I'd really appreciate it.

Thank you!
0 Kudos
2 Replies
JohnGravois
Deactivated User
if you set a breakpoint at that line, are there any differences in the 'geom' object you are passing to map.centerAndZoom() when you switch services?
0 Kudos
BenFousek
Deactivated User
if you set a breakpoint at that line, are there any differences in the 'geom' object you are passing to map.centerAndZoom() when you switch services?


John - that caught my eye too.

Ryan - map.centerAndZoom takes a point as the first argument. https://developers.arcgis.com/en/javascript/jsapi/map.html#centerandzoom  I noticed you were switching through geometry.type. If the geometry isn't a point centerAndZoom will not work.

if (graphic.geometry.type === 'point') {
  map.centerAndZoom(graphic.geometry, 18);
} else {
  map.setExtent(graphic.geometry.getExtent(), true);
}
0 Kudos