//声明一个矢量图层 vectorLayer 控件,用来呈现画面要素
plottingLayer = new SuperMap.Layer.PlottingLayer("plottingLayer");
plottingLayer.style = {
fillColor: "red",
fillOpacity: 0.4,
strokeColor: "red",
strokeOpacity: 1,
strokeWidth: 3,
pointRadius: 6
};
plottingEdit = new SuperMap.Control.PlottingEdit();
//实例化一个 DrawFeature 控件,调用绘制多边形的事件处理器 Handler.Polygon
drawPolygon = new SuperMap.Control.DrawFeature(plottingLayer, SuperMap.Handler.Path);
//监听 featureadded 事件,当添加要素时会触发此事件
drawPolygon.events.on({"featureadded": drawCompleted});
supermap.addControl(plottingEdit);
supermap.addControl(drawPolygon);
supermap.addLayer(plottingLayer);
drawPolygon.activate();
plottingEdit.deactivate();
//定义 drawCompleted 函数,触发 featureadded 事件会调用此函数
//事件参数 eventArgs 包含了绘制的要素 feature 信息 {feature: featureObj}
function drawCompleted(eventArgs) {
// 获取传入参数 eventArgs 的几何信息
var geometry = eventArgs.feature.geometry;
// TODO
// 具体绘制过程可以参见范例《数据集查询编辑---几何查询》
drawPolygon.deactivate();
plottingEdit.activate();
plottingEdit.setEditMode(SuperMap.Plot.EditMode.EDITCIRCUMRECTANGLE);
}