Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Tweeted twitter.com/StackGIS/status/1617628241954496521
Bumped by Community user
Bumped by Community user
Bumped by Community user
added 28 characters in body; edited title
Source Link
Taras
  • 34k
  • 4
  • 73
  • 148

Remove Removing vertex from Polygon geometry (polygon) in OpenLayers 5?

I could able to remove the recent modified vertex of a feature using removePoint method of modify interaction, as well as using deleteCondition event of modify interaction. However, that is not what I am trying to achieve. The usecaseuse case for this this problem is as below.

I have modify interaction added on map. Now when user tries to modify a feature over map, I am highlighting the vertices, like this   

enter image description here

 if(this.modifyInteraction.features_.getLength() && this.modifyInteraction.features_.getArray()[0]){
           //Feature being modified
           let modifyft = this.modifyInteraction.features_.getArray()[0];
           let coord = modifyft.getGeometry().getCoordinates()[0];
           let foundIndex;
           for(var k = 0; k < coord.length; k++){
              if(coord[k][0] == rightClickedVertex.getGeometry().getCoordinates()[0] && 
              coord[k][1] == rightClickedVertex.getGeometry().getCoordinates()[1]){
                 foundIndex = k;
                 break;
              }
           }
           if(foundIndex && foundIndex > -1){
              modifyft.getGeometry().getCoordinates()[0].splice(foundIndex, 1);
              //nothing changes
           }
        }
 if(this.modifyInteraction.features_.getLength() && this.modifyInteraction.features_.getArray()[0]){
           //Feature being modified
           let modifyft = this.modifyInteraction.features_.getArray()[0];
           let coord = modifyft.getGeometry().getCoordinates()[0];
           let foundIndex;
           for(var k = 0; k < coord.length; k++){
              if(coord[k][0] == rightClickedVertex.getGeometry().getCoordinates()[0] && 
              coord[k][1] == rightClickedVertex.getGeometry().getCoordinates()[1]){
                 foundIndex = k;
                 break;
              }
           }
           if(foundIndex && foundIndex > -1){
              modifyft.getGeometry().getCoordinates()[0].splice(foundIndex, 1);
              //nothing changes
           }
        }

Remove vertex from geometry (polygon) in OpenLayers 5?

I could able to remove the recent modified vertex of a feature using removePoint method of modify interaction, as well as using deleteCondition event of modify interaction. However, that is not what I am trying to achieve. The usecase for this this problem is as below.

I have modify interaction added on map. Now when user tries to modify a feature over map, I am highlighting the vertices, like this  enter image description here

 if(this.modifyInteraction.features_.getLength() && this.modifyInteraction.features_.getArray()[0]){
           //Feature being modified
           let modifyft = this.modifyInteraction.features_.getArray()[0];
           let coord = modifyft.getGeometry().getCoordinates()[0];
           let foundIndex;
           for(var k = 0; k < coord.length; k++){
              if(coord[k][0] == rightClickedVertex.getGeometry().getCoordinates()[0] && 
              coord[k][1] == rightClickedVertex.getGeometry().getCoordinates()[1]){
                 foundIndex = k;
                 break;
              }
           }
           if(foundIndex && foundIndex > -1){
              modifyft.getGeometry().getCoordinates()[0].splice(foundIndex, 1);
              //nothing changes
           }
        }

Removing vertex from Polygon geometry in OpenLayers 5

I could able to remove the recent modified vertex of a feature using removePoint method of modify interaction, as well as using deleteCondition event of modify interaction. However, that is not what I am trying to achieve. The use case for this this problem is as below.

I have modify interaction added on map. Now when user tries to modify a feature over map, I am highlighting the vertices, like this 

enter image description here

 if(this.modifyInteraction.features_.getLength() && this.modifyInteraction.features_.getArray()[0]){
           //Feature being modified
           let modifyft = this.modifyInteraction.features_.getArray()[0];
           let coord = modifyft.getGeometry().getCoordinates()[0];
           let foundIndex;
           for(var k = 0; k < coord.length; k++){
              if(coord[k][0] == rightClickedVertex.getGeometry().getCoordinates()[0] && 
              coord[k][1] == rightClickedVertex.getGeometry().getCoordinates()[1]){
                 foundIndex = k;
                 break;
              }
           }
           if(foundIndex && foundIndex > -1){
              modifyft.getGeometry().getCoordinates()[0].splice(foundIndex, 1);
              //nothing changes
           }
        }
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Title edit.
Link
TomazicM
  • 27k
  • 23
  • 31
  • 42

Openlayers 5: Remove vertex from geometry (polygon) in OpenLayers 5?

Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user