我有一个openlayers地图,它有绘制互动。当用户开始在地图上绘制线串时,绘制的线串部分应该与用户下一个绘制的部分不同。
在……
您需要为绘制样式使用样式函数,并将几何图形划分为两个部分以进行样式设置:
var drawStyle = function(feature) { var styles = []; if (feature.getGeometry().getType() == 'LineString') { var coordinates = feature.getGeometry().getCoordinates(); styles.push(new ol.style.Style({ geometry: new ol.geom.LineString(coordinates.slice(-2)), stroke: new ol.style.Stroke({ color: '#0000FF', lineDash: [1, 20], width: 5, lineCap:'square', lineJoin:'round', lineDashOffset:10 }) })); styles.push(new ol.style.Style({ geometry: new ol.geom.MultiPoint(coordinates), image: new ol.style.RegularShape({ points: 4, radius: 6, angle: Math.PI / 4, fill: new ol.style.Fill({ color: 'blue' }), stroke: new ol.style.Stroke({ color: 'blue' }), }) })); if (coordinates.length > 2) { styles.push(new ol.style.Style({ geometry: new ol.geom.LineString(coordinates.slice(0,-1)), stroke: new ol.style.Stroke({ color: '#0000FF', width: 2, lineCap:'square', lineJoin:'round' }) })); } } return styles; }
要从线交互中删除最后一个点,只需使用
line.removeLastPoint();
确保 var line; 声明所以它在按钮单击功能的范围内
var line;