/*---------------- 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.util.ArrayTools; import nl.idgis.giclient.config.Colors; import nl.idgis.giclient.gis.EditListener; import nl.idgis.giclient.geoma.Envelope; import nl.idgis.giclient.gis.ActiveLayerListener; import nl.idgis.giclient.gis.CentreScale; import nl.idgis.giclient.gis.Feature; import nl.idgis.giclient.gis.Layer; import nl.idgis.giclient.gis.GILayer; import nl.idgis.giclient.gis.LayerFilteredFeaturesListener; import nl.idgis.giclient.gis.LayerRefreshListener; import nl.idgis.giclient.gis.LayerVisibleListener; 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.MapLayerSession; import nl.idgis.giclient.gui.mapviewer.MapViewer; import nl.idgis.giclient.Ruler; import nl.idgis.giclient.io.SWFResponse; import nl.idgis.giclient.io.SWFResponseListener; import nl.idgis.giclient.gis.ZoomListener; import nl.idgis.giclient.gis.AnimationLayer; import nl.idgis.giclient.StringTools; import nl.idgis.giclient.timeanimation.Timebar; import nl.idgis.giclient.timeanimation.MovieProgressListener; import nl.idgis.giclient.timeanimation.TimelineCommandListener; import nl.idgis.giclient.gis.SelectableLayer; import nl.idgis.giclient.framework.FrameWork; import nl.idgis.giclient.util.Strings; class nl.idgis.giclient.gui.mapviewer.MapLayer extends MovieClip implements ActiveLayerListener, EditListener, LayerVisibleListener, LayerRefreshListener, LayerFilteredFeaturesListener, SelectionListener, SWFResponseListener, TimelineCommandListener, MovieProgressListener, ZoomListener { public static var PLAY:Number = 2; public static var PAUSE:Number = 3; public static var STOP:Number = 4; public static var NEXTFRAME:Number = 5; public static var PREVIOUSFRAME:Number = 6; private var ruler:Ruler = null; // Set by init object; private var layer:Layer= null; // Set by init object; private var mapViewer:MapViewer = null; // Set by init object; private var highLightColor0:Number = 0x0000FF; private var highLightColor1:Number = 0xFF0088; private var viewerWidth:Number = 0; private var viewerHeight:Number = 0; private var mapLayerSession:MapLayerSession = null; private var previousSWFResponse:SWFResponse = null; private var currentSWFResponse:SWFResponse = null; private var nextSWFResponse:SWFResponse = null; private var editingMapFeatures:Array = null; private var currentEditingMapFeature:MapFeature = null; private var currentframe:Number = 0; function onLoad():Void { viewerWidth = Stage.width; viewerHeight = Stage.height; highLightColor0 = Colors.selectionColor; highLightColor1 = Colors.currentColor; editingMapFeatures = new Array(); Stage.addListener(this); ruler.getGIS().gisEventDispatcher.addActiveLayerListener(this); ruler.rulerEventDispatcher.addEditListener(this); var superLayers:Array = layer.getSuperLayers(); for (var i:Number = 0; i < superLayers.length; i++) { superLayers[i].layerEventDispatcher.addLayerVisibleListener(this); } layer.layerEventDispatcher.addLayerVisibleListener(this); layer.layerEventDispatcher.addLayerRefreshListener(this); layer.layerEventDispatcher.addLayerFilteredFeaturesListener(this); layer.layerEventDispatcher.addSelectionListener(this); if (layer instanceof AnimationLayer) { ruler.getGIS().animationEventDispatcher.addTimelineCommandListener(this); ruler.getGIS().animationEventDispatcher.addMovieProgressListener(this); } ruler.getGIS().gisEventDispatcher.addZoomListener(this); drawAll(); } function onResize():Void { // Centrates the graphic to the new size of the stage. The load of the next graphic will reset this position. if (currentSWFResponse != null) { var graphic:MovieClip = currentSWFResponse.getMovieClip(); if (graphic != null) { // There is always a currentSWFResponse and it always has a movieclip intact, except when nl.idgis.giclient.gui.mapviewer.MapLayer is in the "init" state. These "if" clauses are meant for the init state. graphic._x = Math.round((Stage.width - viewerWidth) / 2); graphic._y = Math.round((Stage.height - viewerHeight) / 2); } } // Makes sure that future loadings of the graphic will be the new size of the stage. viewerWidth = Stage.width; viewerHeight = Stage.height; } function onChangeActiveLayer():Void { highLightMapFeatures(); } function onChangeEditing():Void { highLightMapFeatures(); } private function setGraphicVisibleDelayed() { var obj:Object = new Object(); obj["that"] = this; obj["mapLayerSession"] = mapLayerSession; obj["func"] = function() { this["that"]["setGraphicVisible"](this["mapLayerSession"]); }; _global["setTimeout"](obj, "func", 1); } function onChangeLayerVisible(layer:Layer):Void { // Executes when this layer OR one of its superlayers changes visibility. startMapLayerSession(); setGraphicVisibleDelayed(); if (this.layer instanceof AnimationLayer) { ruler.getGIS().recalcCurrentTimeRange(); } } function onLayerRefresh(layer:Layer):Void { var graphicMapLayerSession:MapLayerSession = MapLayerSession(currentSWFResponse.getProperty("mapLayerSession")); graphicMapLayerSession.setURL(layer, ""); startMapLayerSession(); setGraphicVisibleDelayed(); } function onChangeLayerFilteredFeatures(layer:Layer):Void { startMapLayerSession(); // evt. ook direct naar setGraphic REL MapViewerSession setGraphicVisibleDelayed(); } function onChangeLayerSelectedFeatures(layer:Layer, selected:Boolean, subSelected:Boolean, current:Boolean):Void { //trace("onChangeLayerSelectedFeatures: " + layer.getName()); if (selected) { highLightMapFeatures(); // WORKAROUND FOR CREATING NEW GEOMETRIES; IS NOW CALLED TWICE startMapLayerSession(); setGraphicVisibleDelayed(); // highLightMapFeatures is called indirectly. } else { // subSelected or current. highLightMapFeatures(); } } function getLayer():Layer { return layer; } function getMapFeatures(pixX:Number, pixY:Number, noAlphaCheck:Boolean, mapTippedLayers:Boolean, idsOnly:Boolean, editingMapFeaturesToo:Boolean):Array { var graphic:MovieClip = currentSWFResponse.getMovieClip(); var mapFeature:Object = null; var mapFeatures:Array = new Array(); //if(graphic._name != null) // trace(graphic._name + ".hasMaptip: " + graphic.hasMaptip); if ((graphic._alpha > 0) || (noAlphaCheck)) { if ((graphic.hasMaptip) || (mapTippedLayers == false)) { for (var i:String in graphic) { if ((typeof(graphic[i]) == "movieclip") && (graphic[i] != graphic) && ((graphic[i]._visible) || (!editingMapFeaturesToo)) && (i.indexOf("SelectedMapFeatureDup") == -1) && (i.indexOf("SelectedMapFeatureFill") == -1) && (i.indexOf("SelectedMapFeature") == -1) && (i.indexOf("CurrentMapFeature") == -1)) { mapFeature = graphic[i]; if ((pixX == null) || (pixY == null) || (mapFeature.hitTest(pixX, pixY, true))) { if (idsOnly) { if (mapTippedLayers) { mapFeatures.push(graphic[mapViewer.getFeatureID(i) + "tip"]); } else { mapFeatures.push(mapViewer.getFeatureID(mapFeature._name)); } } else { mapFeatures.push(mapFeature); } } } } if (editingMapFeaturesToo) { 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 { startMapLayerSession(); setGraphicVisibleDelayed(); } private function startMapLayerSession():Void { var inc:Number = 0; if (mapLayerSession != null) { //delete from existing session before starting a new session finishMapLayerSession(mapLayerSession); inc = -1; } var centreScale:CentreScale = ruler.getGIS().getCurrentCentreScale(); mapLayerSession = new MapLayerSession(new Array(this), centreScale); inc += 1; mapViewer.waitToFinishMapLayerSession(mapLayerSession, inc); } function zoom():Void { startMapLayerSession(); asGoodAsItGets(); setGraphicVisibleDelayed(); } function timeZoom():Void { startMapLayerSession(); setGraphicVisibleDelayed(); } private function asGoodAsItGets():Void { var centreScale:CentreScale = mapLayerSession.getCentreScale(); var scale:Number = centreScale.getScale(); var coordPixFactor:Number = ruler.getGIS().getCoordPixFactor(); var graphic:MovieClip = null; var graphicMapLayerSession:MapLayerSession = null; var graphicScale:Number = null; var graphicEnvelope:Envelope = null; var graphicMinX:Number = null; var graphicMaxY:Number = null; var pixX:Number = null; var pixY:Number = null; var scaling:Number = null; // A previousSWFResponse will exist at this point if a session is started in "waiting" state. // A currentSWFResponse will always exist at this point, except if a session is started in the "init" state. // A nextSWFResponse may exist at this point, but will never have a visible graphic. if (previousSWFResponse != null) { graphic = previousSWFResponse.getMovieClip(); graphicMapLayerSession = MapLayerSession(previousSWFResponse.getProperty("mapLayerSession")); } if (currentSWFResponse != null) { graphic = currentSWFResponse.getMovieClip(); graphicMapLayerSession = MapLayerSession(currentSWFResponse.getProperty("mapLayerSession")); } if (previousSWFResponse != null || currentSWFResponse != null) { graphicScale = graphicMapLayerSession.getCentreScale().getScale(); graphicEnvelope = graphicMapLayerSession.getEnvelope(layer); graphicMinX = graphicEnvelope.getMinX(); graphicMaxY = graphicEnvelope.getMaxY(); pixX = Math.round(centreScale.getPixX(viewerWidth, graphicMinX, coordPixFactor)); pixY = Math.round(centreScale.getPixY(viewerHeight, graphicMaxY, coordPixFactor)); scaling = 100 * graphicScale / scale; graphic._x = pixX; graphic._y = pixY; graphic._xscale = scaling; graphic._yscale = scaling; } } private function setGraphicVisible(mapLayerSession:MapLayerSession):Void { var inVisibleLayers:Boolean = ruler.getGIS().isVisibleLayer(layer); mapLayerSession.setInVisibleLayers(layer, inVisibleLayers); var visibleActiveAndHasSelection:Boolean = ((layer.isVisible()) /* && (layer == ruler.getGIS().getActiveLayer()) */ && (layer instanceof SelectableLayer) && (SelectableLayer(layer).getSelectedFeatures().length > 0)); mapLayerSession.setVisibleActiveAndHasSelection(layer, visibleActiveAndHasSelection); if ((inVisibleLayers || visibleActiveAndHasSelection) && layer.isAvailable()) { setGraphic(); } else { finishMapLayerSession(mapLayerSession); mapViewer.waitToFinishMapLayerSession(mapLayerSession, -1); } } private function setGraphic():Void { var centreScale:CentreScale = mapLayerSession.getCentreScale(); var envelope:Envelope = centreScale.toEnvelope(viewerWidth, viewerHeight, ruler.getGIS().getCoordPixFactor()); //var url:String = ruler.getGIClientConfig().getServerURLPrefix(); /*var url:String = GILayer(layer).getServerURL() + "?"; url += "request=GetMap&width=" + viewerWidth + "&height=" + viewerHeight; url += "&layer=" + layer.getName(); url += "&envelope=" + envelope.getMinX() + "," + envelope.getMinY() + "," + envelope.getMaxX() + "," + envelope.getMaxY(); */var inVisibleLayers:Boolean = mapLayerSession.getInVisibleLayers(layer);/* if ((!inVisibleLayers) || ((layer instanceof SelectableLayer) && (SelectableLayer(layer).getFilteredFeatures().length > 0))) { var sl:SelectableLayer = SelectableLayer(layer); var features:Array = null; if ((!inVisibleLayers) && (sl.getFilteredFeatures().length > 0)) { var selectedFeatures:Array = sl.getSelectedFeatures(); var filteredFeatures:Array = sl.getFilteredFeatures(); features = ArrayTools.intersect(selectedFeatures, filteredFeatures); } else if (!inVisibleLayers) { features = sl.getSelectedFeatures(); } else if (sl.getFilteredFeatures().length > 0) { features = sl.getFilteredFeatures(); } var ids:Array = new Array(); for (var i:Number = 0; i < features.length; i++) { ids.push(features[i].getID()); } url += "&id=" + ids.toString(); } if (layer instanceof AnimationLayer) { url += "&TimeRangeStart=" + StringTools.dateTimeToString(ruler.getGIS().getCurrentTimeRangeBegin()); url += "&TimeRangeEnd=" + StringTools.dateTimeToString(ruler.getGIS().getCurrentTimeRangeEnd()); url += "&TimeScale=" + ruler.getGIS().getCurrentTimeScale().toString(); url += "&fps=" + ruler.getGIS().getCurrentFPS().toString(); }*/ var url:String = layer.getMapConnector().getMap( layer, centreScale, viewerWidth, viewerHeight, ruler.getGIS()); var graphicMapLayerSession:MapLayerSession = MapLayerSession(currentSWFResponse.getProperty("mapLayerSession")); if (graphicMapLayerSession.getURL(layer) != url) { mapLayerSession.setEnvelope(layer, envelope); mapLayerSession.setURL(layer, url); mapLayerSession.setSelectedMapFeatureIDs(layer, new Array()); // This is necessary because the session has no init values for the layer specific data. mapLayerSession.setCurrentMapFeatureID(null); // Idem. // if (layer.getType().toUpperCase() == "FEATURE") { var percentage:Number = 10; layer.layerEventDispatcher.mapLayerLoadProgress(layer, percentage); // } if (previousSWFResponse != null) { // There will be a previousSWFResponse if and only if a session is started while nl.idgis.giclient.gui.mapviewer.MapLayer is in the "waiting" state. previousSWFResponse.removeMovieClip(null); previousSWFResponse.removeSWFResponseListener(); // NEEDED FOR GARBAGE COLLECT?? previousSWFResponse = null; } if (nextSWFResponse != null) { // There will be a nextSWFResponse if and only if a session is started while nl.idgis.giclient.gui.mapviewer.MapLayer is in the "loading" state. nextSWFResponse.removeMovieClip(null); nextSWFResponse.removeSWFResponseListener(); } // The currentSWFResponse is left untouched. nextSWFResponse = new SWFResponse(this, this, 0, null); nextSWFResponse.setProperty("mapLayerSession", mapLayerSession); nextSWFResponse.load(url, 0); } else { // DUPLICATE CODE inVisibleLayers = mapLayerSession.getInVisibleLayers(layer); var visibleActiveAndHasSelection:Boolean = mapLayerSession.getVisibleActiveAndHasSelection(layer); if ((inVisibleLayers) || (visibleActiveAndHasSelection)) { if (mapLayerSession.getFadingBehavior() == "POST_LOADING") { currentSWFResponse.fadeIn(200); } } finishMapLayerSession(mapLayerSession); mapViewer.waitToFinishMapLayerSession(mapLayerSession, -1); } } function onLoadProgressSWFResponse(swfResponse:SWFResponse, numBytesLoaded:Number, numBytesTotal:Number):Void { if (numBytesTotal != 0) { var percentage:Number = Math.round(100 * numBytesLoaded / numBytesTotal); layer.layerEventDispatcher.mapLayerLoadProgress(layer, percentage); mapViewer.setNumBytesLoadedAndTotal(layer, numBytesLoaded, numBytesTotal); } } function onLoadErrorSWFResponse(swfResponse:SWFResponse, errorCode:Number, httpStatus:Number):Void { trace("Error loading layer '" + layer.getName() + "', url = '" + swfResponse.getUrl() + "', errorCode: " + errorCode + " httpStatus: " + httpStatus); layer.layerEventDispatcher.mapLayerLoadProgress(layer, 100); mapViewer.setNumBytesLoadedAndTotal(layer, 1, 1); } function onLoadSWFResponse(swfResponse:SWFResponse):Void { // if (layer.getType().toUpperCase() == "FEATURE") { var percentage:Number = 100; layer.layerEventDispatcher.mapLayerLoadProgress(layer, percentage); // } var mapLayerSession:MapLayerSession = MapLayerSession(swfResponse.getProperty("mapLayerSession")); if (this.mapLayerSession == mapLayerSession) { previousSWFResponse = currentSWFResponse; currentSWFResponse = nextSWFResponse; nextSWFResponse.removeSWFResponseListener(this); nextSWFResponse = null; var inVisibleLayers:Boolean = mapLayerSession.getInVisibleLayers(layer); var visibleActiveAndHasSelection:Boolean = mapLayerSession.getVisibleActiveAndHasSelection(layer); if ((inVisibleLayers) || (visibleActiveAndHasSelection)) { if (mapLayerSession.getFadingBehavior() == "POST_LOADING") { currentSWFResponse.fadeIn(200); } } // Registers all map features to the gis model for faster filtering, selecting and setting as current feature. if (layer.isSelectable()) { var mapFeatureIDs:Array = getMapFeatures(null, null, true, false, true, false); SelectableLayer(layer).setNearbyFeatures(mapFeatureIDs); } } if (layer instanceof AnimationLayer) { onTimelineCommand(PAUSE); this.currentframe = 1; var graphic:MovieClip = currentSWFResponse.getMovieClip(); graphic.onEnterFrame = function():Void { if (this._currentframe != this._parent.currentframe) { //do not report progress if paused/stopped this._parent.currentframe = this._currentframe; if (this._parent.ruler.getGIS().isVisibleLayer(this._parent.layer)) { this._parent.ruler.getGIS().setCurrentTimeStamp((this._currentframe - 1)/(this._totalframes - 1)); } if (this._currentframe == this._totalframes) { this._parent.ruler.getGIS().setPlaying(false); } } }; /*for (var i:String in graphic) { if ((typeof(graphic[i]) == "movieclip") && (graphic[i] != graphic)){ graphic[i].onEnterFrame = function():Void { if (this._currentframe == this._totalframes) { this.stop(); } }; } }*/ } finishMapLayerSession(mapLayerSession); mapViewer.waitToFinishMapLayerSession(mapLayerSession, -1); } function finishMapLayerSession(mapLayerSession:MapLayerSession):Void { if (this.mapLayerSession == mapLayerSession) { previousSWFResponse.removeMovieClip(200); previousSWFResponse.removeSWFResponseListener(); previousSWFResponse = null; var inVisibleLayers:Boolean = mapLayerSession.getInVisibleLayers(layer); var visibleActiveAndHasSelection:Boolean = mapLayerSession.getVisibleActiveAndHasSelection(layer); if ((inVisibleLayers) || (visibleActiveAndHasSelection)) { if (mapLayerSession.getFadingBehavior() == "POST_WAITING") { currentSWFResponse.fadeIn(200); } } else { currentSWFResponse.fadeOut(200); } highLightMapFeatures(); if (layer instanceof AnimationLayer) { var percentage:Number = ruler.getGIS().getPlayedPercentage(); onChangeCurrentTimeStamp(percentage); } this.mapLayerSession = null; } } // This method is the only nl.idgis.giclient.gui.mapviewer.MapLayer method that acts outside the scope of a nl.idgis.giclient.gui.mapviewer.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 nl.idgis.giclient.gui.mapviewer.MapLayerSession, the state of the Layer will differ from the state of the nl.idgis.giclient.gui.mapviewer.MapLayerSession. // This is no problem however, because nl.idgis.giclient.gui.mapviewer.MapLayer always adapts to the lastest state of the model. private function highLightMapFeatures():Void { if (!(layer instanceof SelectableLayer)) { return; } var selectedFeatures:Array = SelectableLayer(layer).getSelectedFeatures(); var editingFeatures:Array = SelectableLayer(layer).getSubSelectedFeatures(); var currentFeature:Feature = SelectableLayer(layer).getCurrentFeature(); var mapLayerSession:MapLayerSession = MapLayerSession(currentSWFResponse.getProperty("mapLayerSession")); // TODO previouseSWFResponse? var selectedMapFeatureIDs:Array = mapLayerSession.getSelectedMapFeatureIDs(layer); var currentMapFeatureID:String = mapLayerSession.getCurrentMapFeatureID(layer); var newSelectedMapFeatureIDs:Array = new Array(); var newEditingMapFeatureIDs:Array = new Array(); var newCurrentEditingMapFeatureIDs:Array = new Array(); // Never holds more than 1 element. var newCurrentMapFeatureIDs:Array = new Array(); // Never holds more than 1 element. if ((layer.isVisible()) && (layer.areSuperLayersVisible())) { newSelectedMapFeatureIDs = Layer.getFeatureIDs(selectedFeatures); newEditingMapFeatureIDs = Layer.getFeatureIDs(editingFeatures); newSelectedMapFeatureIDs = ArrayTools.getLeftOver(newSelectedMapFeatureIDs, newEditingMapFeatureIDs); if (currentFeature != null) { if (currentFeature.isEditing()) { newCurrentEditingMapFeatureIDs.push(currentFeature.getID()); } else { newCurrentMapFeatureIDs.push(currentFeature.getID()); } } } var graphic:MovieClip = currentSWFResponse.getMovieClip(); // Resets the selected map features. var toBeRemovedIDs:Array = ArrayTools.getLeftOver(selectedMapFeatureIDs, newSelectedMapFeatureIDs); for (var i:String in toBeRemovedIDs) { /*graphic[toBeRemovedIDs[i] + "SelectedMapFeatureDup"].removeMovieClip(); graphic[toBeRemovedIDs[i] + "SelectedMapFeatureFill"].removeMovieClip(); graphic[toBeRemovedIDs[i] + "SelectedMapFeature"].removeMovieClip();*/ for(var clip:String in graphic) { if(mapViewer.getFeatureID(clip).indexOf(toBeRemovedIDs[i]) != -1) { graphic[clip].removeMovieClip(); } } } var toBeAddedIDs:Array = ArrayTools.getLeftOver(newSelectedMapFeatureIDs, selectedMapFeatureIDs); var featureID:String = null; for (var i:String in toBeAddedIDs) { featureID = toBeAddedIDs[i]; for(var clip:String in graphic) { var currentFeatureID:String = mapViewer.getFeatureID(clip); if(currentFeatureID == featureID) { var featureGraphic:MovieClip = graphic[clip]; if(featureGraphic != null) { var dup:MovieClip = featureGraphic.duplicateMovieClip(clip + "SelectedMapFeatureDup", graphic.getNextHighestDepth()); var color:Color = new Color(dup); color.setRGB(highLightColor0); dup._alpha = 70; var fill:MovieClip = graphic.createEmptyMovieClip(clip + "SelectedMapFeatureFill", graphic.getNextHighestDepth()); fill.beginFill(highLightColor0, 70); fill.moveTo(0, 0); fill.lineTo(_root.width, 0); fill.lineTo(_root.width, _root.height); fill.lineTo(0, _root.height); fill.lineTo(0, 0); fill.setMask(dup); featureGraphic.duplicateMovieClip(clip + "SelectedMapFeature", graphic.getNextHighestDepth()); var colorize:Color = new Color(graphic[clip + "SelectedMapFeature"]); colorize.setRGB(highLightColor0); graphic[clip + "SelectedMapFeature"]._alpha = 70; } } } } mapLayerSession.setSelectedMapFeatureIDs(layer, newSelectedMapFeatureIDs); // Resets the current map feature. var newCurrentMapFeatureID:String = null; if (newCurrentMapFeatureIDs.length > 0) { newCurrentMapFeatureID = newCurrentMapFeatureIDs[0]; } if ((currentMapFeatureID != newCurrentMapFeatureID) && (currentMapFeatureID != null)) { for(var clip:String in graphic) { if(clip.indexOf("CurrentMapFeature") != -1) { graphic[clip].removeMovieClip(); } } } if ((currentMapFeatureID != newCurrentMapFeatureID) && (newCurrentMapFeatureID != null)) { for(var clip:String in graphic) { if(mapViewer.getFeatureID(clip) == newCurrentMapFeatureID && clip.indexOf("Selected") == -1) { graphic[clip].duplicateMovieClip(clip + "CurrentMapFeature", graphic.getNextHighestDepth()); var color:Color = new Color(graphic[clip + "CurrentMapFeature"]); color.setRGB(highLightColor1); graphic[clip + "CurrentMapFeature"]._alpha = 85; graphic[clip + "CurrentMapFeature"]._x -= 2; graphic[clip + "CurrentMapFeature"]._y -= 2; } } } mapLayerSession.setCurrentMapFeatureID(layer, newCurrentMapFeatureID); resetEditingMapFeatures(newEditingMapFeatureIDs, newCurrentEditingMapFeatureIDs); // Resets the visibility of the map features in the graphic. They have to be invisible when there is a corresponding map feature in de geometry layer. var mapFeatures:Array = getMapFeatures(null, null, true, false, false, false); var mapFeature:Object = null; for (var i:String in mapFeatures) { if (typeof(mapFeatures[i]) == "movieclip") { mapFeature = mapFeatures[i]; if (getEditingMapFeature(mapViewer.getFeatureID(mapFeature._name)) == null) { mapFeature._visible = true; } else { mapFeature._visible = false; } } } } private function resetEditingMapFeatures(newEditingMapFeatureIDs:Array, newCurrentEditingMapFeatureIDs:Array):Void { // Resets the editing map features. var editingMapFeatureIDs:Array = getEditingMapFeaturesIDs(); var toBeRemovedIDs:Array = ArrayTools.getLeftOver(editingMapFeatureIDs, newEditingMapFeatureIDs); for (var i:String in toBeRemovedIDs) { removeEditingMapFeature(toBeRemovedIDs[i]); } var toBeAddedIDs:Array = ArrayTools.getLeftOver(newEditingMapFeatureIDs, editingMapFeatureIDs); for (var i:String in toBeAddedIDs) { addEditingMapFeature(toBeAddedIDs[i]); } // Resets the current editing map feature. var currentEditingMapFeatureID:String = null; if (currentEditingMapFeature != null) { currentEditingMapFeatureID = currentEditingMapFeature.getFeature().getID(); } var newCurrentEditingMapFeatureID:String = null; if (newCurrentEditingMapFeatureIDs.length > 0) { newCurrentEditingMapFeatureID = newCurrentEditingMapFeatureIDs[0]; } if ((currentEditingMapFeatureID != newCurrentEditingMapFeatureID) && (currentEditingMapFeatureID != null)) { currentEditingMapFeature.setMapGeometryActive(false); } if ((currentEditingMapFeatureID != newCurrentEditingMapFeatureID) && (newCurrentEditingMapFeatureID != null)) { getEditingMapFeature(newCurrentEditingMapFeatureID).setMapGeometryActive(true); } currentEditingMapFeature = getEditingMapFeature(newCurrentEditingMapFeatureID); } 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(SelectableLayer(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; } function onTimelineCommand(command:Number):Void { if (ruler.getGIS().isVisibleLayer(layer)){ var graphic:MovieClip = currentSWFResponse.getMovieClip(); var playing:Boolean = ruler.getGIS().isPlaying(); if (command == PLAY){ graphic.play(); for (var i:String in graphic) { if ((typeof(graphic[i]) == "movieclip") && (graphic[i] != graphic)){ graphic[i].play(); } } } if (command == PAUSE){ graphic.stop(); for (var i:String in graphic) { if ((typeof(graphic[i]) == "movieclip") && (graphic[i] != graphic)){ graphic[i].stop(); } } } if (command == STOP){ graphic.gotoAndStop(1); for (var i:String in graphic) { if ((typeof(graphic[i]) == "movieclip") && (graphic[i] != graphic)){ //TODO remove from timeline if necessary graphic[i].gotoAndStop(1); } } } if (command == NEXTFRAME){ graphic.nextFrame(); if (playing) { graphic.play(); } for (var i:String in graphic) { if ((typeof(graphic[i]) == "movieclip") && (graphic[i] != graphic)){ graphic[i].nextFrame(); if (playing) { graphic[i].play(); } } } } if (command == PREVIOUSFRAME){ graphic.prevFrame(); if (playing) { graphic.play(); } for (var i:String in graphic) { if ((typeof(graphic[i]) == "movieclip") && (graphic[i] != graphic)){ graphic[i].prevFrame(); if (playing) { graphic[i].play(); } } } } } } function onChangeCurrentTimeStamp(percentage:Number):Void { if (ruler.getGIS().isVisibleLayer(layer)) { var graphic:MovieClip = currentSWFResponse.getMovieClip(); var frame:Number = Math.round((graphic._totalframes - 1) * percentage) + 1; if (frame == graphic._currentframe) { return; } var sof:Number = -1; var nof:Number = -1; var subFrame:Number = -1; var playing:Boolean = ruler.getGIS().isPlaying(); if (playing) { graphic.gotoAndPlay(frame); } else { graphic.gotoAndStop(frame); } for (var i:String in graphic) { if ((typeof(graphic[i]) == "movieclip") && (graphic[i] != graphic)) { sof = graphic[i + "SOF"]; nof = graphic[i + "NOF"]; subFrame = frame - sof; if (subFrame < 1) { graphic[i].removeMovieClip(); // REALLY NECESSARY?? } else { if (playing) { graphic[i].gotoAndPlay(subFrame); } else { graphic[i].gotoAndStop(subFrame); } } } } } } function onZoom() : Void { if(layer instanceof AnimationLayer){ var graphic:MovieClip = currentSWFResponse.getMovieClip(); graphic.removeMovieClip(); } } }