当前位置: 首页 > news >正文

基于MapWinGis的开发探索(四)——图层窗口、地名检索的实现

   此次开发将界面改成换成类型Office2007的,主要继承DevComponents。地图底层现在只添加一些地理图层如道路、河流、路名等,至于有实际应用的图层后期加入,这些ShapeFile文件从CAD图纸的dxf格式转换而来。

(一)图层窗口的实现

MapWinGis本身的图层窗口控件legend强大,源代码相当多,而且包含了很多方法,此次图层窗口的实现主要采用树形控件,将地理图层的图层ID、图层名加载绑定。

 

ExpandedBlockStart.gif ContractedBlock.gif   /**/ /// <summary>
        
/// 添加图层
        
/// </summary>

         private   void  AddLayer()
ExpandedBlockStart.gifContractedBlock.gif        
{
            
//加载前清除树的节点
            tvLayer.Nodes.Clear();
            
//获取所有图层
            string[] files = MapCommon.LoadAllShpFile(Environment.CurrentDirectory + @"\mapfile");
            
if (files != null && files.Length > 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
for (int i=0; i <files.Length ; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    Shapefile shpFile 
= new Shapefile();
                    
bool bOpen= shpFile.Open(files[i], call);
                    
int layerHandle= axMap1.AddLayer(shpFile, true);
                    DevComponents.AdvTree.Node node 
= new DevComponents.AdvTree.Node();
                    node.Text 
=LayerNames.En2Cn(MapCommon.GetFileName(files[i]));
                    node.Tag 
= layerHandle;
                    node.Image 
= Resources.Pic02;
                    tvLayer.Nodes.Add(node);
                    
if (node.Text == LayerNames.RoadName_CN)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{//将路名的文本显示处理
                        ShowLable.GetLable(shpFile, layerHandle, axMap1);
                    }

                }

                map 
= axMap1;
            }

            
            
//加载鼠标滚轮缩放事件
            this.MouseWheel+=new MouseEventHandler(Map_MouseWheel);
        }

 

(二)地名检索的实现

地名检索实现主要是遍历每个图层,寻找地名图层的dbf文件,遍历该文件的存放地名的那一列,将符合要求的地名检索出来,绑定在树形控件上。

 

ExpandedBlockStart.gif ContractedBlock.gif          /**/ /// <summary>
        
/// 模糊查找地名
        
/// </summary>
        
/// <param name="strWhere"></param>

         private   void  Query( string  strWhere)
ExpandedBlockStart.gifContractedBlock.gif        
{
            
//清空树节点
            tvPlace.Nodes.Clear();
            
for (int i = 0; i < Map.NumLayers; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                MapWinGIS.Shapefile shpFile 
= (MapWinGIS.Shapefile)Map.get_GetObject(i);
                
if (System.IO.Path.GetFileNameWithoutExtension(shpFile.Filename) == LayerNames.RoadName)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{//获取路名的ShapeFile文件
                    for (int j = 0; j < shpFile.NumShapes; j++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        
object obj = shpFile.get_CellValue(shpFile.NumFields - 1, j);
                        
if (obj != null && obj.ToString().Contains(strWhere))
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
{//判断地名是否存在
                            Shape shp = shpFile.get_Shape(j);
                            DevComponents.AdvTree.Node tn 
= new DevComponents.AdvTree.Node();
                            tn.Text 
= obj.ToString();
                            tn.Tag 
= shp.SerializeToString();
                            tn.Image 
= Resources.Pic03;
                            tvPlace.Nodes.Add(tn);
                        }

                    }

                }

            }

        }

 

双击树形控件的节点,将地图定位在该地名上。这里主要涉及到地图定位算法的问题:先获取绑定在树形控件的Shape对象的属性,得到ShapeString属性,然后获得ShapeString里的Extents范围,增大Extents范围,将地图Extents范围设置成那个即可定位。

 

ExpandedBlockStart.gif ContractedBlock.gif   /**/ /// <summary>
        
/// 定位
        
/// </summary>
        
/// <param name="shapeString"></param>

         public   void  GoTo( string  shapeString)
