/*---------------- 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.LineString; import nl.idgis.giclient.geoma.Point; class nl.idgis.giclient.geoma.LinearRing extends LineString { function LinearRing(srsName:String, points:Array) { super(srsName, points); if(!isClosed()) { throw new Error("LinearRing.LinearRing: ring is not closed"); return; } } function getGeometries():Array { var geometries:Array = new Array(); for (var i:Number = 0; i < points.length - 1; i++) { geometries.push(points[i]); } geometries = geometries.concat(getLineSegments()); return geometries; } function addPoint(point:Point, permanent:Boolean) { var endPoint:Object = points.pop(); super.addPoint(point, permanent); points.push(endPoint); } function removePoint(point:Point, permanent:Boolean):Void { if (points.length == 2) { // EXCEPTION return; } else { if (point == null) { Point(points[points.length - 2]).setSuperGeometry(null); points.splice(points.length - 2, 1); geometryEventDispatcher.changeGeometry(this, permanent); } else if (point == points[0]) { Point(points[0]).setSuperGeometry(null); points[0] = points[1]; points[points.length - 1] = points[1]; points.splice(1, 1); geometryEventDispatcher.changeGeometry(this, permanent); } else { for (var i:Number = 0; i < points.length; i++) { if (points[i] == point) { point.setSuperGeometry(null); points.splice(i, 1); geometryEventDispatcher.changeGeometry(this, permanent); break; } } } } } function setPointXY(x:Number, y:Number):Void { points[points.length - 2].setXY(x, y); } function toString():String { return("LinearRing (" + points.toString() + ")"); } function clone():LinearRing { //trace("LinearRing.clone()"); if ((points == null) || (points.length == 0)) { return null; } var pnts:Array = new Array(); var pnt0:Point = Point(Point(points[0]).clone()); pnts.push(pnt0); for (var i:Number = 1; i < (points.length -1); i++) { var pnt:Point = Point(Point(points[i]).clone()); pnts.push(pnt); } pnts.push(pnt0); //first and last point must be the same return new LinearRing(getSRS(), pnts); } }