Skip to content

Commit

Permalink
Merge pull request #1232 from OpenGeoscience/guard-empty-polygon
Browse files Browse the repository at this point in the history
fix: Guard converting an empty polygon.
  • Loading branch information
manthey authored Jun 27, 2022
2 parents 3e924c6 + 509a763 commit e746071
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/annotations/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
6 changes: 6 additions & 0 deletions src/annotation/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ var annotation = function (type, args) {
* Clean up any resources that the annotation is using.
*/
this._exit = function () {
if (m_this.layer()) {
m_this.layer().geoOff(geo_event.mousemove, m_this._cursorHandleMousemove);
}
};

/**
Expand Down Expand Up @@ -754,6 +757,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() : (
Expand Down
2 changes: 1 addition & 1 deletion src/annotation/polygonAnnotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])]];
Expand Down
9 changes: 9 additions & 0 deletions src/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,15 @@ var object = function () {
return m_this;
};

/**
* Report the current event handlers.
*
* @returns {object} An object with all of the event handlers.
*/
this._eventHandlers = function () {
return m_eventHandlers;
};

/**
* Free all resources and destroy the object.
*/
Expand Down

0 comments on commit e746071

Please sign in to comment.