AnsweredAssumed Answered

How to configure Local GeoCode Server URL?

Question asked by siva.lntgis on Jan 5, 2018
Latest reply on Jan 8, 2018 by rscheitlin

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[i].attributes.Lon,myObj.features[i].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

Outcomes