@@ -743,25 +743,27 @@ class VLWholeSlideMicroscopyImageViewer {
743743 } ) ;
744744
745745 this [ _drawingSource ] . on ( VectorEventType . CHANGEFEATURE , ( e ) => {
746- const geometry = e . feature . getGeometry ( ) ;
747- const type = geometry . getType ( ) ;
748- // The first and last point of a polygon must be identical. The last point
749- // is an implmentation detail and is hidden from the user in the graphical
750- // interface. However, we must update the last point in case the first
751- // piont has been modified by the user.
752- if ( type === 'Polygon' ) {
753- // NOTE: Polyon in GeoJSON format contains an array of geometries,
754- // where the first element represents the coordinates of the outer ring
755- // and the second element represents the coordinates of the inner ring
756- // (in our case the inner ring should not be present).
757- const layout = geometry . getLayout ( ) ;
758- const coordinates = geometry . getCoordinates ( ) ;
759- const firstPoint = coordinates [ 0 ] [ 0 ] ;
760- const lastPoint = coordinates [ 0 ] [ coordinates [ 0 ] . length - 1 ] ;
761- if ( firstPoint [ 0 ] !== lastPoint [ 0 ] || firstPoint [ 1 ] !== lastPoint [ 1 ] ) {
746+ if ( e . feature !== undefined || e . feature !== null ) {
747+ const geometry = e . feature . getGeometry ( ) ;
748+ const type = geometry . getType ( ) ;
749+ // The first and last point of a polygon must be identical. The last point
750+ // is an implmentation detail and is hidden from the user in the graphical
751+ // interface. However, we must update the last point in case the first
752+ // piont has been modified by the user.
753+ if ( type === 'Polygon' ) {
754+ // NOTE: Polyon in GeoJSON format contains an array of geometries,
755+ // where the first element represents the coordinates of the outer ring
756+ // and the second element represents the coordinates of the inner ring
757+ // (in our case the inner ring should not be present).
758+ const layout = geometry . getLayout ( ) ;
759+ const coordinates = geometry . getCoordinates ( ) ;
760+ const firstPoint = coordinates [ 0 ] [ 0 ] ;
761+ const lastPoint = coordinates [ 0 ] [ coordinates [ 0 ] . length - 1 ] ;
762+ if ( firstPoint [ 0 ] !== lastPoint [ 0 ] || firstPoint [ 1 ] !== lastPoint [ 1 ] ) {
762763 coordinates [ 0 ] [ coordinates [ 0 ] . length - 1 ] = firstPoint ;
763764 geometry . setCoordinates ( coordinates , layout ) ;
764765 e . feature . setGeometry ( geometry ) ;
766+ }
765767 }
766768 }
767769 publish ( container , EVENT . ROI_MODIFIED , _getROIFromFeature ( e . feature , this [ _pyramidMetadata ] ) ) ;
0 commit comments