Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading;
using System.Threading.Tasks;
using Windows.Devices.Geolocation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Services.Maps;
using Windows.Storage.Streams;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Maps;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236

namespace SmartCharging
{
    public sealed partial class MapAddressSelectorControl : UserControl
    {   

       private DispatcherTimer townTextBoxTimer = new DispatcherTimer();
       private DispatcherTimer addressTextBoxTimer = new DispatcherTimer();
       public MapLocation siteLocation { get; private set; }

       public event PropertyChangedEventHandler PropertyChanged;
       private MapLocation _townLocation;
       public MapLocation townLocation
       {
           get { return _townLocation; }
           set
           {
               _townLocation = value;
               NotifyPropertyChanged("townLocation");
           }
       } 

        public MapAddressSelectorControl()
        {
            this.InitializeComponent();
            townTextBoxTimer.Tick += TownTextbox_TimerEventHandler;
            townTextBoxTimer.Interval = new TimeSpan(0, 0, 0, 2);

            addressTextBoxTimer.Tick += AddressTextbox_TimerEventHandler;
            addressTextBoxTimer.Interval = new TimeSpan(0, 0, 0, 2);
            this.GridContainer.DataContext = this;
            this.AddressTextbox.DataContext = this;
           
        }



        private void CityListItem_Tapped(object sender, TappedRoutedEventArgs e)
        {
            CitySelectionFlyout.Hide();
            MapLocation mapLocation = ((sender as Control).DataContext as MapLocation);
            this.townLocation = mapLocation;
            MapControl.Center = mapLocation.Point;
            MapControl.ZoomLevel = 5;
            this.AddressTextbox.IsEnabled = true;
            

        }

        private void AddressListItem_Tapped(object sender, TappedRoutedEventArgs e)
        {
            this.AddressSelectionFlyout.Hide();
            MapLocation mapLocation = ((sender as Control).DataContext as MapLocation);
            this.siteLocation = mapLocation;

            MapIcon MapIcon1 = new MapIcon();
            MapIcon1.Location = mapLocation.Point;
            MapIcon1.NormalizedAnchorPoint = new Point(1.0, 0.5);
            MapIcon1.Visible = true;
            MapIcon1.ZIndex = int.MaxValue;
            MapIcon1.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/position.png"));
            MapControl.MapElements.Clear();
            MapControl.MapElements.Add(MapIcon1);

            MapControl.Center = mapLocation.Point;
            MapControl.ZoomLevel = 15;
        }



        private void TownTextbox_TextChanged(object sender, TextChangedEventArgs e)
        {
            townTextBoxTimer.Stop();
            townTextBoxTimer.Start();
            
        }

        private void AddressTextbox_TextChanged(object sender, TextChangedEventArgs e)
        {
            addressTextBoxTimer.Stop();
            addressTextBoxTimer.Start();
        }

        private async void TownTextbox_TimerEventHandler(object sender, object e)
        {
            string searchString = this.TownTextBox.Text;

            if (searchString.Length >= 3) {
                townTextBoxTimer.Stop();
                MapLocationFinderResult result = await this.GetLocationByString(searchString, null);
                if (result.Status == MapLocationFinderStatus.Success)
                {
                    List<MapLocation> locations = new List<MapLocation>();
                    foreach (MapLocation mapLocation in result.Locations)
                    {
                        if (mapLocation.Address.Town.Contains(searchString))
                            locations.Add(mapLocation);
                    }
                    // Bind the location list to the ListView control.

                    CityList.ItemsSource = locations;
                    FlyoutBase.ShowAttachedFlyout((FrameworkElement)this.TownTextBox);
                }
                else
                {
                    // Tell the user to try again.
                }
            }
            

        }


        private async void AddressTextbox_TimerEventHandler(object sender, object e)
        {
            string searchString = this.AddressTextbox.Text;

            if (searchString.Length >= 3)
            {
                addressTextBoxTimer.Stop();
                MapLocationFinderResult result = await this.GetLocationByString(searchString, this.townLocation.Point);
                if (result.Status == MapLocationFinderStatus.Success)
                {
                    List<MapLocation> locations = new List<MapLocation>();
                    foreach (MapLocation mapLocation in result.Locations)
                    {
                     
                        locations.Add(mapLocation);
                    }
                    // Bind the location list to the ListView control.

                    AddressList.ItemsSource = locations;
                    FlyoutBase.ShowAttachedFlyout((FrameworkElement)this.AddressTextbox);
                }
                else
                {
                    // Tell the user to try again.
                }
            }


        }

        private async Task<MapLocationFinderResult> GetLocationByString(string location, Geopoint startingPosition){
           

            MapLocationFinderResult result = await MapLocationFinder.FindLocationsAsync(location, startingPosition, 50);

            return result;
        }

        public void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this,
                    new PropertyChangedEventArgs(propertyName));
            }
        }



 

       

        
    }
}

Commits for Nextrek/Android/SmartCharging/SmartCharging_WP/SmartCharging/MapAddressSelectorControl.xaml.cs

Diff revisions: vs.
Revision Author Commited Message
691 JMBauan picture JMBauan Sat 05 Sep, 2015 18:08:58 +0000

location selector