コード例 #1
0
        /// <summary>
        /// The constructor.
        /// </summary>
        /// <param name="model"> The model, used for communicating with the server. </param>
        public MapViewModel(IFlightGearCommunicator model)
        {
            this.model = model;

            foreach (string var in properties.Keys)
            {
                model.AddReceiveableVar(var, false);
            }

            // Add the viewmodel to the model's listeners.
            this.model.PropertyChanged +=
                delegate(Object sender, PropertyChangedEventArgs e)
            {
                string name = e.PropertyName;

                // If latitude changed, update latitude.
                if (name == latitudeName)
                {
                    Latitude       = this.model.GetVarValue(latitudeName);
                    PositionUpdate = 0x1;
                }

                // If longitude changed, update longitude.
                else if (name == longitudeName)
                {
                    Longitude      = this.model.GetVarValue(longitudeName);
                    PositionUpdate = 0x2;
                }
            };



            // Add self as a listener to the position change.
            this.PropertyChanged +=
                delegate(Object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "Position")
                {
                    // Calculate the angle between the last position and the new one.
                    this.Rotation = CalculateRotation(lastLocation, Position);

                    // Update last location.
                    this.lastLocation = Position;
                }
            };
        }