欢迎您来到GIS动力

加入收藏 免费注册 用户登陆 帮助中心
首页 新闻动态 技术专栏 银杏树下 学习考研 软件下载 求职招聘 许愿瓶 节日祝福 用户中心 精彩推荐 资源搜索 地图
专栏导航: AO开发 | SO开发 | ArcGIS桌面 | 超图桌面 | 开发语言 | 数据库 | WebGIS | 银杏文学 | 研究生考题 | FreeMap 谈天说地
   您现在位于: 首页技术专栏MapInfo应用开发MAPX → 正文
mapxtreme添加标记和删除标记
07-10-23 09:06:38 作者:星际 出处:

新增2个pointselectiontool,

clientcommand设为MapCommand,clientinteraction设为ClickInteraction,

command一个设为:AddPinPointCommand,一个设为ClearPinPointCommand,

page_load添加

            controlModel.Commands.Add(new AddPinPointCommand());
            controlModel.Commands.Add(new ClearPinPointCommand());

            MapInfo.Mapping.Map myMap = GetMapObj();

            if (myMap != null)
            {
                if (myMap.Layers[SampleConstants.TempLayerAlias] != null)
                {
                    myMap.Layers.Remove(SampleConstants.TempLayerAlias);
                }
            }
            // Need to clean up "dirty" temp table left by other customer requests.
            MapInfo.Engine.Session.Current.Catalog.CloseTable(SampleConstants.TempTableAlias);
            // Need to clear the DefautlSelection.
            MapInfo.Engine.Session.Current.Selections.DefaultSelection.Clear();

            // Creat a temp table and AddPintPointCommand will add features into it.
            MapInfo.Data.TableInfoMemTable ti = new MapInfo.Data.TableInfoMemTable(SampleConstants.TempTableAlias);
            // Make the table mappable
            ti.Columns.Add(MapInfo.Data.ColumnFactory.CreateFeatureGeometryColumn(myMap.GetDisplayCoordSys()));
            ti.Columns.Add(MapInfo.Data.ColumnFactory.CreateStyleColumn());

            MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti);
            // Create a new FeatureLayer based on the temp table, so we can see the temp table on the map.
            myMap.Layers.Insert(0, new FeatureLayer(table, "templayer", SampleConstants.TempLayerAlias));


添加一个方法:

    private MapInfo.Mapping.Map GetMapObj()
    {
        // Get the map
        MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias];
        if (myMap == null)
        {
            myMap = MapInfo.Engine.Session.Current.MapFactory[0];
        }
        return myMap;
    }


