ThinkGeo Cloud
ThinkGeo UI Controls
ThinkGeo Open Source
Help and Support
External Resources
ThinkGeo Cloud
ThinkGeo UI Controls
ThinkGeo Open Source
Help and Support
External Resources
using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Linq; using System.Windows; namespace PopupOverlay { /// <summary> /// Interaction logic for App.xaml /// </summary> public partial class App : Application { } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Collections.ObjectModel; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.WpfDesktopEdition; using System.Globalization; using System.Windows.Navigation; using System.IO; //using LabelingExample.UserControls; namespace PopupOverlay { /// <summary> /// Interaction logic for TestWindow.xaml /// </summary> public partial class TestWindow : Window { Collection<Feature> selectedFeatures; public TestWindow() { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { //Intructions: InstructionLabel.Text = "Click on a state to see its population in popup. You can edit by typing in the popup and press enter to commit the edit."; //Sets the unit of the map to Decimal Degrees because it is in Geodetic. wpfMap1.MapUnit = GeographyUnit.DecimalDegree; //Loads the Decimal Degrees version of the World Map Kit by setting the projection property. WorldMapKitWmsWpfOverlay worldMapKitOverlay = new WorldMapKitWmsWpfOverlay(); worldMapKitOverlay.Projection = WorldMapKitProjection.DecimalDegrees; wpfMap1.Overlays.Add("WorldOverlay", worldMapKitOverlay); //Adds the PopupOverlay to the overlay collection of the wpf map. ThinkGeo.MapSuite.WpfDesktopEdition.PopupOverlay popupOverlay = new ThinkGeo.MapSuite.WpfDesktopEdition.PopupOverlay(); wpfMap1.Overlays.Add("PopupOverlay", popupOverlay); wpfMap1.CurrentExtent = new RectangleShape(-115,45,-70,35); wpfMap1.Refresh(); } private void wpfMap1_MapClick(object sender, MapClickWpfMapEventArgs e) { ShapeFileFeatureLayer statesLayer = new ShapeFileFeatureLayer(@"..\..\Data\USStates.shp"); //Gets the features where the user clicked on. statesLayer.Open(); selectedFeatures = statesLayer.QueryTools.GetFeaturesContaining(e.WorldLocation, ReturningColumnsType.AllColumns); statesLayer.Close(); //Shows on the Popup the population of the state clicked on. if (selectedFeatures.Count > 0) { ThinkGeo.MapSuite.WpfDesktopEdition.PopupOverlay popupOverlay = (ThinkGeo.MapSuite.WpfDesktopEdition.PopupOverlay)wpfMap1.Overlays["PopupOverlay"]; //Sets the location of the Popup where the user clicked on the map. Popup popup = new Popup(e.WorldLocation); //Adds a TextBox to the Popup. TextBox displayer = new TextBox(); //Event for getting the text typed in the TextBox. displayer.KeyDown +=new KeyEventHandler(displayer_KeyDown); displayer.Text = selectedFeatures[0].ColumnValues["POP1990"]; popup.Content = displayer; popup.Background = new SolidColorBrush(Color.FromRgb(255, 0, 0)); //Clears existing Popups and add the new one to the PopupOverlay. popupOverlay.Popups.Clear(); popupOverlay.Popups.Add(popup); popupOverlay.Refresh(); } } //Updates the "Pop1990" column of the selected feature based on the data entered in the Popup. void displayer_KeyDown(object sender, KeyEventArgs e) { //When pressing Enter key, updates the selected feature with the new value for Population. if (e.Key == Key.Return) { //Updates the column "Pop1990" with the value added in the Popup for the selected feature. ThinkGeo.MapSuite.WpfDesktopEdition.PopupOverlay popupOverlay = (ThinkGeo.MapSuite.WpfDesktopEdition.PopupOverlay)wpfMap1.Overlays["PopupOverlay"]; TextBox textBox = (TextBox)popupOverlay.Popups[0].Content; Feature updatedFeature = selectedFeatures[0]; updatedFeature.ColumnValues["POP1990"] = textBox.Text; //Edits the shapefile. Make sure to open the shapefile as Read and Write mode. ShapeFileFeatureLayer statesLayer = new ShapeFileFeatureLayer(@"..\..\Data\USStates.shp", ShapeFileReadWriteMode.ReadWrite); statesLayer.Open(); statesLayer.EditTools.BeginTransaction(); statesLayer.EditTools.Update(selectedFeatures[0]); statesLayer.EditTools.CommitTransaction(); statesLayer.Close(); } } private void wpfMap1_MouseMove(object sender, MouseEventArgs e) { //Gets the PointShape in world coordinates from screen coordinates. Point point = e.MouseDevice.GetPosition(null); ScreenPointF screenPointF = new ScreenPointF((float)point.X, (float)point.Y); PointShape pointShape = ExtentHelper.ToWorldCoordinate(wpfMap1.CurrentExtent, screenPointF, (float)wpfMap1.Width, (float)wpfMap1.Height); textBox1.Text = "X: " + Math.Round(pointShape.X) + " Y: " + Math.Round(pointShape.Y); } } }