示例#1
0
        private void radioButton_Click(object sender, EventArgs e)
        {
            Cursor mic = mapBox1.Cursor;

            mapBox1.Cursor = Cursors.WaitCursor;
            Cursor         = Cursors.WaitCursor;

            if (formSqlServerOpts != null)
            {
                formSqlServerOpts.Close();
                formSqlServerOpts = null;
            }

            try
            {
                //mapImage.ActiveTool = MapImage.Tools.None;
                string text = ((RadioButton)sender).Text;

                switch (text)
                {
                case "Shapefile":
                    mapBox1.Map = ShapefileSample.InitializeMap(tbAngle.Value);
                    break;

                case "GradientTheme":
                    mapBox1.Map = GradiantThemeSample.InitializeMap(tbAngle.Value);
                    break;

                case "WFS Client":
                    mapBox1.Map = WfsSample.InitializeMap(tbAngle.Value);
                    break;

                case "WMS Client":
                    //mapBox1.Map = TiledWmsSample.InitializeMap();
                    mapBox1.Map = WmsSample.InitializeMap(tbAngle.Value);
                    break;

                case "OGR - MapInfo":
                case "OGR - S-57":
                    mapBox1.Map = OgrSample.InitializeMap(tbAngle.Value);
                    break;

                case "GDAL - GeoTiff":
                case "GDAL - '.DEM'":
                case "GDAL - '.ASC'":
                case "GDAL - '.VRT'":
                    mapBox1.Map        = GdalSample.InitializeMap(tbAngle.Value);
                    mapBox1.ActiveTool = MapBox.Tools.Pan;
                    break;

                case "TileLayer - OSM":
                case "TileLayer - OSM with XLS":
                case "TileLayer - Bing Roads":
                case "TileLayer - Bing Aerial":
                case "TileLayer - Bing Hybrid":
                case "TileLayer - GoogleMap":
                case "TileLayer - GoogleSatellite":
                case "TileLayer - GoogleTerrain":
                case "TileLayer - GoogleLabels":
                case "Eniro":
                    /*
                     * tbAngle.Visible = text.Equals("TileLayer - GoogleLabels");
                     * if (!tbAngle.Visible) tbAngle.Value = 0;
                     */
                    mapBox1.Map = TileLayerSample.InitializeMap(tbAngle.Value);
                    ((RadioButton)sender).Text           = (mapBox1.Map.BackgroundLayer.Count > 0)
                            ? ((RadioButton)sender).Text = mapBox1.Map.BackgroundLayer[0].LayerName
                            : ((RadioButton)sender).Text = mapBox1.Map.Layers[0].LayerName;
                    break;

                case "PostGis":
                    mapBox1.Map = PostGisSample.InitializeMap(tbAngle.Value);
                    break;

                case "SpatiaLite":
                    mapBox1.Map = SpatiaLiteSample.InitializeMap(tbAngle.Value);
                    break;

                case "SqlServer":
                    // create empty map with BruTile basemap
                    mapBox1.Map = SqlServerSample.InitializeMap(tbAngle.Value);
                    // check conn string
                    var connStrBuilder = new System.Data.SqlClient.SqlConnectionStringBuilder(Properties.Settings.Default.SqlServerConnectionString);
                    if (string.IsNullOrEmpty(connStrBuilder.DataSource) || string.IsNullOrEmpty(connStrBuilder.InitialCatalog))
                    {
                        mapBox1.Refresh();

                        MessageBox.Show("Requires SqlServer connection string to be defined (Project / Settings)",
                                        "Sql Server", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    // now show SqlServer dialog
                    formSqlServerOpts = new FormSqlServerOpts()
                    {
                        MapBox           = mapBox1,
                        ConnectionString = connStrBuilder.ToString()
                    };
                    formSqlServerOpts.Show(this);
                    break;

                case "Oracle":
                    mapBox1.Map = OracleSample.InitializeMap(tbAngle.Value);
                    break;

                case "shp_TextOnPath":
                    mapBox1.Map = TextOnPathSample.InitializeMapOrig(tbAngle.Value);
                    break;

                case "GdiImageLayer":
                    mapBox1.Map = GdiImageLayerSample.InitializeMap(tbAngle.Value);
                    break;

                default:
                    break;
                }

                //Add checked Map decorations
                foreach (ListViewItem checkedItem in lvwDecorations.CheckedItems)
                {
                    Type mdType;
                    if (MapDecorationTypes.TryGetValue(checkedItem.Text, out mdType))
                    {
                        IMapDecoration md = Activator.CreateInstance(mdType) as IMapDecoration;
                        mapBox1.Map.Decorations.Add(md);
                    }
                }

                mapBox1.Map.Size = Size;
                mapBox1.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Error");
            }
            finally
            {
                Cursor         = Cursors.Default;
                mapBox1.Cursor = mic;
            }
        }
示例#2
0
        private void radioButton_Click(object sender, EventArgs e)
        {
            Cursor mic = mapBox1.Cursor;

            mapBox1.Cursor = Cursors.WaitCursor;
            Cursor         = Cursors.WaitCursor;
            try
            {
                //mapImage.ActiveTool = MapImage.Tools.None;
                string text = ((RadioButton)sender).Text;

                switch (text)
                {
                case "Shapefile":
                    mapBox1.Map = ShapefileSample.InitializeMap(tbAngle.Value);
                    break;

                case "GradientTheme":
                    mapBox1.Map = GradiantThemeSample.InitializeMap(tbAngle.Value);
                    break;

                case "WFS Client":
                    mapBox1.Map = WfsSample.InitializeMap(tbAngle.Value);
                    break;

                case "WMS Client":
                    mapBox1.Map = TiledWmsSample.InitializeMap();
                    //mapBox1.Map = WmsSample.InitializeMap(tbAngle.Value);
                    break;

                case "OGR - MapInfo":
                case "OGR - S-57":
                    mapBox1.Map = OgrSample.InitializeMap(tbAngle.Value);
                    break;

                case "GDAL - GeoTiff":
                case "GDAL - '.DEM'":
                case "GDAL - '.ASC'":
                case "GDAL - '.VRT'":
                    mapBox1.Map        = GdalSample.InitializeMap(tbAngle.Value);
                    mapBox1.ActiveTool = MapBox.Tools.Pan;
                    break;

                case "TileLayer - OSM":
                case "TileLayer - OSM with XLS":
                case "TileLayer - Bing Roads":
                case "TileLayer - Bing Aerial":
                case "TileLayer - Bing Hybrid":
                case "TileLayer - GoogleMap":
                case "TileLayer - GoogleSatellite":
                case "TileLayer - GoogleTerrain":
                case "TileLayer - GoogleLabels":
                case "Eniro":
                    /*
                     * tbAngle.Visible = text.Equals("TileLayer - GoogleLabels");
                     * if (!tbAngle.Visible) tbAngle.Value = 0;
                     */
                    mapBox1.Map = TileLayerSample.InitializeMap(tbAngle.Value);
                    ((RadioButton)sender).Text           = (mapBox1.Map.BackgroundLayer.Count > 0)
                            ?((RadioButton)sender).Text  = mapBox1.Map.BackgroundLayer[0].LayerName
                            : ((RadioButton)sender).Text = mapBox1.Map.Layers[0].LayerName;
                    break;

                case "PostGis":
                    mapBox1.Map = PostGisSample.InitializeMap(tbAngle.Value);
                    break;

                case "SpatiaLite":
                    mapBox1.Map = SpatiaLiteSample.InitializeMap(tbAngle.Value);
                    break;

                case "Oracle":
                    mapBox1.Map = OracleSample.InitializeMap(tbAngle.Value);
                    break;

                case "shp_TextOnPath":
                    mapBox1.Map = TextOnPathSample.InitializeMapOrig(tbAngle.Value);
                    break;

                case "GdiImageLayer":
                    mapBox1.Map = GdiImageLayerSample.InitializeMap(tbAngle.Value);
                    break;

                default:
                    break;
                }

                //Add checked Map decorations
                foreach (ListViewItem checkedItem in lvwDecorations.CheckedItems)
                {
                    Type mdType;
                    if (MapDecorationTypes.TryGetValue(checkedItem.Text, out mdType))
                    {
                        IMapDecoration md = Activator.CreateInstance(mdType) as IMapDecoration;
                        mapBox1.Map.Decorations.Add(md);
                    }
                }

                mapBox1.Map.Size = Size;
                mapBox1.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Error");
            }
            Cursor         = Cursors.Default;
            mapBox1.Cursor = mic;
        }