From fe970f7b60697731d423facc37cb610ebcd71402 Mon Sep 17 00:00:00 2001 From: David Manthey Date: Mon, 27 Jun 2022 14:48:04 -0400 Subject: [PATCH] fix: Guard converting an empty polygon. --- examples/annotations/main.js | 2 +- src/annotation/annotation.js | 3 +++ src/annotation/polygonAnnotation.js | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/annotations/main.js b/examples/annotations/main.js index b435d898b3..4b6098d280 100644 --- a/examples/annotations/main.js +++ b/examples/annotations/main.js @@ -212,7 +212,7 @@ function setBrushMode(mode) { const annot = geo.registries.annotations[shape].func({layer: layer}); brushLayer.addAnnotation(annot); annot._coordinates([{x: 0, y: 0}, {x: size, y: 0}, {x: size, y: size}, {y: size, x: 0}]); - brushLayer.mode('cursor', annot); + brushLayer.mode(brushLayer.modes.cursor, annot); map.draw(); } diff --git a/src/annotation/annotation.js b/src/annotation/annotation.js index 9b1d22537e..c40b2f74d6 100644 --- a/src/annotation/annotation.js +++ b/src/annotation/annotation.js @@ -754,6 +754,9 @@ var annotation = function (type, args) { */ this.coordinates = function (gcs) { var coord = m_this._coordinates() || []; + if (!coord.length && (!coord.outer || !coord.outer.length)) { + coord = []; + } if (m_this.layer()) { var map = m_this.layer().map(); gcs = (gcs === null ? map.gcs() : ( diff --git a/src/annotation/polygonAnnotation.js b/src/annotation/polygonAnnotation.js index bc3b1c1be3..eca5c7e6c6 100644 --- a/src/annotation/polygonAnnotation.js +++ b/src/annotation/polygonAnnotation.js @@ -134,7 +134,7 @@ var polygonAnnotation = function (args) { (coord.inner || []).forEach((h) => result[0].push(h.map((pt) => [pt.x, pt.y]))); return result; } - if (coord.length < 3) { + if (coord.length < 3 || !coord.map) { return []; } return [[coord.map((pt) => [pt.x, pt.y])]];