[GIS] OpenLayers3: How to draw line with beetwen two points

javascriptopenlayers

I've following code:

var source = new ol.source.Vector();
var vector = new ol.layer.Vector({
  source: source
  style: new ol.style.Style({
    stroke: new ol.style.Stroke({
      color: "#ffcc33",
      width: 2
    })
  })
});

map.addLayer(vector);

var drawInteraction = new ol.interaction.Draw({
  source: source,
  type: "LineString"
});

map.addInteraction(drawInteraction);

How I can draw only 2 points start and end?

Best Answer

This is only available in OpenLayers master version, not a release as yet, but there is a new config option on ol.interaction.Draw called maxPoints see: http://openlayers.org/en/master/apidoc/ol.interaction.Draw.html

The relevant pull request which brought in this new functionality is: https://github.com/openlayers/ol3/pull/3673