示例#1
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
            if (tileServerName.Equals(Properties.Resources.WMSMap, StringComparison.InvariantCultureIgnoreCase))
            {
                using (var wmsDialog = new WMSServerParameters())
                {
                    if (wmsDialog.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }
                    _tileManager.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.ChangeService(tileServerName, tileServerUrl);

            if (_bw.IsBusy != true)
            {
                _bw.RunWorkerAsync();
            }
        }