top of page

Route Optimization Using ESRI Georoutes for a WebGIS App

Updated: Jun 16

Esri GeoRoutes is part of Esri's Network Analyst tools and provides advanced routing, directions, and logistics optimization capabilities using network datasets. It’s ideal for applications such as delivery planning, field workforce routing, and public service dispatching.

Route Optimization
Route Optimization

⚙️ Requirements

  • ArcGIS Online or ArcGIS Enterprise (with Network Analyst enabled)

  • ArcGIS REST API access

  • A web application built with JavaScript (ArcGIS API for JavaScript)

  • Optional: Your own network dataset (or use Esri's online services)

📦 Key Components

👨‍💻 Step-by-Step Implementation

1. Add ArcGIS JavaScript API

<script src="https://js.arcgis.com/4.29/"></script>

2. Basic Web Map with Routing

require([
  "esri/Map",
  "esri/views/MapView",
  "esri/rest/route",
  "esri/rest/support/RouteParameters",
  "esri/rest/support/FeatureSet",
  "esri/Graphic",
  "esri/layers/GraphicsLayer"
], function(Map, MapView, route, RouteParameters, FeatureSet, Graphic, GraphicsLayer) {

  const routeUrl = "https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World";

  const map = new Map({ basemap: "streets" });
  const view = new MapView({ container: "viewDiv", map: map, center: [-122.4, 37.78], zoom: 13 });

  const graphicsLayer = new GraphicsLayer();
  map.add(graphicsLayer);

  const stops = [];

  view.on("click", function(event) {
    const stop = new Graphic({
      geometry: event.mapPoint,
      symbol: { type: "simple-marker", color: "blue", size: "8px" }
    });
    graphicsLayer.add(stop);
    stops.push(stop);

    if (stops.length >= 2) {
      const routeParams = new RouteParameters({
        stops: new FeatureSet({ features: stops }),
        returnDirections: true
      });

      route.solve(routeUrl, routeParams).then(function(data) {
        if (data.routeResults.length > 0) {
          graphicsLayer.add(new Graphic({
            geometry: data.routeResults[0].route.geometry,
            symbol: { type: "simple-line", color: [5, 150, 255], width: 4 }
          }));
        }
      });
    }
  });
});

🧠 Optimization Features

  • Time Windows: Optimize delivery by arrival/departure time

  • Barriers: Avoid roads or areas under construction

  • Vehicle Routing Problem (VRP): Plan multi-vehicle routes

  • Travel Modes: Driving, walking, trucking, etc.

  • Traffic: Use historical or live traffic for ETA

🔐 Authentication (ArcGIS Online)

You need an API Key or OAuth token:

esriConfig.apiKey = "YOUR_API_KEY";

Or use OAuth 2.0 with IdentityManager.

🚀 Tips for Production

  • Preprocess and geocode stops for accuracy.

  • Use ArcGIS Enterprise if you need private routing datasets or high performance.

  • Log travel cost (e.g., time, distance) for analytics.

  • Integrate with workforce or dispatch systems via REST API.

📚 Resources



As a developer did you get better understanding of Route Optimization with this article?

  • 0%Yes

  • 0%No


Comments


bottom of page