$("#btnSearch").click(function () {
zoomRow($("#selDivRoad1").val());
});
function zoomRow(id) {
alert("id = "+id);
var roadsLayer1 = new esri.layers.FeatureLayer("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", {
id : "roadLayerId1",
mode: FeatureLayer.MODE_ONDEMAND,
outFields: ["*"],
infoTemplate: new PopupTemplate({
title: "ROAD ID : {****}",
description: "<br />ROAD NAME: {***}"
+ "<br />ROAD CATEGORY: {***}"
+ "<br />OBJECTID: {OBJECTID}"
})
});
//roadsLayer1.clearSelection();
var fieldsSelectionSymbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,new Color([255,0,0]),3);
roadsLayer1.setSelectionSymbol(fieldsSelectionSymbol);
map.addLayer(roadsLayer1);
var query = new Query();
query.where="OBJECTID="+id;
query.geometry = map.extent;
query.spatialRelationship = Query.SPATIAL_REL_ENVELOPEINTERSECTS;
query.returnGeometry = true;
query.outFields = ["ObjectID","*****","***","****"];
roadsLayer1.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW, function(features) {
var stateExtent = features[0].geometry.getExtent().expand(5.0);
map.setExtent(stateExtent);
});
}
Solved! Go to Solution.
Here is my suggested changes. Call the initLayer() function somewhere in your apps startup. Notice line 23 below is commented out. This is what I was telling you to do earlier.
function initLayer() {
var roadsLayer1 = new esri.layers.FeatureLayer("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", {
id: "roadLayerId1",
mode: FeatureLayer.MODE_ONDEMAND,
outFields: ["*"],
infoTemplate: new PopupTemplate({
title: "ROAD ID : {****}",
description: "<br />ROAD NAME: {***}" +
"<br />ROAD CATEGORY: {***}" +
"<br />OBJECTID: {OBJECTID}"
})
});
var fieldsSelectionSymbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([255, 0, 0]), 3);
roadsLayer1.setSelectionSymbol(fieldsSelectionSymbol);
map.addLayer(roadsLayer1);
}
function zoomRow(id) {
alert("id = " + id);
var query = new Query();
query.where = "OBJECTID=" + id;
//query.geometry = map.extent; //Don't do this line
query.spatialRelationship = Query.SPATIAL_REL_ENVELOPEINTERSECTS;
query.returnGeometry = true;
query.outFields = ["ObjectID", "*****", "***", "****"];
roadsLayer1.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW, function(features) {
var stateExtent = features[0].geometry.getExtent().expand(5.0);
map.setExtent(stateExtent);
});
}
Shakyasingh,
So your query uses the maps extent:
query.geometry = map.extent;
So the next time you query after the maps extent has already been zoomed in from the first result the results of the second query is very likely null and thus does not have any geometry.
Another big issue I see in the code is that you add a new featureLayer each time the search button is clicked...
I will change the code so that a new featureLayer must not be added each time the search button is clicked
but how to solve the null issue , please guide
I answered that in the first part of my reply. Don't use the maps extent in the query.
Can You please suggest some code , I am a new comer to GIS web Development so I think I am missing something structurally.
Here is my suggested changes. Call the initLayer() function somewhere in your apps startup. Notice line 23 below is commented out. This is what I was telling you to do earlier.
function initLayer() {
var roadsLayer1 = new esri.layers.FeatureLayer("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", {
id: "roadLayerId1",
mode: FeatureLayer.MODE_ONDEMAND,
outFields: ["*"],
infoTemplate: new PopupTemplate({
title: "ROAD ID : {****}",
description: "<br />ROAD NAME: {***}" +
"<br />ROAD CATEGORY: {***}" +
"<br />OBJECTID: {OBJECTID}"
})
});
var fieldsSelectionSymbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([255, 0, 0]), 3);
roadsLayer1.setSelectionSymbol(fieldsSelectionSymbol);
map.addLayer(roadsLayer1);
}
function zoomRow(id) {
alert("id = " + id);
var query = new Query();
query.where = "OBJECTID=" + id;
//query.geometry = map.extent; //Don't do this line
query.spatialRelationship = Query.SPATIAL_REL_ENVELOPEINTERSECTS;
query.returnGeometry = true;
query.outFields = ["ObjectID", "*****", "***", "****"];
roadsLayer1.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW, function(features) {
var stateExtent = features[0].geometry.getExtent().expand(5.0);
map.setExtent(stateExtent);
});
}
thanks a lot robert
After commenting the below line
//query.geometry = map.extent;
it worked
Thank you so much...