Reopen a closed Polygon to continue drawing

49 views
Skip to first unread message

HARIKRISHNAN S R

unread,
Jul 5, 2019, 3:52:58 PM7/5/19
to OpenLayers Dev
Hi All,

I have been using Openlayers 4 for some time as part of my project. Recently I got a requirement to open a closed Polygon feature to continue drawing.This is kind of an undo funtionality.
So I wrote the code to add one more function to the Draw interaction. This is working as expected.Can anyone suggest if I can raise a pullrequest to the latest Openlayers Library?
ol.interaction.Draw.prototype.reStart = function (selectedFeature) {
    this.abortDrawing_();
    var coordinates, sketchLineGeom;
    var geometry = selectedFeature.getGeometry();
    var selectedCoordinates = geometry.getCoordinates()[0];
    this.sketchFeature_ = this.sketchFeature_?this.sketchFeature_:selectedFeature;
    coordinates = selectedCoordinates;
    if (this.mode_ === ol.interaction.Draw.Mode_.POLYGON) {  
    this.sketchCoords_ =  [coordinates.slice(0,-1)];  
        var last = coordinates[coordinates.length-2];
        this.finishCoordinate_ = last.slice()[0];
        this.sketchCoords_[0].push(last.slice());
        sketchLineGeom = new ol.geom.LineString(coordinates);
        this.sketchLine_=new ol.Feature(sketchLineGeom);
        this.geometryFunction_(this.sketchCoords_, geometry);
        this.sketchLineCoords_ = this.sketchCoords_[0];
      }
      if (coordinates.length === 0) {
        this.finishCoordinate_ = null;
      }
      this.updateSketchFeatures_();
      this.dispatchEvent(new ol.interaction.Draw.Event(
      ol.interaction.DrawEventType.DRAWSTART, this.sketchFeature_));
      };

Thanks,
Harikrishnan S R
Reply all
Reply to author
Forward
0 new messages