/*---------------- 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.Envelope; class nl.idgis.giclient.gis.CentreScale { var centreX:Number; var centreY:Number; var scale:Number; var srsName:String; function CentreScale(srsName:String, centreX:Number, centreY:Number, scale:Number) { this.srsName = srsName; this.centreX = centreX; this.centreY = centreY; //this.scale = Math.round(scale); this.scale = scale; } function getCentreX():Number { return centreX; } function getCentreY():Number { return centreY; } function getScale():Number { return scale; } function setCentreX(centreX:Number):Void { this.centreX = centreX; } function setCentreY(centreY:Number):Void { this.centreY = centreY; } function setScale(scale:Number):Void { //this.scale = Math.round(scale); this.scale = scale; } function setSRS(srsName:String):Void { this.srsName = srsName; } function clone():CentreScale { return new CentreScale(srsName, centreX, centreY, scale); } function toEnvelope(width:Number, height:Number, coordPixFactor:Number):Envelope { var numHorzCoords:Number = width * coordPixFactor * scale; var numVertCoords:Number = height * coordPixFactor * scale; var minX:Number = centreX - numHorzCoords / 2; var minY:Number = centreY - numVertCoords / 2; var maxX:Number = minX + numHorzCoords; var maxY:Number = minY + numVertCoords; return new Envelope(srsName, minX, minY, maxX, maxY); } function toEnvelopeWithBox(width:Number, height:Number, pixAX:Number, pixAY:Number, pixBX:Number, pixBY:Number, coordPixFactor:Number):Envelope { // pixAX must be less then pixBX, in order to create an envelope out of them; same for pixAY and pixBY. if (pixBX < pixAX) { var backUp:Number = pixAX; pixAX = pixBX; pixBX = backUp; } if (pixBY < pixAY) { var backUp:Number = pixAY; pixAY = pixBY; pixBY = backUp; } pixAX = pixAX - (width / 2); pixAY = pixAY - (height / 2); pixBX = pixBX - (width / 2); pixBY = pixBY - (height / 2); var coordAX:Number = centreX + (pixAX * coordPixFactor * scale); var coordAY:Number = centreY - (pixBY * coordPixFactor * scale); // y values for pixels and coords are opposite. var coordBX:Number = centreX + (pixBX * coordPixFactor * scale); var coordBY:Number = centreY - (pixAY * coordPixFactor * scale); // y values for pixels and coords are opposite. var envelope:Envelope = new Envelope(srsName, coordAX, coordAY, coordBX, coordBY); return envelope; } function getCoordX(width:Number, pixX:Number, coordPixFactor:Number):Number { pixX = pixX - (width / 2); var coordX:Number = centreX + (pixX * coordPixFactor * scale); return coordX; } function getCoordY(height:Number, pixY:Number, coordPixFactor:Number):Number { pixY = pixY - (height / 2); var coordY:Number = centreY - (pixY * coordPixFactor * scale); return coordY; } function getPixX(width:Number, coordX:Number, coordPixFactor:Number):Number { var pixX:Number = (coordX - centreX) / (coordPixFactor * scale); pixX = pixX + (width / 2); return pixX; } function getPixY(height:Number, coordY:Number, coordPixFactor:Number):Number { var pixY:Number = (0 - coordY + centreY) / (coordPixFactor * scale); pixY = pixY + (height / 2); return pixY; } function toString():String { return "CentreScale(" + centreX + ", " + centreY + ", " + scale + ")"; } function getSRS():String { return srsName; } }