Determining coordinate relationship to extent
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
goog.provide('ol.Extent');
|
||||
goog.provide('ol.extent');
|
||||
goog.provide('ol.extent.Relationship');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('ol.Coordinate');
|
||||
@@ -15,6 +16,20 @@ goog.require('ol.TransformFunction');
|
||||
ol.Extent;
|
||||
|
||||
|
||||
/**
|
||||
* Relationship to an extent.
|
||||
* @enum {number}
|
||||
*/
|
||||
ol.extent.Relationship = {
|
||||
UNKNOWN: 0,
|
||||
INTERSECTING: 1,
|
||||
ABOVE: 2,
|
||||
RIGHT: 4,
|
||||
BELOW: 8,
|
||||
LEFT: 16
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Builds an extent that includes all given coordinates.
|
||||
*
|
||||
@@ -150,6 +165,38 @@ ol.extent.containsExtent = function(extent1, extent2) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the relationship between a coordinate and extent.
|
||||
* @param {ol.Extent} extent The extent.
|
||||
* @param {ol.Coordinate} coordinate The coordinate.
|
||||
* @return {number} The relationship (bitwise compare with
|
||||
* ol.extent.Relationship).
|
||||
*/
|
||||
ol.extent.coordinateRelationship = function(extent, coordinate) {
|
||||
var minX = extent[0];
|
||||
var minY = extent[1];
|
||||
var maxX = extent[2];
|
||||
var maxY = extent[3];
|
||||
var x = coordinate[0];
|
||||
var y = coordinate[1];
|
||||
var relationship = ol.extent.Relationship.UNKNOWN;
|
||||
if (x < minX) {
|
||||
relationship = relationship | ol.extent.Relationship.LEFT;
|
||||
} else if (x > maxX) {
|
||||
relationship = relationship | ol.extent.Relationship.RIGHT;
|
||||
}
|
||||
if (y < minY) {
|
||||
relationship = relationship | ol.extent.Relationship.BELOW;
|
||||
} else if (y > maxY) {
|
||||
relationship = relationship | ol.extent.Relationship.ABOVE;
|
||||
}
|
||||
if (relationship === ol.extent.Relationship.UNKNOWN) {
|
||||
relationship = ol.extent.Relationship.INTERSECTING;
|
||||
}
|
||||
return relationship;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {ol.Extent} Empty extent.
|
||||
* @todo stability experimental
|
||||
|
||||
Reference in New Issue
Block a user