Select to view content in your preferred language

api version

1195
5
Jump to solution
12-15-2017 01:25 AM
anjelinaponkerat
Frequent Contributor

Hi

I,m using closest facility sample, but the sample can not show direction when I use my own require and function code.  please help me...

<script>

var map,params, infos =[], dndSource, dynamicLayerInfos;
require([
"dojo/dom",
"esri/Color",
"dojo/keys",
"dojo/parser",
"dijit/registry",
"esri/urlUtils",
"esri/config",
"esri/sniff",
"esri/map",
"esri/SnappingManager",
"esri/dijit/Measurement",
"esri/layers/FeatureLayer",
"esri/tasks/GeometryService",
"esri/symbols/SimpleFillSymbol",
"esri/dijit/Scalebar",
"esri/dijit/BasemapGallery",
"esri/dijit/BasemapLayer",
"esri/dijit/Basemap",
"esri/dijit/OverviewMap",
"esri/tasks/locator",
"esri/dijit/Search",
"esri/symbols/PictureMarkerSymbol",
"esri/InfoTemplate",
"esri/dijit/HomeButton",
"esri/geometry/Extent",
"esri/SpatialReference",
"esri/dijit/VisibleScaleRangeSlider",
"esri/geometry/scaleUtils",
"esri/virtualearth/VETiledLayer",
"dijit/form/Button",
"esri/tasks/query",
"esri/geometry/Circle",
"esri/graphic",

"dojo/on",
"esri/toolbars/draw",
"esri/units",
"esri/layers/ArcGISDynamicMapServiceLayer",
"esri/layers/DynamicLayerInfo",
"esri/layers/LayerDataSource",
"esri/layers/LayerDrawingOptions",
"esri/layers/TableDataSource",

"dojo/dom-construct",
"dojo/dom-style",
"dojo/query",
"dojo/_base/array",
"dojo/dnd/Source",

"esri/layers/ImageParameters",
"esri/dijit/Legend",
"dojo/agsjs/layers/GoogleMapsLayer",

"esri/lang",


"esri/layers/GraphicsLayer",
"esri/renderers/SimpleRenderer",

"esri/geometry/Point",
"esri/tasks/FeatureSet",

"esri/tasks/ClosestFacilityTask",
"esri/tasks/ClosestFacilityParameters",

"esri/symbols/SimpleMarkerSymbol",
"esri/symbols/SimpleLineSymbol",
"dijit/form/Button",
"dijit/form/ComboBox",
"dijit/layout/BorderContainer",
"dijit/layout/ContentPane",
"dijit/TitlePane",
"dijit/Dialog",


], function(
dom, Color, keys, parser, registry, urlUtils, esriConfig,
has, Map, SnappingManager, Measurement,
FeatureLayer, GeometryService,
SimpleFillSymbol, Scalebar, BasemapGallery, BasemapLayer, Basemap, OverviewMap, Locator, Search, PictureMarkerSymbol, InfoTemplate, HomeButton, Extent, SpatialReference, VisibleScaleRangeSlider, scaleUtils, VETiledLayer, Button, Query, Circle, Graphic,
on, Draw, units, ArcGISDynamicMapServiceLayer, DynamicLayerInfo, LayerDataSource,
LayerDrawingOptions, TableDataSource, domConstruct, domStyle, query, arrayUtils, Source, ImageParameters, Legend, GoogleMapsLayer,esriLang, GraphicsLayer, SimpleRenderer, Point, FeatureSet, ClosestFacilityTask, ClosestFacilityParameters, SimpleMarkerSymbol, SimpleLineSymbol
) {
var incidentsGraphicsLayer, routeGraphicLayer, closestFacilityTask;
parser.parse();

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Anjelina,

  Once I commented out GoogleMapsLayer from the require array and changed your closest facility solve function to use arrayUtils and not array (which is undefined in your code). I got it to work just fine:

        //solve
        closestFacilityTask.solve(params, function(solveResult) {
          arrayUtils.forEach(solveResult.routes, function(route, index) {
            //build an array of route info
            var attr = arrayUtils.map(solveResult.directions[index].features, function(feature) {
              return feature.attributes.text;
            });
            var infoTemplate = new InfoTemplate("Attributes", "${*}");

            route.setInfoTemplate(infoTemplate);
            route.setAttributes(attr);

            routeGraphicLayer.add(route);
            dom.byId("directionsDiv").innerHTML = "Hover over the route to view directions";
          });

          //display any messages
          if (solveResult.messages.length > 0) {
            dom.byId("directionsDiv").innerHTML = "<b>Error:</b> " + solveResult.messages[0];
          }
        });

View solution in original post

5 Replies
anjelinaponkerat
Frequent Contributor

I can add facility and incident and show those on the map,  then I checked by firebug and found the direction is solved completely but sample can not show it on the map!!!

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Anjelina,

   I don't see anything wrong in the code you have posted so far so the issue must be in the rest of your code.

anjelinaponkerat
Frequent Contributor

hi

This is my code:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=yes">


<title>map</title>
<link rel="stylesheet" href="https://js.arcgis.com/3.22/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="https://js.arcgis.com/3.22/esri/css/esri.css">
<style>
html,
body,html,#main{margin:0;padding:0;height:100%;width:100%;}

#map {
border: solid 1px #B5BCC7;
padding: 0;

}



</body>


</html>

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Anjelina,

  Once I commented out GoogleMapsLayer from the require array and changed your closest facility solve function to use arrayUtils and not array (which is undefined in your code). I got it to work just fine:

        //solve
        closestFacilityTask.solve(params, function(solveResult) {
          arrayUtils.forEach(solveResult.routes, function(route, index) {
            //build an array of route info
            var attr = arrayUtils.map(solveResult.directions[index].features, function(feature) {
              return feature.attributes.text;
            });
            var infoTemplate = new InfoTemplate("Attributes", "${*}");

            route.setInfoTemplate(infoTemplate);
            route.setAttributes(attr);

            routeGraphicLayer.add(route);
            dom.byId("directionsDiv").innerHTML = "Hover over the route to view directions";
          });

          //display any messages
          if (solveResult.messages.length > 0) {
            dom.byId("directionsDiv").innerHTML = "<b>Error:</b> " + solveResult.messages[0];
          }
        });
anjelinaponkerat
Frequent Contributor

Hi

Yes it was related to array. thanks ...

One more thing:

1-How we can use a button to call mouse event, now the tools works by any mouse click but I,m going to have a button to push it and then can add new incident points...

2- why the tools dont return length(Meters or km)  and time of direction? 

3- I need a of button to add new facility points by user click

0 Kudos