From 1c344c7255bdb8c135159a1b97247fc0ba616a9e Mon Sep 17 00:00:00 2001 From: David Manthey Date: Mon, 12 Dec 2016 12:10:13 -0500 Subject: [PATCH] When adding annotations, add a gcs options. New annotations should default to the interface gcs, not the map gcs. Note that this breaks the current interface for annotationLayer.addAnnotation. --- src/annotationLayer.js | 16 +++++++++++++--- tests/cases/annotationLayer.js | 7 +++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/annotationLayer.js b/src/annotationLayer.js index 1a89891932..93cf89a67d 100644 --- a/src/annotationLayer.js +++ b/src/annotationLayer.js @@ -200,14 +200,24 @@ var annotationLayer = function (args) { * Add an annotation to the layer. The annotation could be in any state. * * @param {object} annotation the annotation to add. + * @param {string|geo.transform} [gcs] undefined to use the interface gcs, + * null to use the map gcs, or any other transform */ - this.addAnnotation = function (annotation) { + this.addAnnotation = function (annotation, gcs) { var pos = $.inArray(annotation, m_annotations); if (pos < 0) { m_this.geoTrigger(geo_event.annotation.add_before, { annotation: annotation }); m_annotations.push(annotation); + annotation.layer(this); + var map = this.map(); + gcs = (gcs === null ? map.gcs() : ( + gcs === undefined ? map.ingcs() : gcs)); + if (gcs !== map.gcs()) { + annotation._coordinates(transform.transformCoordinates( + gcs, map.gcs(), annotation._coordinates())); + } this.modified(); this._update(); this.draw(); @@ -348,7 +358,7 @@ var annotationLayer = function (args) { state: geo_annotation.state.create, layer: this }); - this.addAnnotation(m_this.currentAnnotation); + this.addAnnotation(m_this.currentAnnotation, null); actions = this.currentAnnotation.actions(geo_annotation.state.create); $.each(actions, function (idx, action) { m_this.map().interactor().addAction(action); @@ -528,7 +538,7 @@ var annotationLayer = function (args) { options.state = geo_annotation.state.done; options.layer = m_this; options.updated = 'new'; - m_this.addAnnotation(registry.createAnnotation(type, options)); + m_this.addAnnotation(registry.createAnnotation(type, options), null); } }); }; diff --git a/tests/cases/annotationLayer.js b/tests/cases/annotationLayer.js index 7f70f2e969..d408820aa9 100644 --- a/tests/cases/annotationLayer.js +++ b/tests/cases/annotationLayer.js @@ -141,6 +141,13 @@ describe('geo.annotationLayer', function () { expect(addAnnotationBeforeEvent).toBe(2); expect(addAnnotationEvent).toBe(2); expect(lastAddAnnotationEvent.annotation).toBe(rect); + expect(layer.annotations()[1]._coordinates()[1]).not.toEqual({x: 1, y: 0}); + layer.removeAnnotation(rect); + rect = geo.annotation.rectangleAnnotation({ + layer: layer, + corners: [{x: 0, y: 0}, {x: 1, y: 0}, {x: 1, y: 1}, {x: 0, y: 1}]}); + layer.addAnnotation(rect, map.gcs()); + expect(layer.annotations()[1]._coordinates()[1]).toEqual({x: 1, y: 0}); }); it('annotationById', function () { expect(layer.annotationById()).toBe(undefined);