GetFeatureInfoFormat是一个Cesium JS的类,被用于定义解析GetFeatureInfo服务请求响应中数据的格式。
new Cesium.GetFeatureInfoFormat(format)
format
:String
类型,格式化字符串。var viewer = new Cesium.Viewer('cesiumContainer', {
imageryProvider : new Cesium.ArcGisMapServerImageryProvider({
url : 'http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer',
enablePickFeatures: true
})
});
viewer.screenSpaceEventHandler.setInputAction(function onLeftClick(movement) {
var scene = viewer.scene;
if(scene.mode !== Cesium.SceneMode.SCENE3D) {
return;
}
var pickedWindowPosition = movement.position;
var ray = scene.camera.getPickRay(pickedWindowPosition);
var ellipsoid = scene.globe.ellipsoid;
var cartesian = scene.camera.pickEllipsoid(pickedWindowPosition, ellipsoid);
if(cartesian) {
var imageryLayers = viewer.imageryLayers;
var pickFeaturesPromise = imageryLayers.pickImageryLayerFeatures(ray, scene, pickedWindowPosition);
if(!Cesium.defined(pickFeaturesPromise)) {
return;
}
Cesium.when(pickFeaturesPromise, function(features) {
if(features.length > 0) {
var html = buildFeatureInfo(features);
showFeatureInfo(html);
}
});
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
function buildFeatureInfo(features) {
var html = [];
for(var i = 0; i < features.length; ++i) {
var feature = features[i];
if(!Cesium.defined(feature.data) || feature.data === null) {
continue;
}
html.push('<table class="cesium-infoBox-defaultTable"><tbody>');
for(var key in feature.data) {
if(feature.data.hasOwnProperty(key)) {
html.push('<tr><th>' + key + '</th><td>' + feature.data[key] + '</td></tr>');
}
}
html.push('</tbody></table>');
}
return html.join('');
}
function showFeatureInfo(info) {
Sandcastle.updateDocumentHTML(info);
}