ExpandedBlockStart.gifContractedBlock.gif        
{
            Shape shape 
= new MapWinGIS.ShapeClass();
            
if (shape.CreateFromString(shapeString) == true)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                SetMapBounds(shape.Extents.xMax, shape.Extents.yMax, shape.Extents.xMin, shape.Extents.yMin);
            }

        }


ExpandedBlockStart.gifContractedBlock.gif        
/**/ /// <summary>
        
/// 设置地图边界
        
/// </summary>
        
/// <param name="maxX"></param>
        
/// <param name="maxY"></param>
        
/// <param name="minX"></param>
        
/// <param name="minY"></param>

         public   void  SetMapBounds( double  maxX,  double  maxY,  double  minX,  double  minY)
ExpandedBlockStart.gifContractedBlock.gif        
{
            maxX 
= maxX + 100;
            minX 
= minX - 100;

            maxY 
= maxY + 100;
            minY 
= minY - 100;

            MapWinGIS.Extents tExts 
= new Extents();
            tExts.SetBounds(minX, minY, 
0, maxX, maxY, 0);
            GetMap().Extents 
= tExts;
        }

 

定位的结果如下:

转载于:https://www.cnblogs.com/wakerobin/archive/2009/11/05/1596692.html

相关文章:

  • 中间件
  • ArcEngine开发点滴1
  • [转]ATOM 规范 中文版
  • javascript实现组合的递归算法及变种
  • 汇报方案
  • [转]深一层看依赖注入
  • C# 中的委托和事件 copyright http://www.cnblogs.com/JimmyZhang
  • Week Function
  • China MVP Open Day 2009
  • C# Windows Form 刷新父窗体
  • Linq to XML说法——(二)更新,删除,加载
  • 如果可以忘记
  • C#数据库编程
  • net framework3.5新特性1:Lambda表达式
  • ghost误操作
  • 【MySQL经典案例分析】 Waiting for table metadata lock
  • Angular 响应式表单 基础例子
  • Java 11 发布计划来了,已确定 3个 新特性!!
  • LeetCode算法系列_0891_子序列宽度之和
  • Netty+SpringBoot+FastDFS+Html5实现聊天App(六)
  • python docx文档转html页面
  • Redux 中间件分析
  • Vue源码解析(二)Vue的双向绑定讲解及实现
  • 爱情 北京女病人
  • 分类模型——Logistics Regression
  • 前端代码风格自动化系列(二)之Commitlint
  • 前言-如何学习区块链
  • “十年磨一剑”--有赞的HBase平台实践和应用之路 ...
  • 《天龙八部3D》Unity技术方案揭秘
  • ​TypeScript都不会用,也敢说会前端?
  • ​ubuntu下安装kvm虚拟机
  • ​什么是bug?bug的源头在哪里?
  • # 手柄编程_北通阿修罗3动手评:一款兼具功能、操控性的电竞手柄
  • # 数据结构
  • #Linux(Source Insight安装及工程建立)
  • (02)Cartographer源码无死角解析-(03) 新数据运行与地图保存、加载地图启动仅定位模式
  • (22)C#传智:复习,多态虚方法抽象类接口,静态类,String与StringBuilder,集合泛型List与Dictionary,文件类,结构与类的区别
  • (二)丶RabbitMQ的六大核心
  • (附源码)ssm基于微信小程序的疫苗管理系统 毕业设计 092354
  • (六)Hibernate的二级缓存
  • (算法)N皇后问题
  • (转)c++ std::pair 与 std::make
  • *Django中的Ajax 纯js的书写样式1
  • .net oracle 连接超时_Mysql连接数据库异常汇总【必收藏】
  • .NET 中 GetProcess 相关方法的性能
  • .net遍历html中全部的中文,ASP.NET中遍历页面的所有button控件
  • .NET简谈设计模式之(单件模式)
  • .Net转Java自学之路—基础巩固篇十三(集合)
  • /dev下添加设备节点的方法步骤(通过device_create)
  • /proc/vmstat 详解
  • [1204 寻找子串位置] 解题报告
  • [Angular 基础] - 指令(directives)
  • [BUG] Hadoop-3.3.4集群yarn管理页面子队列不显示任务
  • [C++] 默认构造函数、参数化构造函数、拷贝构造函数、移动构造函数及其使用案例
  • [COI2007] Sabor