Skip to content

Commit

Permalink
When adding annotations, add a gcs options.
Browse files Browse the repository at this point in the history
New annotations should default to the interface gcs, not the map gcs.  Note that this breaks the current interface for annotationLayer.addAnnotation.
  • Loading branch information
manthey committed Dec 12, 2016
1 parent 7db86fb commit 1c344c7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/annotationLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
});
};
Expand Down
7 changes: 7 additions & 0 deletions tests/cases/annotationLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1c344c7

Please sign in to comment.