Example #1
0
        /// <summary>
        /// Initialize the DotSpatial plugin
        /// </summary>
        public override void Activate()
        {
            // Add Menu or Ribbon buttons.
            AddButtons();

            //Create the tile manager
            _tileManager = new TileManager();

            //Add handlers for saving/restoring settings
            App.SerializationManager.Serializing += SerializationManagerSerializing;
            App.SerializationManager.Deserializing += SerializationManagerDeserializing;
            App.SerializationManager.NewProjectCreated += SerializationManagerNewProject;

            //EnsureMapProjectionIsWebMercator();

            //Setup the background worker
            _bw = new BackgroundWorker { WorkerSupportsCancellation = true, WorkerReportsProgress = true };
            _bw.DoWork += BwDoWork;
            _bw.RunWorkerCompleted += BwRunWorkerCompleted;
            _bw.ProgressChanged += BwProgressChanged;

            base.Activate();
        }
Example #2
0
        private void EnableBasemapFetching(string tileServerName, string tileServerUrl)
        {
            ProjectionInfo webMerc = KnownCoordinateSystems.Projected.World.WebMercator;

            // Zoom out as much as possible if there are no other layers.
            //reproject any existing layer in non-webMercator projection.
            //if (App.Map.Layers.Count == 0 || App.Map.Projection != webMerc)
            if (App.Map.Layers.Count == 0)
            {
                ForceMaxExtentZoom();
            }
            else if (!App.Map.Projection.Equals(webMerc))
            {
                //get original view extents
                App.ProgressHandler.Progress(String.Empty, 0, "Reprojecting Map Layers...");
                double[] viewExtentXY = new[] { App.Map.ViewExtents.MinX, App.Map.ViewExtents.MinY, App.Map.ViewExtents.MaxX, App.Map.ViewExtents.MaxY };
                double[] viewExtentZ = new[] { 0.0, 0.0 };

                //reproject view extents
                Reproject.ReprojectPoints(viewExtentXY, viewExtentZ, App.Map.Projection, webMerc, 0, 2);

                //set the new map extents
                App.Map.ViewExtents = new Extent(viewExtentXY);

                //if projection is not WebMercator - reproject all layers:
                MapFrameProjectionHelper.ReprojectMapFrame(App.Map.MapFrame, webMerc.ToEsriString());

                App.ProgressHandler.Progress(String.Empty, 0, "Loading Basemap...");
            }

            // Special case for WMS
            WmsServerInfo wmsServerInfo = null;
            if (tileServerName.Equals(Properties.Resources.WMSMap, StringComparison.InvariantCultureIgnoreCase))
            {
                using (var wmsDialog = new WMSServerParameters())
                {
                    if (wmsDialog.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }
                    wmsServerInfo = wmsDialog.WmsServerInfo;
                }
            }

            // Other is a custom service
            if (tileServerName.Equals(Other, StringComparison.InvariantCultureIgnoreCase))
            {
                tileServerUrl = Interaction.InputBox("Please provide the Url for the service.",
                                                     DefaultResponse: "http://tiles.virtualearth.net/tiles/h{key}.jpeg?g=461&mkt=en-us&n=z");

                // Let the user cancel...
                if (String.IsNullOrWhiteSpace(tileServerUrl))
                    return;
            }

            EnableBasemapLayer();

            _tileManager = new TileManager(tileServerName, tileServerUrl, wmsServerInfo);

            if (_bw.IsBusy != true)
            {
                _bw.RunWorkerAsync();
            }
            else
                _bw.CancelAsync();
        }
Example #3
0
        private void EnableBasemapFetching(ServiceProvider provider)
        {
            // Zoom out as much as possible if there are no other layers.
            // reproject any existing layer in non-webMercator projection.
            if (App.Map.Layers.Count == 0)
            {
                ForceMaxExtentZoom();
            }
            else if (!App.Map.Projection.Equals(WebMercProj))
            {
                //get original view extents
                App.ProgressHandler.Progress(String.Empty, 0, "Reprojecting Map Layers...");
                double[] viewExtentXY = { App.Map.ViewExtents.MinX, App.Map.ViewExtents.MinY, App.Map.ViewExtents.MaxX, App.Map.ViewExtents.MaxY };
                double[] viewExtentZ = { 0.0, 0.0 };

                //reproject view extents
                Reproject.ReprojectPoints(viewExtentXY, viewExtentZ, App.Map.Projection, WebMercProj, 0, 2);

                //set the new map extents
                App.Map.ViewExtents = new Extent(viewExtentXY);

                //if projection is not WebMercator - reproject all layers:
                App.Map.MapFrame.ReprojectMapFrame(WebMercProj);

                App.ProgressHandler.Progress(String.Empty, 0, "Loading Basemap...");
            }


            EnableBasemapLayer();
            _tileManager = new TileManager(provider);
            RunOrCancelBW();
        }