Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Get ArcGIS Server Map Service Layer Field Names</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <link rel="stylesheet" href="https://js.arcgis.com/3.23/esri/css/esri.css">
  7. <style>
  8. body{
  9. font-family: "Arial Unicode MS, Arial, sans-serif";
  10. }
  11. #content {
  12. width: 800px; height: 350px; padding: 5px; overflow: auto;
  13. border: solid 2px #AAAAAA; background-color: #FFFFFF;
  14. -moz-border-radius: 5px; -webkit-border-radius: 5px; -o-border-radius: 5px; border-radius: 5px;
  15. -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;
  16. }
  17. .failure { color: red; }
  18. #status { font-size: 12px; }
  19. </style>
  20.  
  21. <script src="https://js.arcgis.com/3.23/"></script>
  22. <script>
  23. 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) {
  24.  
  25. dom.byId("url").value = "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/ZillowNeighborhoods-CA/FeatureServer/0";
  26. dom.byId("content").value = "";
  27. //handle the Go button's click event
  28. on(dom.byId("submitRequest"), "click", getContent);
  29.  
  30.  
  31. function getContent(){
  32.  
  33. var contentDiv = dom.byId("content");
  34. contentDiv.value = "";
  35. domClass.remove(contentDiv, "failure");
  36. dom.byId("status").innerHTML = "Downloading...";
  37.  
  38. //get the url and setup a proxy
  39. var url = dom.byId("url").value;
  40.  
  41. if(url.length === 0){
  42. alert("Please enter a URL");
  43. return;
  44. }
  45.  
  46. var requestHandle = esriRequest({
  47. "url": url,
  48. "content": {
  49. "f": "json"
  50. },
  51. "callbackParamName": "callback"
  52. });
  53. requestHandle.then(requestSucceeded, requestFailed);
  54. }
  55.  
  56. function requestSucceeded(response, io){
  57. var fieldInfo, pad;
  58. pad = dojoString.pad;
  59.  
  60. //toJson converts the given JavaScript object
  61. //and its properties and values into simple text
  62. dojoJson.toJsonIndentStr = " ";
  63. console.log("response as text:\n", dojoJson.toJson(response, true));
  64. dom.byId("status").innerHTML = "";
  65.  
  66. //show field names and aliases
  67. if ( response.hasOwnProperty("fields") ) {
  68. console.log("got some fields");
  69. fieldInfo = array.map(response.fields, function(f) {
  70. return pad("Field:", 8, " ", true) + pad(f.name, 25, " ", true) +
  71. pad("Alias:", 8, " ", true) + pad(f.alias, 25, " ", true) +
  72. pad("Type:", 8, " ", true) + pad(f.type, 25, " ", true);
  73. });
  74. dom.byId("content").value = fieldInfo.join("\n");
  75. } else {
  76. dom.byId("content").value = "No field info found. Please double-check the URL.";
  77. }
  78.  
  79. }
  80. function requestFailed(error, io){
  81.  
  82. domClass.add(dom.byId("content"), "failure");
  83.  
  84. dojoJson.toJsonIndentStr = " ";
  85. dom.byId("content").value = dojoJson.toJson(error, true);
  86.  
  87. }
  88.  
  89.  
  90. });
  91. </script>
  92.  
  93. </head>
  94. <body>
  95. <p>Enter the URL for a layer in a map service to access metadata about a layer in a map service using esriRequest.</p>
  96. <p>
  97. <input type="text" id="url" size="105"/>
  98. <input id="submitRequest" type="button" value="GO" />
  99. <span id="status"></span>
  100. </p>
  101. <h2>Content</h2>
  102. <p>Check the console for the full response. Here we'll display Field names, aliases and types:</p>
  103. <textarea id="content"></textarea>
  104. </body>
  105. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement