AnsweredAssumed Answered

Dear All,  I have created a ArcGIS Javascript API application to Search by some Specific filed like( locality and sub locality etc.) am using query task but it's not working.

Question asked by anuj_arcgis on Apr 10, 2017
Latest reply on Apr 11, 2017 by anuj_arcgis

 

var map;
var app = {};

require([
"esri/map",
"esri/dijit/Legend",
"esri/dijit/Scalebar",
"esri/layers/ArcGISDynamicMapServiceLayer",
"esri/layers/ArcGISTiledMapServiceLayer",
"esri/layers/FeatureLayer",
"dojo/dom",
"dojo/dom-construct",
"esri/config",
"esri/dijit/LayerList",
"esri/InfoTemplate",
"esri/dijit/HomeButton",
"esri/dijit/LocateButton",
"esri/dijit/Search",
"esri/arcgis/utils",
"esri/dijit/Print",
"esri/tasks/PrintTemplate",
"esri/tasks/PrintTask",
"esri/tasks/PrintParameters",
"esri/tasks/GeometryService",
"dojo/on",
"esri/symbols/SimpleLineSymbol",
"esri/symbols/SimpleFillSymbol",
"esri/Color",
"esri/tasks/QueryTask",
"esri/tasks/query",
"dojo/query",
"dijit/registry",

"dojo/parser",
"dojo/_base/array",
"dijit/form/CheckBox",
"dijit/layout/AccordionContainer",
"dijit/layout/BorderContainer", "esri/dijit/Scalebar",
"dijit/layout/ContentPane",
"dojo/domReady!"
],
function (
Map,
Legend, Scalebar,
ArcGISDynamicMapServiceLayer,
Tiled,
FeatureLayer,
dom,
domConstruct,
esriConfig,
LayerList,
InfoTemplate,
HomeButton,
LocateButton,
Search,
arcgisUtils,
Print, PrintTemplate,
PrintTask,
PrintParameters,
GeometryService,
on,
SimpleLineSymbol,
SimpleFillSymbol,
Color,
QueryTask,
Query,
dojoQuery,
registry,
parser,
arrayUtils,
CheckBox
) {

parser.parse();

var legendLayers = [];

esriConfig.defaults.io.proxyUrl = "proxy.ashx";
esriConfig.defaults.io.alwaysUseProxy = false;

map = new Map("map", {
showAttribution: false,
logo: false,
// extent: startExtent,
sliderOrientation: "horizontal"
});
var tiled = new Tiled("https://gis.gsdl.org.in:6443/arcgis/rest/services/DSSDI_Server_New/MapServer");
//map.addLayer(tiled);

//**********************Deaclaring All DynamicLayer*********************//

var health = new ArcGISDynamicMapServiceLayer("http://220.156.189.140:6080/arcgis/rest/services/Revenue/RevenueDepartment_201507151646/MapServer", {
visible: false
});

var Imagery = new ArcGISDynamicMapServiceLayer("http://220.156.189.140:6080/arcgis/rest/services//MyMapServiceim/MyMapServiceim2/MapServer", {
visible: false
});

//var Delhipolice = new ArcGISDynamicMapServiceLayer("http://220.156.189.140:6080/arcgis/rest/services/Delhipolice/MapServer", {
// visible: false
//});

//var Firestation = new ArcGISDynamicMapServiceLayer("http://220.156.189.140:6080/arcgis/rest/services/FireStationFeatureEdit", {
// visible: false
//});

//var Revenue = new ArcGISDynamicMapServiceLayer("http://220.156.189.140:6080/arcgis/rest/services/Revenue/RevenueDepartment_201507151646/MapServer", {
// visible: false
//});


//**********************Deaclaring All FeatureLayer*********************//

//******************Legend*********************************


map.on("layers-add-result", function (evt) {
var layerInfo = arrayUtils.map(evt.layers, function (layer, index) {
return { layer: layer.layer, title: layer.layer.name };
});
if (layerInfo.length > 0) {
var legendDijit = new Legend({
map: map,
layerInfos: layerInfo
}, "legendDiv");
legendDijit.startup();
}
});

//https://gis.gsdl.org.in:6443/arcgis/rest/services/DSSDI_Server_New/MapServer?f=json&callback=dojo.io.script.jsonp_dojoIoScript1._jsonpCallback
//**********************Adding All Layer*********************

map.addLayers([tiled,health,Imagery]);

function AddressSearch()
{
alert("Are You Sure.....!");

var Villname = document.getElementById("addnum").value;

var Khasra = document.getElementById("addnum").value;

AddressSearchTask(Villname, Khasra);
}


function AddressSearchTask(Villname, Khasra)
{
streetname = stname.toUpperCase();
queryTask = new QueryTask("http://220.156.189.140:6080/arcgis/rest/services/Revenue/Revenue_Samaspur/MapServer/0");
query = new Query();
query.returnGeometry = true;
query.outFields = ["VILL_NM", "M_KHASRA_N"];
query.where = "VillageName = '" + VILL_NM + "' AND Khasra_No LIKE '%" + M_KHASRA_N + "%'";

queryTask.execute(query, featureZoom);
}

function featureZoom(feature)
{
map.graphics.clear();
ftype = feature.geometry.type;
//console.log(result);
if(ftype == "point")
{
var pt = feature.geometry;
var factor = 1; //some factor for converting point to extent
var extent = new esri.geometry.Extent(pt.x - factor, pt.y - factor, pt.x + factor, pt.y + factor, pt.spatialReference);
map.setExtent(extent.expand(60));
showFeature(feature);
} else {
var fExtent = feature.geometry.getExtent().expand(3);
map.setExtent(fExtent);
showFeature(feature);
}

}

function showFeature (feature)
{
map.graphics.clear();
ftype = feature.geometry.type;
if(ftype == "point")
{
feature.setSymbol(psymbol)
setTimeout(function(){map.graphics.clear()}, 3000);
} else {
feature.setSymbol(symbol);
setTimeout(function(){map.graphics.clear()}, 3000);
}
map.graphics.add(feature);
}
//**********************Adding LayerList*********************

var list = new LayerList(
{
map: map,
layers: [{
layer:Imagery,
visibility: false,
showOpacitySlider: true,
id: "Imagery",
sublayers: true
},{
layer: health,
visibility: false,
showLegend: true,
showOpacitySlider: true,
sublayers: true,
id:"Revenu"
}]
}, "LayerLists");
list.startup();
//******************** //Add Home Button\\********************
var home = new HomeButton({
map: map
}, "HomeButton");
home.startup();

//******************** // Add LocateButton\\********************

geoLocate = new LocateButton({
map: map
}, "LocateButton");
geoLocate.startup();


//******************** //this enables the search widget to display as a single button\\********************

var s = new Search({
enableButtonMode: true,
enableLabel: false,
enableInfoWindow: true,
showInfoWindowOnSelect: false,
map: map
}, "search");
s.startup();

var scalebar = new Scalebar({
map: map,
scalebarUnit: "dual"
});
// declare geometry service
esriConfig.defaults.geometryService = new GeometryService("https://gis.gsdl.org.in:6443/arcgis/rest/services/Utilities/Geometry/GeometryServer");

// begin print Task
app.printUrl = "https://gis.gsdl.org.in:6443/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task";

function createPrintTask(printTitle) {
var template = new PrintTemplate();
template.layout = document.getElementById("printLayoutId").value;
template.label = "Landscape (PDF)";
template.format = document.getElementById("printFormatId").value;
template.layoutOptions = {
legendLayers: [], // empty array means no legend
scalebarUnit: "Miles",
titleText: printTitle
};

var params = new PrintParameters();
params.map = map;
params.template = template;

var printTask = new PrintTask(app.printUrl);
var printObj = {
printTask: printTask,
params: params
}
return printObj;
}
// end of print task

// Activates printer
on(dom.byId("btnPrintReady"), "click", function () {
document.getElementById("btnPrintReady").innerHTML = "Printing..."
document.getElementById("btnPrintReady").disabled = true;
var printObj = createPrintTask(document.getElementById("printTitleId").value);
var printTask = printObj.printTask;
printTask.execute(printObj.params, function (evt) {
document.getElementById("btnPrintReady").style.display = 'none';
document.getElementById("printResult").href = evt.url;
document.getElementById("printResult").style.display = 'block';
on(dom.byId("printResult"), "click", function () {
document.getElementById("btnPrintReady").innerHTML = "Print";
document.getElementById("btnPrintReady").style.display = 'block';
document.getElementById("btnPrintReady").disabled = false;
document.getElementById("printResult").style.display = 'none';
});
}, function (evt) {
document.getElementById("btnPrintReady").disabled = false;
document.getElementById("btnPrintReady").innerHTML = "Print";
});
});

// Hides print widget
on(dom.byId("closePrint"), "click", function () {
document.getElementById("feedback").style.visibility = 'hidden';
});

// Shows tools
on(dom.byId("showTools"), "click", function () {
document.getElementById("showToolsButton").style.visibility = 'hidden';
document.getElementById("hideToolsButton").style.visibility = 'visible';
document.getElementById("printer").style.visibility = 'visible';
});

// Hide tools
on(dom.byId("hideTools"), "click", function () {
document.getElementById("showToolsButton").style.visibility = 'visible';
document.getElementById("hideToolsButton").style.visibility = 'hidden';
document.getElementById("printer").style.visibility = 'hidden';
document.getElementById("feedback").style.visibility = 'hidden';
});

// Show print widget
on(dom.byId("showPrintWidget"), "click", function () {
document.getElementById("feedback").style.visibility = 'visible';
});

 

//************End of Script******************************//
});

Outcomes