The getVertices method now returns all points, endpoints only, or all except endpoints. r=crschmidt (closes #1966)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@8945 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -155,13 +155,15 @@ OpenLayers.Geometry = OpenLayers.Class({
|
|||||||
* Return a list of all points in this geometry.
|
* Return a list of all points in this geometry.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* nodesOnly - {Boolean} For lines, only return vertices that are
|
* nodes - {Boolean} For lines, only return vertices that are
|
||||||
* endpoints.
|
* endpoints. If false, for lines, only vertices that are not
|
||||||
|
* endpoints will be returned. If not provided, all vertices will
|
||||||
|
* be returned.
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* {Array} A list of all vertices in the geometry.
|
* {Array} A list of all vertices in the geometry.
|
||||||
*/
|
*/
|
||||||
getVertices: function(nodesOnly) {
|
getVertices: function(nodes) {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -406,17 +406,19 @@ OpenLayers.Geometry.Collection = OpenLayers.Class(OpenLayers.Geometry, {
|
|||||||
* Return a list of all points in this geometry.
|
* Return a list of all points in this geometry.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* nodesOnly - {Boolean} For lines, only return vertices that are
|
* nodes - {Boolean} For lines, only return vertices that are
|
||||||
* endpoints.
|
* endpoints. If false, for lines, only vertices that are not
|
||||||
|
* endpoints will be returned. If not provided, all vertices will
|
||||||
|
* be returned.
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* {Array} A list of all vertices in the geometry.
|
* {Array} A list of all vertices in the geometry.
|
||||||
*/
|
*/
|
||||||
getVertices: function(nodesOnly) {
|
getVertices: function(nodes) {
|
||||||
var vertices = [];
|
var vertices = [];
|
||||||
for(var i=0, len=this.components.length; i<len; ++i) {
|
for(var i=0, len=this.components.length; i<len; ++i) {
|
||||||
Array.prototype.push.apply(
|
Array.prototype.push.apply(
|
||||||
vertices, this.components[i].getVertices(nodesOnly)
|
vertices, this.components[i].getVertices(nodes)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return vertices;
|
return vertices;
|
||||||
|
|||||||
@@ -159,21 +159,25 @@ OpenLayers.Geometry.LineString = OpenLayers.Class(OpenLayers.Geometry.Curve, {
|
|||||||
* Return a list of all points in this geometry.
|
* Return a list of all points in this geometry.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* nodesOnly - {Boolean} For lines, only return vertices that are
|
* nodes - {Boolean} For lines, only return vertices that are
|
||||||
* endpoints.
|
* endpoints. If false, for lines, only vertices that are not
|
||||||
|
* endpoints will be returned. If not provided, all vertices will
|
||||||
|
* be returned.
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* {Array} A list of all vertices in the geometry.
|
* {Array} A list of all vertices in the geometry.
|
||||||
*/
|
*/
|
||||||
getVertices: function(nodesOnly) {
|
getVertices: function(nodes) {
|
||||||
var vertices;
|
var vertices;
|
||||||
if(nodesOnly) {
|
if(nodes === true) {
|
||||||
vertices = [
|
vertices = [
|
||||||
this.components[0],
|
this.components[0],
|
||||||
this.components[this.components.length-1]
|
this.components[this.components.length-1]
|
||||||
];
|
];
|
||||||
|
} else if (nodes === false) {
|
||||||
|
vertices = this.components.slice(1, this.components.length-1);
|
||||||
} else {
|
} else {
|
||||||
vertices = this.components;
|
vertices = this.components.slice();
|
||||||
}
|
}
|
||||||
return vertices;
|
return vertices;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -329,14 +329,16 @@ OpenLayers.Geometry.LinearRing = OpenLayers.Class(
|
|||||||
* Return a list of all points in this geometry.
|
* Return a list of all points in this geometry.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* nodesOnly - {Boolean} For lines, only return vertices that are
|
* nodes - {Boolean} For lines, only return vertices that are
|
||||||
* endpoints.
|
* endpoints. If false, for lines, only vertices that are not
|
||||||
|
* endpoints will be returned. If not provided, all vertices will
|
||||||
|
* be returned.
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* {Array} A list of all vertices in the geometry.
|
* {Array} A list of all vertices in the geometry.
|
||||||
*/
|
*/
|
||||||
getVertices: function(nodesOnly) {
|
getVertices: function(nodes) {
|
||||||
return nodesOnly ? [] : this.components.slice(0, this.components.length-1);
|
return (nodes === true) ? [] : this.components.slice(0, this.components.length-1);
|
||||||
},
|
},
|
||||||
|
|
||||||
CLASS_NAME: "OpenLayers.Geometry.LinearRing"
|
CLASS_NAME: "OpenLayers.Geometry.LinearRing"
|
||||||
|
|||||||
@@ -255,13 +255,15 @@ OpenLayers.Geometry.Point = OpenLayers.Class(OpenLayers.Geometry, {
|
|||||||
* Return a list of all points in this geometry.
|
* Return a list of all points in this geometry.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* nodesOnly - {Boolean} For lines, only return vertices that are
|
* nodes - {Boolean} For lines, only return vertices that are
|
||||||
* endpoints.
|
* endpoints. If false, for lines, only vertices that are not
|
||||||
|
* endpoints will be returned. If not provided, all vertices will
|
||||||
|
* be returned.
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* {Array} A list of all vertices in the geometry.
|
* {Array} A list of all vertices in the geometry.
|
||||||
*/
|
*/
|
||||||
getVertices: function(nodesOnly) {
|
getVertices: function(nodes) {
|
||||||
return [this];
|
return [this];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -202,7 +202,7 @@
|
|||||||
|
|
||||||
|
|
||||||
function test_getVertices(t) {
|
function test_getVertices(t) {
|
||||||
t.plan(10);
|
t.plan(14);
|
||||||
|
|
||||||
var points = [
|
var points = [
|
||||||
new OpenLayers.Geometry.Point(10, 20),
|
new OpenLayers.Geometry.Point(10, 20),
|
||||||
@@ -226,6 +226,14 @@
|
|||||||
t.eq(nodes.length, 2, "[nodes only] of correct length length");
|
t.eq(nodes.length, 2, "[nodes only] of correct length length");
|
||||||
t.geom_eq(nodes[0], points[0], "[nodes only] first: correct geometry");
|
t.geom_eq(nodes[0], points[0], "[nodes only] first: correct geometry");
|
||||||
t.geom_eq(nodes[1], points[points.length-1], "[nodes only] last: correct geometry");
|
t.geom_eq(nodes[1], points[points.length-1], "[nodes only] last: correct geometry");
|
||||||
|
|
||||||
|
// no nodes
|
||||||
|
var nodes = line.getVertices(false);
|
||||||
|
t.ok(nodes instanceof Array, "[no nodes] got back an array");
|
||||||
|
t.eq(nodes.length, 2, "[no nodes] of correct length length");
|
||||||
|
t.geom_eq(nodes[0], points[1], "[no nodes] first: correct geometry");
|
||||||
|
t.geom_eq(nodes[1], points[2], "[no nodes] last: correct geometry");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_getVertices(t) {
|
function test_getVertices(t) {
|
||||||
t.plan(16);
|
t.plan(22);
|
||||||
|
|
||||||
var points = [
|
var points = [
|
||||||
new OpenLayers.Geometry.Point(10, 20),
|
new OpenLayers.Geometry.Point(10, 20),
|
||||||
@@ -50,13 +50,23 @@
|
|||||||
|
|
||||||
// nodes only
|
// nodes only
|
||||||
var nodes = multi.getVertices(true);
|
var nodes = multi.getVertices(true);
|
||||||
t.ok(nodes instanceof Array, "got back an array");
|
t.ok(nodes instanceof Array, "[nodes only] got back an array");
|
||||||
t.eq(nodes.length, 4, "of correct length length");
|
t.eq(nodes.length, 4, "[nodes only] of correct length length");
|
||||||
t.geom_eq(nodes[0], points[0], "0: correct geometry");
|
t.geom_eq(nodes[0], points[0], "[nodes only] 0: correct geometry");
|
||||||
t.geom_eq(nodes[1], points[3], "1: correct geometry");
|
t.geom_eq(nodes[1], points[3], "[nodes only] 1: correct geometry");
|
||||||
t.geom_eq(nodes[2], points[0], "2: correct geometry");
|
t.geom_eq(nodes[2], points[0], "[nodes only] 2: correct geometry");
|
||||||
t.geom_eq(nodes[3], points[3], "3: correct geometry");
|
t.geom_eq(nodes[3], points[3], "[nodes only] 3: correct geometry");
|
||||||
|
|
||||||
|
// no nodes
|
||||||
|
var nodes = multi.getVertices(false);
|
||||||
|
t.ok(nodes instanceof Array, "[no nodes] got back an array");
|
||||||
|
t.eq(nodes.length, 4, "[no nodes] of correct length length");
|
||||||
|
t.geom_eq(nodes[0], points[1], "[no nodes] 0: correct geometry");
|
||||||
|
t.geom_eq(nodes[1], points[2], "[no nodes] 1: correct geometry");
|
||||||
|
t.geom_eq(nodes[2], points[1], "[no nodes] 2: correct geometry");
|
||||||
|
t.geom_eq(nodes[3], points[2], "[no nodes] 3: correct geometry");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user