项目场景:
在vue框架使用SuperMap iClient3D for Cesium显示三维地图。
问题描述
在三维地图上显示模型的时候发现,如果进行放大地图查看模型的时候,地图放大到一定的程度,模型没消失不见。
解决方案:
初始化viewer之前设置一下椭球参数
var obj = [6378137.0, 6378137.0, 6356752.3142451793];
Cesium.Ellipsoid.WGS84 = Object.freeze(new Cesium.Ellipsoid(obj[0], obj[1], obj[2]));
完整代码如下:
const options = {};
// 用于在使用重置导航重置地图视图时设置默认视图控制。接受的值是Cesium.Cartographic 和
Cesium.Rectangle.
options.defaultResetView = Cesium.Cartographic.fromDegrees(
120.4045288,
27.7276572,
100.0
);
// 用于启用或禁用罗盘。true是启用罗盘,false是禁用罗盘。默认值为true。如果将选项设置为false,则罗盘将不会添加到地图中。
options.enableCompass = true;
// 用于启用或禁用缩放控件。true是启用,false是禁用。默认值为true。如果将选项设置为false,则缩放控件将不会添加到地图中。
options.enableZoomControls = false;
// 用于启用或禁用距离图例。true是启用,false是禁用。默认值为true。如果将选项设置为false,距离图例将不会添加到地图中。
options.enableDistanceLegend = false;
// 用于启用或禁用指南针外环。true是启用,false是禁用。默认值为true。如果将选项设置为false,则该环将可见但无效。
options.enableCompassOuterRing = true;
var obj = [6378137.0, 6378137.0, 6356752.3142451793];
Cesium.Ellipsoid.WGS84 = Object.freeze(
new Cesium.Ellipsoid(obj[0], obj[1], obj[2])
);
this.viewer = new Cesium.Viewer("cesiumContainer2", {
// infoBox:false //是否显示信息框
contextOptions: {
webgl: {
alpha: true,
depth: false,
stencil: true,
antialias: true,
premultipliedAlpha: true,
preserveDrawingBuffer: true,
failIfMajorPerformanceCaveat: true,
},
allowTextureFilterAnisotropic: true,
},
animation: false, // 是否显示动画控件
shouldAnimate: true,
homeButton: false, // 是否显示Home按钮
fullscreenButton: true, // 是否显示全屏按钮
baseLayerPicker: false, // 是否显示图层选择控件
geocoder: false, // 是否显示地名查找控件
timeline: false, // 是否显示时间线控件
sceneModePicker: false, // 是否显示投影方式控件
navigationHelpButton: false, // 是否显示帮助信息控件
infoBox: false, // 是否显示点击要素之后显示的信息
requestRenderMode: true, // 启用请求渲染模式
scene3DOnly: false, // 每个几何实例将只能以3D渲染以节省GPU内存
sceneMode: 3, // 初始场景模式 1 2D模式 2 2D循环模式 3 3D模式 Cesium.SceneMode
fullscreenElement: document.getElementById("cesiumContainer2"), // 全屏时渲染的HTML元素 暂时没发现用处
selectionIndicator: false,
imageryProvider: new Cesium.WebMapTileServiceImageryProvider({
url: "https://t{s}.tianditu.gov.cn/img_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=img&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default&format=tiles&tk=天地图key",
layer: "img",
subdomains: ["0", "1", "2", "3", "4", "5", "6", "7"],
style: "default",
format: "image/jpeg",
tileMatrixSetID: "w",
credit: new Cesium.Credit("天地图全球影像服务"),
show: false,
maximumLevel: 18,
}),
});