Select to view content in your preferred language

Error in putting point from query on map view in 4.3

1778
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
1 Solution

Accepted Solutions
HemingZhu
Frequent Contributor

put your putFeature.. function in your .require block will do the trick.

View solution in original post

11 Replies
RobertScheitlin__GISP
MVP Emeritus

Jeff,

   What is the WKID of the returned query point VS the views WKID? If you add query.outSpatialReference = view.spatialReference; then you should be good to go.

JeffSauder
Regular Contributor

Hi Robert,

Thanks for the reply. The query layer and the view are both 2868, but I went ahead and put that line in, probably good practice anyway. But I still have the same result.

Thanks,

Jeff

0 Kudos
HemingZhu
Frequent Contributor

i could be that your query service has different spatial reference. so the search result doesn't match with the view in terms of spatial reference.  try add one more statements on your code like this

query.outSpatialReference=view.outSpatialReference;

JeffSauder
Regular Contributor

Im also having the same issue with polygons, the function doesn't keep the map from zooming in like the point example, but it still doesn't draw.  I've tried passing in the feature, and the feature.geometry here also, without luck...

function queryQuads() {
  var qVal = document.getElementById("quadCbo").value;
  queryTask.url="http://gissvr:6080/arcgis/rest/services/GilbertQuery/MapServer/10";
  query.returnGeometry=true;
  query.outSpatialReference = view.spatialReference;
  query.outFields=["*"];
  query.where = "Quad='" + qVal + "'";
  //console.log("Quad='" + qVal + "'");
  queryTask.execute(query).then(function(results) {
    view.goTo(results.features);
    putFeatureOnMap(results.features[0]);
  });

function putFeatureOnMap(geom) {
  window.alert("putFeatureOnMap");
  var sfsFill = new SimpleFillSymbol({
    color: [0,255,0],
    outline: {
      color: [255,0,0],
      width: 2
    }
  });
  var polyGraphic = new Graphic({
    geometry: geom,
    symbol: sfsFill
  });
  view.graphics.add(polyGraphic);
}

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jeff,

   Can you provide a simplified sample for testing?

0 Kudos
JeffSauder
Regular Contributor

Hi Robert,

I actually got it working, but I’m not sure that it’s the best way to go. What happened is that the functions are outside of the main.js function where all the modules are brought in, so I had to declare global variables and set them in the main.js, then instead of create new instances of those variables, just reference the ones that I declared and set the properties. So it works once, then when I do a second query, it does not create a graphic, but the original graphic stays on the map. I am doing this for the query task also, but I am able to reuse the same query and querytask variables. It looks like if I remove the graphic from the view, I can create a new one. So maybe just create a bunch of point and polygon graphic variables? It seems like there would have to be a better way. Being fairly new to this method of programming, and javascript, I’m not sure if that’s the best way to achieve this or not:

//This is an excerpt showing where I declare the variables in the main body where all the esri stuff is accessable

"esri/widgets/Expand",

"esri/widgets/LayerList",

"esri/widgets/Legend",

"dojo/domReady!"

], function(Map, Color, Graphic,

MapView, GraphicsLayer, MapImageLayer, TileLayer,

Extent, Point, Polyline, Polygon,

SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol,

QueryTask, Query,

Expand, LayerList, Legend){

queryTask = new QueryTask();

query = new Query();

pointGraphic=new Graphic();

polygonGraphic=new Graphic();

simpleFill = new SimpleFillSymbol({

color: ,

outline: {

color: ,

width: 2

}

});

//these are the new functions, that just set the properties of those variables defined in the main.js

function putFeatureOnMap(geom) {

window.alert("putFeatureOnMap");

polygonGraphic.geometry=geom;

polygonGraphic.symbol=simpleFill;

view.graphics.add(polygonGraphic);

}

function putFeaturePointOnMap(inPt) {

pointGraphic.geometry=inPt;

pointGraphic.symbol=sMarker;

view.graphics.add(pointGraphic);

}

0 Kudos
HemingZhu
Frequent Contributor

i would test if the graphic is drawn by the follow

queryTask.execute(query).then(function(results) {
    var pPt = results.features[0];
    putFeaturePointOnMap(pPt.geometry);  //I've also tried just passing in pPt

    view.center=pPt.geometry;
    //view.scale=4000;
    //view.goTo(pPt);
  });

0 Kudos
HemingZhu
Frequent Contributor

put your putFeature.. function in your .require block will do the trick.

RobertScheitlin__GISP
MVP Emeritus

I agree with Heming. But if you can not for some reason then just pass the view into your putFeatures along with the point geometry.

0 Kudos