openlayers官方教程(七)Vector Data——Drawing new features

Drawing new features

前面两篇文章我们已经实现了数据的加载和修改,下一步来实现draw交互,可以使用户画新的features并添加到数据源中。

首先第一步,还是在main.js中导入Draw包

import Draw from 'ol/interaction/Draw';

其次,创建一个draw交互并添加到矢量数据源

map.addInteraction(new Draw({
  type: 'Polygon',
  source: source
}));
其中type属性表示所画feature的几何类型,它的值可以是GeoJSON的geometry types。

注意我们也可以导入GeometryType且使用Geometry.POLYGON来代替‘Ploygon’字符。

效果如下:



猜你喜欢

转载自blog.csdn.net/u011435933/article/details/80444935
今日推荐