using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Globalization; using System.Linq; using System.Text; using System.Windows; using System.Windows.Input; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.WpfDesktopEdition; namespace WmsProjectionTest { public enum MapTypes { None = 0, GoogleMap = 1, BingMap = 2 } public class MapControl : WpfMap { //readonly Proj4Projection _projection = new Proj4Projection //{ // InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(27700), // ExternalProjectionParametersString = Proj4Projection.GetBingMapParametersString() //}; public static readonly DependencyProperty MapTypeProperty = DependencyProperty.Register("MapType", typeof(MapTypes), typeof(MapControl), new UIPropertyMetadata( MapTypes.None, OnMapTypePropertyChanged)); private static void OnMapTypePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { //var mapType = (MapTypes)e.NewValue; //var mapControl = (MapControl)d; } public MapTypes MapType { get { return (MapTypes)GetValue(MapTypeProperty); } set { SetValue(MapTypeProperty, value); } } public MapControl() { TrackOverlay = new TrackInteractiveOverlay(); TrackOverlay.TrackEnded -= OnDragEnded; TrackOverlay.TrackEnded += OnDragEnded; TrackOverlay.TrackMode = TrackMode.Rectangle; } //-------------------------------------------------------------------------------- private RectangleShape _extent; public void Clear() { Overlays.Clear(); Refresh(); } InMemoryFeatureLayer selectionLayer; public void AddSource() { MapUnit = GeographyUnit.Meter; BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 198, 255, 255)); var layer = new ShapeFileFeatureLayer(@"ShpFiles\Cardiff_Boundary_region.shp"); layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle(new GeoPen(GeoColor.SimpleColors.Black), new GeoSolidBrush(GeoColor.SimpleColors.Transparent)); layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; Proj4Projection _projection = new Proj4Projection { InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(27700), ExternalProjectionParametersString = Proj4Projection.GetBingMapParametersString() }; _projection.Open(); layer.FeatureSource.Projection = _projection; var staticOverlay = new LayerOverlay() { TransitionEffect = TransitionEffect.None, TileType = TileType.SingleTile }; staticOverlay.Layers.Add("layer", layer); Overlays.Add(staticOverlay); LayerOverlay selectionOverlay = new LayerOverlay { ImageFormat = TileImageFormat.Png }; selectionOverlay.TileType = TileType.SingleTile; var collection = new List { new FeatureSourceColumn("Id") }; selectionLayer = new InMemoryFeatureLayer(collection, new Feature[] { }); selectionLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle(new GeoPen(GeoColor.SimpleColors.Black), new GeoSolidBrush(GeoColor.SimpleColors.Red)); selectionLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; selectionOverlay.Layers.Add("layer1", selectionLayer); Overlays.Add(selectionOverlay); Overlays.MoveToTop(selectionOverlay); layer.Open(); _extent = layer.GetBoundingBox(); layer.Close(); CurrentExtent = _extent; Refresh(); } public void ApplyMap() { var bingMapsOverlay = new BingMapsOverlay("Au9yN0FUHyp5zAoh0zWBjbw81-eSeaiH2J_zTFiCWQ0OYlhYX9i17jR9cnBhQFLJ"); Overlays.Insert(0, "bingMapsOverlay", bingMapsOverlay); Refresh(); } public void DeleteMap() { if (Overlays.Count > 0) Overlays.Remove("bingMapsOverlay"); CurrentExtent = _extent; Refresh(); } private void OnDragEnded(object sender, TrackEndedTrackInteractiveOverlayEventArgs e) { var track = (TrackInteractiveOverlay)sender; try { List features = TrackOverlay.TrackShapeLayer.InternalFeatures.ToList(); foreach (var item in features) { selectionLayer.InternalFeatures.Add(item); } Refresh(); } finally { track.TrackShapeLayer.InternalFeatures.Clear(); } } } }