Hi all,
I am trying to list out all the services names and URL and output it to an html table. I am doing so for each of the folders that we have in our ArcGIS Server. To accomplish that I am using ESRI/request module. I can retrieve the name of the service easy with this module, but can i also retrieve the URL?
ESRI example that I am using:
<!DOCTYPE html> <html> <head> <title>Get ArcGIS Server Map Service Layer Field Names</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" href="http://js.arcgis.com/3.14/esri/css/esri.css"> <style> body{ font-family: "Arial Unicode MS, Arial, sans-serif"; } #content { width: 800px; height: 350px; padding: 5px; overflow: auto; border: solid 2px #AAAAAA; background-color: #FFFFFF; -moz-border-radius: 5px; -webkit-border-radius: 5px; -o-border-radius: 5px; border-radius: 5px; -moz-box-shadow: 0 0 0.5em black; -webkit-box-shadow: 0 0 0.5em black; -o-box-shadow: 0 0 0.5em black; box-shadow: 0 0 0.5em black; } .failure { color: red; } #status { font-size: 12px; } </style> <script src="http://js.arcgis.com/3.14/"></script> <script> require(["dojo/dom", "dojo/on", "dojo/dom-class", "dojo/_base/json", "dojo/_base/array", "dojo/string", "esri/request", "dojo/domReady!"], function(dom, on, domClass, dojoJson, array, dojoString, esriRequest) { dom.byId("url").value = "http://webgisdevint1/arcgis/rest/services/FRAP"; dom.byId("content").value = ""; //handle the Go button's click event on(dom.byId("submitRequest"), "click", getContent); function getContent(){ var contentDiv = dom.byId("content"); contentDiv.value = ""; domClass.remove(contentDiv, "failure"); dom.byId("status").innerHTML = "Downloading..."; //get the url and setup a proxy var url = dom.byId("url").value; if(url.length === 0){ alert("Please enter a URL"); return; } var requestHandle = esriRequest({ "url": url, "content": { "f": "json" }, "callbackParamName": "callback" }); requestHandle.then(requestSucceeded, requestFailed); } function requestSucceeded(response, io){ var fieldInfo, pad; pad = dojoString.pad; //toJson converts the given JavaScript object //and its properties and values into simple text dojoJson.toJsonIndentStr = " "; console.log("response as text:\n", dojoJson.toJson(response,true)); dom.byId("status").innerHTML = ""; //show field names and aliases if ( response.hasOwnProperty("services") ) { console.log("got some services"); fieldInfo = array.map(response.services, function(f) { return pad("", 0, " ", true) + pad(f.name, 0, " ", true) }); dom.byId("content").value = fieldInfo.join("\n"); } else { dom.byId("content").value = "No field info found. Please double-check the URL."; } } function requestFailed(error, io){ domClass.add(dom.byId("content"), "failure"); dojoJson.toJsonIndentStr = " "; dom.byId("content").value = dojoJson.toJson(error, true); } }); </script> </head> <body> <p>Enter the URL for a layer in a map service to access metadata about a layer in a map service using esriRequest.</p> <p> <input type="text" id="url" size="105"/> <input id="submitRequest" type="button" value="GO" /> <span id="status"></span> </p> <p> <h2>Content</h2> <p>Check the console for the full response. Here we'll display Field names, aliases and types:</p> <textarea id="content"></textarea> </p> </body>
Solved! Go to Solution.
Would something like this work for your situation where you start with the base url and then add the service name and type?
Would something like this work for your situation where you start with the base url and then add the service name and type?
Thant would work great ! That is exactly what I am looking for! Would it be hard to add the end result to a table? I m going to spend my day tomorrow looking for that now. Nicely done kelly! Thanks!
Alex,
Yep its fairly easy to display the results in a table. Here's a link to an example that shows the results in a dojo dgrid
Perfect!Thank you so mucj!
This is a great script. Is there a way to list out the sub-layers as well? So instead of
ServiceName .../MapServer
you get
ServiceNameLayer1 .../MapServer/0
ServiceNameLayer2 .../MapServer/1
etc.
Last question related to this topic. How do I loop through each server's folder? Do I use ESRI/request -- folder.name? I am trying to use a drop down menu populated by each folder. Once selected by user then it fires the event of returning all services names. Thanks, Alex