fix: Fix determining annotation correspondence.
In some instances, annotations with different holes could be considered
identical.
Also, don't reuse annotation ids.
MODIFY
src/action.js
src/action.js
@@ -16,10 +16,7 @@ var geo_action = {
zoomrotate: 'geo_action_zoom_rotate',
zoomselect: 'geo_action_zoomselect',
- // annotation actions
- annotation_line: 'geo_annotation_line',
- annotation_polygon: 'geo_annotation_polygon',
- annotation_rectangle: 'geo_annotation_rectangle',
+ // annotation actions -- some are also added by the registry
annotation_edit_handle: 'geo_annotation_edit_handle'
};

MODIFY
src/annotation/annotation.js
src/annotation/annotation.js
@@ -151,6 +151,14 @@ var annotation = function (type, args) {
return m_id;
};
+ /**
+ * Assign a new id to this annotation.
+ */
+ this.newId = function () {
+ annotationId += 1;
+ m_id = annotationId;
+ };
+
/**
* Get or set the name of this annotation.
*

MODIFY
src/annotationLayer.js
src/annotationLayer.js
@@ -481,6 +481,9 @@ var annotationLayer = function (arg) {
this.addAnnotation = function (annotation, gcs, update) {
var pos = $.inArray(annotation, m_annotations);
if (pos < 0) {
+ while (m_this.annotationById(annotation.id())) {
+ annotation.newId();
+ }
m_this.geoTrigger(geo_event.annotation.add_before, {
annotation: annotation
});
@@ -1258,11 +1261,15 @@ var annotationLayer = function (arg) {
this.toPolygonList = function (opts) {
const poly = [];
opts = opts || {};
- opts.annotationIndices = [];
+ const indices = [];
+ if (!opts.annotationIndices) {
+ opts.annotationIndices = {};
+ }
+ opts.annotationIndices[m_this.id()] = indices;
m_annotations.forEach((annotation, idx) => {
if (annotation.toPolygonList) {
annotation.toPolygonList(opts).forEach((p) => poly.push(p));
- opts.annotationIndices.push(idx);
+ indices.push(idx);
}
});
return poly;
@@ -1285,14 +1292,15 @@ var annotationLayer = function (arg) {
const keepIds = {};
const reusedIds = {};
let correspond, exact, annot;
- if (opts.annotationIndices && opts.correspond && opts.correspond.poly1 && opts.annotationIndices.length === opts.correspond.poly1.length) {
+ const indices = (opts.annotationIndices || {})[m_this.id()];
+ if (indices && opts.correspond && opts.correspond.poly1 && indices.length === opts.correspond.poly1.length) {
correspond = opts.correspond.poly1;
exact = opts.correspond.exact1;
annot = m_this.annotations();
}
- if (keep !== 'all' && keep !== 'none') {
+ if (keep !== 'all' && keep !== 'none' && annot) {
annot.forEach((oldAnnot, idx) => {
- if (opts.annotationIndices.indexOf(idx) < 0) {
+ if (indices.indexOf(idx) < 0) {
keepIds[oldAnnot.id()] = true;
}
});
@@ -1306,7 +1314,7 @@ var annotationLayer = function (arg) {
if (correspond) {
for (let i = 0; i < correspond.length; i += 1) {
if (correspond[i] && correspond[i].indexOf(idx) >= 0) {
- const orig = annot[opts.annotationIndices[i]];
+ const orig = annot[indices[i]];
if (keep !== 'all' && keep !== 'none' && exact && exact[i] && exact[i].indexOf(idx) >= 0) {
keepIds[orig.id()] = true;
return;
@@ -1343,7 +1351,7 @@ var annotationLayer = function (arg) {
}
// add new annotations
polyAnnot.forEach((p) => {
- m_this.addAnnotation(registry.createAnnotation('polygon', p), m_this.gcs(), false);
+ m_this.addAnnotation(registry.createAnnotation('polygon', p), m_this.map().gcs(), false);
update = true;
});
if (update) {

MODIFY
src/registry.js
src/registry.js
var $ = require('jquery');
+var geo_action = require('./action');
+
var widgets = {
dom: {}
};
@@ -398,6 +400,7 @@ util.registerAnnotation = function (name, func, features) {
console.warn('The ' + name + ' annotation is already registered');
}
annotations[name] = {func: func, features: features || {}};
+ geo_action['annotation_' + name] = 'geo_annotation_' + name;
return old;
};

MODIFY
src/util/polyops.js
src/util/polyops.js
@@ -327,16 +327,19 @@ function generateCorrespondence(poly1, poly2, newpoly, results) {
results[ekey] = Array(poly.length);
poly.forEach((p, idx) => {
const found = {};
+ let missed = 0;
p.forEach((h) => h.forEach((pt) => {
const key = '_' + pt[0] + '_' + pt[1];
if (pts[key]) {
pts[key].forEach((val) => {
found[val] = (found[val] || 0) + 1;
});
+ } else {
+ missed += 1;
}
}));
Object.keys(found).forEach((nidx) => {
- if (found[nidx] === counts[+nidx]) {
+ if (found[nidx] === counts[+nidx] && !missed && p.length === newpoly[+nidx].length) {
if (!results[ekey][idx]) {
results[ekey][idx] = [];
}

fix: Fix determining annotation correspondence.

In some instances, annotations with different holes could be considered
identical.

Also, don't reuse annotation ids.