vendredi 2 janvier 2015

Trying to add graphic to query result


I'm pretty new to javascript and have some code that zooms to a query results extent, but I also want to highlight the query result.


Console.log shows I'm returning an object but i cant seem to add the "highlightSymbol" to it. Any help is much appreciated:



//add the layers
map.addLayer(topoBasemap);
map.addLayers([administrative,parcels, agriculture, transportation]);

//set extent
var startext = new esri.geometry.Extent({
"xmin" : 186870.18,
"ymin" : 541462.48,
"xmax" : 735481.291,
"ymax" : 967243.73,
"spatialReference" : {
"wkid" : 102711
}
});
map.setExtent(startext);

//get extent info
map.on("extent-change",
function findExtent() {
var e = map.extent;
var s = "";
s = "<b>XMin:</b> " + e.xmin + "<br/>" +
" <b>YMin:</b> " + e.ymin + "<br/>" +
" <b>XMax:</b> " + e.xmax + "<br/>" +
" <b>YMax:</b> " + e.ymax + "<br/>" +
" <b>Spatial Reference: (wkid)</b> " + e.spatialReference.wkid + "<br/>" +
" <b>Center: (x,y)</b> " + e.getCenter().x + ", " + e.getCenter().y;
dom.byId("onExtentChangeInfo").innerHTML = s;
var d = "";
d = "<b>Zoom Level:</b> " + map.getLevel() + "<br/>" +
"<b>Resolution:</b> " + map.getResolution() + "<br/>" +
"<b>Scale:</b> " + map.getScale() + "<br/>";
dom.byId("details").innerHTML = d;
});

//Highlight Symbol
var highlightSymbol = new SimpleFillSymbol(
SimpleFillSymbol.STYLE_SOLID,
new SimpleLineSymbol(
SimpleLineSymbol.STYLE_SOLID,
new Color([255, 0, 0]), 3),
new Color([125, 125, 125, 0.2]));

//Query BLOCK/LOT
var queryTask = new QueryTask(parcels.url);

var query = new Query();
query.returnGeometry = true;
query.outFields = ["*"];
on(dom.byId("execute"), "click", execute);

function execute() {
map.graphics.clear();

query.where = "SSN = '" + dijit.byId("muniSelect").value + "' AND BLOCK = '" + dom.byId("block").value + "' AND LOT = '" + dom.byId("lot").value + "'";
queryTask.execute(query, showResults);
}
function showResults(results) {
var resultItems = [];
var resultCount = results.features.length;
for (var i = 0; i < resultCount; i++) {
var featureAttributes = results.features[i].attributes;
for (var attr in featureAttributes) {
resultItems.push("<b>" + attr + ":</b> " + featureAttributes[attr] + "<br>");
}
resultItems.push("<br>");
}
if (resultCount === 0) {
dom.byId("info").innerHTML = "<h3 style = 'color:#E60000'> No Record Found </h1>";
} else {
dom.byId("info").innerHTML = resultItems.join("");

//Zoom to Result & Set Query Result Symbol
var resultGraphic = new Graphic(results.features, highlightSymbol);
var resultExtent = graphicsUtils.graphicsExtent(results.features);
map.graphics.add(resultGraphic);
map.setExtent(resultExtent.expand(2));

console.log("resultGraphic:", (results.features));
}
}




Aucun commentaire:

Enregistrer un commentaire