void service_SearchResultUpdate(ServiceController sender) { searchResultsMapLayer.Children.Clear(); IList<Location> locations = new List<Location>(); for (int x = 0; x < sender.SearchResults.Count; x++) { GeocodeService.GeocodeResult res = sender.SearchResults[x]; Pushpin pin = new Pushpin(); pin.Location = res.Locations[0]; pin.Tag = res.DisplayName; locations.Add(pin.Location); ToolTipService.SetToolTip(pin, res.DisplayName); searchResultsMapLayer.Children.Add(pin); } if (locations.Count > 0) { //If Search results were found, use the bounding area of the results OpenDataMap.SetView(new LocationRect(locations)); } }
public MainPage() { InitializeComponent(); BirdseyeMode.AddModeToNavigationBar(OpenDataMap); txtTitle.Text = ((App)Application.Current).appName; Uri baseUri = new Uri(((App)Application.Current).pageRootUrl); BaseURL = ((App)Application.Current).pageRootUrl; Service = new ServiceController(BaseURL); Service.SearchResultUpdate += new SearchResultUpdateEventHandler(service_SearchResultUpdate); Service.User.AuthUpdate += new AuthUpdateEventHandler(User_AuthUpdate); Service.Feeds.FeedUpdate += new FeedUpdateEventHandler(Feeds_FeedUpdate); Service.Summaries.SummaryDeleted += new SummaryDeletedEventHandler(Summaries_SummaryDeleted); // Easter egg! This is my house! Location loc = new Location(49.208882, -122.814293); OpenDataMap.AnimationLevel = AnimationLevel.Full; OpenDataMap.SetView(loc, 4);// TODO: attach this to Vancouver Data ( 4 zoom level ) OpenDataMap.MousePan += new EventHandler<MapMouseDragEventArgs>(OpenDataMap_MousePan); _pointDataView = new PointDataView(); _pointDataView.MainPage = this; userControlMapLayer.AddChild(_pointDataView, loc); _pointDataView.Summary = Service.Summaries; _pointDataView.User = Service.User; this.currentUserBadge.twitterImage.MouseLeftButtonUp += TwitterImage_MouseLeftButtonUp; this.currentUserBadge.twitterText.MouseLeftButtonUp += TwitterImage_MouseLeftButtonUp; #region Advanced Search Component Wire-ups Messenger.Default.Register<object>(this, NotificationTokens.GetMapDetails, e => { ApplicationIdCredentialsProvider credProvider = App.Current.Resources["MyCredentials"] as ApplicationIdCredentialsProvider; string culture = OpenDataMap.Culture; Credentials creds = new Credentials() { ApplicationId = credProvider.ApplicationId }; LocationRect rect = OpenDataMap.BoundingRectangle; MapDetails mapDetails = new MapDetails(creds, culture, rect); Messenger.Default.Send<MapDetails>(mapDetails, NotificationTokens.SendMapDetails); }); Messenger.Default.Register<MapItemsControl>(this, e => { searchResultsMapLayer.Children.Clear(); searchResultsMapLayer.Children.Add(e); // TODO: zoom to bounding rect of all added items. RaisePropertyChanged("OpenDataMap"); }); Messenger.Default.Register<Location>(this, (e) => { searchResultsMapLayer.Children.Clear(); Pushpin pin = new Pushpin(); searchResultsMapLayer.AddChild(pin, e); OpenDataMap.SetView(e, 12); RaisePropertyChanged("OpenDataMap"); }); #endregion // We need to receive the Twitter js callback message HtmlPage.RegisterScriptableObject("Page", this); }