2.4.5 拖拽器
拖拽器
拖拽器功能是指通过在三维场景中构建拖拽器来对矢量符号化成模型的数据进行编辑的功能。它会在模型中心点位置构建拖拽器,可以通过操作拖拽器来调整模型的坐标点位、角度和大小。
拖拽器是通过响应器的方式实现的,因此它可以直接在场景中进行操作。一般常用的功能是创建拖拽器和移除拖拽器两种。
拖拽器有移动、旋转、缩放三种操作模式,可以通过鼠标左键单击进行操作模式的切换。
注意:在场景中,拖拽器会有三种颜色表示,其中:红色显示的是与X轴相关的控制对象;绿色显示的是与Y轴相关的控制对象;蓝色显示的是与Z轴相关的控制对象。
拖拽器使用流程
拖拽器是用来编辑矢量符号化模型数据的,比如在场景中的添加摄像头之后,可以通过拖拽器来移动摄像头的位置、对摄像头进行缩放以及改变摄像头的监控方向等。在使用拖拽器时,主要是以下几个流程:
- 创建摄像头图层。该图层是个矢量图层,图层里面配置了模型符号;改图层可以是空的也可以是有要素对象的。
- 添加摄像头。通过要素的添加操作在场景中某个位置添加摄像头。
- 创建拖拽器。创建的拖拽器需要和摄像头图层关联,并且还需要关联对应的属性字段;属性字段参加参数说明。
- 操作拖拽器进行模型更新。拖拽器有移动、旋转、缩放三种模式、可通过单击模型进行模式切换。
- 保存摄像头图层。可以将编辑后的要素保存到图层当中,也可以将拖拽器回调回来的信息保存到数据库或者服务端。
- 移除拖拽器。操作完之后,可以将拖拽器移除,并移除摄像头图层。
下图是拖拽器效果:
参数说明
拖拽器可配置的参数如下表所示:
配置项 | 配置说明 | 值类型 | 备注 |
---|---|---|---|
PickLayerIdList | 图层ID列表 | int列表 | 传-1则默认遍历所有矢量图层,若为多个图层,可使用xx,xx,xx 此种格式。图层Id可以通过图层对象的GetLayerId()方法获取 |
PickColor | 颜色透明度 | R,G,B,A | 颜色取值范围在0-1.0之间,如 "0.9,0.8,0.8,1.0",A的取值必须大于0.2 |
IsChangeColor | 是否变色 | bool | 默认值false,设为true,则PickColor 配置的颜色起效 |
Adjustment | 微调部件步进值 | double | 在移动状态下,每个轴前面有两个圆锥部件,可以通过点击圆锥进行微调。默认为0.01 |
DragSpeed | 拖拽系数 | double | 按住坐标轴进行拖拽的移动速度。默认为1.0 |
AxisXVisible | X旋转面是否显示 | bool | 在旋转状态时,控制与X轴垂直的面的显隐状态。 设为true时,可以通过拾取并拖动该面进行旋转。 默认值false |
AxisYVisible | Y旋转面是否显示 | bool | 在旋转状态时,控制与Y轴垂直的面的显隐状态。 设为true时,可以通过拾取并拖动该面进行旋转。 默认值false |
AxisZVisible | Z旋转面是否显示 | bool | 在旋转状态时,控制与Z轴垂直的面的显隐状态。 设为true时,可以通过拾取并拖动该面进行旋转。 默认值false |
XRotate | 翻滚角关联字段 | string | 控制摄像头模型在X轴方向旋转的字段, 需要与摄像头图层模型符号的Roll 对应 |
YRotate | 偏移角关联字段 | string | 控制摄像头模型在Y轴方向旋转的字段, 需要与摄像头图层模型符号的Pitch 对应 |
ZRotate | 俯仰角关联字段 | string | 控制摄像头模型在Z轴方向旋转的字段, 需要与摄像头图层模型符号的Heading 对应 |
XScale | X轴缩放关联字段 | string | 控制摄像头模型在X轴方向缩放的字段, 需要与摄像头图层模型符号的XScale 对应 |
YScale | Y轴缩放关联字段 | string | 控制摄像头模型在Y轴方向缩放的字段, 需要与摄像头图层模型符号的YScale 对应 |
ZScale | Z轴缩放关联字段 | string | 控制摄像头模型在Z轴方向缩放的字段, 需要与摄像头图层模型符号的ZScale 对应 |
获取结果说明
模型拾取可以通过响应器对象的GetRespnserResult() 方法获取结果。获取的结果值对象参数如下表所示:
配置项 | 配置说明 | 值类型 | 备注 |
---|---|---|---|
FeatureId | 要素ID | int | 编辑后的要素ID值 |
OXAngle | 翻滚角 | double | 编辑后的翻滚角 |
OYAngle | 偏移角 | double | 编辑后的偏移角 |
OZAngle | 俯仰角 | double | 编辑后的俯仰角 |
OXScale | X轴缩放比例 | double | 编辑后X轴方向的缩放比例 |
OYScale | Y轴缩放比例 | double | 编辑后Y轴方向的缩放比例 |
OZScale | Z轴缩放比例 | double | 编辑后Z轴方向的缩放比例 |
LonLatPoint | 要素坐标点 | x,y,z | 摄像头要素所在位置的经度,纬度,高程坐标 |
代码调用示例
Javascript调用
var shpLayer = null;
var editShpLayer = null;
var newFeature = null;
var addState = false;
var axisEditResponser = null;
var lbEvent = null;
var resEvent = null;
var bSave = false;
var xAngle = 0;
var yAngle = 0;
var zAngle = 0;
var xScale = 0;
var yScale = 0;
var zScale = 0;
var pos = "";
var editdId = 0;
//鼠标左键弹起回调
function callBackLButtonFun(posX, posY){
if(addState){
var transformate = map.CreateTransformation();
var pos = transformate.ScreenPosToWorldPos(posX, posY);//将屏幕坐标点转换成经纬度坐标
newFeature.AddPoint(pos.GetX(), pos.GetY(), pos.GetZ());//向编辑图层添加坐标点信息
}
}
//响应器回调
function callBackResponserFun(respType, state){
if(axisEditResponser){
bSave = true;
editdId = axisEditResponser.GetResponserResult().GetConfigValueByKey("FeatureId");//编辑后要素id
xAngle = axisEditResponser.GetResponserResult().GetConfigValueByKey("OXAngle");//红轴欧拉角
yAngle = axisEditResponser.GetResponserResult().GetConfigValueByKey("OYAngle");//绿轴欧拉角
zAngle = axisEditResponser.GetResponserResult().GetConfigValueByKey("OZAngle");//蓝轴欧拉角
xScale = axisEditResponser.GetResponserResult().GetConfigValueByKey("OXScale");//红轴欧拉角
yScale = axisEditResponser.GetResponserResult().GetConfigValueByKey("OYScale");//绿轴欧拉角
zScale = axisEditResponser.GetResponserResult().GetConfigValueByKey("OZScale");//蓝轴欧拉角
pos = axisEditResponser.GetResponserResult().GetConfigValueByKey("LonLatPoint");//经纬度点坐标
//console.log("Id:" + editdId + " pos:" + pos + " xAngle:" + xAngle + " yAngle:" + yAngle + " zAngle:" + zAngle + " xScale:" + xScale + " yScale:" + yScale + " zScale:" + zScale);
}
}
//创建设备图层
function createLayer(){
if(lbEvent == null){
lbEvent = addEvent(obj, "FireOnLButtonUp", callBackLButtonFun);//响应器对应事件均为FireOnResponserNotify
}
if(shpLayer == null){
var reslibName = "reslib";
var pointSymbol = createPointSymbol("1.0,1.0,0.0,1.0");
var modelSymbol = map.CreateSymbol("ModelSymbol");//创建类型为ModelSymbol的符号,必须为ModelSymbol字符串
modelSymbol.AddConfig("Heading", "[ZRotate]");//蓝轴
modelSymbol.AddConfig("Pitch", "[YRotate]");//绿轴
modelSymbol.AddConfig("Roll", "[XRotate]");//红轴
modelSymbol.AddConfig("XScale", "[XScale]");//模型x方向放大比例
modelSymbol.AddConfig("YScale", "[YScale]");//模型y方向放大比例
modelSymbol.AddConfig("ZScale", "[ZScale]");//模型z方向放大比例
modelSymbol.AddConfig("ModelOriginDir", "0,0,1");//模型原始轴向
modelSymbol.AddConfig("FeatureLiftUp", "0");// 要素抬升值
modelSymbol.AddConfig("IsLocalRotation", "true");//是否在局地进行旋转,以保持模型原始的朝向(默认为否)
modelSymbol.AddConfig("Url", gModelDeviceFolderPath + "/ganqiu.wrl");//模型资源路径
modelSymbol.AddConfig("LibraryName", reslibName);//资源名称
var reslib = createResourceLibrary("ModelSymbol", gModelDeviceFolderPath + "/ganqiu.wrl", reslibName);
var pStyle = map.CreateStyle("Point");//创建名称为Point的样式,名称任意
pStyle.SetName("point");//设置别名point
pStyle.AddSymbol("PointSymbol", pointSymbol.GetConfig());//将点符号配置添加到该样式
pStyle.AddFilterName("BuildGeometryFilter");//若不想点显示,此行可注释
pStyle.AddSymbol("ModelSymbol", modelSymbol.GetConfig());//将符号配置添加到该样式,第一参必须为ModelSymbol字符串
pStyle.AddFilterName("SubstituteModelFilter");//设置构建器符号为SubstituteModelFilter,必须为SubstituteModelFilter字符串,此为图标符号化和模型符号化共有
var styleSheet = map.CreateStyleSheet();//创建样式表
styleSheet.AddStyle(pStyle.GetConfig());//将样式配置添加至样式表
styleSheet.AddResLib(reslib.GetConfig());//将资源库添加至样式表
var tlo = map.CreateLayerOptions("shp");//创建图层配置对象
tlo.AddConfig("LayerOptionsName", "FeatureModelLayerOptions");//创建配置类型, FeatureModelLayerOptions代表矢量数据配置,必须是此键值对
tlo.AddConfig("DataSourceTypeName", "fmgeom");//数据源类型,代表fmgeom插件,必须是此键值对
tlo.AddConfig("Driver", "ESRI Shapefile");//数据驱动,针对shp、dxf数据源必须是ESRI Shapefile
tlo.AddConfig("Url", gShpAxisEditPath);//数据路径
tlo.AddConfig("FeatureSourceType", "ogr");//要素数据源类型,针对shp、dxf数据源必须是ogr
tlo.AddConfig("GeometryType", "Point");//几何类型 Point为点 Polyline为线 Polygon为面 此项配置不能少或字符串一定不能错误,否则保存文件不成功
tlo.AddConfig("TileSizeFactor", "1.0");//瓦片大小的影响因子,建议是1.0
tlo.AddConfig("TileSize", "500");//瓦片大小,根据数据实际情况设置,根据数据面积来,面积越大值越大
tlo.AddConfig("LiftUp", "10");//抬升高度,任意值
tlo.AddConfig("MaxRange", "10000.0");//最大显示范围,大于最小显示范围-无穷大
tlo.AddConfig("MinRange", "0.0");//最小显示范围,0-无穷大
tlo.AddConfig("StyleSheet", styleSheet.GetConfig());//将样式表配置添加至图层配置对象,第一参必须为StyleSheet字符串
shpLayer = map.CreateLayer("FeatureModelLayer", tlo);//创建矢量图层,第一项参数必须为FeatureModelLayer
map.AddLayer(shpLayer);//添加矢量图层
var id = shpLayer.GetLayerID();//获取图层id
editShpLayer = map.GetFeatureModelLayer(id);//获取要素图层对象
flyToDestPos(120.218053442,30.2105685604,15.4661341505,1.547688660813076,-0.7241294432698189,17.60054027214769,3);
}else{
alert("请勿重复创建图层!");
}
}
//移除设备图层
function removeLayer(){
removeAxisEditResponser();
if(shpLayer){
map.RemoveLayer(shpLayer);
shpLayer = null;
editShpLayer = null;
}
}
//创建设备编辑器
function createAxisEditResponser(){
if(resEvent == null){
resEvent = addEvent(obj, "FireOnResponserNotify", callBackResponserFun);//响应器对应事件均为FireOnResponserNotify
}
if(axisEditResponser == null){
var resp = map.CreateResponserOptions("AxisEditResponser");
resp.AddConfig("PickLayerIdList", editShpLayer.GetLayerID());
resp.AddConfig("PickColor", "1.0,0.0,0,0.8");//拾取颜色r g b a
resp.AddConfig("IsChangeColor", "true");//是否变色
resp.AddConfig("AxisXVisible", "true");//x旋转面是否显示(红面)
resp.AddConfig("AxisYVisible", "true");//y旋转面是否显示(绿面)
resp.AddConfig("AxisZVisible", "true");//z旋转面是否显示(蓝面)
resp.AddConfig("XRotate", "XRotate");//x轴关联字段(红轴)
resp.AddConfig("YRotate", "YRotate");//y轴关联字段(绿轴)
resp.AddConfig("ZRotate", "ZRotate");//z轴关联字段(蓝轴)
resp.AddConfig("XScale", "XScale");
resp.AddConfig("YScale", "YScale");
resp.AddConfig("ZScale", "ZScale");
resp.AddConfig("Adjustment", "0.1");//微调部件步进值,默认为0.01
resp.AddConfig("DragSpeed", "0.3");//拖拽速度系数,默认为1
axisEditResponser = map.CreateResponser("AxisEditResponser", resp);//坐标轴响应器,必须为AxisEditResponser
axisEditResponser.AddObserver();
map.AddResponser(axisEditResponser);
}else{
alert("响应器已创建!");
}
}
//移除设备编辑器
function removeAxisEditResponser(){
if(axisEditResponser){
map.RemoveResponser("AxisEditResponser");
axisEditResponser = null;
if(resEvent){
delEvent(obj, "FireOnResponserNotify", callBackResponserFun, resEvent);//第四个参数用于IE11事件删除,其他浏览器传null即可
resEvent = null;
}
}
}
//保存设备
function addParamFeature(){
if(editShpLayer){
if(bSave){
editShpLayer.SaveLayer(); //编辑图层保存,一般用于首次创建保存
}
}else{
alert("无矢量图层,无法保存!");
}
}
//创建点Symbol
function createPointSymbol(colorStr){
var symbol = map.CreateSymbol("PointSymbol");//创建类型为PointSymbol的符号,必须为PointSymbol字符串
symbol.AddConfig("Size", "5");//点的大小,范围0-10
symbol.AddConfig("Color", colorStr);//1.0,1.0,0.0,1.0 颜色值(RGBA)0-1,最后一位代表透明度,0为透明,1为不透
return symbol;
}
//创建资源库
function createResourceLibrary(symbolType, resUri, resLibName){
var res = map.CreateResource(symbolType);//创建图标资源,此处必须为Texsymbol
if(symbolType == "SkinSymbol"){
res.AddConfig("image_url", resUri);
res.AddConfig("image_width", "256");//纹理宽度
res.AddConfig("image_height", "256");//纹理高度
res.AddConfig("tiled", "true");//纹理贴图是否瓦片化显示
}else{
res.AddConfig("Uri", resUri);//图标资源路径
}
var reslib = map.CreateResourceLibrary(resLibName);//创建资源库,名称和图层配置LibraryName设置的名称对应
reslib.AddResource(res);//将资源添加至资源库
return reslib;
}
C++调用
BaseObjectCOMLib::ILayerObjectPtr shpLayer;//设备图层对象
BaseObjectCOMLib::IFeatureModelLayerPtr editShpLayer;//要素模型图层对象
BaseObjectCOMLib::IResponserObjectPtr axisEditResponser;//设备编辑器对象
//创建设备图层
void CAxisEditDlg::OnBnClickedcreatelayer()
{
if(shpLayer)
{
return;
}
char temp_status[MAX_PATH];
GetPrivateProfileStringA("Path", "GanqiuPath", "", temp_status, MAX_PATH, mIniPath.c_str());
std::string GanqiuPath(temp_status);
GetPrivateProfileStringA("Path", "ShpAxisEditPath", "", temp_status, MAX_PATH, mIniPath.c_str());
std::string ShpAxisEditPath(temp_status);
//创建点符号
ConfigOptionsCOMLib::ISymbolObjectPtr pointSymbol = map->CreateSymbol("PointSymbol");//创建符号对象,PointSymbol代表点符号
pointSymbol->AddConfig("Size", "5");//点大小,(0-10)
pointSymbol->AddConfig("Color", "1.0,1.0,0.0,1.0");//颜色值(RGBA,各值取值范围0-1之间)
//创建模型符号
ConfigOptionsCOMLib::ISymbolObjectPtr modelSymbol = map->CreateSymbol("ModelSymbol");//创建符号对象,modelSymbol代表模型符号
modelSymbol->AddConfig("Heading", "[ZRotate]");//蓝轴
modelSymbol->AddConfig("Pitch", "[YRotate]");//绿轴
modelSymbol->AddConfig("Roll", "[XRotate]");//红轴
modelSymbol->AddConfig("XScale", "[XScale]");//模型x方向放大比例
modelSymbol->AddConfig("YScale", "[YScale]");//模型y方向放大比例
modelSymbol->AddConfig("ZScale", "[ZScale]");//模型z方向放大比例
modelSymbol->AddConfig("ModelOriginDir", "0,0,1");//模型原始轴向
modelSymbol->AddConfig("FeatureLiftUp", "0");// 要素抬升值
modelSymbol->AddConfig("IsLocalRotation", "true");//是否在局地进行旋转,以保持模型原始的朝向(默认为否)
modelSymbol->AddConfig("Url", GanqiuPath.c_str());//模型资源路径
modelSymbol->AddConfig("LibraryName", "reslib");//资源名称
//创建资源库
ConfigOptionsCOMLib::IResourceObjectPtr res = map->CreateResource("ModelSymbol");//创建图标资源,此处必须为Texsymbol
res->AddConfig("Uri", GanqiuPath.c_str());//图标资源路径
BaseObjectCOMLib::IResourceLibraryPtr reslib = map->CreateResourceLibrary("reslib");//创建资源库,名称和图层配置LibraryName设置的名称对应
reslib->AddResource(res);//将资源添加至资源库
//创建样式
ConfigOptionsCOMLib::IStylePtr pStyle = map->CreateStyle("Point");//创建名称为Point的样式,名称任意
pStyle->SetName("point");//设置别名point
pStyle->AddSymbol("PointSymbol", pointSymbol->GetConfig());//将点符号配置添加到该样式
pStyle->AddFilterName("BuildGeometryFilter");//若不想点显示,此行可注释
pStyle->AddSymbol("ModelSymbol", modelSymbol->GetConfig());//将符号配置添加到该样式,第一参必须为ModelSymbol字符串
pStyle->AddFilterName("SubstituteModelFilter");//设置构建器符号为SubstituteModelFilter,必须为SubstituteModelFilter字符串,此为图标符号化和模型符号化共有
//创建样式表
ConfigOptionsCOMLib::IStyleSheetPtr styleSheet = map->CreateStyleSheet();//创建样式表
styleSheet->AddStyle(pStyle->GetConfig());//将样式配置添加至样式表
styleSheet->AddResLib(reslib->GetConfig());//将资源库添加至样式表
//创建图层
ConfigOptionsCOMLib::ILayerOptionsPtr tlo = (ConfigOptionsCOMLib::ILayerOptionsPtr)map->CreateLayerOptions("shp"); //创建图层配置对象,名称任意
tlo->AddConfig("LayerOptionsName", "FeatureModelLayerOptions");//图层配置对象名称, FeatureModelLayerOptions代表矢量数据配置
tlo->AddConfig("DataSourceTypeName", "fmgeom");//数据源类型,代表fmgeom插件,必须是此键值对
tlo->AddConfig("Driver", "ESRI Shapefile");//数据驱动,针对shp、dxf数据源必须是ESRI Shapefile
tlo->AddConfig("Url", ShpAxisEditPath.c_str());//数据路径
tlo->AddConfig("FeatureSourceType", "ogr");//要素数据源类型,针对shp、dxf数据源必须是ogr
tlo->AddConfig("GeometryType", "Point");//几何类型 Point为点 Polyline为线 Polygon为面 此项配置不能少或字符串一定不能错误,否则保存文件不成功
tlo->AddConfig("TileSizeFactor", "1.0");//瓦片大小的影响因子,建议是1.0
tlo->AddConfig("TileSize", "500");//瓦片大小,根据数据实际情况设置,根据数据面积来,面积越大值越大
tlo->AddConfig("LiftUp", "0");//抬升高度,任意值
tlo->AddConfig("MaxRange", "10000.0");//最大显示范围,大于最小显示范围-无穷大
tlo->AddConfig("MinRange", "0.0");//最小显示范围,0-无穷大
tlo->AddConfig("StyleSheet", styleSheet->GetConfig());//将样式表配置添加至图层配置对象,第一参必须为StyleSheet字符串
shpLayer = map->CreateLayer("FeatureModelLayer", tlo);//创建矢量图层,第一项参数必须为FeatureModelLayer
map->AddLayer(shpLayer);//添加矢量图层
long id = shpLayer->GetLayerID();//获取图层id
editShpLayer = map->GetFeatureModelLayer(id);//获取要素图层对象
}
//移除设备图层
void CAxisEditDlg::OnBnClickedremovelayer()
{
OnBnClickedremoveaxiseditresponser();
if(!shpLayer)
{
return;
}
map->RemoveLayer(shpLayer);
shpLayer = NULL;
editShpLayer = NULL;
}
//创建设备编辑器
void CAxisEditDlg::OnBnClickedcreateaxiseditresponser()
{
if(axisEditResponser)
{
return;
}
ConfigOptionsCOMLib::IResponserOptionPtr resp = map->CreateResponserOptions("AxisEditResponser");
std::stringstream stream;
stream << editShpLayer->GetLayerID();
resp->AddConfig("PickLayerIdList", stream.str().c_str());
resp->AddConfig("PickColor", "1.0,0.0,0,0.8");//拾取颜色r g b a
resp->AddConfig("IsChangeColor", "true");//是否变色
resp->AddConfig("AxisXVisible", "true");//x旋转面是否显示(红面)
resp->AddConfig("AxisYVisible", "true");//y旋转面是否显示(绿面)
resp->AddConfig("AxisZVisible", "true");//z旋转面是否显示(蓝面)
resp->AddConfig("XRotate", "XRotate");//x轴关联字段(红轴)
resp->AddConfig("YRotate", "YRotate");//y轴关联字段(绿轴)
resp->AddConfig("ZRotate", "ZRotate");//z轴关联字段(蓝轴)
resp->AddConfig("XScale", "XScale");
resp->AddConfig("YScale", "YScale");
resp->AddConfig("ZScale", "ZScale");
resp->AddConfig("Adjustment", "0.1");//微调部件步进值,默认为0.01
resp->AddConfig("DragSpeed", "0.3");//拖拽速度系数,默认为1
axisEditResponser = map->CreateResponser("AxisEditResponser", resp);//坐标轴响应器,必须为AxisEditResponser
axisEditResponser->AddObserver();
map->AddResponser(axisEditResponser);
}
//移除设备编辑器
void CAxisEditDlg::OnBnClickedremoveaxiseditresponser()
{
if(!axisEditResponser)
{
return;
}
map->RemoveResponser("AxisEditResponser");
axisEditResponser = NULL;
}
//保存设备图层
void CAxisEditDlg::OnBnClickedaddparamfeature()
{
if(!editShpLayer)
{
return;
}
editShpLayer->SaveLayer();//编辑图层保存,一般用于首次创建保存
}
C#调用
string gShpAxisEditPath;//设备矢量路径
ILayerObject shpLayer;//矢量图层
string gGanqiuPath;//杆球路径
IFeatureModelLayer editShpLayer;//要素模型图层对象
IResponserObject axisEditResponser;//设备编辑器对象
double xAngle = 0;
double yAngle = 0;
double zAngle = 0;
double xScale = 0;
double yScale = 0;
double zScale = 0;
string pos = "";
int editdId = 0;
bool bSave = false;
bool addState = false;
//创建设备图层
private void createLayer_Click(object sender, EventArgs e)
{
if (shpLayer == null)
{
string reslibName = "reslib";
var pointSymbol = map.CreateSymbol("PointSymbol");//创建类型为PointSymbol的符号,必须为PointSymbol字符串
pointSymbol.AddConfig("Size", "5");//点的大小,范围0-10
pointSymbol.AddConfig("Color", "1.0,1.0,0.0,1.0");//1.0,1.0,0.0,1.0 颜色值(RGBA)0-1,最后一位代表透明度,0为透明,1为不透
var modelSymbol = map.CreateSymbol("ModelSymbol");//创建类型为ModelSymbol的符号,必须为ModelSymbol字符串
modelSymbol.AddConfig("Heading", "[ZRotate]");//蓝轴
modelSymbol.AddConfig("Pitch", "[YRotate]");//绿轴
modelSymbol.AddConfig("Roll", "[XRotate]");//红轴
modelSymbol.AddConfig("XScale", "[XScale]");//模型x方向放大比例
modelSymbol.AddConfig("YScale", "[YScale]");//模型y方向放大比例
modelSymbol.AddConfig("ZScale", "[ZScale]");//模型z方向放大比例
modelSymbol.AddConfig("ModelOriginDir", "0,0,1");//模型原始轴向
modelSymbol.AddConfig("FeatureLiftUp", "0");// 要素抬升值
modelSymbol.AddConfig("IsLocalRotation", "true");//是否在局地进行旋转,以保持模型原始的朝向(默认为否)
modelSymbol.AddConfig("Url", gGanqiuPath);//模型资源路径
modelSymbol.AddConfig("LibraryName", reslibName);//资源名称
var res = map.CreateResource("ModelSymbol");//创建图标资源,此处必须为Texsymbol
res.AddConfig("Uri", readini("Path", "GanqiuPath", "", filepath));//图标资源路径
var reslib = map.CreateResourceLibrary(reslibName);//创建资源库,名称和图层配置LibraryName设置的名称对应
reslib.AddResource(res);//将资源添加至资源库
var pStyle = map.CreateStyle("Point");//创建名称为Point的样式,名称任意
pStyle.SetName("point");//设置别名point
pStyle.AddSymbol("PointSymbol", pointSymbol.GetConfig());//将点符号配置添加到该样式
pStyle.AddFilterName("BuildGeometryFilter");//若不想点显示,此行可注释
pStyle.AddSymbol("ModelSymbol", modelSymbol.GetConfig());//将符号配置添加到该样式,第一参必须为ModelSymbol字符串
pStyle.AddFilterName("SubstituteModelFilter");//设置构建器符号为SubstituteModelFilter,必须为SubstituteModelFilter字符串,此为图标符号化和模型符号化共有
var styleSheet = map.CreateStyleSheet();//创建样式表
styleSheet.AddStyle(pStyle.GetConfig());//将样式配置添加至样式表
styleSheet.AddResLib(reslib.GetConfig());//将资源库添加至样式表
var tlo = map.CreateLayerOptions("shp");//创建图层配置对象
tlo.AddConfig("LayerOptionsName", "FeatureModelLayerOptions");//创建配置类型, FeatureModelLayerOptions代表矢量数据配置,必须是此键值对
tlo.AddConfig("DataSourceTypeName", "fmgeom");//数据源类型,代表fmgeom插件,必须是此键值对
tlo.AddConfig("Driver", "ESRI Shapefile");//数据驱动,针对shp、dxf数据源必须是ESRI Shapefile
tlo.AddConfig("Url", gShpAxisEditPath);//数据路径
tlo.AddConfig("FeatureSourceType", "ogr");//要素数据源类型,针对shp、dxf数据源必须是ogr
tlo.AddConfig("GeometryType", "Point");//几何类型 Point为点 Polyline为线 Polygon为面 此项配置不能少或字符串一定不能错误,否则保存文件不成功
tlo.AddConfig("TileSizeFactor", "1.0");//瓦片大小的影响因子,建议是1.0
tlo.AddConfig("TileSize", "500");//瓦片大小,根据数据实际情况设置,根据数据面积来,面积越大值越大
tlo.AddConfig("LiftUp", "0");//抬升高度,任意值
tlo.AddConfig("MaxRange", "10000.0");//最大显示范围,大于最小显示范围-无穷大
tlo.AddConfig("MinRange", "0.0");//最小显示范围,0-无穷大
tlo.AddConfig("StyleSheet", styleSheet.GetConfig());//将样式表配置添加至图层配置对象,第一参必须为StyleSheet字符串
shpLayer = map.CreateLayer("FeatureModelLayer", tlo);//创建矢量图层,第一项参数必须为FeatureModelLayer
map.AddLayer(shpLayer);//添加矢量图层
var id = shpLayer.GetLayerID();//获取图层id
editShpLayer = map.GetFeatureModelLayer(id);//获取要素图层对象
flyToDestPos(120.218053442, 30.2105685604, 15.4661341505, 1.547688660813076, -0.7241294432698189, 17.60054027214769, 3);
}
else
{
MessageBox.Show("请勿重复创建图层!");
}
}
//移除设备图层
private void removeLayer_Click(object sender, EventArgs e)
{
if (axisEditResponser!=null)
{
map.RemoveResponser("AxisEditResponser");
axisEditResponser = null;
}
if (shpLayer!=null)
{
map.RemoveLayer(shpLayer);
shpLayer = null;
editShpLayer = null;
}
else
{
MessageBox.Show("请勿重复移除图层!");
}
}
//创建设备编辑器
private void createAxisEditResponser_Click(object sender, EventArgs e)
{
if (axisEditResponser == null)
{
var resp = map.CreateResponserOptions("AxisEditResponser");
resp.AddConfig("PickLayerIdList", editShpLayer.GetLayerID());
resp.AddConfig("PickColor", "1.0,0.0,0,0.8");//拾取颜色r g b a
resp.AddConfig("IsChangeColor", "true");//是否变色
resp.AddConfig("AxisXVisible", "true");//x旋转面是否显示(红面)
resp.AddConfig("AxisYVisible", "true");//y旋转面是否显示(绿面)
resp.AddConfig("AxisZVisible", "true");//z旋转面是否显示(蓝面)
resp.AddConfig("XRotate", "XRotate");//x轴关联字段(红轴)
resp.AddConfig("YRotate", "YRotate");//y轴关联字段(绿轴)
resp.AddConfig("ZRotate", "ZRotate");//z轴关联字段(蓝轴)
resp.AddConfig("XScale", "XScale");
resp.AddConfig("YScale", "YScale");
resp.AddConfig("ZScale", "ZScale");
resp.AddConfig("Adjustment", "0.1");//微调部件步进值,默认为0.01
resp.AddConfig("DragSpeed", "0.3");//拖拽速度系数,默认为1
axisEditResponser = map.CreateResponser("AxisEditResponser", resp);//坐标轴响应器,必须为AxisEditResponser
axisEditResponser.AddObserver();
map.AddResponser(axisEditResponser);
}
else
{
MessageBox.Show("响应器已创建!");
}
}
//移除设备编辑器
private void removeAxisEditResponser_Click(object sender, EventArgs e)
{
if (axisEditResponser != null)
{
map.RemoveResponser("AxisEditResponser");
axisEditResponser = null;
}
else
{
MessageBox.Show("无需重复删除!");
}
}
//保存设备
private void addParamFeature_Click(object sender, EventArgs e)
{
if (bSave)
{
editShpLayer.SaveLayer(); //编辑图层保存,一般用于首次创建保存
}
else
{
MessageBox.Show("无矢量图层,无法保存!");
}
}
//响应器回调
private void axVPSDKCtrl1_FireOnResponserNotify(object sender, AxSDKCtrlLib._IVPSDKCtrlEvents_FireOnResponserNotifyEvent e)
{
if (axisEditResponser!=null)
{
bSave = true;
editdId = axisEditResponser.GetResponserResult().GetConfigValueByKey("FeatureId");//编辑后要素id
xAngle = axisEditResponser.GetResponserResult().GetConfigValueByKey("OXAngle");//红轴欧拉角
yAngle = axisEditResponser.GetResponserResult().GetConfigValueByKey("OYAngle");//绿轴欧拉角
zAngle = axisEditResponser.GetResponserResult().GetConfigValueByKey("OZAngle");//蓝轴欧拉角
xScale = axisEditResponser.GetResponserResult().GetConfigValueByKey("OXScale");//红轴欧拉角
yScale = axisEditResponser.GetResponserResult().GetConfigValueByKey("OYScale");//绿轴欧拉角
zScale = axisEditResponser.GetResponserResult().GetConfigValueByKey("OZScale");//蓝轴欧拉角
pos = axisEditResponser.GetResponserResult().GetConfigValueByKey("LonLatPoint");//经纬度点坐标
}
}
//鼠标左键弹起回调
private void axVPSDKCtrl1_FireOnLButtonUp(object sender, AxSDKCtrlLib._IVPSDKCtrlEvents_FireOnLButtonUpEvent e)
{
if (addState)
{
var transformate = map.CreateTransformation();
var pos = transformate.ScreenPosToWorldPos(e.xPos, e.yPos);//将屏幕坐标点转换成经纬度坐标
}
}