mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
Add iD.geo.Extent#rectangle
This commit is contained in:
committed by
Bryan Housel
parent
caf464e3d3
commit
c50a290cd1
@@ -2,17 +2,8 @@ iD.Tree = function(head) {
|
||||
var rtree = rbush(),
|
||||
rectangles = {};
|
||||
|
||||
function extentRectangle(extent) {
|
||||
return [
|
||||
extent[0][0],
|
||||
extent[0][1],
|
||||
extent[1][0],
|
||||
extent[1][1]
|
||||
];
|
||||
}
|
||||
|
||||
function entityRectangle(entity) {
|
||||
var rect = extentRectangle(entity.extent(head));
|
||||
var rect = entity.extent(head).rectangle();
|
||||
rect.id = entity.id;
|
||||
rectangles[entity.id] = rect;
|
||||
return rect;
|
||||
@@ -90,7 +81,7 @@ iD.Tree = function(head) {
|
||||
rtree.load(_.map(insertions, entityRectangle));
|
||||
}
|
||||
|
||||
return rtree.search(extentRectangle(extent)).map(function(rect) {
|
||||
return rtree.search(extent.rectangle()).map(function(rect) {
|
||||
return head.entity(rect.id);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -45,6 +45,10 @@ _.extend(iD.geo.Extent.prototype, {
|
||||
(this[0][1] + this[1][1]) / 2];
|
||||
},
|
||||
|
||||
rectangle: function() {
|
||||
return [this[0][0], this[0][1], this[1][0], this[1][1]];
|
||||
},
|
||||
|
||||
polygon: function() {
|
||||
return [
|
||||
[this[0][0], this[0][1]],
|
||||
@@ -100,7 +104,7 @@ _.extend(iD.geo.Extent.prototype, {
|
||||
},
|
||||
|
||||
toParam: function() {
|
||||
return [this[0][0], this[0][1], this[1][0], this[1][1]].join(',');
|
||||
return this.rectangle().join(',');
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -24,7 +24,7 @@ iD.services.nominatim = function() {
|
||||
|
||||
var extent = iD.geo.Extent(location).padByMeters(1000);
|
||||
|
||||
cache.insert([extent[0][0], extent[0][1], extent[1][0], extent[1][1], result.address.country_code]);
|
||||
cache.insert(extent.rectangle().concat(result.address.country_code));
|
||||
|
||||
callback(null, result.address.country_code);
|
||||
});
|
||||
|
||||
@@ -57,7 +57,20 @@ describe("iD.geo.Extent", function () {
|
||||
|
||||
describe("#center", function () {
|
||||
it("returns the center point", function () {
|
||||
expect(iD.geo.Extent([0, 0], [5, 10]).center()).to.eql([2.5, 5]);
|
||||
expect(iD.geo.Extent([0, 0], [5, 10]).center()).to.eql([2.5, 5]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#rectangle", function () {
|
||||
it("returns the extent as a rectangle", function () {
|
||||
expect(iD.geo.Extent([0, 0], [5, 10]).rectangle()).to.eql([0, 0, 5, 10]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#polygon", function () {
|
||||
it("returns the extent as a polygon", function () {
|
||||
expect(iD.geo.Extent([0, 0], [5, 10]).polygon())
|
||||
.to.eql([[0, 0], [0, 10], [5, 10], [5, 0], [0, 0]]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user