• MapXtreme使用编辑工具


    MapXtreme的工具分为四类:View工具(Zoom、Center、Pan),Select工具(选点、线、面等),Add工具(添点、线、面)及Custom工具,目前需要使用add工具,与使用MapInfo一致,在添加点、线、面时需要创建临时表及临时图层及对工具的过滤,在选择前需要:

       private void PrePareForDraw()
            {
                // first close the temporary table -- an easy way to clean it up
                // (otherwise the table will remain open after the map is cleared)
                MapInfo.Data.Table tblTemp = Session.Current.Catalog.GetTable("Temp");
                if (tblTemp != null) tblTemp.Close();
                //mapControl1.Map.Clear();
    
                // create a temporary table and add a featurelayer for it
                FeatureLayer layerTemp = new FeatureLayer(
                    Session.Current.Catalog.CreateTable(
                    TableInfoFactory.CreateTemp("Temp"), new TableSessionInfo()));
                mapControl1.Map.Layers.Add(layerTemp);
    
                // set the insertion and edit filters to allow all tools to work on Temp
                ToolFilter toolFilter =
                    (ToolFilter)mapControl1.Tools.AddMapToolProperties.InsertionLayerFilter;
                if (toolFilter != null && !toolFilter.IncludeLayer(layerTemp))
                    toolFilter.SetExplicitInclude(layerTemp, true);
                toolFilter = (ToolFilter)mapControl1.Tools.SelectMapToolProperties.EditableLayerFilter;
                if (toolFilter != null && !toolFilter.IncludeLayer(layerTemp))
                    toolFilter.SetExplicitInclude(layerTemp, true);
          // setview mapControl1.Map.SetView(mapControl1.Map.Center, Session.Current.CoordSysFactory.CreateLongLat(DatumID.WGS84), mapControl1.Map.Scale); }

    然后选择添加工具,例如添加多边形:

    mapControl1.Tools.LeftButtonTool = "AddPolygon";

    画出来的多边形如右图所示:

    自定义多边形样式后,先从mapcontrol 的Tools 中去掉默认的添加多边形工具,再添加带自定义多边形样式后的AddPolygon Tool,具体代码为:

     MapInfo.Data.Table tblTemp = Session.Current.Catalog.GetTable("CustomTemp");
                if (tblTemp != null) tblTemp.Close();
    
                // create a temporary table and add a featurelayer for it
                FeatureLayer layerTemp = new FeatureLayer(
                    Session.Current.Catalog.CreateTable(
                    TableInfoFactory.CreateTemp("CustomTemp"), new TableSessionInfo()));
                mapControl1.Map.Layers.Add(layerTemp);
                
                
                // Set the map layer filter for the insertion layer.
                IMapLayerFilter insertionLayerFilter = MapLayerFilterFactory.FilterSpecificLayers(layerTemp);
    
    
                // Set the default style for the new objects (red fill with blue border).
                CompositeStyle style = new CompositeStyle(
                    new MapInfo.Styles.AreaStyle(
                        MapInfo.Styles.StockStyles.BlueLineStyle(),
                        MapInfo.Styles.StockStyles.RedFillStyle()),
                    MapInfo.Styles.StockStyles.BlackLineStyle(),
                    new MapInfo.Styles.TextStyle(),
                    MapInfo.Styles.StockStyles.DefaultSymbol()
                    );
    
                AddMapToolProperties addMapToolProperties = new AddMapToolProperties(
                    MapLayerFilterFactory.FilterForTools(mapControl1.Map, insertionLayerFilter,
                    MapLayerFilterFactory.FilterVisibleLayers(true),
                    "CustomPolygonAddMapToolProperties", null), style);
    
                // Create an Add polygon tool with non-default properties.
                MapTool maptool = new AddPolygonMapTool(true, mapControl1.Viewer,
                    mapControl1.Handle.ToInt32(), mapControl1.Tools,
                    new MouseToolProperties(Cursors.Default, Cursors.Default,
                    Cursors.Default), mapControl1.Tools.MapToolProperties,
                    addMapToolProperties);
     // Remove default AddPolygon Tool then add new AddPolygon Tool
                if (mapControl1.Tools.ContainsKey("AddPolygon"))
                {
                    mapControl1.Tools.Remove("AddPolygon");
                }

                mapControl1.Tools.Add("AddPolygon", maptool);

                mapControl1.Tools.LeftButtonTool = "AddPolygon";

    画出多边形如右图所示:

  • 相关阅读:
    项目笔记:统计页面功能实现
    jquery easyui datagrid实现数据改动
    Skia图片解码模块流程分析
    TRIZ的成功案例
    基于HTML5的Web SCADA工控移动应用
    webservices系列(五)——javaweb整合Axis2及多service配置
    org.hibernate.PropertyValueException: not-null property references a null or transient value: model.
    线程池和异步线程
    [leetcode]Implement strStr()
    Python工作日类库Busines Holiday介绍
  • 原文地址:https://www.cnblogs.com/nygfcn1234/p/3046989.html
Copyright © 2020-2023  润新知