How to configure Local GeoCode Server URL?

843
3
01-05-2018 06:15 AM
SivaramKrishnan2
New Contributor III

Hi

      I'm trying to implement direction widget in my application and i'm using the JS API 3.2 hosted locally since i don't have internet connectivity.My application is working fine but it is

throwing URL not found error for the ESRI GeoCode service

So how can i overcome this issue and where i can configure the local GeoCode service URL since all my reference are local.

please find the below 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=no">
<title>Directions</title>
<link rel="stylesheet" href="claro.css">
<link rel="stylesheet" href="esri.css">
<style>
html, body, #map {
height:100%;
width:100%;
margin:0;
padding:0;
}
body {
background-color:#FFF;
overflow:hidden;
font-family:"Trebuchet MS";
}
.esriStopsGetDirectionsContainer{display:none;}
#fade {
display: none;
position:absolute;
top: 0%;
left: 0%;
width: 100%;
height: 100%;
background-color: #ababab;
z-index: 1001;
-moz-opacity: 0.8;
opacity: .70;
filter: alpha(opacity=80);
}

#modal {
display: none;
position: absolute;
top: 45%;
left: 45%;
width: 64px;
height: 64px;
padding:30px 15px 0px;
border: 3px solid #ababab;
box-shadow:1px 1px 10px #ababab;
border-radius:20px;
background-color: white;
z-index: 1002;
text-align:center;
overflow: auto;
}
</style>

<script src="3.22/init.js"></script>
<script>
// assign default values
var longitude = 77.099936;
var latitude = 28.556238;
var facilitiesGraphicsLayer;
require([
"esri/urlUtils", "esri/map", "esri/dijit/Directions",
"dojo/parser", "esri/layers/ArcGISDynamicMapServiceLayer",
"esri/layers/GraphicsLayer","esri/renderers/SimpleRenderer",
"esri/symbols/SimpleMarkerSymbol","esri/symbols/SimpleLineSymbol","esri/SpatialReference",
"esri/Color","esri/graphic", "esri/geometry/Point","esri/tasks/FeatureSet","esri/symbols/PictureFillSymbol","esri/layers/ArcGISTiledMapServiceLayer",
"dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dojo/domReady!"
], function(
urlUtils, Map, Directions,
parser,ArcGISDynamicMapServiceLayer,GraphicsLayer,
SimpleRenderer,SimpleMarkerSymbol,SimpleLineSymbol,SpatialReference,
Color,Graphic,Point,FeatureSet,PictureFillSymbol,ArcGISTiledMapServiceLayer
) {
parser.parse();

//session storage
if(typeof(Storage) !== "undefined")
{
for(var i=0; i < sessionStorage.length; i++)
{
var propertyName = sessionStorage.key(i);
if(i==0 && sessionStorage.getItem(propertyName)!=null && sessionStorage.getItem(propertyName)!=""){latitude = sessionStorage.getItem(propertyName) }
if(i==1 && sessionStorage.getItem(propertyName)!=null && sessionStorage.getItem(propertyName)!=""){longitude = sessionStorage.getItem(propertyName)}
}
alert(latitude);
alert(longitude);
}
else {
alert("Sorry, your browser does not support web storage...");
}
document.getElementById('modal').style.display = 'block';
document.getElementById('fade').style.display = 'block';
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var myObj = JSON.parse(this.responseText);
facilitiesGraphicsLayer.add(new Graphic(new Point(longitude,latitude,new SpatialReference({wkid:4326}))));
for(i = 0 ; i <myObj.features.length; i++)
{// gps point will be considered as features[0]
facilitiesGraphicsLayer.add(new Graphic(new Point(myObj.features.attributes.Lon,myObj.features.attributes.Lat,new SpatialReference({wkid:4326}))));
}
}
};
xmlhttp.open("GET", "LocDetails.json", true);
xmlhttp.send();

var map = new Map("map");
var demographicsLayer = new ArcGISTiledMapServiceLayer("https://<server name>/webgis/rest/services/<>/MapServer");
map.addLayer(demographicsLayer);
//sample code

var facilityPointSymbol = new SimpleMarkerSymbol(
SimpleMarkerSymbol.STYLE_SQUARE,
20,
new SimpleLineSymbol(
SimpleLineSymbol.STYLE_SOLID,
new Color([89,95,35]), 2
),
new Color([130,159,83,0.40])
);
var stopSymbol = new SimpleMarkerSymbol().setStyle(SimpleMarkerSymbol.STYLE_CROSS).setSize(15);
stopSymbol.outline.setWidth(3);
var facilitiesGraphicsLayer = new GraphicsLayer();
var facilityRenderer = new SimpleRenderer(stopSymbol);
facilitiesGraphicsLayer.setRenderer(facilityRenderer);

map.addLayer(facilitiesGraphicsLayer);
var gpsLon = 77.138365;
var gpsLat = 28.605584;

//default will point to ArcGIS world routing service
var directions = new Directions({
map: map,
geometryTaskUrl: "https://<server name>/arcgis/rest/services/Utilities/Geometry/GeometryServer",
routeTaskUrl : "https://<server name>/webgis/rest/services/Network/NA/NAServer/Route",
stops : facilitiesGraphicsLayer.graphics,
showOptimalRouteOption : true,
optimalRoute : true,
autoSolve :true,
showActivateButton :false,
showBarriersButton :false,
directionsLengthUnits : "esriKilometers",
showClearButton : false
// --------------------------------------------------------------------
// New constuctor option and property showSaveButton added at version
// 3.17 to allow saving route. For more information see the API Reference.
// https://developers.arcgis.com/javascript/3/jsapi/directions-amd.html#showsavebutton
//
// Uncomment the line below to add the save button to the Directions widget
// --------------------------------------------------------------------
// , showSaveButton: true
},"dir");
directions.startup();
directions.getDirections();

directions.on("directions-finish", function(event){
// do something
document.getElementById('modal').style.display = 'none';
document.getElementById('fade').style.display = 'none';
});
});
</script>
</head>
<body class="claro">
<div data-dojo-type="dijit/layout/BorderContainer"
data-dojo-props="design:'headline', gutters:false"
style="width:100%;height:100%;">
<div data-dojo-type="dijit/layout/ContentPane"
data-dojo-props="region:'right'"
style="width:250px;">

<div id="dir"></div>
</div>
<div id="map"
data-dojo-type="dijit/layout/ContentPane"
data-dojo-props="region:'center'">
</div>
<div id="fade"> <span id="modal"><img id="loader" src="loading.gif" /></span></div>
<!-- <div id="modal">
<img id="loader" src="loading.gif" />
</div> -->
</div>
</body>
</html>

Thanks

Siva

0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus

Siva,

 This look like a JS API question and you have posted it in the Web Application Builder space. Does this question have anything to do with WAB?

0 Kudos
SivaramKrishnan2
New Contributor III

Robert, 

I'm Using the Direction Widget Available in WAB 2.5 Developwe edition, there also im facing same kind of issue.Since we are not connected to internet we are using our own RouteTask Url and Geometry Services and it is throwing URL not found for ArcGIS GeoCode Service, So how can we avoid this by giving our own Geocode URl or any other solution available.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Sivaram,

  And you have specified the urls for the Geocoder URL and Route URL in the directions widgets setting dialog?

0 Kudos