MapX地图操作

创建图层

        public void CreateLayer(string LayerName)
        {

            MapXLib.CoordSys coor = axMap.DisplayCoordSys;
            MapXLib.Layer myLayer = axMap.Layers.CreateLayer(LayerName, Type.Missing, 0, 100, coor);//100为KeyLength,可决定图层中feature的KeyValue的长度
            myLayer.Editable = true;
            myLayer.Visible = true;
            axMap.Layers.AnimationLayer = myLayer;
        }

清除图层上的图元

        public void ClearFeature(string LayerName)
        {

            MapXLib.Layer layer = axMap.Layers._Item(LayerName);
            MapXLib.Feature fea;
            MapXLib.Features feas;

            while (layer.AllFeatures.Count > 0)
            {
                feas = layer.AllFeatures;
                fea = feas._Item(1);
                layer.DeleteFeature(fea);
            };
        }

添加图元到图层

     public void AddCarToLayer(string DevicesName)
         {
                MapXLib.Feature fe = new MapXLib.FeatureClass();

                fe.Attach(axMap.GetOcx());

                fe.Style.SymbolType = MapXLib.SymbolTypeConstants.miSymbolTypeBitmap;
                fe.Style.SymbolBitmapTransparent = true;
                fe.Style.SymbolBitmapSize = 20;
                fe.Style.SymbolBitmapName = "carOver0.bmp";
                
                fe.Point.Set(dp.x, dp.y);
                fe.KeyValue = DevicesName;
                m_CarLayer.AddFeature(fe, Type.Missing);
            
                m_CarLayer.Refresh();
                axMap.Refresh();
}

添加线段

            MapXLib.Points linePoints = new MapXLib.PointsClass();
         
       {为linePoints添加点}
MapXLib.Layer layer
= axMap.Layers._Item("LineLayer"); MapXLib.Feature lineFeature = axMap.FeatureFactory.CreateLine(linePoints, axMap.DefaultStyle); layer.AddFeature(lineFeature, Type.Missing);

 

添加圆形

            MapXLib.Point centerP = new MapXLib.PointClass();
            centerP.Set(centerPoint.x, centerPoint.y);

            MapXLib.Layer layer = axMap.Layers._Item("RegionLayer");
            MapXLib.Feature regionFeature = axMap.FeatureFactory.CreateCircularRegion((short)MapXLib.CircleTypeConstants.miCircleTypeScreen, centerP, radius, MapXLib.MapUnitConstants.miUnitMeter, 100, RegionCustomStyle(AreaType));
            layer.AddFeature(regionFeature, Type.Missing);

 

添加矩形

            MapXLib.Points points = new MapXLib.PointsClass();
            MapXLib.Point ltP = new MapXLib.PointClass();
            ltP.Set(ltPoint.x, ltPoint.y);
            MapXLib.Point rtP = new MapXLib.PointClass();
            rtP.Set(rbPoint.x, ltPoint.y);
            MapXLib.Point lbP = new MapXLib.PointClass();
            lbP.Set(ltPoint.x, rbPoint.y);
            MapXLib.Point rbP = new MapXLib.PointClass();
            rbP.Set(rbPoint.x, rbPoint.y);

            points.Add(ltP, 1);
            points.Add(rtP, 2);
            points.Add(lbP, 4);
            points.Add(rbP, 3);

            MapXLib.Layer layer = axMap.Layers._Item("RegionLayer");
            MapXLib.Feature regionFeature = axMap.FeatureFactory.CreateRegion(points, RegionCustomStyle(AreaType));
            layer.AddFeature(regionFeature, Type.Missing);

添加多边形

            MapXLib.Layer layer = axMap.Layers._Item("RegionLayer");
            MapXLib.Feature regionFeature = axMap.FeatureFactory.CreateRegion(points, RegionCustomStyle(AreaType));
            layer.AddFeature(regionFeature, Type.Missing);

显示可视范围

axMap.CtlBounds = 自定义的RECT;

删除图元

                MapXLib.Feature fea = m_CarLayer.GetFeatureByKey(feaKey);
                m_CarLayer.DeleteFeature(fea);

更新图元图片、位置等信息

                string feaKey = m_CarLayer.FeatureKeyFromFeatureName(carName);
                MapXLib.Feature fea = m_CarLayer.GetFeatureByKey(feaKey);
                fea.Style.SymbolBitmapName = CarBMP;
                fea.Point.Set(newPoint.x, newPoint.y);
                fea.Update(fea, Type.Missing);

两点间距离

axMap.Distance(ptStart.x, ptStart.y, ptEnd.x, ptEnd.y)

 

posted @ 2013-12-10 17:19  cg.2019  阅读(1947)  评论(0编辑  收藏  举报