Select to view content in your preferred language

Error in putting point from query on map view in 4.3

1781
11
Jump to solution
06-12-2017 09:59 AM
JeffSauder
Regular Contributor

Hi all,

I wrote some javascript code to query a point based on input values, and zoom to the location and put a point graphic on the map.  The zoom and scale work fine, the query works good, but it will not draw the point on the map.  In fact , when I call the function putFeaturePointOnMap the scale and goTo functions don't run, so nothing happens.  If I comment out the function call, everything works OK. The alert and console.log statements fire when I run this, so I know that it's going to the function, and the console.log returns the x value of the point, so I know it's not undefined.  I've tried passing the feature itself, and the feature geometry, with no luck.

Thanks in advance to anyone who can answer this, I've triple checked everything and cannot understand why this will not work.

function queryAddress() {
  var aVal=document.getElementById("addrNumText").value;
  aVal+=" " + document.getElementById("stDirCbo").value;
  aVal+=" " + document.getElementById("streetCbo").value;
  console.log(aVal);
  queryTask.url="http://gissvr:6080/arcgis/rest/services/GilbertQuery/MapServer/8";
  query.returnGeometry=true;
  query.outFields=["*"];
  query.where= "FULLADDR='" + aVal + "'";
  queryTask.execute(query).then(function(results) {
    var pPt = results.features[0];
    putFeaturePointOnMap(pPt.geometry);  //I've also tried just passing in pPt
    view.scale=4000;
    view.goTo(pPt);
  });
}
function putFeaturePointOnMap(inPt) {
  window.alert("PutonMap");
  console.log("point=" + inPt.x);
  var smsMarker = new SimpleMarkerSymbol({
    color: [0,255,0],
    size: 12
  });
  var ptGraphic = new Graphic({
    geometry: inPt,
    symbol: smsMarker
  });
  view.graphics.add(ptGraphic);
}

0 Kudos
11 Replies
JeffSauder
Regular Contributor

Thanks guys I think you pointed me in the right direction at least.  I put the function in the require block but then the query task that was calling it couldn't find it, I even tried reordering the script files that bring in the js files in the html file.  But I see a little more clearly how this all works together now, I will keep going at it...

0 Kudos
mattprice
Occasional Contributor

query.outSpatialReference = view.spatialReference;

I had the same issue when trying to add a graphic returned from a query in state plain to an esri basemap.  Unless the two projections are the same I think you need to set the outSpatialReference to the projection on the features you are querying so the results can be projected on the fly. Matt

query.outSpatialReference = { wkid:102643 };  State plain same as the features I was querying, not set to the view projection.

0 Kudos