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();
Solved! Go to Solution.
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];
}
});
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!!!
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.
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>
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];
}
});
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