• Cesium对WMS地图服务进行查询并弹框展示信息


    一、简介

    Cesium加载WMS地图服务,然后调用接口GetFeatureInfo对要素信息进行查询

    二、测试接口

    1. {
    2. type: "Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon",
    3. coordinates: 数组
    4. }
    5. 查询点
    6. http://123.56.67.147:8080/geoserver_gis/tiger/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&FORMAT=image%2Fpng&TRANSPARENT=true
    7. &QUERY_LAYERS=tiger%3Apoi&STYLES&LAYERS=tiger%3Apoi&exceptions=application%2Fvnd.ogc.se_inimage
    8. &INFO_FORMAT=application%2Fjson&FEATURE_COUNT=50&X=50&Y=50&SRS=EPSG%3A4326&WIDTH=101&HEIGHT=101
    9. &BBOX=-74.01160955429077%2C40.70826172828674%2C-74.00944232940674%2C40.710428953170776
    10. {
    11. "type": "FeatureCollection",
    12. "features": [{
    13. "type": "Feature",
    14. "id": "poi.1",
    15. "geometry": {
    16. "type": "Point",
    17. "coordinates": [-74.0104611, 40.70758763]
    18. },
    19. "geometry_name": "the_geom",
    20. "properties": {
    21. "NAME": "museam",
    22. "THUMBNAIL": "pics/22037827-Ti.jpg",
    23. "MAINPAGE": "pics/22037827-L.jpg"
    24. }
    25. }, {
    26. "type": "Feature",
    27. "id": "poi.2",
    28. "geometry": {
    29. "type": "Point",
    30. "coordinates": [-74.01083751, 40.70754684]
    31. },
    32. "geometry_name": "the_geom",
    33. "properties": {
    34. "NAME": "stock",
    35. "THUMBNAIL": "pics/22037829-Ti.jpg",
    36. "MAINPAGE": "pics/22037829-L.jpg"
    37. }
    38. }, {
    39. "type": "Feature",
    40. "id": "poi.3",
    41. "geometry": {
    42. "type": "Point",
    43. "coordinates": [-74.01053024, 40.70938712]
    44. },
    45. "geometry_name": "the_geom",
    46. "properties": {
    47. "NAME": "art",
    48. "THUMBNAIL": "pics/22037856-Ti.jpg",
    49. "MAINPAGE": "pics/22037856-L.jpg"
    50. }
    51. }, {
    52. "type": "Feature",
    53. "id": "poi.4",
    54. "geometry": {
    55. "type": "Point",
    56. "coordinates": [-74.00857344, 40.71194565]
    57. },
    58. "geometry_name": "the_geom",
    59. "properties": {
    60. "NAME": "lox",
    61. "THUMBNAIL": "pics/22037884-Ti.jpg",
    62. "MAINPAGE": "pics/22037884-L.jpg"
    63. }
    64. }, {
    65. "type": "Feature",
    66. "id": "poi.5",
    67. "geometry": {
    68. "type": "Point",
    69. "coordinates": [-74.01183158, 40.70852996]
    70. },
    71. "geometry_name": "the_geom",
    72. "properties": {
    73. "NAME": "church",
    74. "THUMBNAIL": "pics/22037839-Ti.jpg",
    75. "MAINPAGE": "pics/22037839-L.jpg"
    76. }
    77. }, {
    78. "type": "Feature",
    79. "id": "poi.6",
    80. "geometry": {
    81. "type": "Point",
    82. "coordinates": [-74.00153046, 40.71988512]
    83. },
    84. "geometry_name": "the_geom",
    85. "properties": {
    86. "NAME": "fire",
    87. "THUMBNAIL": "pics/28640984-Ti.jpg",
    88. "MAINPAGE": "pics/28640984-L.jpg"
    89. }
    90. }],
    91. "totalFeatures": 6,
    92. "numberMatched": 6,
    93. "numberReturned": 6,
    94. "timeStamp": "2023-09-12T03:31:50.145Z",
    95. "crs": {
    96. "type": "name",
    97. "properties": {
    98. "name": "urn:ogc:def:crs:EPSG::4326"
    99. }
    100. }
    101. }
    102. 查询线
    103. http://123.56.67.147:8080/geoserver_gis/tiger/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&FORMAT=image%2Fpng&TRANSPARENT=true
    104. &QUERY_LAYERS=tiger%3Atiger_roads&STYLES&LAYERS=tiger%3Atiger_roads&exceptions=application%2Fvnd.ogc.se_inimage
    105. &INFO_FORMAT=application%2Fjson&FEATURE_COUNT=50&X=50&Y=50&SRS=EPSG%3A4326&WIDTH=101&HEIGHT=101
    106. &BBOX=-73.95326614379883%2C40.78451156616211%2C-73.9185905456543%2C40.81918716430664
    107. {
    108. "type": "FeatureCollection",
    109. "features": [{
    110. "type": "Feature",
    111. "id": "tiger_roads.2060",
    112. "geometry": {
    113. "type": "MultiLineString",
    114. "coordinates": [
    115. [
    116. [-73.937885, 40.803733],
    117. [-73.936415, 40.803118]
    118. ]
    119. ]
    120. },
    121. "geometry_name": "the_geom",
    122. "properties": {
    123. "CFCC": "A41",
    124. "NAME": "E 124th St"
    125. }
    126. }, {
    127. "type": "Feature",
    128. "id": "tiger_roads.2061",
    129. "geometry": {
    130. "type": "MultiLineString",
    131. "coordinates": [
    132. [
    133. [-73.938409, 40.803092],
    134. [-73.93683, 40.802478]
    135. ]
    136. ]
    137. },
    138. "geometry_name": "the_geom",
    139. "properties": {
    140. "CFCC": "A41",
    141. "NAME": "E 123rd St"
    142. }
    143. }, {
    144. "type": "Feature",
    145. "id": "tiger_roads.2068",
    146. "geometry": {
    147. "type": "MultiLineString",
    148. "coordinates": [
    149. [
    150. [-73.93729, 40.801837],
    151. [-73.935041, 40.800874]
    152. ]
    153. ]
    154. },
    155. "geometry_name": "the_geom",
    156. "properties": {
    157. "CFCC": "A41",
    158. "NAME": "E 122nd St"
    159. }
    160. }, {
    161. "type": "Feature",
    162. "id": "tiger_roads.2069",
    163. "geometry": {
    164. "type": "MultiLineString",
    165. "coordinates": [
    166. [
    167. [-73.93683, 40.802478],
    168. [-73.934561, 40.801515]
    169. ]
    170. ]
    171. },
    172. "geometry_name": "the_geom",
    173. "properties": {
    174. "CFCC": "A41",
    175. "NAME": "E 123rd St"
    176. }
    177. }, {
    178. "type": "Feature",
    179. "id": "tiger_roads.2070",
    180. "geometry": {
    181. "type": "MultiLineString",
    182. "coordinates": [
    183. [
    184. [-73.937748, 40.801196],
    185. [-73.935478, 40.80025]
    186. ]
    187. ]
    188. },
    189. "geometry_name": "the_geom",
    190. "properties": {
    191. "CFCC": "A41",
    192. "NAME": "E 121st St"
    193. }
    194. }, {
    195. "type": "Feature",
    196. "id": "tiger_roads.2100",
    197. "geometry": {
    198. "type": "MultiLineString",
    199. "coordinates": [
    200. [
    201. [-73.936415, 40.803118],
    202. [-73.934145, 40.802073]
    203. ]
    204. ]
    205. },
    206. "geometry_name": "the_geom",
    207. "properties": {
    208. "CFCC": "A41",
    209. "NAME": "E 124th St"
    210. }
    211. }, {
    212. "type": "Feature",
    213. "id": "tiger_roads.5134",
    214. "geometry": {
    215. "type": "MultiLineString",
    216. "coordinates": [
    217. [
    218. [-73.93683, 40.802478],
    219. [-73.936415, 40.803118]
    220. ]
    221. ]
    222. },
    223. "geometry_name": "the_geom",
    224. "properties": {
    225. "CFCC": "A41",
    226. "NAME": "3rd Ave"
    227. }
    228. }, {
    229. "type": "Feature",
    230. "id": "tiger_roads.5135",
    231. "geometry": {
    232. "type": "MultiLineString",
    233. "coordinates": [
    234. [
    235. [-73.93729, 40.801837],
    236. [-73.93683, 40.802478]
    237. ]
    238. ]
    239. },
    240. "geometry_name": "the_geom",
    241. "properties": {
    242. "CFCC": "A41",
    243. "NAME": "3rd Ave"
    244. }
    245. }, {
    246. "type": "Feature",
    247. "id": "tiger_roads.5140",
    248. "geometry": {
    249. "type": "MultiLineString",
    250. "coordinates": [
    251. [
    252. [-73.935041, 40.800874],
    253. [-73.934561, 40.801515]
    254. ]
    255. ]
    256. },
    257. "geometry_name": "the_geom",
    258. "properties": {
    259. "CFCC": "A41",
    260. "NAME": "2nd Ave"
    261. }
    262. }],
    263. "totalFeatures": "unknown",
    264. "numberReturned": 9,
    265. "timeStamp": "2023-09-12T05:38:36.569Z",
    266. "crs": {
    267. "type": "name",
    268. "properties": {
    269. "name": "urn:ogc:def:crs:EPSG::4326"
    270. }
    271. }
    272. }
    273. 查询面
    274. http://123.56.67.147:8080/geoserver_gis/tiger/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&FORMAT=image%2Fpng&TRANSPARENT=true
    275. &QUERY_LAYERS=tiger%3Agiant_polygon&STYLES&LAYERS=tiger%3Agiant_polygon&exceptions=application%2Fvnd.ogc.se_inimage
    276. &INFO_FORMAT=application%2Fjson&FEATURE_COUNT=50&X=50&Y=50&SRS=EPSG%3A4326&WIDTH=101&HEIGHT=101&BBOX=-74.8828125%2C-64.3359375%2C-3.8671875%2C6.6796875
    277. {
    278. "type": "FeatureCollection",
    279. "features": [{
    280. "type": "Feature",
    281. "id": "giant_polygon.1",
    282. "geometry": {
    283. "type": "MultiPolygon",
    284. "coordinates": [
    285. [
    286. [
    287. [-180, -90],
    288. [-180, 90],
    289. [180, 90],
    290. [180, -90],
    291. [-180, -90]
    292. ]
    293. ]
    294. ]
    295. },
    296. "geometry_name": "the_geom",
    297. "properties": {}
    298. }],
    299. "totalFeatures": "unknown",
    300. "numberReturned": 1,
    301. "timeStamp": "2023-09-12T03:01:33.391Z",
    302. "crs": {
    303. "type": "name",
    304. "properties": {
    305. "name": "urn:ogc:def:crs:EPSG::4326"
    306. }
    307. }
    308. }

    三、示例源码

    1. html>
    2. <html>
    3. <head>
    4. <meta charset="utf-8">
    5. <link rel="stylesheet" href="./css/common.css">
    6. <title>
    7. WMS地图服务点击查询【面图层】
    8. title>
    9. <script src="./js/config.js">script>
    10. <script src="./scripts/vue.min.js">script>
    11. <script type="text/javascript" src="../anov-gis-sdk/index.js">script>
    12. <link rel="stylesheet" href="../anov-gis-sdk/index.css">
    13. head>
    14. <body>
    15. <div id="cesiumContainer">
    16. div>
    17. body>
    18. html>
    19. <script>
    20. var app = new Vue({
    21. el: '#cesiumContainer',
    22. mounted() {
    23. // let viewer = ANOVGIS.CesiumView.init("cesiumContainer");
    24. window.viewer = new ANOVGIS.Viewer("cesiumContainer", {
    25. // imageryProvider: undefined
    26. });
    27. // 底图
    28. viewer.imageryLayers.addImageryProvider(
    29. ANOVGIS.ImageryLayerFactory.createImageryLayer(ANOVGIS.ImageryType.TDT, {
    30. style: "img",
    31. key: globalConfig.tdtKey
    32. }));
    33. // wms服务
    34. var layer = ANOVGIS.ImageryLayerFactory.createImageryLayer(ANOVGIS.ImageryType.WMS, {
    35. rectangle: Cesium.Rectangle.fromDegrees(116.1955337524414, 39.75703811645508, 116.62583923339844, 40.03786087036133),
    36. url: 'http://172.16.223.165:8080/geoserver/twins/wms?',
    37. layers: " twins:architecture",
    38. parameters: {
    39. transparent: true,
    40. format: "image/png",
    41. },
    42. highlight: {
    43. material: 'rgba(255,255,0,0.6)',
    44. height: 0.01
    45. }
    46. })
    47. layer.bindPopup({
    48. viewer: viewer,
    49. showTitle: true,
    50. useDefaultHtmlTemplate: true,//用默认模板
    51. });
    52. layer.addEventListener(ANOVGIS.MouseEventType.CLICK, (e) => {
    53. let infoData = {
    54. title: e.feature.data.properties.name || '未查到建筑名称',
    55. fieldsMap: [
    56. {
    57. nameC: '建筑层高:',
    58. value: e.feature.data.properties.floor
    59. }]
    60. }
    61. layer.popup.show(e.position, infoData);
    62. console.log(e);
    63. })
    64. var layer1 = viewer.imageryLayers.addImageryProvider(layer);
    65. viewer.flyTo(layer1)
    66. }
    67. });
    68. script>

  • 相关阅读:
    要努力,但也别焦虑
    网络安全(黑客)自学
    Python中套接字实现服务端和客户端3-3
    Java 设计模式——状态模式
    【无标题】
    操作系统实验一 Linux基本操作
    为什么需要 Buffer Pool?
    STL模板库笔记
    卡码网语言基础课 | 12. 位置互换
    Mybatis-plus 用法
  • 原文地址:https://blog.csdn.net/u014556081/article/details/132863020