tedp
Version:
terra dp init
126 lines (104 loc) • 3.35 kB
HTML
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="./dist/tumap.js"></script>
<style>
* {
margin: 0;
padding: 0;
}
#mapContainer{
position:absolute;
width:100%;
height:100%;
}
.control-box{
position:absolute;
right:10px;
top:5px;
background:rgba(0,0,0,.5);
border:1px solid rgba(255,255,255,.8);
border-radius: 6px;
overflow: hidden;
color:#fff;
font-size:13px;
padding: 5px;
box-sizing: border-box;
}
.control-box>span{
margin-left: 5px;
}
.input-text{
width:120px;
height:25px;
line-height:25px;
box-sizing: border-box;
}
.control-button{
height:25px;
line-height:25px;
cursor: pointer;
padding: 2px 5px;
box-sizing: border-box;
margin-left:10px;
}
</style>
</head>
<body>
<!--地图容器-->
<div id="mapContainer"></div>
<div class="control-box">
<input class="input-text" type="text" id="testText" value="标签文字" />
<input class="control-button" type="button" value="添加标题" onclick="createLabel()" >
<input class="control-button" type="button" value="显示" onclick="showLabels(true)" >
<input class="control-button" type="button" value="隐藏" onclick="showLabels(false)" >
<input class="control-button" type="button" value="移除" onclick="removeLabels()" >
</div>
<script type="text/javascript">
var map = TUMap.createMap({
//地图容器
id:"mapContainer",
//UE4服务地址 必须设置 当前示例以地址栏地址 为服务地址 ,用户需要替换为自己的服务地址
url:window.parent.window.exampleServerUrl ,//"http://localhost:81/",
onInit:function(){
createLabel();
}
}) ;
//标签数组
var labels = [] ;
//创建标签
function createLabel(){
var labelText = document.getElementById("testText").value;
for (var i = 0; i < 10; i++) {
labels.push(map.createLabel({
x : Math.random()*-30000,//位置 x
y : Math.random()*-30000,//位置 y
z : 1000,//位置 z
size : {width:480,height:180},//标签尺寸 需要手动设置
text : labelText,//标签文字
type : 'Type1',//标签类型
scale : 1,
backgroundColor : "rgba(0,0,0,.8)",
fillColor : "#00ff00",
}));
}
//移动下位置
map.focusOn(new TUVector3(66,-105,277),new TURotator(0,-47,-155),37849 );
}
//显示文字
function showLabels(value){
labels.forEach(function(label){
label.show(value) ;
})
}
//隐藏文字
function removeLabels(){
labels.forEach(function(label){
label.removeFromMap() ;
})
}
</script>
</body>
</html>