Hi all,
Half of the time when I click button to zoom to graphics, My map ends up in the middle of the gulf of Mexico. I also get that error:
My code is:
function initSelectToolbar(event) {
//Create Home button
var initialExtent = map.extent;
dojo.create("div", {
className: "esriSimpleSliderHomeButton",
title: 'Zoom to Full Extent',
onclick: function () {
if (initialExtent === undefined) {
initialExtent = map.extent;
}
map.setExtent(initialExtent);
}
}, dojo.query(".esriSimpleSliderIncrementButton")[0], "after");
console.log("start edits");
selectionToolbar = new Draw(event.map);
var selectQuery = new Query();
selectQuery.outFields = ["*"];
var targetGeometry;
on(selectionToolbar, "DrawEnd", function (geometry) {
selectionToolbar.deactivate();
$("#Modal1").show();
selectQuery.geometry = geometry;
featureLayer.selectFeatures(selectQuery, FeatureLayer.SELECTION_NEW, function (targetGeometry) {
targetGeometry = graphicsUtils.getGeometries(featureLayer.getSelectedFeatures());
console.log(targetGeometry);
geometryService.union(targetGeometry, function (geometry) {
featureLayer.clearSelection();
//Graphics to be shown on web map
var symbol = new SimpleFillSymbol("none", new SimpleLineSymbol("solid", new Color([255, 255, 255]), 2), new Color([255, 255, 255, 0.25]));
var graphic = new Graphic(geometry, symbol);
map.graphics.add(graphic);
var extent = graphicsUtils.graphicsExtent(map.graphics.graphics);
map.setExtent(extent);
//feature set
var features = [];
var FeaturesetGraphs = new FeatureSet();
FeaturesetGraphs.features = features;
features.push(graphic);
console.log("Test =" + FeaturesetGraphs);
//Geoporcessing serice
var params = {
"feature_set": FeaturesetGraphs,
"output_test_zip": "output_test_zip",
"Area_of_Interest": FeaturesetGraphs
};
gp.submitJob(params, completeCallback, statusCallback);
function statusCallback(jobInfo) {
var status = jobInfo.jobStatus;
if (status === "esriJobFailed") {
console.log(status);
} else if (status === "esriJobSucceeded") {
console.log("succeeded");
}
}
function completeCallback(jobInfo) {
console.log("getting data");
if (jobInfo.jobStatus !== "esriJobFailed") {
gp.getResultData(jobInfo.jobId, "output_test_zip", downloadFile);
}
}
function downloadFile(outputFile) {
var theurl = outputFile.value.url;
$('#downloadLink').append($('<a>').attr('href', theurl).attr('download', "Test").text('Project Download (FGDB)'));
}
console.log("unioned features");
}, function (err) {
console.log(err);
});
});
});
}
function sumtrees(event) {
var sum = 0;
//summarize the cumulative tree in the area selected
arrayUtil.forEach(event.features, function (feature) {
sum += feature.attributes.Sum_TREECO;
});
$("#messages").text(sum)
}
Any idea?
map.setExtent(graphicsUtils.graphicsExtent(featureLayer.getSelectedFeatures()), true);
This code worked!