AnsweredAssumed Answered

UNABLE TO ZOOM TO POINT FEATURE

Question asked by abbabharath on Oct 17, 2016
Latest reply on Oct 18, 2016 by rscheitlin

Here is my code i am able to add graphics but unable to zoom please help

 

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=7, IE=9, IE=10">
<!--The viewport meta tag is used to improve the presentation and behavior of the samples
on iOS devices-->
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>Identify with Popup</title>


<link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.5/js/esri/css/esri.css">
<style>
html, body, #mapDiv {
height:100%;
width:100%;
margin:0;
padding:0;
}
</style>

<script src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.5/"></script>
<script type="text/javascript">
dojo.require("esri.map");
dojo.require("esri.tasks.query");

var map, queryTask, query;
var symbol, infoTemplate;
var totalExtent;

function init() {
map = new esri.Map("mapDiv", {
center: [19.46, 50.382],
zoom: 4
});

dynamicmap = new esri.layers.ArcGISDynamicMapServiceLayer("http://localhost:6080/arcgis/rest/services/edit/MapServer");
map.addLayer(dynamicmap);

queryTask = new esri.tasks.QueryTask("http://localhost:6080/arcgis/rest/services/edit/MapServer/20");

// //initialize query
query = new esri.tasks.Query();
query.returnGeometry = true;
query.outFields = ["LTP_ID ", "OBJECTID "];

//create symbol for selected features
symbol = new esri.symbol.SimpleMarkerSymbol();
symbol.setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE);
symbol.setSize(10);
symbol.setColor(new esri.Color([255, 255, 0, 0.5]));

}


function executeQueryTask(sTownID) {
// debugger;
//set query based on what user typed in for population;
//query.where = "POP04 > " + population;
// var sTownID = $get('population').value ;

query.where = "LTP_ID ='" + sTownID + "'";


//execute query
queryTask.execute(query, showResults);
// var zm = queryTask.execute(query, showResults);
// map.centerAndZoom(zm, 2);
}

function showResults(featureSet) {
debugger;

//remove all graphics on the maps graphics layer
map.graphics.clear();

//Performance enhancer - assign featureSet array to a single variable.
var resultFeatures = featureSet.features;

//Loop through each feature returned

for (var i = 0, il = resultFeatures.length; i < il; i++) {
//Get the current feature from the featureSet.
//Feature is a graphic
var graphic = resultFeatures[i];
//graphic.setSymbol(symbol);

//Set the infoTemplate.
//graphic.setInfoTemplate(infoTemplate);

//Add graphic to the map graphics layer.
map.graphics.add(graphic);

map.setExtent(graphic.geometry.getExtent(), true);
}

dojo.ready(init);
</script>
</head>

<body>
<br/>
Enter Value : <input type="text" id="pop" />

<input type="button" value="Get Details" onclick="executeQueryTask(dojo.byId('pop').value);" />
<div id="mapDiv" style="width:1000px; height:800px; border:1px solid #000;"></div>

</body>

</html>

Outcomes