使用Maps SDK添加本地slpk

Posted on 2024-04-18 14:43  云起  阅读(14)  评论(0编辑  收藏  举报
SceneView m_sceneView;
public void LoadSceneLayerFromSLPK(SceneView sceneView, string slpkPath)
{
	if (!File.Exists(slpkPath))
		throw new Exception("文件不存在");

	if (null == sceneView.Scene)
		CreateScene(sceneView);
	Uri treespk = new System.Uri(slpkPath);
	var sceneLayer = new ArcGISSceneLayer();
	// add the scene layer to the scene
	sceneLayer.Source = treespk;
	sceneLayer.Name = "三维";
	sceneLayer.Loaded += SceneLayer_Loaded;
	sceneLayer.SurfacePlacement = SurfacePlacement.Relative;

	sceneView.Scene.OperationalLayers.Add(sceneLayer);//添加三维图层
}
public async void CreateScene(SceneView sceneView)
{
	m_sceneView = sceneView;
	// Create new Scene
	Scene myScene = new Scene();
	// Set Scene's base map property
	myScene.Basemap = Basemap.CreateImagery();
	myScene.Basemap.BaseLayers[0].Name = "影像";
	sceneView.Scene = myScene;
}
private void SceneLayer_Loaded(object sender, EventArgs e)
{
	var arcGISSceneLayer = sender as ArcGISSceneLayer;
	if (null == arcGISSceneLayer)
		return;
	var fullExtent = arcGISSceneLayer.FullExtent;
	if (null == fullExtent)
		return;
	var center = fullExtent.GetCenter();
	var camera = new Camera(center.Y, center.X, 500, 60, 0, 71.17);
	m_sceneView.SetViewpointCameraAsync(camera);
}

这时候,图层已经能加载进来,但是是飘在空中的。这是因为没有设置对应的高程表面,导致高程的偏移。需要添加一个高程表面,我使用的是dem作为高程表面,也可以使用高程服务。

public async void CreateScene(SceneView sceneView)
{
	m_sceneView = sceneView;
	// Create new Scene
	Scene myScene = new Scene();
	// Set Scene's base map property
	myScene.Basemap = Basemap.CreateImagery();
	myScene.Basemap.BaseLayers[0].Name = "影像";
	sceneView.Scene = myScene;

	var el = new RasterElevationSource(new string[] { @"DEM.tif" });
	el.Name = "elevation";
	await el.LoadAsync();
	var su = new Surface();
	su.ElevationSources.Add(el);
	sceneView.Scene.BaseSurface = su;
}

Copyright © 2024 云起
Powered by .NET 9.0 on Kubernetes