将w s a d的键盘元素分别指示为向视图的上方 下方 左方 右方观看。
1、加载网络三维地图
var map = new WebScene({
portalItem:{id:"d8695805cb324135846f4b03eaeddeaa"}
});
var view = new SceneView({
container:"viewDiv",
map:map
});
2、将id="description"的标签指示信息放到地图上去
view.ui.add("description","bottom-left");
3、设置观察角度
view.on("key-down",function(event){
switch(event.key){
case "w":
event.stopPropagation(); //阻止冒泡事件
if(view.camera.tilt>2){
view.goTo({
position:view.camera.position,
tilt:view.camera.tilt-1
})
};
break;
case "s":
event.stopPropagation();
if(view.camera.tilt<160){
view.goTo({
position:view.camera.position,
tilt:view.camera.tilt+1
})
};
break;
case "a":
event.stopPropagation();
view.goTo({
position:view.camera.postion,
heading:view.camera.heading-1
});
break;
case "d":
event.stopPropagation();
view.goTo({
position:view.camera.position,
heading:view.camera.heading+1
});
break;
}
})