private void FlickrRequest_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { if (e.Error != null) { MessageBox.Show(e.Error.Message); } else { this.FeatureSets.Remove(flickrsSet); FlickrResult frResult = FlickrResult.Deserialize(e.Result); flickrsSet = new GeoFeatureCollection("title,photoUrl,ownerName,dateTaken", "Title,Photo,Owner,Date", "title", "Flickr"); if (frResult != null && frResult.photoPage != null && frResult.photoPage.photos != null) { foreach (FlickrPhoto item in frResult.photoPage.photos) { Graphic graphic = new Graphic(); graphic.Geometry = (new MapPoint(item.longitude, item.latitude, new SpatialReference(4326))).GeographicToWebMercator(); graphic.Attributes.Add("title", item.title); graphic.Attributes.Add("photoUrl", item.photoUrl); graphic.Attributes.Add("ownerName", item.ownerName); graphic.Attributes.Add("dateTaken", item.dateTaken); graphic.Symbol = flickrSymbol; graphic.MapTip = flickrTipTemplate; graphicsLayer.Graphics.Add(graphic); flickrsSet.Add(graphic); } this.FeatureSets.Add(flickrsSet); this.ToggleWidgetContent(1); } } this.IsBusy = false; }
private void TwitterRequest_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { if (e.Error != null) { MessageBox.Show(e.Error.Message); } else { this.FeatureSets.Remove(twitterSet); TwitterResult twResult = TwitterResult.Deserialize(e.Result); twitterSet = new GeoFeatureCollection("title,photoUrl,authorUri,content", "Title,Photo,Author,Content", "title", "Tweets"); if (twResult != null) { foreach (TweetItem item in twResult.items) { Graphic graphic = new Graphic(); graphic.Geometry = (new MapPoint(item.geoLocation.x, item.geoLocation.y, new SpatialReference(4326))).GeographicToWebMercator(); graphic.Attributes.Add("title", item.author.authorName); graphic.Attributes.Add("photoUrl", item.authorLinks[1].linkUrl); graphic.Attributes.Add("authorUri", item.author.authorUri); graphic.Attributes.Add("content", item.content); graphic.Symbol = twitterSymbol; graphic.MapTip = twitterTipTemplate; graphicsLayer.Graphics.Add(graphic); twitterSet.Add(graphic); } this.FeatureSets.Add(twitterSet); this.ToggleWidgetContent(1); } } this.IsBusy = false; }
private void Query_ResultReady(object sender, QueryResultEventArgs args) { this.ClearGraphics(2); // Toggle to Results Panel if (args.Results != null && args.Results.Features.Count > 0) { isFirstLoad = true; // Suppress filter results by map extent or pan map QueryResultMessage.Visibility = Visibility.Collapsed; FeatureSet fset = args.Results; Symbol symbol = ChooseSymbol(fset.GeometryType.ToString(), false); GeoFeatureCollection dataset = new GeoFeatureCollection(args.QueryLayer.OutputFields, args.QueryLayer.OutputLabels, fset.DisplayFieldName, args.QueryLayer.Title); foreach (Graphic feature in fset.Features) { feature.Symbol = symbol; feature.Geometry.SpatialReference = fset.SpatialReference; this.GraphicsLayer.Graphics.Add(feature); dataset.Add(feature); } this.FeatureSets.Add(dataset); this.GraphicsTipTemplate = args.QueryLayer.MapTipTemplate; this.MapControl.ZoomTo(GeometryTool.ExpandGeometryExtent(this.GraphicsLayer.FullExtent, 0.25)); } else { QueryResultMessage.Visibility = Visibility.Visible; QueryResultMessage.Text = string.Format("Sorry! {0}", (string.IsNullOrEmpty(args.ErrorMsg)) ? "No features are found." : args.ErrorMsg); } this.IsBusy = false; }
private void SubmitReportButton_Click(object sender, RoutedEventArgs e) { if (lstGraphicWidget.SelectedIndex == -1) { MessageBox.Show("Please select a widget with selected graphic", "Message", MessageBoxButton.OK); return; } double bufferDistance = 0; if (!double.TryParse(txtBufferDistance.Text, out bufferDistance)) { MessageBox.Show("Buffer distance is invalid. Please input a valid number", "Message", MessageBoxButton.OK); return; } string widgetTitle = (string)lstGraphicWidget.SelectedItem; WidgetBase widget = WidgetManager.FindWidgetByTitle(widgetTitle); Graphic centerGraphic = widget.SelectedGraphic; GeoFeatureCollection dataset = widget.FindFeatureSetWithSelection(); string displayField = (dataset != null) ? dataset.DisplayFieldName : ""; string featureLayer = (dataset != null) ? dataset.FeatureLayerName : ""; if (centerGraphic.Attributes.ContainsKey("Address")) //Locator { addressValue = (string)centerGraphic.Attributes["Address"]; } else if (centerGraphic.Attributes.ContainsKey(displayField)) { addressValue = (string)centerGraphic.Attributes[displayField]; } if (bufferDistance > 0) { this.IsBusy = true; string bufUnits = (string)(lstBufferUnits.SelectedItem as ComboBoxItem).Content; locationName = string.Format("{0} {1} around {2}", txtBufferDistance.Text, bufUnits.ToLower(), featureLayer); CreateBufferZone(bufferDistance, centerGraphic, bufUnits, locationName); } else if (centerGraphic.Geometry is Polygon) { this.IsBusy = true; centerGraphic.Geometry.SpatialReference = new SpatialReference(this.MapSRWKID); locationName = string.Format("Within {0}", featureLayer); centerGraphic.Attributes.Add("AREA_ID", locationName); AuthenticateUser(centerGraphic); } }
/// <summary> /// Remove a dataset from the Grid /// </summary> protected virtual void RemoveDataset(GeoFeatureCollection dataset) { if (this.LeftWindow != null && dataset != null) { StackPanel leftStack = this.LeftWindow as StackPanel; UIElement valueStack = leftStack.Children.FirstOrDefault(child => (child as StackPanel).Tag == dataset); if (valueStack != null) { int k = leftStack.Children.IndexOf(valueStack); if (k > 0) // { leftStack.Children.RemoveAt(k); // Remove Value Stack leftStack.Children.RemoveAt(k - 1); // Remove Title Stack } } } }
/// <summary> /// Select a Graphic item and show its attributes /// </summary> /// <param name="graphic">The graphic be selected</param> public void SelectItem(Graphic graphic) { bool found = false; if (this.LeftWindow is StackPanel) { StackPanel leftStack = this.LeftWindow as StackPanel; SimpleLinkButton linkOld = leftStack.Tag as SimpleLinkButton; if (linkOld != null) { linkOld.IsActive = false; } for (int i = 0; i < leftStack.Children.Count / 2; i++) { StackPanel titleStack = leftStack.Children[i * 2] as StackPanel; StackPanel valueStack = leftStack.Children[(i * 2) + 1] as StackPanel; GeoFeatureCollection dataset = valueStack.Tag as GeoFeatureCollection; foreach (SimpleLinkButton link in valueStack.Children) { if (link.Tag == graphic) { leftStack.Tag = link; link.IsActive = true; this.SelectedItem = graphic; FillDataInRightWindow(graphic, dataset); found = true; break; } } if (!found) { ToggleButton toggler = titleStack.Children[0] as ToggleButton; if (valueStack.Visibility == Visibility.Visible) { ToggleLeftFeatureList(toggler); } } } } }
private void YouTubeRequest_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { if (e.Error != null) { MessageBox.Show(e.Error.Message); } else { this.FeatureSets.Remove(youtubeSet); YouTubeResult ytResult = YouTubeResult.Deserialize(e.Result); youtubeSet = new GeoFeatureCollection("title,thumbnail,description,publishDate,playerUrl", "Title,Thumbnail,Description,Publish Date,Player Url", "title", "YouTube"); if (ytResult != null) { foreach (YouTubeItem ytItem in ytResult.items) { Graphic graphic = new Graphic(); graphic.Geometry = (new MapPoint(ytResult.items[0].geometry.rssPoint.x, ytResult.items[0].geometry.rssPoint.y, new SpatialReference(4326))).GeographicToWebMercator(); graphic.MouseLeftButtonDown += new MouseButtonEventHandler(YouTube_MouseLeftButtonDown); graphic.Attributes.Add("title", ytItem.media.title); graphic.Attributes.Add("thumbnail", ytItem.media.thumbnail[1].url); //hddefault.jpg (480 x 360) graphic.Attributes.Add("aspectRatio", ytItem.media.aspectRatio); graphic.Attributes.Add("description", ytItem.media.description); graphic.Attributes.Add("publishDate", ytItem.media.publishDate); graphic.Attributes.Add("contentUrl", ytItem.media.content[0].source); graphic.Attributes.Add("playerUrl", "http://www.youtube.com/watch?v=" + ytItem.media.videoID); graphic.Symbol = youtubeSymbol; graphic.MapTip = youtubeTipTemplate; graphicsLayer.Graphics.Add(graphic); youtubeSet.Add(graphic); } this.FeatureSets.Add(youtubeSet); this.ToggleWidgetContent(1); } } this.IsBusy = false; }
private void LeftFeatureLink_Click(object sender, RoutedEventArgs e) { if (sender is SimpleLinkButton) { StackPanel leftStack = this.LeftWindow as StackPanel; SimpleLinkButton leftLinkOld = leftStack.Tag as SimpleLinkButton; if (leftLinkOld != null) { leftLinkOld.IsActive = false; } SimpleLinkButton leftLinkNew = sender as SimpleLinkButton; leftStack.Tag = leftLinkNew; leftLinkNew.IsActive = true; StackPanel valueStack = leftLinkNew.Parent as StackPanel; GeoFeatureCollection dataset = valueStack.Tag as GeoFeatureCollection; this.SelectedItem = (Graphic)leftLinkNew.Tag; FillDataInRightWindow(this.SelectedItem, dataset); OnSelectedItemChange(new SelectedItemChangeEventArgs(this.SelectedItem)); } }
private void AddGeoRSSGraphics(List <GeoRSSItem> rssItems) { if (this.GraphicsLayer == null) { MessageBox.Show("GraphicsLayer for this widget is not created. Please set property HasGraphics 'true'."); return; } GeoFeatureCollection dataset = new GeoFeatureCollection("Title", "GeoRSS"); foreach (GeoRSSItem rssItem in rssItems) { Graphic graphic = new Graphic(); graphic.Geometry = rssItem.Geometry; graphic.Symbol = ChooseSymbol(rssItem.Geometry); graphic.Attributes.Add("Title", rssItem.Title); graphic.Attributes.Add("Description", rssItem.Description); graphic.Attributes.Add("PubDate", rssItem.pubDate); graphic.Attributes.Add("Link", rssItem.Link); this.GraphicsLayer.Graphics.Add(graphic); dataset.Add(graphic); } this.FeatureSets.Add(dataset); // Make it available for the Print Widget }
private void IdentifyTask_ExecuteCompleted(object sender, IdentifyEventArgs e) { string mapName = (string)e.UserState; string preName = "^?^"; GeoFeatureCollection features = null; foreach (IdentifyResult result in e.IdentifyResults) { if (result.LayerName != preName) { if (features != null) { this.FeatureSets.Add(features); } AddToGraphicsLayer(result.Feature, (string)result.Value, result.DisplayFieldName, result.LayerName); features = new GeoFeatureCollection(result.DisplayFieldName, result.LayerName, mapName); features.Add(result.Feature); preName = result.LayerName; } else if (features != null) { AddToGraphicsLayer(result.Feature, (string)result.Value, result.DisplayFieldName, result.LayerName); features.Add(result.Feature); } } // Add the last layer results if (features != null) { this.FeatureSets.Add(features); } this.IsBusy = false; }
protected virtual void FillDataInRightWindow(Graphic feature, GeoFeatureCollection dataset) { Grid rightGrid = null; if ((this.RightWindow != null) && (this.RightWindow is Grid)) { rightGrid = this.RightWindow as Grid; rightGrid.Children.Clear(); rightGrid.RowDefinitions.Clear(); rightGrid.ColumnDefinitions.Clear(); } else { rightGrid = new Grid(); this.RightWindow = rightGrid; } if (feature == null) { return; } rightGrid.ColumnDefinitions.Add(new ColumnDefinition()); rightGrid.ColumnDefinitions.Add(new ColumnDefinition()); int k = 0; string value = ""; TextBlock fieldBlock = null; TextBlock valueBlock = null; HyperlinkButton valueLink = null; Dictionary <string, string> fieldAlias = (dataset == null) ? (new Dictionary <string, string>()) : StringHelper.ConvertToDictionary(dataset.OutputFields, dataset.OutputLabels, ','); if (fieldAlias.Count == 0) { foreach (string key in feature.Attributes.Keys) { if (!key.StartsWith("Shape")) { fieldAlias.Add(key, key); } } } foreach (string key in fieldAlias.Keys) { rightGrid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); fieldBlock = new TextBlock() { Text = fieldAlias[key] + ":", FontWeight = FontWeights.Bold, HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(2, 1, 2, 1) }; rightGrid.Children.Add(fieldBlock); Grid.SetColumn(fieldBlock, 0); Grid.SetRow(fieldBlock, k); value = (feature.Attributes.ContainsKey(key) && feature.Attributes[key] != null) ? feature.Attributes[key].ToString() : ""; if (value.StartsWith("http://", StringComparison.CurrentCultureIgnoreCase)) { valueLink = new HyperlinkButton() { FontWeight = FontWeights.Normal, Margin = new Thickness(2, 1, 2, 1) }; valueLink.NavigateUri = new Uri(value); valueLink.TargetName = "_blank"; Grid.SetColumn(valueLink, 1); Grid.SetRow(valueLink, k); if (value.EndsWith(".jpg", StringComparison.CurrentCultureIgnoreCase) || value.EndsWith(".png", StringComparison.CurrentCultureIgnoreCase)) { rightGrid.RowDefinitions[k].Height = new GridLength(160); valueLink.Content = new Image() { Source = new BitmapImage(new Uri(value, UriKind.Absolute)), Height = 160, Stretch = Stretch.Uniform }; } else { valueLink.Content = value; } rightGrid.Children.Add(valueLink); } else { valueBlock = new TextBlock() { FontWeight = FontWeights.Normal, HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(2, 1, 2, 1) }; Grid.SetColumn(valueBlock, 1); Grid.SetRow(valueBlock, k); valueBlock.Text = value; valueBlock.MaxWidth = 300; valueBlock.TextWrapping = TextWrapping.Wrap; rightGrid.Children.Add(valueBlock); } k++; } }
/// <summary> /// Bind a dataset to the Grid /// </summary> protected virtual void BindDataset(GeoFeatureCollection dataset) { if ((dataset != null) && (dataset.Count > 0)) { StackPanel leftStack = null; if ((this.LeftWindow != null) && (this.LeftWindow is StackPanel)) { leftStack = this.LeftWindow as StackPanel; } else { leftStack = new StackPanel() { Orientation = Orientation.Vertical }; this.LeftWindow = leftStack; } StackPanel titleStack = new StackPanel() { Orientation = Orientation.Horizontal, Margin = new Thickness(1, 1, 1, 1) }; StackPanel valueStack = new StackPanel() { Orientation = Orientation.Vertical, Margin = new Thickness(15, 0, 0, 0), Tag = dataset }; // Create a head stack containing a toggle button and a feature layer name block ToggleButton toggler = new ToggleButton() { Tag = valueStack, Width = 16, Height = 14, VerticalAlignment = VerticalAlignment.Top }; toggler.Background = new SolidColorBrush(Colors.Transparent); toggler.Foreground = new SolidColorBrush(Colors.Gray); toggler.MouseOverColor = new SolidColorBrush(Colors.Blue); toggler.Click += new RoutedEventHandler(LeftFeatureListToggler_Click); TextBlock titleText = new TextBlock() { TextWrapping = TextWrapping.Wrap }; titleText.Text = (string.IsNullOrEmpty(dataset.FeatureLayerName)) ? "Unknown Feature" : dataset.FeatureLayerName; if (!string.IsNullOrEmpty(dataset.DataSourceName)) { titleText.Text += "\n(" + dataset.DataSourceName + ")"; } titleStack.Children.Add(toggler); titleStack.Children.Add(titleText); // Create a list stack of display field values string displayValue = ""; SimpleLinkButton valueLink = null; foreach (Graphic feature in dataset) { displayValue = (string)feature.Attributes[dataset.DisplayFieldName]; valueLink = new SimpleLinkButton() { Tag = feature, Cursor = Cursors.Hand, Margin = new Thickness(1, 1, 1, 1) }; valueLink.Text = (string.IsNullOrEmpty(displayValue)) ? "[Empty]" : displayValue; valueLink.Click += new RoutedEventHandler(LeftFeatureLink_Click); valueLink.MouseEnter += new MouseEventHandler(LeftFeatureLink_MouseEnter); valueLink.MouseLeave += new MouseEventHandler(LeftFeatureLink_MouseLeave); valueStack.Children.Add(valueLink); //Select the first one if (SelectedItem == null) { SelectedItem = feature; leftStack.Tag = valueLink; valueLink.IsActive = true; FillDataInRightWindow(feature, dataset); OnSelectedItemChange(new SelectedItemChangeEventArgs(feature)); } } leftStack.Children.Add(titleStack); leftStack.Children.Add(valueStack); this.SelectItem(dataset[0]); } }