<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Navigation for closest facility not showing in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/navigation-for-closest-facility-not-showing/m-p/1108615#M75001</link>
    <description>&lt;P&gt;I'm not seeing what you talking about. Can you be more specific?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 18 Oct 2021 21:50:17 GMT</pubDate>
    <dc:creator>JeffersonTotimeh</dc:creator>
    <dc:date>2021-10-18T21:50:17Z</dc:date>
    <item>
      <title>Navigation for closest facility not showing</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/navigation-for-closest-facility-not-showing/m-p/1108473#M74994</link>
      <description>&lt;P&gt;I'm working on a project and I want to add the closest facility function to my work. The code runs perfectly but the route to the closest facility doesn't seem to work. I tried using other people's code but same results. Please how do I fix this problem.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;meta charset="utf-8"&amp;gt;
  &amp;lt;meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no"&amp;gt;
  &amp;lt;title&amp;gt;ArcGIS Developer Guide: Closest facility routing&amp;lt;/title&amp;gt;
  &amp;lt;style&amp;gt;
    html, body, #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }
  &amp;lt;/style&amp;gt;

  &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.21/esri/themes/light/main.css"&amp;gt;
  &amp;lt;script src="https://js.arcgis.com/4.21/"&amp;gt;&amp;lt;/script&amp;gt;

  &amp;lt;script&amp;gt;
    require([
      "esri/config",
      "esri/Map",
      "esri/views/MapView",
      "esri/Graphic",
      "esri/layers/GraphicsLayer",
      "esri/rest/closestFacility",
      "esri/rest/support/ClosestFacilityParameters",
      "esri/rest/support/FeatureSet",
      "esri/geometry/Point",
      "esri/symbols/Symbol",
      "esri/rest/locator"
    ], (
      esriConfig,
      Map,
      MapView,
      Graphic,
      GraphicsLayer,
      closestFacility,
      ClosestFacilityParameters,
      FeatureSet,
      Point,
      Symbol,
      locator,
    )=&amp;gt; {

      esriConfig.apiKey = "YOUR_API_KEY";

      let placeCategory = "Gas station";

      let startSymbol = {
        type: "simple-marker",
        color: "white",
        size: "10px",
        outline: {
          color: "black",
          width: "1px",
        },
      };

      let facilitySymbol = {
        type: "simple-marker",
        color: "black",
        size: "11px",
        outline: {
          color: "white",
          width: "1px",
        },
      };

      let routeSymbol = {
        type: "simple-line",
        color: [50, 150, 255, 0.75],
        width: "5",
      };

      const locatorUrl = "http://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer";

      const closestFacilityUrl = "https://route-api.arcgis.com/arcgis/rest/services/World/ClosestFacility/NAServer/ClosestFacility_World/solveClosestFacility/";


      const routeLayer = new GraphicsLayer();
      const facilitiesLayer = new GraphicsLayer();
      const selectedFacilitiesLayer = new GraphicsLayer();
      const startLayer = new GraphicsLayer();

      let map = new Map({
        basemap: "arcgis-navigation",
        layers: [routeLayer, facilitiesLayer, selectedFacilitiesLayer, startLayer],
      });

      let view = new MapView({
        container: "viewDiv",
        map: map,
        center: [-123.18586,49.24824],
        zoom: 12,
        constraints: {
          snapToZoom: false
        }
      });

      view.popup.actions = [];

      const places = [
        ["Gas station", "gas-station"],
        ["College", "school"],
        ["Grocery", "grocery-store"],
        ["Hotel", "hotel"],
        ["Hospital", "hospital"]
      ];

      const select = document.createElement("select", "");
      select.setAttribute("class", "esri-widget esri-select");
      select.setAttribute(
        "style",
        "width: 175px; font-family: 'Avenir Next'; font-size: 1em"
      );

      places.forEach((p) =&amp;gt; {
        const option = document.createElement("option");
        option.value = p[0];
        option.innerHTML = p[0];
        select.appendChild(option);
      });

      view.ui.add(select, "top-right");

      view.when(() =&amp;gt; {
        addStart(view.center);
        findFacilities(view.center, true);
      });

      view.on("click", (event)=&amp;gt; {
        view.hitTest(event).then((response)=&amp;gt; {
          if (response.results.length === 1) {
            findFacilities(event.mapPoint, false);
          }
        });
      });

      select.addEventListener("change", (event) =&amp;gt; {
        placeCategory = event.target.value;
        findFacilities(startLayer.graphics.getItemAt(0).geometry, true);
      });

      // Find places and add them to the map
      function findFacilities(pt, refresh) {
        view.popup.close();
        //startLayer.graphics.removeAll();
        addStart(pt);
        if (refresh) {
          // Add facilities
          locator
            .addressToLocations(locatorUrl,{
              location: pt,
              searchExtent: view.extent,
              categories: [placeCategory],
              maxLocations: 25,
              outFields: ["Place_addr", "PlaceName"],
              outSpatialReference: view.spatialReference
            })
            .then((results)=&amp;gt; {
              facilitiesLayer.removeAll();
              // Add graphics
              showFacilities(results);
              // Find closest place
              findClosestFacility(startLayer.graphics.getItemAt(0), facilitiesLayer.graphics);
            });
          } else {
            findClosestFacility(startLayer.graphics.getItemAt(0), facilitiesLayer.graphics);
          }
      }

      function addStart(pt) {
        startLayer.graphics.removeAll();
        startLayer.add(new Graphic({
          geometry: pt,
          symbol: startSymbol
        }));
      }

      function findClosestFacility(startGraphic, facilityGraphics) {
        routeLayer.removeAll();
        selectedFacilitiesLayer.removeAll();
        let params = new ClosestFacilityParameters({
          incidents: new FeatureSet({
            features: [startGraphic],
          }),
          facilities: new FeatureSet({
            features: facilityGraphics.toArray(),
          }),
          returnRoutes: true,
          returnFacilities: true,
          defaultTargetFacilityCount: 3,
        });

        closestFacility.solve(closestFacilityUrl, params).then(
          (results) =&amp;gt; {
            results.routes.forEach((route, i)=&amp;gt; {
              // Add closest route
              route.symbol = routeSymbol;
              routeLayer.add(route);
              // Add closest facility
              const facility = results.facilities[route.attributes.FacilityID - 1];
              addSelectedFacility(i + 1, facility.latitude, facility.longitude, route.attributes);
            });
          },
          (error) =&amp;gt; {
            console.log(error.details);
          }
        );
      }

      function showFacilities(results) {
        results.forEach((result,i)=&amp;gt; {
          facilitiesLayer.add(
            new Graphic({
              attributes: result.attributes,
              geometry: result.location,
              symbol: {
                type: "web-style",
                name: getIconName(placeCategory),
                styleName: "Esri2DPointSymbolsStyle",
              },
              popupTemplate: {
                title: "{PlaceName}",
                content: "{Place_addr}" +
                  "&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;" +
                  result.location.longitude.toFixed(5) +
                  "," +
                  result.location.latitude.toFixed(5),
              },
            })
          );
        });
      }

      function addSelectedFacility(number, latitude, longitude, attributes) {
        selectedFacilitiesLayer.add(new Graphic({
          symbol: {
            type: "simple-marker",
            color: [255, 255, 255,1.0],
            size: 18,
            outline: {
              color: [50,50,50],
              width: 1
            }
          },
          geometry: {
            type: "point",
            latitude: latitude,
            longitude: longitude
          },
          attributes: attributes
        }));
        selectedFacilitiesLayer.add(new Graphic({
          symbol: {
            type: "text",
            text: number,
            font: { size: 11, weight: "bold" },
            yoffset: -4,
            color: [50,50,50]
          },
        geometry: {
          type: "point",
          latitude: latitude,
          longitude: longitude
        },
        attributes: attributes
        }));
      }

      function getIconName(category) {
        let iconName;
        switch (category) {
          case "Grocery":
            iconName = "grocery-store";
            break;
          case "College":
            iconName = "school";
            break;
          case "Gas station":
            iconName = "gas-station";
            break;
          case "Hospital":
            iconName = "hospital";
            break;
          case "Hotel":
            iconName = "hotel";
            break;
        }
        return iconName;
      }
    });

&amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
  &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 18 Oct 2021 16:32:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/navigation-for-closest-facility-not-showing/m-p/1108473#M74994</guid>
      <dc:creator>JeffersonTotimeh</dc:creator>
      <dc:date>2021-10-18T16:32:14Z</dc:date>
    </item>
    <item>
      <title>Re: Navigation for closest facility not showing</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/navigation-for-closest-facility-not-showing/m-p/1108560#M74999</link>
      <description>&lt;P&gt;Could you clarify what part of it doesn't work?&lt;/P&gt;&lt;P&gt;I used my own API key for your sample code and it looks like it functions as it should. If you aren't getting any routes at all then you may need to configure the Location Services for your API key. This can be done on through:&lt;/P&gt;&lt;P&gt;Developer's site&amp;gt;Dashboard&amp;gt;API Keys&amp;gt;Your App's API Key&amp;gt;Location Services&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 19:36:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/navigation-for-closest-facility-not-showing/m-p/1108560#M74999</guid>
      <dc:creator>woriginal1</dc:creator>
      <dc:date>2021-10-18T19:36:02Z</dc:date>
    </item>
    <item>
      <title>Re: Navigation for closest facility not showing</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/navigation-for-closest-facility-not-showing/m-p/1108615#M75001</link>
      <description>&lt;P&gt;I'm not seeing what you talking about. Can you be more specific?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 21:50:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/navigation-for-closest-facility-not-showing/m-p/1108615#M75001</guid>
      <dc:creator>JeffersonTotimeh</dc:creator>
      <dc:date>2021-10-18T21:50:17Z</dc:date>
    </item>
    <item>
      <title>Re: Navigation for closest facility not showing</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/navigation-for-closest-facility-not-showing/m-p/1108628#M75003</link>
      <description>&lt;P&gt;@ woriginal I've have configured it but it still doesn't work is it because I'm using the default API KEY?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 22:29:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/navigation-for-closest-facility-not-showing/m-p/1108628#M75003</guid>
      <dc:creator>JeffersonTotimeh</dc:creator>
      <dc:date>2021-10-18T22:29:31Z</dc:date>
    </item>
    <item>
      <title>Re: Navigation for closest facility not showing</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/navigation-for-closest-facility-not-showing/m-p/1108821#M75011</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/529958"&gt;@JeffersonTotimeh&lt;/a&gt;, yes, you must supply your own valid API key.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html#apiKey" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html#apiKey&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/documentation/mapping-apis-and-services/security/api-keys/" target="_blank"&gt;https://developers.arcgis.com/documentation/mapping-apis-and-services/security/api-keys/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Oct 2021 14:39:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/navigation-for-closest-facility-not-showing/m-p/1108821#M75011</guid>
      <dc:creator>Noah-Sager</dc:creator>
      <dc:date>2021-10-19T14:39:55Z</dc:date>
    </item>
    <item>
      <title>Re: Navigation for closest facility not showing</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/navigation-for-closest-facility-not-showing/m-p/1108923#M75017</link>
      <description>&lt;P&gt;You should create your own API key for your app then insert the API key into the YOUR_API_KEY part of your code below (keep the quotations):&lt;/P&gt;&lt;PRE&gt;esriConfig.apiKey = "YOUR_API_KEY";&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;The above code can be found on Line 45 of your sample code.&lt;/P&gt;&lt;P&gt;I was able to get your sample code to work with my own API key by enabling 3 of the Location Services provided:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Geocoding (not stored)&lt;/LI&gt;&lt;LI&gt;Routing&lt;/LI&gt;&lt;LI&gt;Closest Facility&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="woriginal1_0-1634663545112.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/25553iBA9CF942EA45F693/image-size/medium?v=v2&amp;amp;px=400" role="button" title="woriginal1_0-1634663545112.png" alt="woriginal1_0-1634663545112.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Oct 2021 17:13:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/navigation-for-closest-facility-not-showing/m-p/1108923#M75017</guid>
      <dc:creator>woriginal1</dc:creator>
      <dc:date>2021-10-19T17:13:35Z</dc:date>
    </item>
    <item>
      <title>Re: Navigation for closest facility not showing</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/navigation-for-closest-facility-not-showing/m-p/1110569#M75065</link>
      <description>&lt;P&gt;I did but it still didn't show&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Oct 2021 15:41:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/navigation-for-closest-facility-not-showing/m-p/1110569#M75065</guid>
      <dc:creator>JeffersonTotimeh</dc:creator>
      <dc:date>2021-10-24T15:41:33Z</dc:date>
    </item>
    <item>
      <title>Re: Navigation for closest facility not showing</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/navigation-for-closest-facility-not-showing/m-p/1110570#M75066</link>
      <description>&lt;P&gt;I tried enabling it but it didn't work&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Oct 2021 15:41:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/navigation-for-closest-facility-not-showing/m-p/1110570#M75066</guid>
      <dc:creator>JeffersonTotimeh</dc:creator>
      <dc:date>2021-10-24T15:41:57Z</dc:date>
    </item>
    <item>
      <title>Re: Navigation for closest facility not showing</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/navigation-for-closest-facility-not-showing/m-p/1110997#M75069</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/529958"&gt;@JeffersonTotimeh&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Are you getting any errors in the console?&lt;/P&gt;&lt;P&gt;I used the exact code you provided except with the API key I created myself that has the 3 following services enabled: Geocoding (not stored), Routing, and Closest Facility.&lt;/P&gt;&lt;P&gt;Make sure you have those enabled and the API key in the code replaced with your own because it works for me.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="woriginal1_0-1635190781897.png" style="width: 516px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/26119i9C0C10A681134C90/image-dimensions/516x284?v=v2" width="516" height="284" role="button" title="woriginal1_0-1635190781897.png" alt="woriginal1_0-1635190781897.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Oct 2021 19:40:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/navigation-for-closest-facility-not-showing/m-p/1110997#M75069</guid>
      <dc:creator>woriginal1</dc:creator>
      <dc:date>2021-10-25T19:40:43Z</dc:date>
    </item>
  </channel>
</rss>

