效果
代码
if (value === 'Square') {
value = 'Circle';
//正方形图形(圆)
geometryFunction = ol.interaction.Draw.createRegularPolygon(4);
}
else if (value=='Circle'){
geometryFunction = ol.interaction.Draw.createRegularPolygon(0);
}
else if (value === 'Box') {
value = 'Circle';
maxPoints = 2;
geometryFunction=ol.interaction.Draw.createBox();
}
//实例化交互绘制类对象并添加到地图容器中
draw = new ol.interaction.Draw({
//绘制层数据源
source: source,
/** @type {ol.geom.GeometryType}几何图形类型 */
type: value,
//几何信息变更时调用函数
geometryFunction: geometryFunction,
//最大点数
maxPoints: maxPoints
// ,geometryName:""+(feture123) //唯一的标识
});
map.addInteraction(draw);