`

MapxTreme测试:绘制图标和文字标注

阅读更多
代码:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MapInfo.Mapping;
using MapInfo.WebControls;
using ApplicationStateManager;
using MapInfo.Data;
public partial class _Default : System.Web.UI.Page
{
    private void Page_Load(object sender, System.EventArgs e)
    {
        ViewEntireMap();
        // If the StateManager doesn't exist in the session put it else get it.
        if (StateManager.GetStateManagerFromSession() == null)
            StateManager.PutStateManagerInSession(new AppStateManager());
        // Now Restore State
        StateManager.GetStateManagerFromSession().ParamsDictionary[StateManager.ActiveMapAliasKey] = MapControl1.MapAlias;
        StateManager.GetStateManagerFromSession().RestoreState();
    }
    // At the time of unloading the page, save the state
    private void Page_UnLoad(object sender, System.EventArgs e)
    {
        StateManager.GetStateManagerFromSession().SaveState();
    }
    protected void ButtonViewEntire_Click(object sender, EventArgs e)
    {
        ViewEntireMap();
    }

    private void ViewEntireMap()
    {
        //try {
        Map myMap = GetMapObj();
        myMap.Clear();
        MapInfo.Mapping.MapGeosetLoader gl = new MapGeosetLoader(Server.MapPath("App_Data\\海洋测试.gst"));
        myMap.Load(gl);
        double x = 111.0;
        double y = 22.0;
        myMap.Center = new MapInfo.Geometry.DPoint(x,y);
        mpxDrawImg(myMap,x,y,"truckImg");
        //            mpxDrawText(myMap, "truckText", "A13431");
        mpxDrawText(myMap, x, y, "truckText", "桂A99999");
        //}
        //catch (Exception e) {
           
        //}
    }

    private MapInfo.Mapping.Map GetMapObj()
    {
        MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias];
        if (myMap == null)
        {
            myMap = MapInfo.Engine.Session.Current.MapFactory[0];
        }
        return myMap;
    }
    /// <summary>
    /// 创建mapx表
    /// </summary>
    /// <param name="pMap">地图</param>
    /// <param name="pTabName"></param>
    /// <param name="pColumnName"></param>
    /// <returns></returns>
    private MapInfo.Data.Table mpxMkTable(MapInfo.Geometry.CoordSys pCoordSys, string pTabName,string pColumnName){
        MapInfo.Data.Catalog Cat = MapInfo.Engine.Session.Current.Catalog;
        MapInfo.Data.Table tblTemp = Cat.GetTable(pTabName);
        if (tblTemp != null) Cat.CloseTable(pTabName);
        MapInfo.Data.TableInfoMemTable imt = new MapInfo.Data.TableInfoMemTable(pTabName);
        imt.Columns.Add(MapInfo.Data.ColumnFactory.CreateFeatureGeometryColumn(pCoordSys));
        imt.Columns.Add(MapInfo.Data.ColumnFactory.CreateStyleColumn());
        imt.Columns.Add(MapInfo.Data.ColumnFactory.CreateStringColumn(pColumnName, 40));
        return Cat.CreateTable(imt);
    }
    /// <summary>
    /// 往表里增加一行
    /// </summary>
    /// <param name="pTable">表名</param>
    /// <param name="pGeometry">坐标</param>
    /// <param name="pStyle">样式</param>
    /// <param name="pColumnName">列名</param>
    /// <param name="pColumnValue">列值</param>
    private void mpxTableAddRow(MapInfo.Data.Table pTable,MapInfo.Geometry.FeatureGeometry pGeometry,MapInfo.Styles.Style pStyle,string pColumnName,string pColumnValue) {
        Feature ftr = new Feature(pTable.TableInfo.Columns);
        ftr.Geometry = pGeometry;
        ftr.Style = pStyle;
        ftr[pColumnName] = pColumnValue;
        pTable.InsertFeature(ftr);
    }
    /// <summary>
    /// 创建文本样式
    /// </summary>
    /// <param name="pColor">文本颜色</param>
    /// <param name="pSize">字体大小</param>
    /// <param name="pFontName">字体名称</param>
    /// <returns></returns>
    private MapInfo.Styles.TextStyle mpxMkTextStyle(System.Drawing.Color pColor, double pSize, string pFontName) {
        MapInfo.Styles.TextStyle ts = new MapInfo.Styles.TextStyle();
        ts.Font.ForeColor = pColor;
        ts.Font.Size = pSize;
        ts.Font.Name = pFontName;
        ts.ApplyStyle(ts);
        return ts;
    }
    /// <summary>
    /// 创建文本样式
    /// </summary>
    /// <param name="pSize">字体大小</param>
    /// <param name="pFontName">字体名称</param>
    /// <returns></returns>
    private MapInfo.Styles.TextStyle mpxMkTextStyle(double pSize, string pFontName) {
        MapInfo.Styles.TextStyle ts = new MapInfo.Styles.TextStyle();
        ts.Font.ForeColor = System.Drawing.Color.Black;
        ts.Font.Size = pSize;
        ts.Font.FontWeight = MapInfo.Styles.FontWeight.Bold;
        ts.Font.Name = pFontName;
        return ts;
    }
    /// <summary>
    /// 创建图层点坐标
    /// </summary>
    /// <param name="pSys"></param>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <returns></returns>
    private MapInfo.Geometry.FeatureGeometry mpxMkFeaturePoint(MapInfo.Geometry.CoordSys pSys,double x,double y) {
        MapInfo.Geometry.Point pt = new MapInfo.Geometry.Point(pSys, x, y);
        MapInfo.Geometry.FeatureGeometry geo = pt as MapInfo.Geometry.FeatureGeometry;
        return geo;
    }
    /// <summary>
    /// 绘制文本
    /// </summary>
    /// <param name="pSys">坐标系统,如:myMap.GetDisplayCoordSys()</param>
    /// <param name="x">经度</param>
    /// <param name="y">纬度</param>
    /// <param name="pTabName">用于创建图层的表名</param>
    /// <param name="pText">要绘制的文本</param>
    private void mpxDrawText(MapInfo.Mapping.Map pMap,double x,double y,string pTabName,string pText) {
        //MapInfo.Styles.TextStyle sty2 = new MapInfo.Styles.TextStyle();
        //sty2.Font.ForeColor = System.Drawing.Color.Red;
        //sty2.Font.TextEffect = MapInfo.Styles.TextEffect.Halo;
        //MapInfo.Geometry.DRect rt = new MapInfo.Geometry.DRect(x, y, x + 30, y + 12);
        //MapInfo.Geometry.LegacyText lt =
        //        new MapInfo.Geometry.LegacyText(pMap.GetDisplayCoordSys(), rt, pText);
        //MapInfo.Data.Feature ft = new MapInfo.Data.Feature(lt, sty2);
        //MapInfo.Data.Table dt = mpxMkTable(pMap.GetDisplayCoordSys(), pTabName, "name");
        //dt.InsertFeature(ft);
        //LabelSource source = new LabelSource(dt);         //创建数据源
        //source.DefaultLabelProperties.Caption = "name";
        //LabelLayer lyr = new LabelLayer();                //创建图层
        //lyr.Sources.Append(source);
        //pMap.Layers.Add(lyr);
//        DRect drect = new DRect(ftr.Geometry.Centroid.x + 2, ftr.Geometry.Centroid.y, ftr.Geometry.Centroid.x + 30, ftr.Geometry.Centroid.y + 12);
        string sColumnName = "name";     //创建表
        MapInfo.Data.Table dt = mpxMkTable(pMap.GetDisplayCoordSys(), pTabName, sColumnName);
        MapInfo.Styles.TextStyle ts = mpxMkTextStyle(System.Drawing.Color.Blue, 8.0, "宋体");
        MapInfo.Geometry.FeatureGeometry pt = mpxMkFeaturePoint(pMap.GetDisplayCoordSys(), x, y);
        mpxTableAddRow(dt, pt, ts, sColumnName, pText);   //往表里增加记录
        LabelSource source = new LabelSource(dt);         //创建数据源
        source.DefaultLabelProperties.Caption = "name";
        source.DefaultLabelProperties.Style.Font.ForeColor = System.Drawing.Color.Blue;
        source.DefaultLabelProperties.Layout.Offset = 23;
        LabelLayer lyr = new LabelLayer();                //创建图层
        lyr.Sources.Append(source);
        pMap.Layers.Add(lyr);                             //将图层加到地图
        ////创建表
        //MapInfo.Data.Table mpxTable = mkMapxTable(pMap, layerName);
        ////创建文字样式
        //MapInfo.Styles.TextStyle ts=new MapInfo.Styles.TextStyle();
        //ts.Font.ForeColor = System.Drawing.Color.Black;
        //ts.Font.Size = 9;
        //ts.Font.Name = "宋体";
        ////创建标源
        //LabelSource ls = new LabelSource(mpxTable);
        //ls.DefaultLabelProperties.Caption = pText;
        //ls.DefaultLabelProperties.Style = ts;
        ////创建标注层
        //LabelLayer lly = new LabelLayer();//pText);
        //lly.Sources.Append(ls);
        //try {
        //    pMap.Layers.Add(lly);
        //}
        //catch (Exception e) {
        //}
    }
    private void mpxDrawImg(MapInfo.Mapping.Map pMap, double x, double y, string pTabName) {
       
        string sColName = "name";
        MapInfo.Data.Table dt = mpxMkTable(pMap.GetDisplayCoordSys(), pTabName, sColName);        //创建表
        MapInfo.Geometry.FeatureGeometry pt = mpxMkFeaturePoint(pMap.GetDisplayCoordSys(), x, y); //创建点和样式
        MapInfo.Styles.BitmapPointStyle cs =
            new MapInfo.Styles.BitmapPointStyle("v13.BMP", MapInfo.Styles.BitmapStyles.None, System.Drawing.Color.White, 24);
        mpxTableAddRow(dt, pt, cs, "name", "truck");         //往表增加记录
        FeatureLayer lyr = new FeatureLayer(dt);
        pMap.Layers.Add(lyr);
        //FeatureLayer lyr = new FeatureLayer(tblTemp);
        //    new Feature(tblTemp.TableInfo.Columns);
        //ftr.Geometry = pt;
        //ftr.Style = cs;
        //ftr[sColName] = "车号";
        //tblTemp.InsertFeature(ftr);
       
        //MapInfo.Data.Catalog Cat = MapInfo.Engine.Session.Current.Catalog;
        ////创建临时层
        //MapInfo.Data.TableInfoMemTable tblInfoTemp = new MapInfo.Data.TableInfoMemTable("Point");
        //MapInfo.Data.Table tblTemp = Cat.GetTable("Point");
        //if (tblTemp != null) Cat.CloseTable("Point");
        //tblInfoTemp.Columns.Add(ColumnFactory.CreateFeatureGeometryColumn(pMap.GetDisplayCoordSys()));
        //tblInfoTemp.Columns.Add(ColumnFactory.CreateStyleColumn());
        //tblInfoTemp.Columns.Add(ColumnFactory.CreateStringColumn("Name", 40));
        //tblInfoTemp.Columns.Add(ColumnFactory.CreateStringColumn("Dept", 15));
        //tblInfoTemp.Columns.Add(ColumnFactory.CreateIntColumn("Level"));
        //tblTemp = Cat.CreateTable(tblInfoTemp);
        //FeatureLayer lyr = new FeatureLayer(tblTemp);
        //pMap.Layers.Add(lyr);
        //MapInfo.Geometry.FeatureGeometry pt = mpxMkFeaturePoint(pMap.GetDisplayCoordSys(), x, y);
        ////MapInfo.Geometry.FeatureGeometry pt =
        ////    new MapInfo.Geometry.Point(
        ////        lyr.CoordSys, pMap.Center //pMap.Center//new MapInfo.Geometry.DPoint(1, 1) // //
        ////    ) as MapInfo.Geometry.FeatureGeometry;
        ////MapInfo.Styles.SimpleVectorPointStyle cs=
        ////    new MapInfo.Styles.SimpleVectorPointStyle(35, System.Drawing.Color.Red, 13);
        //MapInfo.Styles.BitmapPointStyle cs =
        //    new MapInfo.Styles.BitmapPointStyle("v13.BMP", MapInfo.Styles.BitmapStyles.None, System.Drawing.Color.White, 24);
        ////MapInfo.Styles.CompositeStyle cs = new MapInfo.Styles.CompositeStyle(new MapInfo.Styles.BitmapPointStyle(
        //Feature ftr = new Feature(tblTemp.TableInfo.Columns);
        //ftr.Geometry = pt;
        //ftr.Style = cs;
        //ftr["Name"] = "Kelly";
        ////ftr["Dept"] = "Sales";
        ////ftr["Level"] = 3;
        //tblTemp.InsertFeature(ftr);
        //----------------//
        //MapInfo.Mapping.FeatureLayer oLayer;
        //MapInfo.Data.Table otable;
        //MapInfo.Data.Feature oftr;
        //MapInfo.Styles.SimpleVectorPointStyle ostyle1;
        //MapInfo.Styles.SimpleLineStyle ostyle2;
        //MapInfo.Styles.AreaStyle ostyle3;
        //MapInfo.Styles.TextStyle ostyle4;
        //MapInfo.Styles.FontPointStyle ostyle = new MapInfo.Styles.FontPointStyle() ;
        ////MapInfo.Styles.SimpleVectorPointStyle ostyle;
        //MapInfo.Geometry.Point opoint;
        //MapInfo.Data.Key k;
        //oLayer = (MapInfo.Mapping.FeatureLayer)pMap.Layers[pLayerName];
        //otable = oLayer.Table;
        //opoint = new MapInfo.Geometry.Point(pMap.GetDisplayCoordSys(), pMap.Center.x, pMap.Center.y);
        //ostyle1 = new MapInfo.Styles.CompositeStyle(ostyle3, ostyle2, ostyle4, ostyle1,);
        //ostyle.Font.Name = "宋体";
        //ostyle.PointSize = 30;
        //ostyle.Color = System.Drawing.Color.Red;
        //oftr = new MapInfo.Data.Feature(opoint, ostyle);
        //k = otable.InsertFeature(oftr) ;
        //MapInfo.Data.MIConnection cnn = new MapInfo.Data.MIConnection();
        //cnn.Open();
        //MapInfo.Data.MICommand cmm = new MapInfo.Data.MICommand();
        //cmm.Connection = cnn;
        //cmm.CommandText = "insert into ASIA(Id,Name,Obj,MI_Style) values(@id,@name,@obj,@style)";
        //MapInfo.Styles.FontPointStyle sty = new MapInfo.Styles.FontPointStyle(66, new MapInfo.Styles.Font("Arial", 13), 0, System.Drawing.Color.Red, 18);
        //cmm.Parameters.Add("@id", 431431);
        //cmm.Parameters.Add("@name", "bsbs");
        //cmm.Parameters.Add("@obj", new MapInfo.Geometry.Point(pMap.GetDisplayCoordSys(),0.00,0.00));
        //cmm.Parameters.Add("@style", sty);
        //cmm.ExecuteNonQuery();
        //cnn.Close();
        //----------------//
        //----------------//
        //MapInfo.Data.MIDbType.FeatureGeometry pt = new MapInfo.Geometry.Point(
        //System.Collections.ArrayList arStyles = new System.Collections.ArrayList();
        //MapInfo.Styles.BitmapPointStyle style2 = new MapInfo.Styles.BitmapPointStyle();
        //style2.ThemeValue = "A";
        //style2.BitmapName = "ecumenic.bmp";
        //style2.Size = 10;
        //style2.Style = MapInfo.Styles.All;
        //style2.ShowWhiteBackground = false;
        ////style2._color=Color.Blue; //这句可设置位图颜色,但是怎么让位图不设置颜色..默认为红色
        //arStyles.Add(style2);
        //FeatureLayer lyr = (FeatureLayer)pMap.Layers[pLayerName];
        //lyr.Modifiers.Clear();
        //MapInfo.Mapping.Thematics.IndividualValueTheme thm =
        //    new MapInfo.Mapping.Thematics.IndividualValueTheme(lyr, "i", "i");
        //thm.ApplyStylePart = MapInfo.Mapping.Thematics.StylePart.All;
        //for (int i = 0; i < thm.Bins.Count; i++) {
        //    thm.Bins[i].Style.SymbolStyle.PointSize = 30;
        //}
        //mapUtils.CreateIndividualValueTheme(MapControl1.Map, arStyles, "flBTSPoint", LegendControl1, "i", "i");
    }
    protected void ButtonZoomIn_Click(object sender, EventArgs e)
    {
        Map myMap = GetMapObj();
        if (myMap == null) return;
        myMap.Zoom = new MapInfo.Geometry.Distance(myMap.Zoom.Value / 2, myMap.Zoom.Unit);
    }
    protected void ButtonZoomOut_Click(object sender, EventArgs e)
    {
        Map myMap = GetMapObj();
        if (myMap == null) return;
        myMap.Zoom = new MapInfo.Geometry.Distance(myMap.Zoom.Value * 2, myMap.Zoom.Unit);
       
       
    }

分享到:
评论

相关推荐

    Mapxtreme图元定时刷新,Mapxtreme2008 for .NET图标定时刷新,

    在实际应用中,Mapxtreme图元定时刷新的功能广泛应用于交通监控、环境监测、物流跟踪等领域,通过实时更新地图上的图标,帮助决策者快速掌握现场情况,提高管理和响应效率。 总之,Mapxtreme 2008 for .NET的图元...

    MapXtreme2005开发指南

    - **标注和图例**:用来解释地图内容的文字或符号。 - **主题图**:根据特定属性对地图进行分类和着色。 - **工具**:为用户提供操作地图的各种工具。 - **工作空间**:存储地图和相关资源的文件夹集合。 - **坐标系...

    MapXtreme Java Developer Guide

    《MapXtreme Java开发指南...总之,《MapXtreme Java开发指南》是GIS开发者不可或缺的资源,它不仅介绍了MapXtreme Java Edition的强大功能,还提供了实用的编程指导和迁移策略,帮助开发者在GIS应用开发领域取得成功。

    mapxtreme 桌面完整示例

    5. **图形与标注**:MapXtreme允许在地图上绘制自定义图形和标注,这对于地图注解和解释非常有用。示例可能会展示如何创建和编辑这些元素。 6. **投影与坐标系统**:地图的投影选择和转换是GIS的重要组成部分。学习...

    mapXtreme 入门资料大全

    1. **地图对象模型**:MapXtreme基于一个复杂的地图对象模型,包括地图、图层、图例、标注、地理编码等多个元素。这些对象之间相互作用,构建出动态且功能丰富的地图界面。 2. **数据源与图层**:MapXtreme支持多种...

    mapxtreme添加标记 删除标记

    在`mapxtreme添加标记和删除标记.txt`文件中,可能会详细阐述如何实现这些操作,包括使用的API、示例代码以及注意事项。例如,文件可能包含了如何创建自定义标记图标、如何动态加载数据并根据数据添加标记、如何在...

    使用mapxtreme插件进行使用

    7. **部署与测试**:将开发完成的应用打包部署,进行功能验证和性能优化。 四、学习资源 "mapxtreme学习"这个压缩包文件可能包含了MapXtreme的教程文档、示例代码或视频教程,这些资源可以帮助初学者快速掌握...

    mapxtreme 实现专题图

    5. **应用专题图**:将定义好的规则应用到地图图层,MapXtreme会自动根据规则计算每个区域的样式,并在地图上绘制出来。这可以通过调用MapXtreme API中的相关方法来实现。 6. **交互性与动态更新**:MapXtreme支持...

    C#和Mapxtreme的webgis源码

    C#和MapXtreme是构建WebGIS应用的两种关键技术。C#是一种面向对象的编程语言,被广泛用于开发Windows应用程序、Web服务以及.NET框架下的各种应用。MapXtreme则是杰仕登软件公司(GeoServer Solutions)推出的一款...

    MapXtreme2008中文教程

    通过实例代码,用户将学会如何添加标记、绘制图形、实现点击事件处理等功能,进一步提升MapXtreme2008的应用开发能力。 MapXtreme2008的最新特性也是教程的重点之一,例如增强的性能优化、3D地图支持和新的数据分析...

    c# mapxtreme 图层上画线

    本文将详细讲解如何在MapXtreme图层上绘制线段,涉及的主要知识点包括地图对象的初始化、图层的管理、点坐标处理和线形绘制。 首先,我们需要引用MapXtreme的相关库,这通常通过在项目中添加对MapXtreme .NET DLL的...

    MapXtremeJava4.8install.zip

    MapXtreme Java 4.8 是一款由MapInfo公司开发的专业地图开发工具,它允许开发者在Java环境中创建、管理和展示地理信息系统(GIS)的应用程序。这个“MapXtremeJava4.8install.zip”文件是一个安装包,包含了运行...

    mapxtreme最新包

    MapXtreme与MapInfo紧密集成,用户可以使用MapInfo进行地图编辑和分析,然后通过MapXtreme在Web上发布和交互。两者结合,可以实现从数据管理到应用发布的完整GIS流程。 6. **开发与集成**: 使用MapXtreme的开发...

    MapXtreme培训教材

    MapXtreme是一款由Mapinfo公司开发的企业级地图应用服务器,专为Intranet或Extranet环境设计,旨在利用地图展示企业的信息和资源,提升决策效率和资产管理。本教材详细介绍了MapXtreme的各个方面,包括安装配置、...

    MapXtreme_CHM_中文帮助文档

    MapXtreme是一款由MapInfo公司开发的地理信息系统(GIS)软件,专为企业和组织提供高级的地理位置服务和地图解决方案。这款产品具有强大的地图绘制、数据管理、空间分析以及地图服务发布功能,广泛应用于电信、物流...

Global site tag (gtag.js) - Google Analytics