Prototype.cs :  » GIS » DeepEarth » DeepEarthPrototype » Behaviors » 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 » DeepEarthPrototype » Behaviors » Prototype.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.Windows;
using System.Windows.Input;

using DeepEarth;
using DeepEarth.Geometry;
using DeepEarthPrototype.Controls;

namespace DeepEarthPrototype.Behaviors{
    public class Prototype 
    {
        private Map _Map;
        private bool isMouseDown;
        private bool isMouseDrag;
        private GeometryLayer shapeLayer;

        public Prototype(Map map) 
        {
            _Map = map;
            map.Events.MapMouseUp += this.MouseUp;
            map.Events.MapMouseDown += this.MouseDown;
            map.Events.MapMouseMove += this.MouseMove;
            map.Events.MapKeyDown += Events_MapKeyDown;
            map.Events.MapKeyUp += Events_MapKeyUp;
        }



        bool _IsAKeyDown = false;
        void Events_MapKeyDown(Map map, KeyEventArgs args)
        {
            if (args.Key == Key.A) _IsAKeyDown = true;
        }
        void Events_MapKeyUp(Map map, KeyEventArgs args)
        {
            if (args.Key == Key.A) _IsAKeyDown = false;
        }

        private void MouseDown(Map map, MouseButtonEventArgs args)
        {
            if (Keyboard.Modifiers == ModifierKeys.Shift)
            {
                args.Handled = true;
                isMouseDown = true;
                isMouseDrag = false;
            }
        }

        private void MouseMove(Map map, MouseEventArgs args)
        {
            if (isMouseDown)
            {
                isMouseDrag = true;
            }
        }

        private void MouseUp(Map map, MouseButtonEventArgs args)
        {
            if (isMouseDown && !isMouseDrag)
            {
                Point coord = map.CoordHelper.PixelToGeo(args.GetPosition(map));

                if (shapeLayer == null)
                {
                    ///TODO: RoadWarrior, to demo this, create a subclass of ShapeLayer for specialty behavior.
                    //shapeLayer = new ShapeLayer(map)
                    //{
                    //    ID = "PROTOTYPE",
                    //    InfoBoxOffset = new Point(-20, 0),
                    //    InfoBoxContentProvider = (shape, callback) =>
                    //    {
                    //        var pin = (PointBase)shape;
                    //        var point = pin.Point;
                    //        var description = string.Format("Created point at {0:N6}, {1:N6}", point.X, point.Y);
                    //        callback(description);
                    //    }
                    //};
                    shapeLayer = new GeometryLayer(map){ID = "PROTOTYPE"};

                    map.Layers.Add(shapeLayer);

                    //create the info box
          //infoBox = new InfoBox();
          //shapeLayer.Shapes.Add(infoBox);
          //infoBox.HideInfoBox();  // initially hide the infobox
                }

                // create the pushpin if the "A" key is held down;  We don't want this behaviour with normal clicks.

                if (_IsAKeyDown)
                {
                    //var pushpin = new Pushpin(shapeLayer) { Point = coord };
                    var pushpin = new Pushpin() { Point = coord };
                    //pushpin.MouseLeftButtonDown += OnPushpinMouseDown;
                    shapeLayer.Add(pushpin);

                    args.Handled = true;
                }
            }

            isMouseDown = false;
            isMouseDrag = false;
        }

        //static void OnPushpinMouseDown(object sender, System.EventArgs e)
        //{
        //    var shape = (GeometryBase)sender;

        //    if (ReferenceEquals(InfoBox.Instance.ActiveShape, shape)) {
        //        InfoBox.HideInfoBox(true);
        //    } else {
        //        InfoBox.ShowInfoBox(shape);
        //    }
        //}

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