#13690 VectorSource#getFeaturesInExtent add projection parameter
This commit is contained in:
@@ -858,3 +858,47 @@ export function wrapX(extent, projection) {
|
||||
}
|
||||
return extent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fits the extent to the real world
|
||||
*
|
||||
* If the extent does not cross the anti meridian, this will return the extent in an array
|
||||
* If the extent crosses the anti meridian, the extent will be sliced, so each part fits within the
|
||||
* real world
|
||||
*
|
||||
*
|
||||
* @param {Extent} extent Extent.
|
||||
* @param {import("./proj/Projection.js").default} projection Projection
|
||||
* @return {Array<Extent>} The extent within the real world extent.
|
||||
*/
|
||||
export function wrapAndSliceX(extent, projection) {
|
||||
if (projection.canWrapX()) {
|
||||
const projectionExtent = projection.getExtent();
|
||||
|
||||
if (!isFinite(extent[0]) || !isFinite(extent[2])) {
|
||||
return [[projectionExtent[0], extent[1], projectionExtent[2], extent[3]]];
|
||||
}
|
||||
|
||||
wrapX(extent, projection);
|
||||
const worldWidth = getWidth(projectionExtent);
|
||||
|
||||
if (getWidth(extent) > worldWidth) {
|
||||
// the extent wraps around on itself
|
||||
return [[projectionExtent[0], extent[1], projectionExtent[2], extent[3]]];
|
||||
} else if (extent[0] < projectionExtent[0]) {
|
||||
// the extent crosses the anti meridian, so it needs to be sliced
|
||||
return [
|
||||
[extent[0] + worldWidth, extent[1], projectionExtent[2], extent[3]],
|
||||
[projectionExtent[0], extent[1], extent[2], extent[3]],
|
||||
];
|
||||
} else if (extent[2] > projectionExtent[2]) {
|
||||
// the extent crosses the anti meridian, so it needs to be sliced
|
||||
return [
|
||||
[extent[0], extent[1], projectionExtent[2], extent[3]],
|
||||
[projectionExtent[0], extent[1], extent[2] - worldWidth, extent[3]],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return [extent];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user