Example #1
0
        public SCMap AddLayerSql(string connectionName, string query, LayerSqlOptions options = null)
        {
            options ??= new LayerSqlOptions();

            var map = this.Map;

            var layer = new VectorItemsLayer()
            {
                AllowEditItems     = false,
                EnableHighlighting = false,
                EnableSelection    = false
            };

            if (!string.IsNullOrWhiteSpace(options.Name))
            {
                layer.Name = options.Name;
            }
            if (!string.IsNullOrWhiteSpace(options.ShapeTitlesPattern))
            {
                layer.ShapeTitlesPattern    = options.ShapeTitlesPattern;
                layer.ShapeTitlesVisibility = VisibilityMode.Visible;
            }
            else
            {
                layer.ShapeTitlesVisibility = VisibilityMode.Hidden;
            }

            var connections = DBConnections.LoadConnections();
            var connection  = connections.FindConnection(connectionName);

            if (connection == null)
            {
                throw new Exception($"Cannot find connection '{connectionName}'.");
            }
            if (!ConnectionFactory.IsMSSQLServer(connection.Provider))
            {
                throw new Exception("DBMS must be Microsoft SQL Server.");
            }

            var adapter = new SqlGeometryDataAdapter
            {
                ConnectionString  = connection.ConnectionString,
                SqlText           = query,
                SpatialDataMember = options.SpatialColumn
            };

            layer.Data = adapter;

            map.Layers.Add(layer);
            CurrentLayer = layer;

            return(this);
        }
Example #2
0
        protected override void UpdateMap()
        {
            var map = MapContext.Map;

            var layer = new VectorItemsLayer()
            {
                AllowEditItems     = false,
                EnableHighlighting = false,
                EnableSelection    = false
            };

            if (!string.IsNullOrWhiteSpace(Name))
            {
                layer.Name = Name;
            }
            if (!string.IsNullOrWhiteSpace(ShapeTitlesPattern))
            {
                layer.ShapeTitlesPattern    = ShapeTitlesPattern;
                layer.ShapeTitlesVisibility = VisibilityMode.Visible;
            }
            else
            {
                layer.ShapeTitlesVisibility = VisibilityMode.Hidden;
            }

            var connections = DBConnections.LoadConnections();
            var connection  = connections.FindConnection(ConnectionName);

            if (connection == null)
            {
                throw new Exception($"Cannot find connection '{ConnectionName}'.");
            }
            if (!ConnectionFactory.IsMSSQLServer(connection.Provider))
            {
                throw new Exception("DBMS must be Microsoft SQL Server.");
            }

            var adapter = new SqlGeometryDataAdapter
            {
                ConnectionString  = connection.ConnectionString,
                SqlText           = Query,
                SpatialDataMember = SpatialColumn
            };

            layer.Data = adapter;

            map.Layers.Add(layer);

            MapContext.CurrentLayer = layer;
        }
Example #3
0
        private void Form1_Load(object sender, System.EventArgs e)
        {
            SqlGeometryDataAdapter adapter = new SqlGeometryDataAdapter()
            {
                ConnectionString  = connectionString,
                SqlText           = "SELECT TOP 1000 [id], [GeomCol1],[TextCol] FROM [dbo].[DemoTable]",
                SpatialDataMember = "GeomCol1"
            };
            VectorItemsLayer layer = new VectorItemsLayer()
            {
                Data = adapter,
                ShapeTitlesPattern = "{TextCol}"
            };

            layer.DataLoaded += layer_DataLoaded;
            mapControl1.Layers.Add(layer);
            mapControl1.MapEditor.ShowEditorPanel = true;
            mapControl1.MapEditor.MapItemEdited  += MapEditor_MapItemEdited;
        }