Select to view content in your preferred language

Is there an example on how to get drivetime polygons for a time greater than 15 minutes using esri.leaflet?

647
1
04-05-2017 02:18 PM
DanielArmstrong
Deactivated User

Is there an example on how to get drivetime polygons for a time greater than 15 minutes using esri.leaflet?

I can use the sample code pretty much as is to generate single polygons for any time up to 15 minutes,
but greater than that the response seems to default to 5 minutes. I have a routine that gives me a token based on
the client ID and secret from the app I registered with Esri and use this as shown in code below. I am thinking it is an
authentication problem dis-allowing times greater than 15 minutes but I am not sure. If anyone has a suggestion PLEASE HELP!!!

Thanks in advance.

I create a service as follows:
var gpService = L.esri.GP.service({
url: "https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Network/ESRI_DriveTime_US/GPServer/Creat...",
useCors: false
});
gpService.on('authenticationrequired', function (e) {
e.retry(esriToken);
});
gpService.authenticate(esriToken);
gpTask = gpService.createTask();
gpTask.token(esriToken);
driveTimes = L.featureGroup();
leafMap.addLayer(driveTimes);

Later on I call this function to create the polygon after a user enters time in minutes and clicks a button:

function drawDriveTimePolygon(lat, lon, minutes) {
driveTimes.clearLayers();
gpTask.setParam("Drive_Times", minutes);
gpTask.setParam("Input_Location", L.latLng(lat, lon));
gpTask.token(esriToken);
gpTask.run(driveTimeCallback);
function driveTimeCallback(error, response, raw) {
driveTimes.addLayer(L.geoJSON(response.Output_Drive_Time_Polygons));
var points = response.Output_Drive_Time_Polygons.features[0].geometry.coordinates[0];
var arrayLength = points.length;
var vertices = [];
for (var i = 0; i < arrayLength; i++) {
vertices.push(new L.latLng(points[0], points[1]));
}
var polygon = new L.Polygon(vertices)
.setStyle({ color: shapeColor })
.addTo(leafMap);
}
}

Tags (1)
0 Kudos
1 Reply
RickeyFight
MVP Regular Contributor

If you look at the service you are referencing it has 3 options. 

Default Value:

        5 10 15

    CreateDriveTimePolygons (Network/ESRI_DriveTime_US) 

    You would need to publish your own drive time service. 

    0 Kudos