在customizedcommands.cs中添加(取info时新增过这个类,把下面代码加进去)

    /// <summary>
    /// Summary description for PinPointCommand.
    /// </summary>
    [Serializable]
    public class AddPinPointCommand : MapInfo.WebControls.MapBaseCommand
    {
        /// <summary>
        /// Constructor for this command, sets the name of the command
        /// </summary>
        /// <remarks>None</remarks>
        public AddPinPointCommand()
        {
            Name = "AddPinPointCommand";
        }

        /// <summary>
        /// This method gets the map object out of the mapfactory with given mapalias and
        /// Adds a point feature into a temp layer, exports it to memory stream and streams it back to client.
        /// </summary>
        /// <remarks>None</remarks>
        public override void Process()
        {
            // Extract points from the string
            System.Drawing.Point[] points = this.ExtractPoints(this.DataString);

            MapControlModel model = MapControlModel.GetModelFromSession();
            model.SetMapSize(MapAlias, MapWidth, MapHeight);

            MapInfo.Mapping.Map map = model.GetMapObj(MapAlias);
            if (map == null) return;

            // There will be only one point, convert it to spatial
            MapInfo.Geometry.DPoint point;
            map.DisplayTransform.FromDisplay(points[0], out point);

            IMapLayer lyr = map.Layers[SampleConstants.TempLayerAlias];
            if (lyr == null)
            {
                TableInfoMemTable ti = new TableInfoMemTable(SampleConstants.TempTableAlias);
                // Make the table mappable
                ti.Columns.Add(ColumnFactory.CreateFeatureGeometryColumn(map.GetDisplayCoordSys()));
                ti.Columns.Add(ColumnFactory.CreateStyleColumn());

               MapInfo .Data.Table   table = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti);
                map.Layers.Insert(0, new FeatureLayer(table, "templayer", SampleConstants.TempLayerAlias));
            }
            lyr = map.Layers[SampleConstants.TempLayerAlias];
            if (lyr == null) return;
            FeatureLayer fLyr = lyr as FeatureLayer;

            MapInfo.Geometry.Point geoPoint = new MapInfo.Geometry.Point(map.GetDisplayCoordSys(), point);
            // Create a Point style which is a red pin point.
            SimpleVectorPointStyle vs = new SimpleVectorPointStyle();
            vs.Code = 67;
            vs.Color = Color.Red;
            vs.PointSize = Convert.ToInt16(24);
            vs.Attributes = StyleAttributes.PointAttributes.BaseAll;
            vs.SetApplyAll();

            //BitmapPointStyle vs = new BitmapPointStyle();
            //vs.Name = @"C:\Documents and Settings\董霆\桌面\GIS\sample\images\star.gif";
            //vs.PointSize = Convert.ToInt16(24);
            //vs.Attributes = StyleAttributes.PointAttributes.BaseAll;
            //vs.SetApplyAll();


            // Create a Feature which contains a Point geometry and insert it into temp table.
            Feature pntFeature = new Feature(geoPoint, vs);
            MapInfo.Data.Key key = fLyr.Table.InsertFeature(pntFeature);

            // Send contents back to client.
            MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);
            StreamImageToClient(ms);
        }
    }
    /// <summary>
    /// Summary description for PinPointCommand.
    /// </summary>
    [Serializable]
    public class ClearPinPointCommand : MapInfo.WebControls.MapBaseCommand
    {
        /// <summary>
        /// Constructor for this command, sets the name of the command
        /// </summary>
        /// <remarks>None</remarks>
        public ClearPinPointCommand()
        {
            Name = "ClearPinPointCommand";
        }

        /// <summary>
        /// This method gets the map object out of the mapfactory with given mapalias
        /// and This method delete the pin point features added by AddPinPointCommand in a given point
        /// and then streams the image back to client.
        /// </summary>
        /// <remarks>None</remarks>
        public override void Process()
        {
            System.Drawing.Point[] points = ExtractPoints(DataString);
            MapControlModel model = MapControlModel.GetModelFromSession();
            model.SetMapSize(MapAlias, MapWidth, MapHeight);
            MapInfo.Mapping.Map map = model.GetMapObj(MapAlias);
            if (map == null) return;
            PointDeletion(map, points[0]);
            MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);
            StreamImageToClient(ms);
        }
        /// <summary>
        /// Delete a feature in the temporary layer.
        /// </summary>
        /// <param name="mapAlias">MapAlias of the map</param>
        /// <param name="point">Point in pixels</param>
        private void PointDeletion(Map map, System.Drawing.Point point)
        {
            // Do the search and show selections
            SearchInfo si = MapInfo.Mapping.SearchInfoFactory.SearchNearest(map, point, 10);
            (si.SearchResultProcessor as ClosestSearchResultProcessor).Options = ClosestSearchOptions.StopAtFirstMatch;

            MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog[SampleConstants.TempTableAlias];
            if (table != null)
            {
                IResultSetFeatureCollection ifc = Session.Current.Catalog.Search(table, si);
                foreach (Feature f in ifc)
                {
                    table.DeleteFeature(f);
                }
                ifc.Close();
            }
        }
    }


    /// <summary>
    /// Summary description for SampleConstants.
    /// </summary>
    public class SampleConstants
    {
        public static string TempLayerAlias = "PinPointLayer";
        public static string TempTableAlias = "PinPointTable";

        private SampleConstants() { }
    }

 


运行会提示找不到:SimpleVectorPointStyle所引用的类,这是引用的mapinfo.styles

再运行会提示找不到:Session,这是引用的mapinfo.engine

原文:http://www.cnblogs.com/njnudt/archive/2007/07/17/821005.html


(本文已被浏览 次)
发布人:admin
推荐给好友:发送给好友
上篇新闻:
下篇新闻:
相关评论
发表我的评论
  • 尊重网上道德,遵守《全国人大常委会关于维护互联网安全的决定》及中华人民共和国其他各项有关法律法;
  • 本站有权保留或删除您发表的任何评论内容;
  •   相关文章  

    关于我们 友情链接 ┋ 与我在线 ┋ 管理 ┋ TOP
    网站当前版本:GisPower CMS V3.0
    『GIS 动力』- http://www.gispower.org/
    联系我们:webmaster#gispower.org
    Copyright (c) 2003-2007 GisPOwer.Org. All Rights Reserved.

                   滇ICP备05006901号