在易景地球上实现按钮等效果
lua代码如下:
=========================================================
--创建一个基本大小的框
ctrl = evGUI.Create("Base", evGUIRoot)
ctrl:SetSize(240,64)
evGUIRoot:AddEvent("onFrame",function ( )
--ctrl:AlignBottom()
ctrl:SetPos( ctrl.Bounds.x , evGUIRoot.Bounds.h - ctrl.Bounds.h - 20);
ctrl:AlignCenterH()
end)
function createBtn(href, szx,szy, x,y, tp,onclick)
local btn = evGUI.Create("Button",ctrl)
btn.Background=false
btn:SetImage(href,true)
btn:SetSize(szx,szy)
btn:SetPos(x,y)
btn.Tooltip = tp
btn:AddEvent("onPress",onclick)
return btn;
end
local cam = evControl.CameraControl
left = 10
top = 0
createBtn("D:\\data\\图标\\view-pan-64x64.png",64,64, left,top, '平移', function(obj)
lon = cam:GetLongitude()
lat = cam:GetLatitude()
alt = cam:GetAltitude()
head = cam:GetHeading()
tilt = cam:GetTilt()
--判断落在哪个区域
local mp = evGUI.MousePosition()
local cx = mp.x - obj.Bounds.x - 32 - ctrl.Bounds.x
local cy = mp.y- obj.Bounds.y -32 - ctrl.Bounds.y
evprint(cx,cy)
evCamInner:Slip(cx * 1.0 / 32)
evCamInner:Walk(cy * 1.0 / 32)
end
)
left = left+ 64 + 4
createBtn("D:\\data\\图标\\view-zoom-in-32x32.png",32, 32,left, top, '前进', function(obj)
evCamInner:Walk(1)
end
)
createBtn("D:\\data\\图标\\view-zoom-out-32x32.png",32,32, left, top + 32,'后退', function(obj)
evCamInner:Walk(-1)
end
)
left = left+ 32 + 4
createBtn("D:\\data\\图标\\view-heading-left-32x32.png",32,32, left, top, '左转', function(obj)
lon = cam:GetLongitude()
lat = cam:GetLatitude()
alt = cam:GetAltitude()
head = cam:GetHeading()
tilt = cam:GetTilt()
--左转
head = head - 10
cam:SetDirection(tilt,head)
end
)
createBtn("D:\\data\\图标\\view-heading-right-32x32.png",32,32, left, top + 32, '右转', function(obj)
lon = cam:GetLongitude()
lat = cam:GetLatitude()
alt = cam:GetAltitude()
head = cam:GetHeading()
tilt = cam:GetTilt()
--左转
head = head + 10
cam:SetDirection(tilt,head)
end
)
left = left+ 32 + 4
createBtn("D:\\data\\图标\\view-pitch-up-32x32.png",32,32, left, top, '抬头', function(obj)
lon = cam:GetLongitude()
lat = cam:GetLatitude()
alt = cam:GetAltitude()
head = cam:GetHeading()
tilt = cam:GetTilt()
--左转
tilt = tilt + 10
cam:SetDirection(tilt,head)
end
)
createBtn("D:\\data\\图标\\view-pitch-down-32x32.png",32, 32,left, top + 32, '低头', function(obj)
lon = cam:GetLongitude()
lat = cam:GetLatitude()
alt = cam:GetAltitude()
head = cam:GetHeading()
tilt = cam:GetTilt()
--左转
tilt = tilt - 10
cam:SetDirection(tilt,head)
end
)
left = left+ 32 + 4
createBtn("D:\\data\\图标\\view-elevation-up-32x32.png",32,32, left, top, '抬升', function(obj)
lon = cam:GetLongitude()
lat = cam:GetLatitude()
alt = cam:GetAltitude()
head = cam:GetHeading()
tilt = cam:GetTilt()
--抬升
alt = alt * 1.2
cam:FlyToDirect(lon, lat, alt, 0.5)
end
)
createBtn("D:\\data\\图标\\view-elevation-down-32x32.png",32, 32,left, top + 32,'降低', function(obj)
lon = cam:GetLongitude()
lat = cam:GetLatitude()
alt = cam:GetAltitude()
head = cam:GetHeading()
tilt = cam:GetTilt()
--降低
alt = alt * 0.8
cam:FlyToDirect(lon, lat, alt, 0.5)
end
)
======================================================
lua代码如下:
=========================================================
--创建一个基本大小的框
ctrl = evGUI.Create("Base", evGUIRoot)
ctrl:SetSize(240,64)
evGUIRoot:AddEvent("onFrame",function ( )
--ctrl:AlignBottom()
ctrl:SetPos( ctrl.Bounds.x , evGUIRoot.Bounds.h - ctrl.Bounds.h - 20);
ctrl:AlignCenterH()
end)
function createBtn(href, szx,szy, x,y, tp,onclick)
local btn = evGUI.Create("Button",ctrl)
btn.Background=false
btn:SetImage(href,true)
btn:SetSize(szx,szy)
btn:SetPos(x,y)
btn.Tooltip = tp
btn:AddEvent("onPress",onclick)
return btn;
end
local cam = evControl.CameraControl
left = 10
top = 0
createBtn("D:\\data\\图标\\view-pan-64x64.png",64,64, left,top, '平移', function(obj)
lon = cam:GetLongitude()
lat = cam:GetLatitude()
alt = cam:GetAltitude()
head = cam:GetHeading()
tilt = cam:GetTilt()
--判断落在哪个区域
local mp = evGUI.MousePosition()
local cx = mp.x - obj.Bounds.x - 32 - ctrl.Bounds.x
local cy = mp.y- obj.Bounds.y -32 - ctrl.Bounds.y
evprint(cx,cy)
evCamInner:Slip(cx * 1.0 / 32)
evCamInner:Walk(cy * 1.0 / 32)
end
)
left = left+ 64 + 4
createBtn("D:\\data\\图标\\view-zoom-in-32x32.png",32, 32,left, top, '前进', function(obj)
evCamInner:Walk(1)
end
)
createBtn("D:\\data\\图标\\view-zoom-out-32x32.png",32,32, left, top + 32,'后退', function(obj)
evCamInner:Walk(-1)
end
)
left = left+ 32 + 4
createBtn("D:\\data\\图标\\view-heading-left-32x32.png",32,32, left, top, '左转', function(obj)
lon = cam:GetLongitude()
lat = cam:GetLatitude()
alt = cam:GetAltitude()
head = cam:GetHeading()
tilt = cam:GetTilt()
--左转
head = head - 10
cam:SetDirection(tilt,head)
end
)
createBtn("D:\\data\\图标\\view-heading-right-32x32.png",32,32, left, top + 32, '右转', function(obj)
lon = cam:GetLongitude()
lat = cam:GetLatitude()
alt = cam:GetAltitude()
head = cam:GetHeading()
tilt = cam:GetTilt()
--左转
head = head + 10
cam:SetDirection(tilt,head)
end
)
left = left+ 32 + 4
createBtn("D:\\data\\图标\\view-pitch-up-32x32.png",32,32, left, top, '抬头', function(obj)
lon = cam:GetLongitude()
lat = cam:GetLatitude()
alt = cam:GetAltitude()
head = cam:GetHeading()
tilt = cam:GetTilt()
--左转
tilt = tilt + 10
cam:SetDirection(tilt,head)
end
)
createBtn("D:\\data\\图标\\view-pitch-down-32x32.png",32, 32,left, top + 32, '低头', function(obj)
lon = cam:GetLongitude()
lat = cam:GetLatitude()
alt = cam:GetAltitude()
head = cam:GetHeading()
tilt = cam:GetTilt()
--左转
tilt = tilt - 10
cam:SetDirection(tilt,head)
end
)
left = left+ 32 + 4
createBtn("D:\\data\\图标\\view-elevation-up-32x32.png",32,32, left, top, '抬升', function(obj)
lon = cam:GetLongitude()
lat = cam:GetLatitude()
alt = cam:GetAltitude()
head = cam:GetHeading()
tilt = cam:GetTilt()
--抬升
alt = alt * 1.2
cam:FlyToDirect(lon, lat, alt, 0.5)
end
)
createBtn("D:\\data\\图标\\view-elevation-down-32x32.png",32, 32,left, top + 32,'降低', function(obj)
lon = cam:GetLongitude()
lat = cam:GetLatitude()
alt = cam:GetAltitude()
head = cam:GetHeading()
tilt = cam:GetTilt()
--降低
alt = alt * 0.8
cam:FlyToDirect(lon, lat, alt, 0.5)
end
)
======================================================
实现的效果如下图:
红框显示为按钮的效果