[OpenLayers-Commits] r2013 - in sandbox/vector/lib/OpenLayers: . Parser
commits at openlayers.org
commits at openlayers.org
Wed Dec 6 01:48:06 EST 2006
Author: camerons
Date: 2006-12-06 01:48:06 -0500 (Wed, 06 Dec 2006)
New Revision: 2013
Modified:
sandbox/vector/lib/OpenLayers/BaseTypes.js
sandbox/vector/lib/OpenLayers/Geometry.js
sandbox/vector/lib/OpenLayers/Parser/GML.js
Log:
Add Bounds.extendBounds()
Set the bounds for all geometries as they are loaded by Parser/GML
Modified: sandbox/vector/lib/OpenLayers/BaseTypes.js
===================================================================
--- sandbox/vector/lib/OpenLayers/BaseTypes.js 2006-12-06 02:09:12 UTC (rev 2012)
+++ sandbox/vector/lib/OpenLayers/BaseTypes.js 2006-12-06 06:48:06 UTC (rev 2013)
@@ -468,6 +468,30 @@
return new OpenLayers.Bounds(this.left + x, this.bottom + y,
this.right + x, this.top + y);
},
+
+ /**
+ * Extend the bounds to include the box specificated.
+ * Can be used to extend the bounds to a point as well
+ * using extendBounds(x,y).
+ * This function assumes that left<right and bottom<top.
+ * @param {Object} left
+ * @param {Object} bottom
+ * @param {Object} right
+ * @param {Object} top
+ */
+ extendBounds:function(left,bottom,right,top){
+ if(left&&bottom){
+ this.left=(left<this.left)?left:this.left;
+ this.bottom=(bottom<this.bottom)?bottom:this.bottom;
+ if(right&&top){
+ this.right=(right>this.right)?right:this.right;
+ this.top=(top>this.top)?top:this.top;
+ }else{
+ this.right=(left<this.left)?left:this.left;
+ this.top=(bottom<this.bottom)?bottom:this.bottom;
+ }
+ }
+ },
/**
* @param {OpenLayers.LonLat} ll
Modified: sandbox/vector/lib/OpenLayers/Geometry.js
===================================================================
--- sandbox/vector/lib/OpenLayers/Geometry.js 2006-12-06 02:09:12 UTC (rev 2012)
+++ sandbox/vector/lib/OpenLayers/Geometry.js 2006-12-06 06:48:06 UTC (rev 2013)
@@ -12,7 +12,7 @@
style: null,
/** @type OpenLayers.Bounds */
- extent: null,
+ bounds: null,
/**
* Cross reference back to the feature that owns this geometry so
@@ -29,7 +29,38 @@
initialize: function() {
this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME+ "_");
},
+
+ /**
+ * Set the bounds for this Geometry.
+ * @param {OpenLayers.Bounds} bounds
+ */
+ setBounds: function(bounds){
+ this.bounds=bounds;
+ },
+
+ /**
+ * Extend the existing bounds to include the new bounds. If existing
+ * bounds=null, then set a new Bounds.
+ * @param {Object} bounds
+ */
+ extendBounds: function(bounds){
+ if(!this.bounds){
+ this.setBounds(bounds);
+ }else{
+ this.bounds.extendBounds(bounds);
+ }
+ },
+
+ /**
+ * Get the bounds for this Geometry. The bounds will be null if not it has
+ * not been set.
+ * Once the bounds is set, it is not calculated again, this makes queries
+ * faster.
+ * @return {OpenLayers.Bounds}
+ */
+ getBounds: function(){
+ return this.bounds;
+ },
CLASS_NAME: "OpenLayers.Geometry"
-
};
\ No newline at end of file
Modified: sandbox/vector/lib/OpenLayers/Parser/GML.js
===================================================================
--- sandbox/vector/lib/OpenLayers/Parser/GML.js 2006-12-06 02:09:12 UTC (rev 2012)
+++ sandbox/vector/lib/OpenLayers/Parser/GML.js 2006-12-06 06:48:06 UTC (rev 2013)
@@ -33,7 +33,7 @@
// Determine dimension of the FeatureCollection. Ie, dim=2 means (x,y) coords
// dim=3 means (x,y,z) coords
// GML3 can have 2 or 3 dimensions. GML2 only 2.
- var dim;
+ var dim;
var coordNodes=OpenLayers.Ajax.getElementsByTagNameNS(featureNodes[0], "http://www.opengis.net/gml","gml", "posList");
if(coordNodes.length==0)coordNodes=OpenLayers.Ajax.getElementsByTagNameNS(featureNodes[0], "http://www.opengis.net/gml","gml", "pos");
if(coordNodes.length>0){
@@ -47,10 +47,10 @@
if (feature) {
this.featureCollection.push(feature);
-
- // Set Attributes for this class
- attributes=new OpenLayers.Attributes.GML(featureNodes[i]);
- feature.setAttributes(attributes);
+
+ // Set Attributes for this class
+ attributes=new OpenLayers.Attributes.GML(featureNodes[i]);
+ feature.setAttributes(attributes);
}
}
},
@@ -77,7 +77,7 @@
processXMLNode: function(xmlNode) {
var geom;
- var points;
+ var p; // [points,bounds]
var feature = new OpenLayers.Feature();
feature.toState(OpenLayers.State.UNKNOWN);
@@ -88,8 +88,9 @@
var polygons = OpenLayers.Ajax.getElementsByTagNameNS(multipolygon,
"http://www.opengis.net/gml", "gml", "Polygon");
for (var i = 0; i < polygons.length; i++) {
- polygon = this.parsePolygonNode(polygons[i]);
+ polygon = this.parsePolygonNode(polygons[i],geom);
geom.addComponents(polygon);
+ geom.extendBounds(polygon.getBounds());
}
}
// match MultiLineString
@@ -102,10 +103,12 @@
var lineStrings = OpenLayers.Ajax.getElementsByTagNameNS(multilinestring, "http://www.opengis.net/gml", "gml", "LineString");
for (var i = 0; i < lineStrings.length; i++) {
- points=this.parseCoords(lineStrings[i]);
- if(points){
- var lineString = new OpenLayers.Geometry.LineString(points);
+ p=this.parseCoords(lineStrings[i]);
+ if(p.points){
+ var lineString = new OpenLayers.Geometry.LineString(p.points);
geom.addComponents(lineString);
+ // TBD Bounds only set for one of multiple geometries
+ geom.extendBounds(p.bounds);
}
}
}
@@ -120,8 +123,10 @@
var points = OpenLayers.Ajax.getElementsByTagNameNS(multiPoint, "http://www.opengis.net/gml", "gml", "Point");
for (var i = 0; i < points.length; i++) {
- point = this.parseCoords(points[i])[0];
- geom.addComponents(point);
+ p = this.parseCoords(points[i]);
+ geom.addComponents(p.points[0]);
+ // TBD Bounds only set for one of multiple geometries
+ geom.extendBounds(p.bounds);
}
}
// match Polygon
@@ -137,9 +142,11 @@
"http://www.opengis.net/gml", "gml", "LineString").length != 0) {
var lineString = OpenLayers.Ajax.getElementsByTagNameNS(xmlNode,
"http://www.opengis.net/gml", "gml", "LineString")[0];
- points = this.parseCoords(lineString);
- if (points) {
- geom = new OpenLayers.Geometry.LineString(points);
+ p = this.parseCoords(lineString);
+ if (p.points) {
+ geom = new OpenLayers.Geometry.LineString(p.points);
+ // TBD Bounds only set for one of multiple geometries
+ geom.extendBounds(p.bounds);
}
}
// match Point
@@ -148,9 +155,11 @@
var point = OpenLayers.Ajax.getElementsByTagNameNS(xmlNode,
"http://www.opengis.net/gml", "gml", "Point")[0];
- points = this.parseCoords(point);
- if (points) {
- geom = points[0];
+ p = this.parseCoords(point);
+ if (p.points) {
+ geom = p.points[0];
+ // TBD Bounds only set for one of multiple geometries
+ geom.extendBounds(p.bounds);
}
}
@@ -169,12 +178,23 @@
"http://www.opengis.net/gml", "gml", "LinearRing");
var rings = [];
+ var p;
+ var polyBounds;
for (var i = 0; i < linearRings.length; i++) {
- points = this.parseCoords(linearRings[i]);
- rings.push(new OpenLayers.Geometry.LinearRing(points));
+ p = this.parseCoords(linearRings[i]);
+ ring1=new OpenLayers.Geometry.LinearRing(p.points);
+ ring1.extendBounds(p.bounds);
+ if(polyBounds){
+ polyBounds.extend(p.bounds);
+ }else{
+ polyBounds=p.bounds;
+ }
+ rings.push(ring1);
}
- return new OpenLayers.Geometry.Polygon(rings);
+ var poly=new OpenLayers.Geometry.Polygon(rings);
+ poly.extendBounds(polyBounds);
+ return poly;
},
/**
@@ -187,11 +207,11 @@
*/
parseCoords : function(xmlNode) {
// var geom = OpenLayers.Ajax.getElementsByTagNameNS(xmlNode, "http://www.opengis.net/gml", "gml", geomType);
- var points=null;
- var lonlat;
+ var x,y,left,bottom,right,top,bounds;
+ var p=new Array(); // return value = [points,bounds]
if (xmlNode) {
- points=new Array();
+ p.points=new Array();
// match ".//gml:pos|.//gml:posList|.//gml:coordinates"
// Note: GML2 coordinates are of the form:x y,x y,x y
@@ -219,10 +239,18 @@
while ( nums[nums.length-1] == "" ) nums.pop();
for(i=0; i<nums.length;i=i+this.dim) {
- points.push(new OpenLayers.Geometry.Point(parseFloat(nums[i]),parseFloat(nums[i+1])));
+ x=parseFloat(nums[i]);
+ y=parseFloat(nums[i+1]);
+ p.points.push(new OpenLayers.Geometry.Point(x,y));
+
+ if(!p.bounds){
+ p.bounds=new OpenLayers.Bounds(x,y,x,y);
+ }else{
+ p.bounds.extendBounds(x,y);
+ }
}
}
- return points;
+ return p;
},
/** @final @type String */
More information about the Commits
mailing list