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.