Hello,
I am currently in the process of creating a web application, in which I would like for the user to be able to type in their address, and have this location appear on the map. I have already accomplished this task. Next, I have created a geoprocessing model in ArcMap which should create a buffer around this point, and will find restaurants which intersect this buffer, and display them on the map. The model has 2 parameters, one distance parameter (linear unit), and one input parameter(feature set), which I have set as 'map.graphics' in my script. When I try to run the operation in a browser, i get a generic error: 'init.js:182 Error: Unable to complete operation'. I was wondering if anyone could tell me what they think I am doing wrong. Any help at all would be appreciated. Thanks so much in advance. Here is myJavaScript code:
require([
"dojo/parser",
"esri/map",
"esri/layers/ArcGISDynamicMapServiceLayer",
"esri/InfoTemplate",
"esri/dijit/Search",
"esri/dijit/LayerList",
"esri/dijit/Scalebar",
"esri/symbols/SimpleMarkerSymbol",
"esri/Color",
"esri/graphic",
"esri/tasks/Geoprocessor",
"esri/tasks/LinearUnit",
"esri/tasks/locator",
"esri/tasks/FeatureSet",
"dojo/on",
"dojo/_base/array",
"dojo/dom",
"dijit/registry",
"dijit/layout/BorderContainer",
"dijit/layout/ContentPane",
"dijit/layout/AccordionContainer",
"dijit/layout/AccordionPane",
"dijit/layout/TabContainer",
"dijit/form/Button",
"dijit/form/Select",
"dijit/form/HorizontalSlider",
"dijit/form/HorizontalRule",
"dijit/form/HorizontalRuleLabels",
"dojo/domReady!"
], function (parser, Map, ArcGISDynamicMapServiceLayer, InfoTemplate, Search, LayerList, Scalebar, SimpleMarkerSymbol, Color, Graphic, Geoprocessor, LinearUnit, Locator, FeatureSet, on, arrayUtils, dom, registry){
parser.parse();
var map = new Map("map", { //Create the basemap
basemap: "streets",
center: [-77.6559716660883, 38.1850243980318],
zoom: 11
});
var dynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer("http://gis.spotsylvania.va.us/arcgis/rest/services/SoccerTournamentWebApp/SoccerTournamentMap_Initial/MapServer"); //Request Congressional Districts dynamic map service layer from ArcGIS Server.
map.addLayer(dynamicMapServiceLayer);
layers = [ //Create layers for insertion into LayerList constructor
{
layer:dynamicMapServiceLayer,
showSubLayers: true,
showLegend: true,
showOpacitySlider: true,
visibility: true,
id: "Click arrow to the right to expand the layer list and map legend"
}
]
var onMapLoad = function() {
var layerList = new LayerList({
map: map,
layers: layers
},"layerlist");
layerList.startup();
};
onMapLoad();
var scaleBar = new Scalebar({
map: map,
attachTo: "bottom-left",
scalebarStyle: "ruler",
scalebarUnit: "english"
});
var locator = new Locator("http://gis.spotsylvania.va.us/arcgis/rest/services/SoccerTournamentWebApp/AddressLocator/GeocodeServer");
var s = new Search({
map: map,
}, "search");
s.startup();
registry.byId("locate").on("click", locate);
function locate() {
if(dom.byId("Street").value == "") {
alert("Make sure that you have filled in all of the text boxes to find your location. Restaurants near you cannot be found unless your current location is known.")
}
else if(dom.byId("City").value == "") {
alert("Make sure that you have filled in all of the text boxes to find your location. Restaurants near you cannot be found unless your current location is known.")
}
else if(dom.byId("State").value == "") {
alert("Make sure that you have filled in all of the text boxes to find your location. Restaurants near you cannot be found unless your current location is known.")
}
else if(dom.byId("ZIP").value == "") {
alert("Make sure that you have filled in all of the text boxes to find your location. Restaurants near you cannot be found unless your current location is known.")
}
else {
map.graphics.clear();
var address = {"Single Line Input" : dom.byId("Street").value.toString() + "," + " " + dom.byId("City").value.toString() + "," + " " + dom.byId("State").value.toString() + "," + " " + dom.byId("ZIP").value.toString()};
console.log(address)
locator.outSpatialReference = map.spatialReference;
var options = {
address: address,
outFields: ["*"]
}
}
locator.addressToLocations(options, showResults);
}
function showResults(results) {
var candidate;
var symbol = new SimpleMarkerSymbol();
var infoTemplate = new InfoTemplate(
"Your Current Location",
"Address: ${address}"
);
symbol.setStyle(SimpleMarkerSymbol.STYLE_SQUARE);
symbol.setColor(new Color([255,0,0,0.75]));
var geom;
arrayUtils.every(results, function(candidate) {
console.log(candidate.score);
if (candidate.score > 80){
var attributes = {
address: candidate.address,
score: candidate.score
};
geom = candidate.location;
var graphic = new Graphic(geom, symbol,attributes,infoTemplate);
map.graphics.add(graphic);
return false;
}
else
{
return true;
}
});
if ( geom !== undefined ) {
map.centerAndZoom(geom, 12);
}
};
registry.byId("findRestaurants").on("click", findRestaurants);
function findRestaurants() {
var gp = new Geoprocessor("http://gis.spotsylvania.va.us/arcgis/rest/services/SoccerTournamentWebApp/FindRestaurantsNearMe/GPServer/Find%20Restaraunts%20Close%20to%20Me");
gp.setOutputSpatialReference({wkid:102100});
var distance = dom.byId("distance").value;
var distUnit = new LinearUnit();
distUnit.distance = distance;
distUnit.units = "esriMiles";
var inputFeatures = new FeatureSet();
var features = [];
features.push(map.graphics);
console.log(features);
inputFeatures.features = features;
var params = { "Distance": distUnit, "Feature_Set": features };
console.log(gp);
console.log(params);
gp.execute(params, drawRestaurants);
};
function drawRestaurants(results) {
var symbol1 = new SimpleMarkerSymbol();
var infoTemplate1 = new InfoTemplate(
"${Name of Facility}",
"Address: ${address}"
);
symbol1.setStyle(SimpleMarkerSymbol.STYLE_SQUARE);
symbol1.setColor(new Color([0,0,255]));
var features = results[0].value.features;
for (var f=0; f<features.length; f++) {
var feature = features;
feature.setSymbol(symbol1);
map.graphics.add(feature);
}
};
});