您的位置:首页 > Web前端 > CSS

MapXtreme图元改变样式

2014-03-24 11:13 267 查看
            由于项目的需要图元图层Sector需要改变某些图元的样式(需要红色AreaStyle 样式)并永久显示,网上找了很多方法都没找到。后来通过实践解决了这个问题,记录如下:

方法一:

            //expression为筛选图元表达式,sector为图元图层

            MapInfo.Data.SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchWhere(expression);

            MapInfo.Data.IResultSetFeatureCollection ifs = MapInfo.Engine.Session.Current.Catalog.Search("Sector", si);

            MapInfo.Mapping.FeatureLayer featureLayer = (MapInfo.Mapping.FeatureLayer)mapControl.Map.Layers["Sector"];

            MapInfo.Data.Table table = featureLayer.Table;

            foreach (MapInfo.Data.Feature f in ifs)

            {

                MapInfo.Geometry.DPoint dp = new MapInfo.Geometry.DPoint(f.Geometry.GeometricCentroid.x, f.Geometry.GeometricCentroid.y);

                MapInfo.Styles.AreaStyle simpleStyle = new MapInfo.Styles.AreaStyle();

                simpleStyle.Interior = new MapInfo.Styles.SimpleInterior(2, Color.Red, Color.Red, false);

                MapInfo.Styles.CompositeStyle compositeStyle = new MapInfo.Styles.CompositeStyle(simpleStyle);

                MapInfo.Data.Feature pointRow = new MapInfo.Data.Feature(table.TableInfo.Columns);

                f.Style = compositeStyle;

                //必须加上下面这两句,否则没效果

                f.Geometry.EditingComplete();

                table.UpdateFeature(f);

            }

方法二:

        //expression为筛选图元表达式,tempTableName为图层Table名称

            MapInfo.Data.MIConnection connection = new MapInfo.Data.MIConnection();

            MapInfo.Data.MICommand command = connection.CreateCommand();

            command
.Parameters.Add("@style", MIDbType.Style);

            command .CommandText = "update " + tempTableName + " set Obj = Obj,MI_Style = @style where "+expression;

            connection.Open();

            CompositeStyle style = new CompositeStyle();

            style.AreaStyle = new AreaStyle(new SimpleLineStyle(new LineWidth(1, LineWidthUnit.Pixel), 2, color, false), new          SimpleInterior(2, color, color, true));

            command.Parameters["@style"].Value = style;

            command.ExecuteNonQuery();

            command.Cancel();

            command.Dispose();

            connection.Close();

            connection.Dispose();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息