Skip to content

Instantly share code, notes, and snippets.

@patrickarlt
Created January 7, 2014 17:30
Show Gist options
  • Save patrickarlt/8303014 to your computer and use it in GitHub Desktop.
Save patrickarlt/8303014 to your computer and use it in GitHub Desktop.
require([
"esri/map",
"esri/request",
"esri/geometry/Polyline",
"esri/symbols/SimpleLineSymbol",
"esri/graphic",
"dojo/domReady!"],
function(Map, request, Polyline, SimpleLineSymbol, Graphic) {
//Init Esri Basemap
window.map = new Map("mapDiv", {
center: [-122.68,45.53],
zoom: 11,
basemap: "gray"
});
var polylineJson = {
"paths":[[[-122.68,45.53], [-122.58,45.55],
[-122.57,45.58],[-122.53,45.6]]]
};
window.symbol = new SimpleLineSymbol().setWidth(10);
window.geometry = new Polyline(polylineJson);
window.polyline = new esri.Graphic(geometry, symbol);
map.on('load', function () {
map.graphics.add(polyline);
});
var serviceUrl = "https://logistics.arcgis.com/arcgis/rest/services/World/VehicleRoutingProblem/GPServer/SolveVehicleRoutingProblem/submitJob?parameters";
var currentToken = "t3Sk71Rm6M7tguGzwY3tc0Ifu0GvkClKcWyh1cac8twAQccmooj8du-NgJuc36PHgaqdpVYKLqEiPD96I4muvkxLZp0ZbzhxlzUaYuHSYc67wLHhdAvmgOJY0Bptv3s2zTzmxsgqLsxwtiAZvfi6yw..";
var routeRequest = request({
url: serviceUrl,
content: {
orders: JSON.stringify([
{
geometry: {
x: -122.68,
y: 45.53
},
attributes: {
name: "First_Order"
}
},
{
geometry: {
x: -122.58,
y: 45.55
},
attributes: {
name: "Second_Order"
}
},
{
geometry: {
x: -122.57,
y: 45.58
},
attributes: {
name: "Third_Order"
}
}
]),
depots: JSON.stringify([
{
geometry: {
x: -122.53,
y: 45.6
},
attributes: {
name: "The_Cafe"
}
}
]),
routes: JSON.stringify([
{
attributes: {
name: "First_Route",
StartDepotName: "The_Cafe",
EndDepotName: "The_Cafe"
}
}
]),
default_date: (new Date()).getTime(),
token : currentToken,
f : "json"},
handleAs: "json",
callbackParamName: "callback"
});
function areWeThereYet(jobId) {
setInterval(function(){
console.log('are we there yet?');
request({
url: "https://logistics.arcgis.com/arcgis/rest/services/World/VehicleRoutingProblem/GPServer/SolveVehicleRoutingProblem/jobs/" + jobId,
content: {
jobId: jobId,
token: currentToken,
f: "json"
}
}).then(
function(response) {
console.log("Success: ", response);
}, function(error) {
console.log("Error: ", error.message);
});
}, 2500);
}
// Call the Route function here, figure out some way to deal with the weird 'are we there yet' callback.
routeRequest.then(
function(response) {
console.log("Success: ", response);
areWeThereYet(response.jobId);
}, function(error) {
console.log("Error: ", error.message);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment