/*---------------- 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.config.Colors; import nl.idgis.giclient.geoma.Geometry; import nl.idgis.giclient.geoma.Point; import nl.idgis.giclient.gui.mapviewer.MapGeometry; import nl.idgis.giclient.gui.mapviewer.MapViewer; import nl.idgis.giclient.modes.MapViewerAction; import nl.idgis.giclient.util.Strings; import nl.idgis.giclient.webserviceconnector.giconnector.GIConnector; import nl.idgis.giclient.io.XMLResponseListener; import nl.idgis.giclient.io.XMLResponse; import nl.idgis.giclient.geoma.GMLFactory; import nl.idgis.giclient.gis.SelectableLayer; class nl.idgis.giclient.modes.MapViewerSelectByGeometry implements MapViewerAction, XMLResponseListener { private var selectionGeometry:Geometry = null; private var bufferedGeometry:Geometry = null; private var selectionMapGeometry:MapGeometry = null; private var bufferedMapGeometry:MapGeometry; private var mapViewer:MapViewer = null; private var numMouseDowns:Number = 0; private var intervalID:Number = null; private var double:Boolean = false; private var newGeometry:Boolean = true; private var selectionLayer:SelectableLayer = null; private var buffer:Number = 0; var select:Boolean=true;//set by initObject function resetNumMouseDowns():Void { if (numMouseDowns >= 1) { numMouseDowns = 0; clearInterval(intervalID); } } function enter(mapViewer:MapViewer):Void { } function exit(boozoo:MapViewer):Void { var mapViewer = _root.mapViewer; removeMapGeometry(mapViewer); selectionGeometry = null; bufferedGeometry = null; mapViewer.ruler.getGIS().setSelectionGeometry(null); mapViewer.ruler.getGIS().setBufferedSelectionGeometry(null); mapViewer.ruler.getGIS().setBuffer(0); } function performPress(mapViewer:MapViewer, pressX:Number, pressY:Number, point:Point):Void { if(newGeometry){ selectionGeometry = null; newGeometry = false; } this.mapViewer = mapViewer; if (numMouseDowns == 0) { intervalID = setInterval(this, "resetNumMouseDowns", 400); } numMouseDowns++; double = false; if (numMouseDowns == 2) { double = true; resetNumMouseDowns(); } if (point == null) { point = mapViewer.pixel2Point(mapViewer._xmouse, mapViewer._ymouse); } if (selectionGeometry == null) { if (selectionMapGeometry != null) { removeMapGeometry(mapViewer); } createGeometry(point); selectionMapGeometry = MapGeometry(mapViewer.getGeometryLayer().addMapGeometry(selectionGeometry, MapGeometry.SELECTION, Colors.selectionGeometryColor, "")); } else { var eventObject:Object = new Object(); eventObject["mode"] = "Create"; eventObject["type"] = "MouseDown"; eventObject["double"] = double; eventObject["backKey"] = Key.isDown(Key.BACKSPACE); eventObject["point"] = point; selectionMapGeometry.performEvent(eventObject); } } function performRelease(mapViewer:MapViewer):Void { } function performMouseUp(mapViewer:MapViewer):Void { } function performMouseMove(mapViewer:MapViewer):Void { if (!newGeometry) { var point:Point = mapViewer.pixel2Point(mapViewer._xmouse, mapViewer._ymouse); var eventObject:Object = new Object(); eventObject["mode"] = "Create"; eventObject["type"] = "MouseMove"; eventObject["point"] = point; selectionMapGeometry.performEvent(eventObject); } } function performDrag(mapViewer:MapViewer):Void { } function onKeyPress(mapViewer:MapViewer):Void { } private function setSelection(){ mapViewer.ruler.getGIS().setSelectionGeometry(selectionGeometry); mapViewer.ruler.getGIS().setBufferedSelectionGeometry(null); mapViewer.ruler.getGIS().setBuffer(0); if(select){ mapViewer.ruler.getGIS().selectByGeometry(selectionGeometry,selectionLayer); } } private function setBufferedSelection(){ mapViewer.ruler.getGIS().setBufferedSelectionGeometry(bufferedGeometry); mapViewer.ruler.getGIS().setBuffer(buffer); if(select){ mapViewer.ruler.getGIS().selectByGeometry(bufferedGeometry,selectionLayer); } } private function removeMapGeometry(mapViewer:MapViewer):Void { _root.frameWork["frames"]["textInputFrame"].removeMovieClip(); mapViewer.getGeometryLayer().removeMapGeometry(selectionMapGeometry); mapViewer.getGeometryLayer().removeMapGeometry(bufferedMapGeometry); selectionMapGeometry = null; bufferedMapGeometry = null; } private function createGeometry(point:Point):Void { } private function showBufferFrame():Void{ var initObject:Object = {scrollContent: "lib://BufferInputFrame", paneTitle: Strings.getFile("Geoide").getString("UserInput"), isScrolling: false, resizable: false, hasShader: false, doorzichtig:false, _x:100, _y:100}; initObject["contentProperties"] = new Object(); initObject["contentProperties"]["question"] = (Strings.getFile("Geoide").getString("InputBufferQuestion")); initObject["contentProperties"]["inputType"] = "Number"; initObject["contentProperties"]["returnObject"] = this; initObject["contentProperties"]["returnFunction"] = catchBuffer; initObject["contentProperties"]["ruler"] = mapViewer.ruler; _root.frameWork.makeFrame("textInputFrame",initObject,200,100); } function catchBuffer(buffer:Number):Void{ if (buffer == null) { _root.frameWork["frames"]["textInputFrame"].removeMovieClip(); } else { var connector:GIConnector = GIConnector(mapViewer.ruler.getGIS().getTransformConnector()); connector.getBuffer(selectionGeometry, buffer, this); _root.frameWork["frames"]["textInputFrame"].removeMovieClip(); this.buffer = buffer; } } function onLoadXMLResponse(xmlResponse : XMLResponse) : Void { bufferedGeometry= GMLFactory.parseGML(xmlResponse.firstChild); bufferedMapGeometry = MapGeometry(mapViewer.getGeometryLayer().addMapGeometry(bufferedGeometry, MapGeometry.BUFFER, Colors.selectionColor, "")); bufferedMapGeometry.onChangeGeometry(); setBufferedSelection(); } }