Thanks Robert,
I tried to implement your suggestion above here: PASTA
However the previous map layer remains. I'll post my javascript below.
var app;
require([
"esri/map",
"esri/layers/ArcGISDynamicMapServiceLayer",
"esri/dijit/BasemapToggle",
"dojo/on",
"dojo/parser",
"esri/tasks/Geoprocessor",
"dojo/dom",
"dijit/layout/BorderContainer",
"dijit/form/Button",
"dojo/domReady!",
"dijit/form/HorizontalSlider",
"dijit/form/HorizontalRuleLabels",
"dijit/form/HorizontalRule"
], function (Map,ArcGISDynamicMapServiceLayer,BasemapToggle,on,parser,Geoprocessor,dom,HorizontalSlider,HorizontalRuleLabels,HorizontalRule)
{
parser.parse();
map = new Map("map", {
basemap: "topo",
center: [-124.5, 44.15],
zoom: 8
});
var toggle = new BasemapToggle({
map: map,
basemap: "satellite"
}, "BasemapToggle");
toggle.startup();
// Make 2 Horizontal Sliders Programatically
// Create the rules
var rulesNode = dojo.create(
"div", {}, dojo.byId("horizSlider"), "first");
var sliderRules = new dijit.form.HorizontalRule({
container: "bottomDecoration",
count: 11,
style: "width: 5px;"
}, rulesNode);
var rulesNode2 = dojo.create(
"div", {}, dojo.byId("horizSlider2"), "first");
var sliderRules2 = new dijit.form.HorizontalRule({
container: "bottomDecoration",
count: 11,
style: "width: 5px;"
}, rulesNode);
// Create the labels
var labelsNode = dojo.create(
"div", {}, dojo.byId("horizSlider"), "first");
var sliderLabels = new dijit.form.HorizontalRuleLabels({
container: "topDecoration",
labelStyle: "font-style: italic; font-size: 0.75em"
}, labelsNode);
var labelsNode2 = dojo.create(
"div", {}, dojo.byId("horizSlider2"), "first");
var sliderLabels2 = new dijit.form.HorizontalRuleLabels({
container: "topDecoration",
labelStyle: "font-style: italic; font-size: 0.75em"
}, labelsNode);
// Create the sliders
var horizSlider = new dijit.form.HorizontalSlider({
minimum: 0,
maximum: 1,
pageIncrement: .20,
value: .20,
intermediateChanges: true,
style: "height: 200px;"
}, "horizSlider");
var horizSlider2 = new dijit.form.HorizontalSlider({
minimum: 0,
maximum: 1,
pageIncrement: .20,
value: .20,
intermediateChanges: true,
style: "height: 200px;"
}, "horizSlider2");
// Start up the widgets
horizSlider.startup();
//horizSlider2.startup();
sliderRules.startup();
//sliderRules2.startup();
sliderLabels.startup();
//sliderLabels2.startup();
var horizLabel = dojo.byId("horizValue");
var horizLabel2 = dojo.byId("horizValue2");
function updateHorizontalLabel() {
// Update label
horizLabel.innerHTML = horizSlider.get("value");
}
function updateHorizontalLabel2() {
// Update label
horizLabel2.innerHTML = horizSlider2.get("value");
}
dojo.connect(horizSlider,"onChange",updateHorizontalLabel);
// Update label right away
updateHorizontalLabel();
dojo.connect(horizSlider2,"onChange",updateHorizontalLabel2);
// Update label right away
updateHorizontalLabel2();
var weightedValue1 = dojo.byId("WeightedValueValue1");
var weightedValue2 = dojo.byId("WeightedValueValue2");
var Weight1;
var Weight2;
function updateWeighting() {
// Update weighting calculations
var weightSum = horizSlider.get("value")+horizSlider2.get("value");
var weightFactor = 1/weightSum;
weightedValue1.innerHTML = horizSlider.get("value")*weightFactor;
weightedValue2.innerHTML = horizSlider2.get("value")*weightFactor;
Weight1 = horizSlider.get("value")*weightFactor;
Weight2 = horizSlider2.get("value")*weightFactor;
}
dojo.connect(horizSlider,"onChange",updateWeighting);
// Update the weighting right away
updateWeighting();
dojo.connect(horizSlider2,"onChange",updateWeighting);
// Update the weighting right away
updateWeighting();
// Geoprocessing
/* Step 1: Initialize Geoprocessing Task as a global variable.
That is, declare the variable outside a function definition
since we will be using gpTask variable in other methods */
var gpTaskUrl="http://bhc.coas.oregonstate.edu:6080/arcgis/rest/services/geoprocessing/WeightedSum/GPServer/Weighte...";
var gpTask = new Geoprocessor(gpTaskUrl);
// Set output spatial reference property to map's spatial reference.
// myMap is assumed to be an instance of map container esri.map.
gpTask.outSpatialReference=map.spatialReference;
on(dom.byId("hotspotButton"), "click", myGPSubmitJob);
//Step 3: Run the task
function myGPSubmitJob(n){
// Get the input rasters
var Raster1 = "Midwater Device\\Initial\\suitability";
var Raster2 = "Cetaceans\\Initial\\suitability";
var params= {"Raster1":Raster1, "Weight1":Weight1, "Raster2":Raster2, "Weight2":Weight2};
// Setup event handlers.
dojo.connect(gpTask, "onJobComplete",onTaskComplete);
dojo.connect(gpTask, "onError",onTaskFailure);
dojo.connect(gpTask, "onStatusUpdate",onTaskStatus);
gpTask.submitJob(params);
}
// On Job Complete Callback add a dynamic map service using ResultMapService
function onTaskComplete(jobInfo, gpResultLayerPrevious){
if(gpResultLayer){
map.removeLayer(gpResultLayer);
}
//replace mapservice url with your url and append jobid
var mapurl = "http://bhc.coas.oregonstate.edu:6080/arcgis/rest/services/geoprocessing/WeightedSum/MapServer/jobs/" + jobInfo.jobId;
//create a dynamic map service
var gpResultLayer = new esri.layers.ArcGISDynamicMapServiceLayer(mapurl, {
id: "WeightedSum",
opacity: 0.5
});
//remove any existing model results and add new model result to the web application.
map.addLayer(gpResultLayer);
// reset the gpResultlayerPrevious
gpResultLayerPrevious = gpResultLayer;
}
// Event handler for onStatusUpdate event
function onTaskStatus(jobInfo) {
//write status to console to help debugging
console.log(jobInfo.jobStatus);
}
// Event handler for onError event
function onTaskFailure(error) {
// Report error
alert("Error:"+ error);
}
app = {
myGPSubmitJob: myGPSubmitJob,
gpResultLayer: null
};
});