NearMapTileSource.cs :  » GIS » DeepEarth » DeepEarth » Client » Services » NearMap » 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 » DeepEarth » Client » Services » NearMap » NearMapTileSource.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.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using DeepEarth.Client.MapControl;
using DeepEarth.Client.MapControl.Layers;

namespace DeepEarth.Client.Services.NearMap{
    public enum NearMapModes
    {
        NearMap
    }
    public class NearMapTileSource : TileSource
    {
        private const int DefaultMaxZoomLevel = 21;
        private const int DefaultTileSize = 256;
        private const string TilePath = "http://www.nearmap.com/maps/hl=en&x={X}&y={Y}&z={Z}&nml=Vert&s=Ga";
        private bool _IsTilesDownloadStarted;
        private NearMapModes _MapMode;

    public string DateMap {get; set;}

        //Constructor Called by XAML instanciation; Wait for MapMode to be set to initialize services
        public NearMapTileSource()
            : base(Map.DefaultInstance, (int)Math.Pow(2, DefaultMaxZoomLevel) * DefaultTileSize,
                   (int)Math.Pow(2, DefaultMaxZoomLevel) * DefaultTileSize,
                   DefaultTileSize,
                   DefaultTileSize,
                    0)
        {
            
        }

        public NearMapTileSource(NearMapModes mode)
            : base(Map.DefaultInstance, (int)Math.Pow(2, DefaultMaxZoomLevel) * DefaultTileSize,
                (int)Math.Pow(2, DefaultMaxZoomLevel) * DefaultTileSize,
                DefaultTileSize,
                DefaultTileSize,
                0)
        {
            MapMode = mode;
        }

        public NearMapModes MapMode
        {
            get { return _MapMode; }
            set
            {
                if (_IsTilesDownloadStarted)
                {
                    throw new InvalidOperationException();
                }

                _MapMode = value;
                ID = value.ToString();
                MaxZoomLevel = DefaultMaxZoomLevel;
                _IsInitialized = true;
                if (InitializeCompleted != null) InitializeCompleted(this, null);
            }
        }

        #region TileSource Overrides

        private bool _IsInitialized;

        public override bool IsInitialized
        {
            get { return _IsInitialized; }
        }

        public override Color TileColor
        {
            get
            {
                Color baseColor = Colors.Black;
                switch (_MapMode)
                {
                    case NearMapModes.NearMap:
                        baseColor = Color.FromArgb(0xFF, 0x1A, 0x44, 0x7A);
                        break;
                }
                return baseColor;
            }
        }

        public override Uri GetTile(int tileLevel, int tilePositionX, int tilePositionY)
        {
            if (IsInitialized)
            {
                int zoom = TileToZoom(tileLevel);
                _IsTilesDownloadStarted = true;
                string url = TilePath;

                url = url.Replace("{Z}", zoom.ToString());
                url = url.Replace("{X}", tilePositionX.ToString());
                url = url.Replace("{Y}", tilePositionY.ToString());
        if (!string.IsNullOrEmpty(DateMap))
        {
          url = url + "&nmd=" + DateMap;
        }
                return new Uri(url);
            }
            return null;
        }

        public override event EventHandler InitializeCompleted;

        #endregion

        public override UIElement GetCopyright()
        {
            const string logoPath = "http://a1.twimg.com/profile_images/472103490/Nearmap-arrow_normal.jpg";
            var link = new HyperlinkButton { TargetName = "_blank", NavigateUri = new Uri("http://www.nearmap.com/legal/licence.aspx") };
            ToolTipService.SetToolTip(link, "Copyright NearMap");
            link.Content = new Image { Source = new BitmapImage(new Uri(logoPath)), Height = 48, Width = 48 };
            return link;
        }
    }
}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.