• arcgis js 4.x加载超图发布的wms服务并进行空间属性查询


    1. <html>
    2. <head>
    3. <meta charset="utf-8" />
    4. <meta name="viewport"
    5. content="initial-scale=1,maximum-scale=1,user-scalable=no" />
    6. <link rel="stylesheet"
    7. href="https://js.arcgis.com/4.25/esri/themes/light/main.css" />
    8. <script src="https://js.arcgis.com/4.25/init.js"></script>
    9. <style>
    10. html,
    11. body {
    12. padding: 0;
    13. margin: 0;
    14. height: 100%;
    15. }
    16. #viewDiv {
    17. float: left;
    18. width: 100%;
    19. height: 100%
    20. }
    21. </style>
    22. <script>
    23. require(["esri/Map", "esri/geometry/Extent",
    24. "esri/geometry/SpatialReference",
    25. "esri/views/MapView",
    26. "esri/views/SceneView",
    27. "esri/layers/WMSLayer",
    28. "esri/request",
    29. ], (
    30. Map, Extent, SpatialReference,
    31. MapView, SceneView,
    32. WMSLayer, esriRequest) => {
    33. var wmsLayer = new WMSLayer({
    34. url: "http://localhost:8090/iserver/services/map/wms/testlayer",
    35. })
    36. var map = new Map({
    37. layers: [wmsLayer]
    38. });
    39. const sceneView = new SceneView({
    40. container: "viewDiv",
    41. map: map
    42. });
    43. sceneView.on("click", async ({ x, y }) => {
    44. await wmsLayer.load();
    45. console.log(wmsLayer.featureInfoFormat);
    46. var layers = "";
    47. wmsLayer.allSublayers.forEach(function (item, i) {
    48. console.log(item.name)
    49. if (item.name != "0") {
    50. if (item.name == "0.0") {
    51. layers += item.name;
    52. } else {
    53. layers += ',' + item.name;
    54. }
    55. }
    56. })
    57. const { xmin, ymin, xmax, ymax, spatialReference: { latestWkid, wkid } } = sceneView.extent;
    58. const bbox = `${xmin},${ymin},${xmax},${ymax}`;
    59. const crs = `EPSG:${latestWkid ?? wkid}`;
    60. console.log(wmsLayer.featureInfoUrl)
    61. const { data } = await esriRequest(wmsLayer.featureInfoUrl, {
    62. query: {
    63. SERVICE: "WMS",
    64. LAYERS: layers,
    65. QUERY_LAYERS: layers,
    66. REQUEST: "GetFeatureInfo",
    67. INFO_FORMAT: "application/json",
    68. FEATURE_COUNT: 20,
    69. BBOX: bbox,
    70. CRS: crs,
    71. SRS: crs,
    72. X: Math.round(x),
    73. Y: Math.round(y),
    74. VERSION: "1.1.1",
    75. WIDTH: sceneView.width,
    76. HEIGHT: sceneView.height,
    77. },
    78. responseType: "xml"
    79. });
    80. const json = xmlToJson(data);
    81. });
    82. //xml格式数据转json格式数据
    83. function xmlToJson(xml) {
    84. var obj = {};
    85. if (xml.nodeType == 1) {
    86. if (xml.attributes.length > 0) {
    87. obj["@attributes"] = {};
    88. for (var j = 0; j < xml.attributes.length; j++) {
    89. var attribute = xml.attributes.item(j);
    90. obj["@attributes"][attribute.nodeName] = attribute.nodeValue;
    91. }
    92. }
    93. } else if (xml.nodeType == 3) {
    94. obj = xml.nodeValue;
    95. }
    96. if (xml.hasChildNodes()) {
    97. for (var i = 0; i < xml.childNodes.length; i++) {
    98. var item = xml.childNodes.item(i);
    99. var nodeName = item.nodeName;
    100. if (typeof (obj[nodeName]) == "undefined") {
    101. obj[nodeName] = xmlToJson(item);
    102. } else {
    103. if (typeof (obj[nodeName].length) == "undefined") {
    104. var old = obj[nodeName];
    105. obj[nodeName] = [];
    106. obj[nodeName].push(old);
    107. }
    108. obj[nodeName].push(xmlToJson(item));
    109. }
    110. }
    111. }
    112. return obj;
    113. };
    114. });
    115. </script>
    116. </head>
    117. <body>
    118. <div id="viewDiv"></div>
    119. </body>
    120. </html>

    参考文档:WMSLayer | API Reference | ArcGIS Maps SDK for JavaScript 4.28 | ArcGIS Developers

  • 相关阅读:
    Netlogo 简化版Scatter 分散
    H-WORM家族远控木马分析与处置
    Python单元测试
    100道大厂面试题总结,可以测试自己能考多少分
    Day39——互斥锁,线程技术
    Machine learning week 9(Andrew Ng)
    条码二维码读取设备在医疗设备自助服务的重要性
    Go入门案列1:实现一个家庭收支记账系统
    笙默考试管理系统-MyExamTest----codemirror(36)
    气体净化与特种气体除杂——吸附
  • 原文地址:https://blog.csdn.net/xlp789/article/details/134213730