/*---------------- 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.gis.EditListener; import nl.idgis.giclient.gis.ActiveLayerListener; import nl.idgis.giclient.gis.Feature; import nl.idgis.giclient.gis.Layer; import nl.idgis.giclient.gis.SelectionListener; import nl.idgis.giclient.gui.mapviewer.MapFeature; import nl.idgis.giclient.gui.mapviewer.MapGeometry; import nl.idgis.giclient.gui.mapviewer.MapLayer; import nl.idgis.giclient.gis.UnboundFeatureLayer; import nl.idgis.giclient.gis.SelectableLayer; class nl.idgis.giclient.gui.mapviewer.MapUnboundFeatureLayer extends MapLayer implements ActiveLayerListener, EditListener, SelectionListener { function onLoad():Void { editingMapFeatures = new Array(); ruler.getGIS().gisEventDispatcher.addActiveLayerListener(this); ruler.rulerEventDispatcher.addEditListener(this); layer.layerEventDispatcher.addSelectionListener(this); drawAll(); } function onChangeActiveLayer():Void { highLightMapFeatures(); } function onChangeEditing():Void { highLightMapFeatures(); } function onChangeLayerSelectedFeatures(layer:Layer, selected:Boolean, subSelected:Boolean, current:Boolean):Void { if ((subSelected) || (current)) { highLightMapFeatures(); } } function getMapFeatures(pixX:Number, pixY:Number, noAlphaCheck:Boolean, mapTippedLayers:Boolean, idsOnly:Boolean, editingMapFeaturesToo:Boolean):Array { var mapFeature:MapFeature = null; var mapFeatures:Array = new Array(); var mapGeometry:MapGeometry = null; for (var i:String in editingMapFeatures) { mapFeature = MapFeature(editingMapFeatures[i]); if (mapFeature != currentEditingMapFeature) { mapGeometry = mapFeature.getMapGeometry(); if (mapGeometry != null) { if ((pixX == null) || (pixY == null) || (mapGeometry.hitTest(pixX, pixY, true))) { if (idsOnly) { mapFeatures.push(mapFeature.getFeature().getID()); } else { mapFeatures.push(mapFeature); } } } } } if (currentEditingMapFeature != null) { mapFeature = currentEditingMapFeature; mapGeometry = mapFeature.getMapGeometry(); if (mapGeometry != null) { if ((pixX == null) || (pixY == null) || (mapGeometry.hitTest(pixX, pixY, true))) { if (idsOnly) { mapFeatures.push(mapFeature.getFeature().getID()); } else { mapFeatures.push(mapFeature); } } } } return mapFeatures; } private function drawAll():Void { highLightMapFeatures(); } // This method is the only nl.idgis.giclient.gui.mapviewer.MapUnboundFeatureLayer method that acts outside the scope of a MapLayerSession. For instance, to see if a selection exists it calls directly on Layer instead of mapLayerSession.getVisibleActiveAndHasSelection(layer) // Advantage is that this method can be called directly from the onChange methods. Disadvantage could be that, calling this method from a MapLayerSession, the state of the Layer will differ from the state of the MapLayerSession. // This is no problem however, because nl.idgis.giclient.gui.mapviewer.MapUnboundFeatureLayer always adapts to the lastest state of the model. private function highLightMapFeatures():Void { var activeAndEditing:Boolean = ((ruler.getGIS().getActiveLayer() == null) && (ruler.isEditing())); var subSelectedFeatures:Array = UnboundFeatureLayer(layer).getSubSelectedFeatures(); var currentFeature:Feature = UnboundFeatureLayer(layer).getCurrentFeature(); var newEditingMapFeatureIDs:Array = new Array(); var newCurrentEditingMapFeatureIDs:Array = new Array(); // Never holds more than 1 element. if (activeAndEditing) { newEditingMapFeatureIDs = Layer.getFeatureIDs(subSelectedFeatures); if (currentFeature != null) { newCurrentEditingMapFeatureIDs.push(currentFeature.getID()); } } var toBeRemovedIDs:Array = null; var toBeAddedIDs:Array = null; resetEditingMapFeatures(newEditingMapFeatureIDs, newCurrentEditingMapFeatureIDs); } private function getEditingMapFeaturesIDs():Array { var editingMapFeaturesIDs:Array = new Array(); for (var i:Number = 0; i < editingMapFeatures.length; i++) { editingMapFeaturesIDs.push(editingMapFeatures[i].getFeature().getID()); } return editingMapFeaturesIDs; } private function getEditingMapFeature(id:String):MapFeature { if ((id == null) || (id == "")) { // EXCEPTION return null; } var editingMapFeature:MapFeature = null; for (var i:Number = 0; i < editingMapFeatures.length; i++) { editingMapFeature = MapFeature(editingMapFeatures[i]); if (editingMapFeature.getFeature().getID() == id) { return editingMapFeature; } } return null; } private function addEditingMapFeature(id:String):Void { if ((id == null) || (id == "")) { // EXCEPTION return; } editingMapFeatures.push(new MapFeature(UnboundFeatureLayer(layer).getSubSelectedFeature(id), mapViewer.getGeometryLayer())); } private function removeEditingMapFeature(id:String):Void { if ((id == null) || (id == "")) { // EXCEPTION return; } var editingMapFeature:MapFeature = null; for (var i:Number = 0; i < editingMapFeatures.length; i++) { editingMapFeature = MapFeature(editingMapFeatures[i]); if (editingMapFeature.getFeature().getID() == id) { editingMapFeature.remove(); editingMapFeatures.splice(i, 1); return; } } } function getCurrentEditingMapFeature():MapFeature { return currentEditingMapFeature; } }