I want to consume a erdas apolla WMS service using ArcGIS Javascript API on my GIS application, but the WMS service is not rendering on my map, how should I authenticate the username and password?

1824
5
05-22-2017 06:09 AM
SantoshV
New Contributor II

I am using the following 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>Map with WMS</title>

<link rel="stylesheet" href="https://js.arcgis.com/3.20/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="https://js.arcgis.com/3.20/esri/css/esri.css">
<style>
html, body, #map {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
body {
background-color: #FFF;
overflow: hidden;
font-family: "Trebuchet MS";
}
</style>
<script src="https://js.arcgis.com/3.20/"></script>

<script>
var map;

require(["esri/map", "esri/layers/WMSLayer", "esri/config", "dojo/domReady!"],
function(Map, WMSLayer, esriConfig) {

esriConfig.defaults.io.proxyUrl = "/proxy/";

map = new Map("map", {
basemap: "streets",
center: [-98, 37],
zoom: 5
});

var wmsLayer = new WMSLayer("http://103.203.139.72/erdas-apollo/coverage/District_Jai?REQUEST=GetCapabilities&SERVICE=WMS&VERSION...", {
format: "png",
visibleLayers: [2]
});

map.addLayer(wmsLayer);
});
</script>
</head>

<body>
<div id="map">
</div>
</body>
</html>

Where do I type in the username and password.

0 Kudos
5 Replies
FC_Basson
MVP Regular Contributor

You shoule be able to specify the authentication through a resource proxy: GitHub - Esri/resource-proxy: Proxy files for DotNet, Java and PHP. 

SantoshV
New Contributor II

Hi thank you for your response, I did follow the steps and created a proxy page, but now I get the following error

{"error": {"code": 403,"message":"Proxy has not been set up for this URL. Make sure there is a serverUrl in the configuration file that matches: http://106.207.134.26/erdas-apollo/coverage/District_Newark_FCC?amp;SERVICE=WMS&VERSION=1.3.0&SERVIC... http://106.207.134.26/erdas-apollo/coverage/District_Newark_FCC?amp;SERVICE=WMS&VERSION=1.3.0&SERVICE=WMS&REQUEST=GetCapabilities"}}

what am I missing??

0 Kudos
FC_Basson
MVP Regular Contributor

According to the error message you haven't set up the proxy.config file properly.  For the WMS server you want to access the config file (for the PHP example) needs to look something like this:

<?xml version="1.0" encoding="utf-8" ?>
<ProxyConfig allowedReferers="http://yourdomain.com/sitefolder/"
   logFile="proxy_log.log"
   mustMatch="true">
   <serverUrls> 
     <serverUrl url="http://103.203.139.72/erdas-apollo/coverage"
       matchAll="true"
       username="user123"
       password="password123"/> 
   </serverUrls>
</ProxyConfig>‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
SantoshV
New Contributor II

Tried that my proxy file looks like this, still no luck  

<?xml version="1.0" encoding="utf-8" ?>
<ProxyConfig
mustMatch="true"
logFile="proxy_log.log"
allowedReferers="http://localhost/resource-proxy-master/DotNet">

<serverUrls>

<serverUrl
url="http://103.203.139.72/erdas-apollo/coverage/District_Alabama_FCC?REQUEST=GetCapabilities&SERVICE=WMS..."
username = "user123"
password = "password123"
matchAll="true"/>

</serverUrls>

</ProxyConfig>
<!-- See https://github.com/Esri/resource-proxy for more information -->

0 Kudos
FC_Basson
MVP Regular Contributor

Have you added the proxy rule in your Javascript?

urlUtils.addProxyRule({
  urlPrefix: "http://103.203.139.72/erdas-apollo/coverage",
  proxyUrl: "/proxy/"
 });
0 Kudos