title: ol3: how to add coordinate programmatically while drawing
body: <p>I'm trying to add coordinates programmatically to the geometry while drawing.</p>
  
  <p>I can access the geometry in the geometryfunction and this works, but when i move the cursor the geometry resets to the old one without the coordinate inserted in the geometryFunction. </p>
  
  <p>I've tried it also with the drawinteractions features collection but gives the same result.</p>
  
  <p>Thank you!</p>
  
  <p>EDIT:
  it works with the geometryfunction, but it's necessary to move to cursor after the insert to see the changes. It's possible to see it immediate? </p>
  
  <pre><code>var map = new ol.Map({
    target: 'map',
    layers: [
      new ol.layer.Tile({
        source: new ol.source.MapQuest({
          layer: 'sat'
        })
      })
    ],
    view: new ol.View({
      center: ol.proj.transform([37.41, 8.82], 'EPSG:4326', 'EPSG:3857'),
      zoom: 4
    })
  });
  var source = new ol.source.Vector();
  var layer = new ol.layer.Vector({
    source: source,
    name: 'layer'
  });
  map.addLayer(layer);
  var drawFeaturesCollection = new ol.Collection();
  var drawInteraction = new ol.interaction.Draw({
    'type': 'Polygon',
    'source': source,
    'geometryFunction': onDrawPolygon,
    'features': drawFeaturesCollection
  });
  drawInteraction.on('drawend', function(e) {
    currentDrawingGeom = undefined;
  });
  map.addInteraction(drawInteraction);
  var currentDrawingGeom;
  var addCoordinate = false;
  var coord1 = [2690583.395638204, 585201.8885513092];
  var coord2 = [2270583.395638204, 543201.8885513092];
  var added1 = false;
  
  function onDrawPolygon(coordinates, geometry) {
    if (geometry) {
      if (addCoordinate) {
        coordinates[0].splice(coordinates.length - 2, 0, added1 ? coord2 : coord1);
        added1 = !added1;
        addCoordinate = false;
      }
      geometry.setCoordinates(coordinates);
    } else {
      geometry = new ol.geom.Polygon(coordinates);
    }
    currentDrawingGeom = geometry;
    return geometry;
  }
  
  function addCoord() {
    addCoordinate = true;
  }
  
  function clearLayer() {
    layer.getSource().clear();
  }
  
  function addCoordColl() {
    var coords = currentDrawingGeom.getCoordinates();
    coords[0].splice(coords.length - 2, 0, coord1);
    currentDrawingGeom.setCoordinates(coords);
  }
  </code></pre>
  
  <p>here a codepen example:
      <a href="http://codepen.io/lukasoberhoeller/pen/EyamBr" rel="nofollow">http://codepen.io/lukasoberhoeller/pen/EyamBr</a></p>
  
  <p>thank you!</p>