mirror of
https://github.com/FoggedLens/iD.git
synced 2026-04-22 03:36:37 +02:00
Cache geometry
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
iD.behavior.DrawWay = function(context, wayId, index, mode, baseGraph) {
|
||||
var way = context.entity(wayId),
|
||||
isArea = way.geometry() === 'area',
|
||||
isArea = context.geometry(wayId) === 'area',
|
||||
finished = false,
|
||||
annotation = t((way.isDegenerate() ?
|
||||
'operations.start.annotation.' :
|
||||
|
||||
+3
-1
@@ -16,7 +16,9 @@ _.extend(iD.Node.prototype, {
|
||||
},
|
||||
|
||||
geometry: function(graph) {
|
||||
return graph.isPoi(this) ? 'point' : 'vertex';
|
||||
return graph.transient(this, 'geometry', function() {
|
||||
return graph.isPoi(this) ? 'point' : 'vertex';
|
||||
});
|
||||
},
|
||||
|
||||
move: function(loc) {
|
||||
|
||||
@@ -25,8 +25,10 @@ _.extend(iD.Relation.prototype, {
|
||||
});
|
||||
},
|
||||
|
||||
geometry: function() {
|
||||
return this.isMultipolygon() ? 'area' : 'relation';
|
||||
geometry: function(graph) {
|
||||
return graph.transient(this, 'geometry', function() {
|
||||
return this.isMultipolygon() ? 'area' : 'relation';
|
||||
});
|
||||
},
|
||||
|
||||
// Return the first member with the given role. A copy of the member object
|
||||
|
||||
+4
-2
@@ -70,8 +70,10 @@ _.extend(iD.Way.prototype, {
|
||||
return false;
|
||||
},
|
||||
|
||||
geometry: function() {
|
||||
return this.isArea() ? 'area' : 'line';
|
||||
geometry: function(graph) {
|
||||
return graph.transient(this, 'geometry', function() {
|
||||
return this.isArea() ? 'area' : 'line';
|
||||
});
|
||||
},
|
||||
|
||||
addNode: function(id, index) {
|
||||
|
||||
@@ -8,7 +8,7 @@ iD.operations.Rotate = function(selection, context) {
|
||||
operation.available = function() {
|
||||
return selection.length === 1 &&
|
||||
context.entity(entityId).type === 'way' &&
|
||||
context.entity(entityId).geometry() === 'area';
|
||||
context.geometry(entityId) === 'area';
|
||||
};
|
||||
|
||||
operation.disabled = function() {
|
||||
|
||||
@@ -47,8 +47,12 @@ describe('iD.Relation', function () {
|
||||
});
|
||||
|
||||
describe("#geometry", function () {
|
||||
it("returns 'relation'", function () {
|
||||
expect(iD.Relation().geometry()).to.equal('relation');
|
||||
it("returns 'area' for multipolygons", function () {
|
||||
expect(iD.Relation({tags: {type: 'multipolygon'}}).geometry(iD.Graph())).to.equal('area');
|
||||
});
|
||||
|
||||
it("returns 'relation' for other relations", function () {
|
||||
expect(iD.Relation().geometry(iD.Graph())).to.equal('relation');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -176,11 +176,11 @@ describe('iD.Way', function() {
|
||||
|
||||
describe("#geometry", function() {
|
||||
it("returns 'line' when the way is not an area", function () {
|
||||
expect(iD.Way().geometry()).to.equal('line');
|
||||
expect(iD.Way().geometry(iD.Graph())).to.equal('line');
|
||||
});
|
||||
|
||||
it("returns 'area' when the way is an area", function () {
|
||||
expect(iD.Way({tags: { area: 'yes' }}).geometry()).to.equal('area');
|
||||
expect(iD.Way({tags: { area: 'yes' }}).geometry(iD.Graph())).to.equal('area');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user