Skip to content

Commit

Permalink
replaced unwrap logic with bbox-fns
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJDufour committed Nov 24, 2023
1 parent a4e638c commit 94b0a9e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"leaflet": "^1.9.4"
},
"dependencies": {
"bbox-fns": "^0.13.0",
"bbox-fns": "^0.19.0",
"geography-markup-language": "^0.2.0",
"get-epsg-code": "1.1.0",
"preciso": "^0.12.0",
Expand Down
23 changes: 3 additions & 20 deletions src/geo-extent.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import bboxArray from "bbox-fns/bbox-array.js";
import booleanContains from "bbox-fns/boolean-contains.js";
import booleanIntersects from "bbox-fns/boolean-intersects.js";
import densePolygon from "bbox-fns/dense-polygon.js";
import unwrap from "bbox-fns/unwrap.js";

import getEPSGCode from "get-epsg-code";
import { Envelope } from "geography-markup-language";
Expand Down Expand Up @@ -538,27 +539,9 @@ export class GeoExtent {
// extent is within the normal extent of the earth, so return clone
if (xmin > -180 && xmax < 180) return [this.clone()];

// handle special case where extent overflows xmin and then overlaps itself
if (xmin < -180 && xmax >= xmin + 360) return [new this.constructor([-180, ymin, 180, ymax], { srs: 4326 })];
const bboxes = unwrap(this.bbox, [-180, -90, 180, 90]);

if (xmax > 180 && xmin <= xmax - 360) return [new this.constructor([-180, ymin, 180, ymax], { srs: 4326 })];

let extents = [];

// extent overflows left edge of the world
if (xmin < -180) {
extents.push(new this.constructor([xmin + 360, ymin, 180, ymax], { srs }));
}

// add extent for part between -180 to 180 longitude
extents.push(new this.constructor([xmin < -180 ? -180 : xmin, ymin, xmax > 180 ? 180 : xmax, ymax], { srs }));

// extent overflows right edge of the world
if (this.xmax > 180) {
extents.push(new this.constructor([-180, ymin, xmax - 360, ymax], { srs }));
}

return extents;
return bboxes.map(bbox => new this.constructor(bbox, { srs: 4326 }));
}

asEsriJSON() {
Expand Down
4 changes: 2 additions & 2 deletions test/test.unwrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ test("unwrap right overflow", ({ eq }) => {
const extent = new GeoExtent([175, -85, 185, 90], { srs: 4326 });
const unwrapped = extent.unwrap().map(ext => ext.bbox);
eq(unwrapped, [
[175, -85, 180, 90],
[-180, -85, -175, 90]
[-180, -85, -175, 90],
[175, -85, 180, 90]
]);
});

Expand Down

0 comments on commit 94b0a9e

Please sign in to comment.