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


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


How I can draw only 2 points start and end?

2 Answers 2


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


There is a good example in the ol docs : http://openlayers.org/en/v3.5.0/examples/draw-features.html

Look at the source code !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.