Features not found with query.geometry

2372
3
Jump to solution
03-23-2016 10:48 AM
EvelynHernandez
Occasional Contributor III

Hello,

Im trying to make a query with the map.onclick to get the features founded around the click.

I have added 2 featurelayers that have some values that i want to get when the user clicks to make another analysis.

The problem that now im having is that even if i make a polygon to search for any value, my featureSet doesnt give me any.

My code is:

function clickSearch(mapPoint){

  var rectangle = new esri.geometry.Polygon(new esri.SpatialReference(mapPoint.spatialReference.wkid));

  rectangulo.addRing(createRectangle(mapPoint,20));

  console.log(rectangulo);

  var queryTask = new esri.tasks.QueryTask(layers.read_layer_interr_sed());

  var query = new esri.tasks.Query;

  query.spatialRelationship=esri.tasks.Query.SPATIAL_REL_CONTAINS;

  query.geometry = rectangulo;

  query.outFields=['*'];

  query.returnGeometry = true;

  queryTask.execute(query,(featureSet)=>{

      console.log("found something here...what is it?");

      if(featureSet.features.length!=0){

        console.log(featureSet.features);

      }else console.log("nothing");

           

  },(error)=>{

    console.log("no encontre na" , error);

  });

}

function createRectangle(mapPoint,delta){

    var arrayOfPoints = [];

  arrayOfPoints[0] = new esri.geometry.Point(mapPoint.x-delta,mapPoint.y-delta,mapPoint.spatialReference);

  arrayOfPoints[1] = new esri.geometry.Point(mapPoint.x-delta,mapPoint.y+delta,mapPoint.spatialReference);

  arrayOfPoints[2] = new esri.geometry.Point(mapPoint.x+delta,mapPoint.y+delta,mapPoint.spatialReference);

  arrayOfPoints[3] = new esri.geometry.Point(mapPoint.x+delta,mapPoint.y-delta,mapPoint.spatialReference);

  arrayOfPoints[4] = new esri.geometry.Point(mapPoint.x-delta,mapPoint.y-delta,mapPoint.spatialReference);

  return arrayOfPoints;

  }

Note:

Im not using require to load the modules.

Im programming with ReactJS, webpack server and i just installed the api in that server.

I have been used all the elements for the api in this way:

Example for featureLayer.

var myDynamicSedLayer = new esri.layers.FeatureLayer(layers.read_layer_interr_sed(),{

       mode: esri.layers.FeatureLayer.MODE_SNAPSHOT,

       infoTemplate: myinfotemplate.getSubFailure(),

       outFields: ["*"]

    });

Anyone knows what could be happening? or any example doing this.

I already search about it in the sample api.

Thanks in advice.

0 Kudos
1 Solution

Accepted Solutions
EvelynHernandez
Occasional Contributor III

Well, im using the legacy side and not amd to play with reactjs, so how in the samples some of them are with AMD and legacy code, i choose legacy.

Well now i think i fix part of my problem doing this:

  myDynamicLayer1.on("click",(event)=>{

        //  console.log(event.graphic.attributes);

    });

In this way i will be able to get any attribute that im looking for the click and then using it to more complex analysis or queries.

Thanks for your response.

View solution in original post

3 Replies
EvelynHernandez
Occasional Contributor III

I changed my question.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Evelyn,

  You have seriously limited the number of people that will be able to help you (probably by 95% or more) now that you have chosen to use react instead of vanilla javascript, just FYI.

Are you sure you need SPATIAL_REL_CONTAINS and not SPATIAL_REL_INTERSECTS?

0 Kudos
EvelynHernandez
Occasional Contributor III

Well, im using the legacy side and not amd to play with reactjs, so how in the samples some of them are with AMD and legacy code, i choose legacy.

Well now i think i fix part of my problem doing this:

  myDynamicLayer1.on("click",(event)=>{

        //  console.log(event.graphic.attributes);

    });

In this way i will be able to get any attribute that im looking for the click and then using it to more complex analysis or queries.

Thanks for your response.