Exemplo n.º 1
0
        //投影信息改变了
        private void _PrjSystem_ProjectedSystemChanged(object sender)
        {
            foreach (Layer sLayer in _Layers)
            {
                //计算投影
                bool sRead = sLayer.ReadOnly;
                sLayer.ReadOnly = false;
                if (sLayer.GeoType == typeof(PointD))
                {
                    PointD sPoint;
                    foreach (DataRow mRow in sLayer.Records.Rows)
                    {
                        sPoint = mRow.Field <PointD>(1);
                        if (sPoint != null)
                        {
                            mRow[2] = _PrjSystem.ToProjCo(sPoint);
                        }
                    }
                }
                else if (sLayer.GeoType == typeof(MultiPolyLine))
                {
                    MultiPolyLine sMultiPolyLine;
                    foreach (DataRow mRow in sLayer.Records.Rows)
                    {
                        sMultiPolyLine = mRow.Field <MultiPolyLine>(1);
                        if (sMultiPolyLine != null)
                        {
                            mRow[2] = _PrjSystem.ToProjCo(sMultiPolyLine);
                        }
                    }
                }
                else if (sLayer.GeoType == typeof(MultiPolygon))
                {
                    MultiPolygon sMultiPolygon;
                    foreach (DataRow mRow in sLayer.Records.Rows)
                    {
                        sMultiPolygon = mRow.Field <MultiPolygon>(1);
                        if (sMultiPolygon != null)
                        {
                            mRow[2] = _PrjSystem.ToProjCo(sMultiPolygon);
                        }
                    }
                }

                Geometry sGeo;
                foreach (DataRow mRow in sLayer.Records.Rows)
                {
                    if (!Convert.IsDBNull(mRow[2]))
                    {
                        sGeo    = (Geometry)mRow[2];
                        mRow[3] = LayerTools.GetCenterPoint(sGeo);
                    }
                }

                sLayer.MBR    = LayerTools.GetLayerGeoMBR(sLayer);
                sLayer.PRJMBR = _PrjSystem.ToProjCo(sLayer.MBR);
                sLayer.Records.AcceptChanges();     //保存更改
                sLayer.GenerateIndex();             //计算地理索引
                MapPerformaceChanged?.Invoke(this); //重绘一级地图
                sLayer.ReadOnly = sRead;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 添加图层
        /// </summary>
        /// <param name="layer">图层</param>
        public void AddLayer(Layer layer)
        {
            //计算投影
            if (layer.GeoType == typeof(PointD))
            {
                PointD sPoint;
                foreach (DataRow mRow in layer.Records.Rows)
                {
                    sPoint = mRow.Field <PointD>(1);
                    if (sPoint != null)
                    {
                        mRow[2] = _PrjSystem.ToProjCo(sPoint);
                    }
                }
            }
            else if (layer.GeoType == typeof(MultiPolyLine))
            {
                MultiPolyLine sMultiPolyLine;
                foreach (DataRow mRow in layer.Records.Rows)
                {
                    sMultiPolyLine = mRow.Field <MultiPolyLine>(1);
                    if (sMultiPolyLine != null)
                    {
                        mRow[2] = _PrjSystem.ToProjCo(sMultiPolyLine);
                    }
                }
            }
            else if (layer.GeoType == typeof(MultiPolygon))
            {
                MultiPolygon sMultiPolygon;
                foreach (DataRow mRow in layer.Records.Rows)
                {
                    sMultiPolygon = mRow.Field <MultiPolygon>(1);
                    if (sMultiPolygon != null)
                    {
                        mRow[2] = _PrjSystem.ToProjCo(sMultiPolygon);
                    }
                }
            }

            Geometry sGeo;

            foreach (DataRow mRow in layer.Records.Rows)
            {
                if (!Convert.IsDBNull(mRow[2]))
                {
                    sGeo    = (Geometry)mRow[2];
                    mRow[3] = LayerTools.GetCenterPoint(sGeo);
                }
            }
            if (layer.MBR == null)
            {
                layer.MBR = LayerTools.GetLayerGeoMBR(layer);
            }

            layer.PRJMBR = _PrjSystem.ToProjCo(layer.MBR);
            layer.Records.AcceptChanges(); //保存更改
            layer.GenerateIndex();         //计算地理索引

            //将地图数据锁住,不允许修改
            layer.ReadOnly = true;


            layer.VisiblityChanged += Layer_VisiblityChanged;
            layer.SymbolChanged    += Layer_SymbolChanged;
            layer.RecordsChanged   += Layer_RecordsChanged;

            _Layers.Insert(0, layer);
            if (_DataSet.Tables.Contains(layer.Name))
            {
                layer.Name += "_";
            }
            _DataSet.Tables.Add(layer.Records);
            _TreeNode.Nodes.Insert(0, layer.Node);

            LayerAdded?.Invoke(this, layer);    //通知外部已经添加了图层
            MapPerformaceChanged?.Invoke(this); //重绘一级地图
        }