Select to view content in your preferred language

How to prevent selection of Polygon which is already selected (Spatial Query) in ArcGIS JS 3.xx

721
1
Jump to solution
07-30-2019 05:40 AM
AlifShaikh
Emerging Contributor

Hi,

Below is the code which is for spatial query.


var map;
 var resultFromquery = [];
 require(["esri/map", "esri/layers/ArcGISDynamicMapServiceLayer",
 "esri/layers/ImageParameters","esri/geometry/Extent","esri/InfoTemplate","esri/SpatialReference","esri/tasks/query","esri/tasks/QueryTask","esri/graphic","esri/tasks/FeatureSet","esri/symbols/Symbol", "dojo/domReady!"], 
 function(Map,ArcGISDynamicMapServiceLayer,ImageParameters,Extent,InfoTemplate,SpatialReference,query,QueryTask,graphic,FeatureSet,Symbol) 
 {
 map = new Map("map", {
 basemap: "topo", 
 center: [75.831,18.895], // longitude, latitude
 zoom: 10,
 //maxScale:8800
 });
 map.on("click", mapReady);
 var dynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer("Mapservice");
 dynamicMapServiceLayer.setVisibleLayers([0]);
 map.addLayer(dynamicMapServiceLayer);
 infoTemplate = new esri.InfoTemplate("${BLDGNO}", "Locality: ${SUBLOCALITY}<br />StateName: ${STATENAME}<br />Pincode: ${PINCODE}");
 symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color([255,0,0]), 2), new dojo.Color([255,255,0,0.5]));
 }); 
 function mapReady(evt) 
 {
 queryTask = new esri.tasks.QueryTask("Mapservice");
 query = new esri.tasks.Query();
 query.returnGeometry = true;
 query.outFields = ["BLDGNO", "SUBLOCALITY", "STATENAME","CITYNAME","PINCODE"];
 query.geometry = evt.mapPoint;
 queryTask.execute(query, showResults);
}
 function showResults(featureSet) 
 {
 dojo.forEach(featureSet.features,function(feature)
 {
 var graphic = feature;
 resultFromquery.push(feature.attributes);
 graphic.setSymbol(symbol);
 graphic.setInfoTemplate(infoTemplate);
 map.graphics.add(graphic);
 });
 }
 document.getElementById('SubmitBtn').onclick = function myFunction() 
 { 
 
 try
 {
 var i;
 var BLDGNO ="";
 var PINCODE="";
 for (i=0;i<resultFromquery.length;i++)
 {
 BLDGNO = resultFromquery[i].BLDGNO;
 PINCODE = resultFromquery[i].PINCODE;
 console.log(BLDGNO , PINCODE);

 }
 }
 catch (err)
 {
 alert(err.message);
 }
 }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I wanted to know how to prevent (to show a alert or message) selecting the polygon which is already selected.

Thanks,

AS

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

AS,

   You would have to get an array of ObjectIds that are already selected and 

  1. Add them as a definition expression to your Query (i.e. "NOT IN(2 ,45, 87)"). This would prevent them from being re-selected.
  2. Or loop through your query results and alert if an ObjectId matches your array of pre-existing selected ObjectIds

View solution in original post

1 Reply
RobertScheitlin__GISP
MVP Emeritus

AS,

   You would have to get an array of ObjectIds that are already selected and 

  1. Add them as a definition expression to your Query (i.e. "NOT IN(2 ,45, 87)"). This would prevent them from being re-selected.
  2. Or loop through your query results and alert if an ObjectId matches your array of pre-existing selected ObjectIds