/*---------------- 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.framework.bars.Bar; import nl.idgis.giclient.gis.MapMouseMoveListener; import nl.idgis.giclient.gis.ZoomListener; import nl.idgis.giclient.Ruler; import nl.idgis.giclient.gis.Map; import nl.idgis.giclient.gis.SRSChangeListener; import nl.idgis.giclient.gis.ActiveMapListener; import nl.idgis.giclient.util.Strings; import mx.controls.ComboBox; import mx.core.UIObject; class nl.idgis.giclient.framework.bars.ScaleBar extends Bar implements ZoomListener, MapMouseMoveListener, ActiveMapListener, SRSChangeListener { private var ruler:Ruler = null; private var srs:Array = null; function setRuler(ruler:Ruler):Void { this.ruler = ruler; ruler.getGIS().gisEventDispatcher.addZoomListener(this); ruler.getGIS().gisEventDispatcher.addMapMouseMoveListener(this); ruler.getGIS().gisEventDispatcher.addSRSChangeListener(this); ruler.getGIS().gisEventDispatcher.addActiveMapListener(this); drawAll(); } function onZoom():Void { this["scaleInput"].text = Math.round(ruler.getGIS().getCurrentCentreScale().getScale()); } function onMapMouseMove(x:Number, y:Number):Void { if(ruler.getSRSInfo().isProjection( ruler.getGIS().getActiveMap().getSRS())) { var xStr:String = "" + Math.round(x * 100) / 100; var yStr:String = "" + Math.round(y * 100) / 100; if((Math.round(x * 100) % 100) == 0) xStr += ".00"; else if((Math.round(x * 100) % 10) == 0) xStr += "0"; if((Math.round(y * 100) % 100) == 0) yStr += ".00"; else if((Math.round(y * 100) % 10) == 0) yStr += "0"; this["coordTextField"].text = "x: " + xStr + " y: " + yStr; } else { var xStr:String = "" + Math.round(x * 10000) / 10000; var yStr:String = "" + Math.round(y * 10000) / 10000; if((Math.round(x * 10000) % 10000) == 0) xStr += ".0000"; else if((Math.round(x * 10000) % 1000) == 0) xStr += "000"; else if((Math.round(x * 10000) % 100) == 0) xStr += "00"; else if((Math.round(x * 10000) % 10) == 0) xStr += "0"; if((Math.round(y * 10000) % 10000) == 0) yStr += ".0000"; else if((Math.round(y * 10000) % 1000) == 0) yStr += "000"; else if((Math.round(y * 10000) % 100) == 0) yStr += "00"; else if((Math.round(y * 10000) % 10) == 0) yStr += "0"; this["coordTextField"].text = "lat: " + xStr + " lon: " + yStr; } } private function drawScaleInput():Void { var scales:Array = ruler.getGIS().getActiveMap().getScales(); if(scales != null && scales.length != 0) { attachMovie("ComboBox", "scaleInput", 6); for(var i:Number = 0; i < scales.length; i++) { this["scaleInput"].addItem(scales[i]); } this["scaleInput"].editable = true; this["scaleInput"].addEventListener("close", onEnter); } else { attachMovie("TextInput", "scaleInput", 6); } this["scaleInput"].restrict = "0-9"; if(ruler.getGIS().getActiveMap().getSupportedSRS().length > 1) { this["scaleInput"]._x = 55; this["scaleInput"]._y = 21; } else { this["scaleInput"]._x = 95; this["scaleInput"]._y = 3; } this["scaleInput"].setStyle("fontFamily", "_sans"); this["scaleInput"].setStyle("fontSize", 10); this["scaleInput"].setSize(80, 17); this["scaleInput"].addEventListener("enter", onEnter); this["scaleInput"].text = Math.round(ruler.getGIS().getCurrentCentreScale().getScale()); } private function drawAll():Void { var srs:Array = ruler.getGIS().getActiveMap().getSupportedSRS(); var textFormat:TextFormat = new TextFormat(); textFormat.font = "_sans"; textFormat.size = 10; attachMovie("NavigationButton", "NavW", 1, {_x: 20, _y: 20, gism: ruler.getGIS(), buttonTip: ( Strings.getFile("Geoide").getString("Left"))}); attachMovie("NavigationButton", "NavO", 2, {_x: 20, _y: 20, gism: ruler.getGIS(), buttonTip: ( Strings.getFile("Geoide").getString("Right"))}); attachMovie("NavigationButton", "NavN", 3, {_x: 20, _y: 20, gism: ruler.getGIS(), buttonTip: ( Strings.getFile("Geoide").getString("Up"))}); attachMovie("NavigationButton", "NavZ", 4, {_x: 20, _y: 20, gism: ruler.getGIS(), buttonTip:( Strings.getFile("Geoide").getString("Down"))}); var labelText:String = "1 :"; createTextField("textField", 5, 40, srs.length > 1 ? 21 : 5, 55, 20); this["textField"].setNewTextFormat(textFormat); this["textField"].text = labelText; createTextField("coordTextField", 7, srs.length > 1 ? 140 : 45, 21, 140, 20); this["coordTextField"].setNewTextFormat(textFormat); if(ruler.getSRSInfo().isProjection( ruler.getGIS().getActiveMap().getSRS())) this["coordTextField"].text = "x: y:"; else this["coordTextField"].text = "lat: lon:"; if(srs.length > 1) { createTextField("srsLabel", 8, 45, 3, 100, 20); this["srsLabel"].setNewTextFormat(textFormat); this["srsLabel"].text = "SRS:"; attachMovie("ComboBox", "cb", 9); this["cb"]._x = 85; this["cb"]._y = 2; this["cb"].setStyle("fontFamily", "_sans"); this["cb"].setStyle("fontSize", 10); this["cb"].setSize(195, 17); this["cb"].addEventListener("change", this); setWidth(290); } else { setWidth(190); } afterChangeActiveMap(); } function onSRSChange():Void { var map:Map = ruler.getGIS().getActiveMap(); var currentSrs:String = map.getSRS(); for(var i:Number = 0; i < srs.length; i++) { if(srs[i] == currentSrs) { this["cb"].selectedIndex = i; break; } } this["cb"].enabled = srs.length > 1; } function change(eventObject) { this["cb"].enabled = false; ruler.getGIS().setSRS(srs[eventObject.target.selectedIndex]); } function onEnter():Void { var newScale:Number = Number(_parent["scaleInput"].text); if(Math.round(_parent.ruler.getGIS().getCurrentScale()) != newScale) { _parent.ruler.getGIS().setCurrentScale(newScale); } } function beforeChangeActiveMap() : Void { } function afterChangeActiveMap() : Void { srs = ruler.getGIS().getActiveMap().getSupportedSRS(); if(srs.length > 1) { var currentSrs:String = ruler.getGIS().getActiveMap().getSRS(); this["cb"].removeAll(); for(var i:Number = 0; i < srs.length; i++) { this["cb"].addItem(ruler.getSRSInfo().getTitle(srs[i])); if(srs[i] == currentSrs) this["cb"].selectedItem = i; } } if(this["scaleInput"] != null) { this["scaleInput"].removeMovieClip(); } _global["setTimeout"](this, "drawScaleInput", 1); } }