/*---------------- FILE HEADER --------------------------------------- This file is part of Geoide. Copyright (C) 2005-2006 by: IDgis B.V. http://www.idgis.nl This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Contact: Herman Assink IDgis bv P.O. Box 15 7450 AA Holten The Netherlands E-Mail: herman.assink@idgis.nl * @version 1.4.0 * @author IDgis team * ------------------------------------------------------------------------*/ import nl.idgis.giclient.geoma.Geometry; import nl.idgis.giclient.geoma.Point; import nl.idgis.giclient.gis.CentreScale; class nl.idgis.giclient.geoma.Envelope extends Geometry { private var minX:Number; private var minY:Number; private var maxX:Number; private var maxY:Number; /** * Constructor of Envelope */ function Envelope(srsName:String, minX:Number, minY:Number, maxX:Number, maxY:Number) { super(srsName); this.minX = minX; this.minY = minY; this.maxX = maxX; this.maxY = maxY; } function getCenterPoint():Point { return new Point(getSRS(), (maxX + minX) / 2, (maxY + minY) / 2); } /** * @return the minimal x value of the envelope. */ function getMinX():Number { return minX; } /** * @return the minimal y value of the envelope. */ function getMinY():Number { return minY; } /** * @return the maximal x value of the envelope. */ function getMaxX():Number { return maxX; } /** * @return the maximal y value of the envelope. */ function getMaxY():Number { return maxY; } /** * @return envelope (implement interface) */ function getEnvelope():Envelope { return this; } function getCoords():Array { var coords:Array = new Array(); coords.push(new Point(srsName, minX, minY)); coords.push(new Point(srsName, maxX, maxY)); return coords; } function getCornerPoints():Array { var cornerPoints:Array = new Array(); cornerPoints.push(new Point(srsName, minX, minY)); cornerPoints.push(new Point(srsName, minX, maxY)); cornerPoints.push(new Point(srsName, maxX, maxY)); cornerPoints.push(new Point(srsName, maxX, minY)); return cornerPoints; } function equals(envelope:Envelope):Boolean { if ((envelope != null) && (minX == envelope.minX) && (minY == envelope.minY) && (maxX == envelope.maxX) && (maxY == envelope.maxY)) { return true; } else { return false; } } /** * @return if the passed envelope is contained in this envelope */ function contains(geom:Geometry):Boolean { var env:Envelope = geom.getEnvelope(); if (env.minX >= this.minX && env.maxX <= this.maxX && env.minY >= this.minY && env.maxY <= this.maxY) { return true; } else { return false; } } /** * Is used to retrieve a centreScale object belonging to this envelope. * @param width, the width of the object of which the centrescale should be retrieved (the mapviewer) * @param height, the height of the object of which the centrescale should be retrieved (the mapviewer) * @return the centreScale object belonging to this envelope and height of width of the object. */ function toCentreScale(width:Number, height:Number, coordPixFactor:Number):CentreScale { var centreX:Number = (minX + maxX) / 2; var centreY:Number = (minY + maxY) / 2; var scale:Number = 0; if (((maxX - minX) / width) > ((maxY - minY) / height)) { // Either the width or height decides the scale. scale = (maxX - minX) / (width * coordPixFactor); } else { scale = (maxY - minY) / (height * coordPixFactor); } return new CentreScale(srsName, centreX, centreY, scale); } function clone():Envelope { return new Envelope(srsName, minX, minY, maxX, maxY); } function toString():String { return "Envelope(" + minX + ", " + minY + ", " + maxX + ", " + maxY + ")"; } }