作者:kk
文章目录
- 一、iServer转发A的REST服务为WMS服务
- 二、使用WebGL加载转发后的WMS服务
- 三、获取到点击地图返回的信息并解析
一、iServer转发A的REST服务为WMS服务
步骤:快速创建服务->ArcGIS REST地图服务->输入ArcGIS REST地图服务地址eg:http://ip:6080/arcgis/rest/services/WMS/MapServer
能力文档:
二、使用WebGL加载转发后的WMS服务
var wms = new Cesium.WebMapServiceImageryProvider({url : 'http://ip:8090/iserver/services/map-arcgis-WMS/wms111/%E5%9B%BE%E5%B1%82',layers : '0',parameters:{srs:"EPSG:0",format:"image/png",transparent:true},getFeatureInfoParameters:{info_format:'text/html',query_layers:['0.0'],srs:"EPSG:0"},enablePickFeatures:true,tilingScheme:new Cesium.WebMercatorTilingScheme({projection:new Cesium.GeographicProjection(),})})var layer = viewer.imageryLayers.addImageryProvider(wms);
注:这里的参数都是从wms能力文档里面获取的,小编的应用场景是平面场景,且加载的是高斯投影坐标系的数据,因此tilingScheme需要设置为WebMercatorTilingScheme(代表平面场景),projection设置为GeographicProjection(代表非墨卡托拉伸),其他的参数可以看一下帮助文档里面的释义:http://support.supermap.com.cn:8090/webgl/web/apis/3dwebgl.html
加载效果:
三、获取到点击地图返回的信息并解析
var handler &#61; new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);handler.setInputAction(function (movement) {var ray &#61; viewer.camera.getPickRay(movement.position);var cartesian &#61; viewer.scene.globe.pick(ray, viewer.scene);if (cartesian) {var cartographic &#61; Cesium.Cartographic.fromCartesian(cartesian);if (cartographic) {var xy &#61; new Cesium.Cartesian2();var alti &#61; viewer.camera.positionCartographic.height;var level &#61; getLevel(alti);if (wms.ready) {xy &#61; wms.tilingScheme.positionToTileXY(cartographic, level, xy);var promise &#61; wms.pickFeatures(xy.x, xy.y, level, cartographic.longitude, cartographic.latitude);Cesium.when(promise, function (data) {console.log(data[0].data.children[0].getElementsByTagName("fields")[0])var fields&#61;data[0].data.children[0].getElementsByTagName("fields")[0];var fieldAliases&#61;data[0].data.children[0].getElementsByTagName("fieldAliases")[0];console.log("fields-----------------------------------------------------------------------------------")for(var i&#61;0;i<fields.attributes.length;i&#43;&#43;){console.log(fields.attributes[i].name,&#39;————————&#39;,fields.attributes[i].value)}console.log("fieldAliases-----------------------------------------------------------------------------------")for(var i&#61;0;i<fieldAliases.attributes.length;i&#43;&#43;){console.log(fieldAliases.attributes[i].name,&#39;————————&#39;,fieldAliases.attributes[i].value)}});}}}}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
输出结果&#xff1a;