GeoServices.xaml.cs :  » GIS » DeepEarth » ExampleControl » Controls » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GIS » DeepEarth 
DeepEarth » ExampleControl » Controls » GeoServices.xaml.cs
/// Deep Earth is a community project available under the Microsoft Public License (Ms-PL)
/// Code is provided as is and with no warrenty  Use at your own risk
/// View the project and the latest code at http://codeplex.com/deepearth/

using System;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media;
using System.Windows.Browser;
using System.Windows.Controls;
using DeepEarth.Client.MapControl;
using DeepEarth.Client.MapControl.Geometry;
using DeepEarth.Client.MapControl.Layers;
using DeepEarth.Client.Services.Bing;

namespace ExampleControl.Controls{
    public partial class GeoServices : ILayer
    {
        //sample layer
        public static string Token;
        private readonly Random _Rand = new Random(DateTime.Now.Second);
        private readonly List<int> _ZOrderBucket = new List<int> {0, 1, 2, 3, 4};
        private bool _DevPinsConfigured;
        private Map _Map;
        private GeometryLayer devPinLayer;
        private GeometryLayer shapeLayer;

        public string ApplicationID { get; set; }

        public GeoServices()
        {
            // Required to initialize variables
            InitializeComponent();
            Loaded += GeoServices_Loaded;
        }

        void GeoServices_Loaded(object sender, RoutedEventArgs e)
        {
            // Test for DesignTime for display in Blend
            if (HtmlPage.IsEnabled)
            {
                _Map = MapInstance;

                GeocodeService = new Geocode(ApplicationID);
                RouteService = new Route(ApplicationID);

                AddPolygon.Click += AddPolygon_Click;
                Rotate.Click += Rotate_Click;
                ZoomToLocation.Click += ZoomToLocation_Click;
                ToggleDevPins.Click += ToggleDevPins_Click;

                MapInstance.Events.MapLoaded += (o, ev) => ConfigureDevPins();
            }
        }

        public Geocode GeocodeService { get; set; }
        public Route RouteService { get; set; }

        public Orientation Orientation
        {
            get { return _OrientationPanel.Orientation; }
            set { _OrientationPanel.Orientation = value; }
        }


        #region ILayer APIs

        public string ID { get; set; }
        public bool IsVisible { get; set; }

        public Map MapInstance
        {
            get
            {
                if (_Map == null) _Map = Map.GetMapInstance(this);
                return _Map;
            }
            set
            {
                if (ReferenceEquals(_Map, value))
                {
                    return;
                }

                _Map = value;
            }
        }

        #endregion

        private void ToggleDevPins_Click(object sender, RoutedEventArgs e)
        {
            if (devPinLayer == null)
            {
                ConfigureDevPins();
            }
            else
            {
                devPinLayer.IsVisible = !devPinLayer.IsVisible;
            }
        }

        private void ConfigureDevPins()
        {
            if (_DevPinsConfigured == false)
            {
                if (devPinLayer == null)
                {
                    devPinLayer = new GeometryLayer(MapInstance) { ID = "DEVPINLAYER" };
                    devPinLayer.UpdateMode = GeometryLayer.UpdateModes.ElementUpdate;
                    MapInstance.Layers.Add(devPinLayer);
                }

                AddPinToLayer(new Point(-77.0365, 38.897), "RoadWarriorPinStyle", devPinLayer);
                AddPinToLayer(new Point(153.430172, -27.998868), "NoobiePinStyle", devPinLayer);
                AddPinToLayer(new Point(153.025, -27.470), "SoulPinStyle", devPinLayer);
                AddPinToLayer(new Point(-83.437448, 42.352317), "SMBeckerPinStyle", devPinLayer);
                AddPinToLayer(new Point(-77.0467, 38.33096), "AquasealPinStyle", devPinLayer);

                
                _DevPinsConfigured = true;
            }
        }

        private void AddPinToLayer(Point location, string styleKey, GeometryLayer layer)
        {
            var pin = new DevPin() { Point = location, Style = (Application.Current.Resources[styleKey] as Style) };
            layer.Add(pin);
            Canvas.SetZIndex(pin, GetNextRandomZ());
        }

        private int GetNextRandomZ()
        {
            int index = _Rand.Next(0, _ZOrderBucket.Count);
            int nextZ = _ZOrderBucket[index];
            _ZOrderBucket.RemoveAt(index);
            return nextZ;
        }

        private void AddPolygon_Click(object sender, RoutedEventArgs e)
        {
            ////Sample Polygons added to the map
            if (shapeLayer == null)
            {
                shapeLayer = new GeometryLayer(MapInstance) { ID = "POLYGONLAYER" };
                shapeLayer.UpdateMode = GeometryLayer.UpdateModes.PanOnlyUpdate; 
                shapeLayer.Opacity = 0.4;

                MapInstance.Layers.Insert(1, shapeLayer);
            }

            var points = new ObservableCollection<Point> { new Point(0, 0), new Point(20, 0), new Point(20, 20), new Point(0, 20) };
            var polygon = new Polygon() { Points = points };
            polygon.Fill = new SolidColorBrush(Colors.Green);
            shapeLayer.Add(polygon);


            var linePoints = new ObservableCollection<Point> { new Point(-88, 42), new Point(-75, 39) };
            LineString line = new LineString() { Points = linePoints };
            line.LineThickness = 4;
            line.LineColor = Colors.White;
            shapeLayer.Add(line);

            //Add points at each end of the 
            shapeLayer.Add(new PointBase { Point = new Point(-88, 42) });
            shapeLayer.Add(new PointBase { Point = new Point(-75, 39) });


        }



        private void Rotate_Click(object sender, RoutedEventArgs e)
        {
            Point center = MapInstance.GeoCenter;
            double zoom = MapInstance.ZoomLevel;
            MapInstance.RotationAngle += -20;
            MapInstance.SetViewCenter(center, zoom);
        }

        private void ZoomToLocation_Click(object sender, RoutedEventArgs e)
        {
            MapInstance.SetViewCenter(new Point(153.02633, -27.47036), 16);
        }


    }
}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.