Click here to Skip to main content
15,898,736 members
Articles / Mobile Apps / Windows Phone 7

Bike In City with Windows Phone 7

Rate me:
Please Sign up or sign in to vote.
4.97/5 (62 votes)
5 Jan 2011CPOL33 min read 111.5K   3.1K   101  
Learn how to build a small mobile application to visualize data from the city bike sharing system. Get the nearest stations, find the number of free bikes, and compute directions to other stations.
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.Device.Location;
using System.ComponentModel;
using BikeInCity.Utils;

namespace BikeInCity.Model
{
  public class BikeSituation : INotifyPropertyChanged
  {

    #region private fields
    private ObservableCollection<BikeStation> _arrivalStations;
    private ObservableCollection<BikeStation> _departureStations;
    private BikeCoordinate _departure;
    private BikeCoordinate _arrival;
    private BikeRoute _currentRoute;
    private BikeStation _currentStation;
    private double _zoom;

    #endregion

    #region public properties
    /// <summary>
    /// Collection of stations near the arrival place
    /// </summary>
    public ObservableCollection<BikeStation> ArrivalStations
    {
      get
      {
        if (_arrivalStations == null)
        {
          _arrivalStations = new ObservableCollection<BikeStation>();
        }
        return _arrivalStations;
      }
      set
      {
        _arrivalStations = value;
        OnPropertyChanged("ArrivalStations");
      }
    }

    /// <summary>
    /// Collection of stations near the departure place
    /// </summary>
    public ObservableCollection<BikeStation> DepartureStations
    {
      get
      {
        if (_departureStations == null)
        {
          _departureStations = new ObservableCollection<BikeStation>();
        }
        return _departureStations;
      }
      set
      {
        _departureStations = value;
        OnPropertyChanged("DepartureStations");
      }
    }

    /// <summary>
    /// Location of the arival place. We have to ignore it because of the serialization problems of GeoCoordinate class.
    /// </summary>
    public BikeCoordinate Departure
    {
      get
      {
        return _departure;
      }
      set
      {
        _departure = value;
        OnPropertyChanged("Departure");
      }
    }

    /// <summary>
    /// Location of the arival place. 
    /// </summary>
    public BikeCoordinate Arrival
    {
      get
      {
        return _arrival;
      }
      set
      {
        _arrival = value;
        OnPropertyChanged("Arrival");
      }
    }

    /// <summary>
    /// Current selected statio
    /// </summary>
    public BikeStation CurrentStation
    {
      get { return _currentStation; }
      set
      {
        if (value != _currentStation)
        {
          _currentStation = value;
          OnPropertyChanged("CurrentStation");
        }
      }
    }

    /// <summary>
    /// Selected route
    /// </summary>
    public BikeRoute CurrentRoute
    {
      get
      {
        return _currentRoute;
      }
      set
      {
        if (_currentRoute != value)
        {
          _currentRoute = value;
          OnPropertyChanged("CurrentRoute");
        }
      }
    }

    /// <summary>
    /// Current zoom
    /// </summary>
    public double Zoom
    {
      get { return _zoom; }
      set
      {
        var coercedZoom = Math.Max(BikeConst.MinZoomLevel, Math.Min(BikeConst.MaxZoomLevel, value));
        if (_zoom != coercedZoom)
        {
          _zoom = value;
          OnPropertyChanged("Zoom");
        }
      }
    }
    #endregion

    #region INotifyPropertyChanged Members

    public event PropertyChangedEventHandler PropertyChanged;

    protected virtual void OnPropertyChanged(string propertyName)
    {
      PropertyChangedEventHandler handler = this.PropertyChanged;
      if (handler != null)
      {
        var e = new PropertyChangedEventArgs(propertyName);
        handler(this, e);
      }
    }

    #endregion
  }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Junior) OCTO Technology
Czech Republic Czech Republic
Writing software at ITG RFQ-hub.
LinkedIn
Blog
GitHub
Articles at OCTO blog

Comments and Discussions