2D 地图在线编辑器
本节内容
添加实体
添加实体是编辑地图最基本的操作。在本系统中可以创建点、线、椭圆、矩形和多边形这些图形实体。
添加实体操作通过oMapViewer类的startAddOperation()方法来实现的,它接受两个参数,一个要将实体添加到的图层名称,另一个是添加实体的类型。
用法如下:
oMapViewer.startAddOperation(Dynamic_Layer_Name, 1); //“1”表示添加点实体
oMapViewer.startAddOperation(Dynmaic_Layer_Name, 2); //“2”表示添加线实体
oMapViewer.startAddOperation(Dynamic_Lyaer_Name, 3); //“3”表示添加多边形实体
oMapViewer.startAddOperation(Dynamic_Layer_Name, 10); //“10”表示添加矩形实体
oMapViewer.startAddOperation(Dynamic_Layer_Name, 20); //“20”标示添加矩形实体
对齐实体
添加实体后可以对实体进行对齐操作。对实体进行对齐操作,使用的是oMapViewer类的startAlignOperation()方法来实现的,它同样也接受两个参数,一个是图层名称,另一个是为对齐的类型。
用法如下:
oMapViewer.startAlignOperation(Dynamic_Layer_Name, 1); //左对齐
oMapViewer.startAlignOperation(Dynamic_Layer_Name, 2); //右对齐
oMapViewer.startAlignOperation(Dynamic_Layer_Name, 3); //上对齐
oMapViewer.startAlignOperation(Dynamic_Layer_Name, 4); //下对齐
oMapViewer.startAlignOperation(Dynamic_Layer_Name, 5); //水平居中
oMapViewer.startAlignOperation(Dynamic_Layer_Name, 6); //垂直居中
oMapViewer.startAlignOperation(Dynamic_Layer_Name, 100); //等大小
oMapViewer.startAlignOperation(Dynamic_Layer_Name, 101); //等宽度
oMapViewer.startAlignOperation(Dynamic_Layer_Name, 102); //等高度
oMapViewer.startAlignOperation(Dynamic_Layer_Name, 200); //水平等距
oMapViewer.startAlignOperation(Dynamic_Layer_Name, 201); //垂直等距
查看实体信息
绘制图形后可以查看图形的相关属性。查看实体属性是通过oMapViewer类的setCurrentTool(4)方法来实现,里面的参数“4”是操作的类型说明。
用法如下:
oMapViewer.setCurrentTool(4);
自由编辑
可以对添加的实体进行移动、删除等操作。要执行这些操作首先要切换到自由编辑状态。切换到自由编辑使用的是oMapViewer类的startFreeDragOperation()方法。它接受一个图层名作为其参数。
用法如下:
oMapViewer.startFreeDragOperation(Dynamic_Layer_Name);
在自由编辑状态中可以拖动和删除实体,删除实体使用的是oMapViewer类startDeleteOperation()方法,同样它接受一个图层名作为其参数。
用法如下:
oMapViewer.startDeleteOperation(Dynamic_Layer_Name);
系统还提供了撤销操作和恢复操作的功能,它们分别调用了oMapViewer类的undoEdit()方法和redoEdit()方法。
用法如下:
oMapViewer.undoEdit(1);
oMapViewer.redoEdit(1);
图像操作
可以在地图中添加图片,并且控制图片的显隐。
添加图片使用的是oMapViewer类的insertSimpleImageLayer()方法实现的。
用法如下:
oMapViewer.insertSimpleImageLayer(0, Image_Layer_Name, ‘url’, 0, 0, 50, 50);
此方法使用的参数分别说明如下:
long index: 插入到指定的index位置之前。bstr layername: 图层名称,不能重复。bstr imageUrl:图像的url,为jpg或者gif,bmp等互联网常见图片格式。float xOrg, yOrg, width, height:这四个参数描述目标位置矩形坐标,建议控制在常用经纬度范围内。
隐藏图像时,首先得到需要得到图像对象的引用,然后通过设置其visible属性来控制图像的显隐。
用法如下:
var imageLayer = oMapViewer.geoLayers.getLayerByName(Image_Layer_Name);
if(imageLayer != null)
{
imageLayer.visible = !imageLayer.visible;
oMapViewer.redraw();
}
地图编辑选项
除了对添加的图形实体进行操作外,还可以设置地图自身的属性。
填充:
添加图形时可以设置所添加的图形,如矩形的内部是否进行填充。此功能是通过oMapViewer类的fillLegend属性来实现的。当此属性取值为“fillLegend”时标示进行填充,当取值为“emptyLegend”时标示不进行填充。
用法如下:
oMapViewer.fillLegend = fillLegend; //进行填充
oMapViewer.fillLegend = emptyLegend; //不进行填充
边线:
可以通过oMapViewer类的boundLegend属性来设置添加的实体时是否绘制其边线。当boundLegend取值为“boundLegend”时表示绘制边框,当取值为“emptyLegend”时表示不绘制边框线。
用法如下:
oMapViewer.boundLegend = boundLegend; //使用边框线
oMapViewer.boundLegend = emptyLegend; //不使用边框线
使用网格:
oMapViewer类的isUseGrid属性可以设置地图是否显示网格。当此属性取值为true时表示使用网格,当取值为false时表示不使用网格。
用法如下:
oMapViewer.isUseGrid = true; //使用网格
oMapViewer.isUseGrid = false; //不使用网格
设置网格间距:
当使用网格的时候,还可以控制网格间距的大小。此功能是通过oMapViewer类的gridStep属性来实现的。gridStep的单位是地图的逻辑坐标。
用法如下:
oMapViewer.gridStep = parseFloat(“2.0”); //设置边框间距为2.0
oMapViewer.gridStep = parseFloat(“3.0”); //设置边框间距为3.0