// 通过config.js中的getEngineType,获取引擎类型(EngineType)用于设置启动方式
var EngineType = getEngineType();
let obj = [6378137.0, 6378137.0, 6356752.3142451793];
SuperMap3D.Ellipsoid.WGS84 = Object.freeze(new SuperMap3D.Ellipsoid(obj[0], obj[1], obj[2]));
// 创建3D场景查看器,配置渲染参数
var viewer = new SuperMap3D.Viewer('Container', {
contextOptions: {
contextType: Number(EngineType), // Webgl2:2 ; WebGPU:3
msaaLevel: 4 // 多重采样抗锯齿级别
},
orderIndependentTranslucency: false // 关闭顺序无关透明度
});
// 等待场景初始化完成后执行init函数
viewer.scenePromise.then(function(scene){
// 设置分辨率缩放比例,提高渲染质量
viewer.resolutionScale = window.devicePixelRatio;
// 将viewer和scene设置为全局变量
window.viewer = viewer;
window.scene = viewer.scene;
// 关闭帧率显示
viewer.scene.debugShowFramesPerSecond = false;
// 显示地球
viewer.scene.globe.show = true;
// 关闭FXAA抗锯齿
viewer.scene.postProcessStages.fxaa.enabled = false;
var scene = viewer.scene;
// MVT服务地址
var url = "http://localhost:8090/iserver/services/map-mvt-NingHaiLuCeShi4326test/restjsr/v1/vectortile/maps/%E5%AE%81%E6%B5%B7%E8%B7%AF%E6%B5%8B%E8%AF%95_4326%40test";
// 创建矢量瓦片地图
var mvtMap = scene.addVectorTilesMap({
url: url, // MVT服务地址
canvasWidth: 512, // 画布宽度
name: 'testMVT', // 地图名称
viewer: viewer, // 查看器对象
style3D: {
altitudeMode: SuperMap3D.HeightReference.RELATIVE_TO_GROUND,
},
});
// 定位至图层范围
var layerReadyPromise = mvtMap.readyPromise;
SuperMap3D.when(layerReadyPromise, function (data) {
var bounds = mvtMap.rectangle; // 获取地图边界
// 设置相机视角到地图中心
scene.camera.setView({
destination: new SuperMap3D.Cartesian3.fromRadians(
// (bounds.east + bounds.west) * 0.5, // 经度中心
// (bounds.north + bounds.south) * 0.5, // 纬度中心
SuperMap3D.Math.toRadians(118.76699999999998),
SuperMap3D.Math.toRadians(32.066449999164387),
10000 // 高度
),
orientation: {
heading: 0, // 航向角
roll: 0 // 翻滚角
}
});
});