bruce-models 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bruce-models.es5.js +105 -19
- package/dist/bruce-models.es5.js.map +1 -1
- package/dist/bruce-models.umd.js +105 -19
- package/dist/bruce-models.umd.js.map +1 -1
- package/dist/lib/entity/getters/entity-globe.js +104 -18
- package/dist/lib/entity/getters/entity-globe.js.map +1 -1
- package/dist/types/entity/getters/entity-globe.d.ts +2 -0
- package/package.json +1 -1
package/dist/bruce-models.es5.js
CHANGED
|
@@ -3819,15 +3819,13 @@ function isCellFetched(cell) {
|
|
|
3819
3819
|
if (cell.Fetched) {
|
|
3820
3820
|
return true;
|
|
3821
3821
|
}
|
|
3822
|
-
// TODO: If all cells of the size smaller are fetched then this is fetched.
|
|
3823
|
-
// TODO: If this is a cell within a larger cell that is fetched then this is fetched.
|
|
3824
3822
|
return false;
|
|
3825
3823
|
}
|
|
3826
3824
|
function getOrCreateCell(cells, cellSize, lon, maxLon, lat, maxLat) {
|
|
3827
3825
|
var id = cellSize + "_" + lon + "_" + maxLon + "_" + lat + "_" + maxLat;
|
|
3828
3826
|
var cell = getCell(cells, cellSize, lon, maxLon, lat, maxLat);
|
|
3829
3827
|
if (!cell) {
|
|
3830
|
-
cell =
|
|
3828
|
+
cell = new Cell();
|
|
3831
3829
|
cell.Boundaries = {
|
|
3832
3830
|
minLatitude: lat,
|
|
3833
3831
|
maxLatitude: maxLat,
|
|
@@ -3836,7 +3834,7 @@ function getOrCreateCell(cells, cellSize, lon, maxLon, lat, maxLat) {
|
|
|
3836
3834
|
};
|
|
3837
3835
|
cell.IsFetched = function () { return isCellFetched(cell); };
|
|
3838
3836
|
}
|
|
3839
|
-
return cell;
|
|
3837
|
+
return [id, cell];
|
|
3840
3838
|
}
|
|
3841
3839
|
/**
|
|
3842
3840
|
* This is a helper for making entity requests based on a grid area.
|
|
@@ -3850,34 +3848,122 @@ var EntityGlobe;
|
|
|
3850
3848
|
this.cells = {};
|
|
3851
3849
|
}
|
|
3852
3850
|
Grid.prototype.GetCellsForView = function (viewRect) {
|
|
3853
|
-
var
|
|
3854
|
-
var minLat = viewRect.south;
|
|
3855
|
-
var minLon = viewRect.west;
|
|
3856
|
-
var maxLat = viewRect.north;
|
|
3857
|
-
var maxLon = viewRect.east;
|
|
3851
|
+
var _this = this;
|
|
3858
3852
|
var MAX_CELLS = 150;
|
|
3853
|
+
var minLat = viewRect.south, minLon = viewRect.west, maxLat = viewRect.north, maxLon = viewRect.east;
|
|
3859
3854
|
var cellDegreeSize = getCellSizeFromHeight(viewRect.alt);
|
|
3860
|
-
var
|
|
3861
|
-
var
|
|
3862
|
-
var
|
|
3863
|
-
var
|
|
3855
|
+
var _a = [minLon, minLat].map(function (v) { return floorValueToCellSize(cellDegreeSize, v); }), curMinLon = _a[0], curMinLat = _a[1];
|
|
3856
|
+
var _b = [maxLon - curMinLon, maxLat - curMinLat].map(function (v) { return v / cellDegreeSize; }), width = _b[0], height = _b[1];
|
|
3857
|
+
var ids = [];
|
|
3858
|
+
var cells = [];
|
|
3859
|
+
var max = [curMinLon, curMinLat];
|
|
3860
|
+
var intersections = this.intersections(viewRect);
|
|
3861
|
+
var addCell = function (x, y) {
|
|
3862
|
+
var lon1 = x * cellDegreeSize + curMinLon;
|
|
3863
|
+
var lat1 = y * cellDegreeSize + curMinLat;
|
|
3864
|
+
var lon2 = lon1 + cellDegreeSize;
|
|
3865
|
+
var lat2 = lat1 + cellDegreeSize;
|
|
3866
|
+
var _a = getOrCreateCell(_this.cells, cellDegreeSize, lon1, lon2, lat1, lat2), id = _a[0], cell = _a[1];
|
|
3867
|
+
{
|
|
3868
|
+
var cell_bounds = { south: lat1, west: lon1, north: lat2, east: lon2 };
|
|
3869
|
+
var subcells = [];
|
|
3870
|
+
for (var _i = 0, intersections_1 = intersections; _i < intersections_1.length; _i++) {
|
|
3871
|
+
var id_1 = intersections_1[_i];
|
|
3872
|
+
var c = _this.cells[id_1].GetBounds();
|
|
3873
|
+
if (contains(c, cell_bounds)) {
|
|
3874
|
+
cell.Fetched = true;
|
|
3875
|
+
return;
|
|
3876
|
+
}
|
|
3877
|
+
if (intersects(c, cell_bounds)) {
|
|
3878
|
+
var cropped = crop(c, cell.GetBounds());
|
|
3879
|
+
subcells.push(cropped);
|
|
3880
|
+
}
|
|
3881
|
+
}
|
|
3882
|
+
var filled = 0;
|
|
3883
|
+
while (subcells.length > 0) {
|
|
3884
|
+
var c = subcells.pop();
|
|
3885
|
+
filled += area(c);
|
|
3886
|
+
for (var _b = 0, subcells_1 = subcells; _b < subcells_1.length; _b++) {
|
|
3887
|
+
var s = subcells_1[_b];
|
|
3888
|
+
filled -= intersection(s, c);
|
|
3889
|
+
}
|
|
3890
|
+
}
|
|
3891
|
+
if (filled + Number.EPSILON * 2 > area(cell.GetBounds())) {
|
|
3892
|
+
cell.Fetched = true;
|
|
3893
|
+
return;
|
|
3894
|
+
}
|
|
3895
|
+
var x2_1 = max[0], y2_1 = max[1];
|
|
3896
|
+
x2_1 = Math.max(x2_1, lon2);
|
|
3897
|
+
y2_1 = Math.max(y2_1, lat2);
|
|
3898
|
+
max = [x2_1, y2_1];
|
|
3899
|
+
}
|
|
3900
|
+
ids.push(id);
|
|
3901
|
+
cells.push(cell);
|
|
3902
|
+
cells[id] = cell;
|
|
3903
|
+
};
|
|
3864
3904
|
for (var x = 0; x < width; x++) {
|
|
3865
3905
|
for (var y = 0; y < height; y++) {
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
var cell = getOrCreateCell(this.cells, cellDegreeSize, lon, lon + cellDegreeSize, lat, lat + cellDegreeSize);
|
|
3869
|
-
cells.push(cell);
|
|
3870
|
-
if (cells.length > MAX_CELLS) {
|
|
3906
|
+
addCell(x, y);
|
|
3907
|
+
if (cells.length >= MAX_CELLS) {
|
|
3871
3908
|
break;
|
|
3872
3909
|
}
|
|
3873
3910
|
}
|
|
3874
3911
|
}
|
|
3912
|
+
var x2 = max[0], y2 = max[1];
|
|
3913
|
+
if (x2 != curMinLon && y2 != curMinLat) {
|
|
3914
|
+
this.patches.push([{ west: curMinLon, east: x2, south: curMinLat, north: y2 }, ids]);
|
|
3915
|
+
}
|
|
3875
3916
|
return cells;
|
|
3876
3917
|
};
|
|
3918
|
+
Grid.prototype.intersections = function (withRect) {
|
|
3919
|
+
return this.patches
|
|
3920
|
+
.filter(function (_a) {
|
|
3921
|
+
var rect = _a[0], _ = _a[1];
|
|
3922
|
+
return intersects(rect, withRect);
|
|
3923
|
+
})
|
|
3924
|
+
.map(function (_a) {
|
|
3925
|
+
var _ = _a[0], ids = _a[1];
|
|
3926
|
+
return ids;
|
|
3927
|
+
})
|
|
3928
|
+
.reduce(function (all, ids) {
|
|
3929
|
+
all.push.apply(all, ids);
|
|
3930
|
+
return all;
|
|
3931
|
+
}, []);
|
|
3932
|
+
};
|
|
3877
3933
|
return Grid;
|
|
3878
3934
|
}());
|
|
3879
3935
|
EntityGlobe.Grid = Grid;
|
|
3880
|
-
})(EntityGlobe || (EntityGlobe = {}));
|
|
3936
|
+
})(EntityGlobe || (EntityGlobe = {}));
|
|
3937
|
+
function intersects(l, r) {
|
|
3938
|
+
var w = l.west, s = l.south, n = l.north, e = l.east;
|
|
3939
|
+
var wr = r.west, sr = r.south, nr = r.north, er = r.east;
|
|
3940
|
+
return !(e <= wr || w >= er || n <= sr || s >= nr);
|
|
3941
|
+
}
|
|
3942
|
+
function contains(l, r) {
|
|
3943
|
+
var w = l.west, s = l.south, n = l.north, e = l.east;
|
|
3944
|
+
var wr = r.west, sr = r.south, nr = r.north, er = r.east;
|
|
3945
|
+
return !(er < e || wr > w || nr > n || sr < s);
|
|
3946
|
+
}
|
|
3947
|
+
function crop(rect, by) {
|
|
3948
|
+
var w = rect.west, s = rect.south, n = rect.north, e = rect.east;
|
|
3949
|
+
var wc = by.west, sc = by.south, nc = by.north, ec = by.east;
|
|
3950
|
+
w = Math.max(w, ec);
|
|
3951
|
+
e = Math.min(e, wc);
|
|
3952
|
+
s = Math.max(s, nc);
|
|
3953
|
+
n = Math.min(n, sc);
|
|
3954
|
+
return { west: w, south: s, north: n, east: e };
|
|
3955
|
+
}
|
|
3956
|
+
function intersection(l, r) {
|
|
3957
|
+
var w = l.west, s = l.south, n = l.north, e = l.east;
|
|
3958
|
+
var wr = r.west, sr = r.south, nr = r.north, er = r.east;
|
|
3959
|
+
var x = Math.min(e, er) - Math.max(w, wr);
|
|
3960
|
+
var y = Math.min(n, nr) - Math.max(s, sr);
|
|
3961
|
+
return (x > 0 && y > 0) ? x * y : 0;
|
|
3962
|
+
}
|
|
3963
|
+
function area(rect) {
|
|
3964
|
+
var w = rect.west, s = rect.south, n = rect.north, e = rect.east;
|
|
3965
|
+
return Math.abs((e - w) * (n - s));
|
|
3966
|
+
}
|
|
3881
3967
|
|
|
3882
3968
|
var MAX_AREA_IN_DEGREES = 90;
|
|
3883
3969
|
var MAX_RETRY_ATTEMPTS = 1;
|