private void SerializeProject(MapStruct map, string saveFileName)
        {
            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter oFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            // System.Runtime.Serialization.Formatters.Soap.SoapFormatter oFormatter = new System.Runtime.Serialization.Formatters.Soap.SoapFormatter();

            System.IO.FileStream oFileStream = new System.IO.FileStream(saveFileName, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite);
            oFormatter.Serialize(oFileStream, map);
        }
        public MapStruct DeserializeProject(string projectFileName)
        {
            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter oFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            //System.Runtime.Serialization.Formatters.Soap.SoapFormatter oFormatter = new System.Runtime.Serialization.Formatters.Soap.SoapFormatter();
            MapStruct oMap = new MapStruct();

            using (System.IO.FileStream oFileStream = new System.IO.FileStream(projectFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read))
            {
                oMap = oFormatter.Deserialize(oFileStream) as MapStruct;
            }

            return(oMap);
        }
        public MapStruct LoadProjectByMapInfos(string projectFileName, AxMapObjects2.AxMap mapControl)
        {
            ProjectSerialization oProjectSerialization = new ProjectSerialization();
            MapStruct            oMapStruct            = oProjectSerialization.DeserializeProject(projectFileName);
            List <ILayerStruct>  oLayers = oMapStruct.Layers;

            MapObjects2.DataConnection oConn = new MapObjects2.DataConnectionClass();

            foreach (ILayerStruct oLayer in oLayers)
            {
                if (oLayer is MapLayerInfoStruct)
                {
                    MapObjects2.MapLayer oMapLayer = new MapObjects2.MapLayerClass();
                    oConn.Database = System.IO.Path.GetDirectoryName(oLayer.FileName);

                    if (oConn.Connect())
                    {
                        oMapLayer.GeoDataset = oConn.FindGeoDataset(oLayer.DataSetName);

                        this.SetLayerRender(oMapLayer, (oLayer as MapLayerInfoStruct).Render);
                        this.ConvertSymbol((oLayer as MapLayerInfoStruct).Symbol, oMapLayer.Symbol);

                        oMapLayer.Name    = oLayer.AliasName;
                        oMapLayer.Visible = oLayer.Visible;
                        oMapLayer.Tag     = string.Format("{0}-{1}", oLayer.MinLevel, oLayer.MaxLevel);
                        mapControl.Layers.Add(oMapLayer);
                        oConn.Disconnect();
                    }
                }
                else if (oLayer is ImageLayerInfoStruct)
                {
                    //not implement
                    //MapObjects2.ImageLayer oImageLayer = new MapObjects2.ImageLayerClass();
                    //oImageLayer.Name = oLayer.Name;
                }
            }

            MapObjects2.Rectangle oViewExtent = new MapObjects2.RectangleClass();

            oViewExtent.Left   = oMapStruct.BBox.MinX;
            oViewExtent.Top    = oMapStruct.BBox.MinY;
            oViewExtent.Right  = oMapStruct.BBox.MaxX;
            oViewExtent.Bottom = oMapStruct.BBox.MaxY;
            mapControl.Extent  = oViewExtent;
            //mapControl.CoordinateSystem = oMapStruct.CoordinateSystem;

            return(oMapStruct);
        }
        public void SaveMapInfosToProject(AxMapObjects2.AxMap mapControl, string saveFileName, MapStruct currentMapInfos)
        {
            MapStruct oMapStruct = new MapStruct();

            oMapStruct.BBox.MinX   = mapControl.Extent.Left;
            oMapStruct.BBox.MinY   = mapControl.Extent.Top;
            oMapStruct.BBox.MaxX   = mapControl.Extent.Right;
            oMapStruct.BBox.MaxY   = mapControl.Extent.Bottom;
            oMapStruct.BBox.Width  = mapControl.Extent.Width;
            oMapStruct.BBox.Height = mapControl.Extent.Height;

            // oMapStruct.CoordinateSystem = mapControl.CoordinateSystem;

            short iLayersCount = mapControl.Layers.Count;

            for (short i = (short)(iLayersCount - 1); i >= 0; i--)
            {
                object oLayer = mapControl.Layers.Item(i);

                if (oLayer is MapObjects2.MapLayer)
                {
                    MapObjects2.MapLayer oMapLayer       = oLayer as MapObjects2.MapLayer;
                    MapLayerInfoStruct   oMapLayerStruct = new MapLayerInfoStruct();

                    oMapLayerStruct.FileName    = currentMapInfos.FindLayer(oMapLayer.Name).FileName;
                    oMapLayerStruct.LayerType   = (short)oMapLayer.LayerType;
                    oMapLayerStruct.AliasName   = oMapLayer.Name;
                    oMapLayerStruct.DataSetName = System.IO.Path.GetFileNameWithoutExtension(oMapLayerStruct.FileName);
                    oMapLayerStruct.ShapeType   = (short)oMapLayer.shapeType;
                    oMapLayerStruct.Visible     = oMapLayer.Visible;
                    oMapLayerStruct.MinLevel    = int.Parse(oMapLayer.Tag.Split('-')[0]);
                    oMapLayerStruct.MaxLevel    = int.Parse(oMapLayer.Tag.Split('-')[1]);

                    oMapLayerStruct.Render = this.ExportLayerRender(oMapLayer);
                    this.DeconvertSymbol(oMapLayer.Symbol, oMapLayerStruct.Symbol);
                    oMapStruct.Layers.Add(oMapLayerStruct as ILayerStruct);
                }
                else if (oLayer is MapObjects2.ImageLayer)
                {
                    throw new NotImplementedException();
                }
            }

            this.SerializeProject(oMapStruct, saveFileName);
        }
Exemple #5
0
        public FeatureInformations GetIdentifyFeatureInfos(MapObjects2.Point mousePosition, AxMapObjects2.AxMap mapControl, MapProject.MapStruct mapInfosCollection)
        {
            FeatureInformations oFeatureInfos = null;

            foreach (ILayerStruct oLayerInfos in mapInfosCollection.Layers)
            {
                if (oLayerInfos.LayerType != (short)LayerTypeConstants.moMapLayer)
                {
                    continue;
                }

                MapUtil.MapOperation oMapOper  = new MapOperation();
                MapObjects2.MapLayer oMapLayer = oMapOper.GetLayerByName(mapControl, oLayerInfos.AliasName) as MapObjects2.MapLayer;

                if (oMapLayer.Visible == false)
                {
                    continue;
                }

                Recordset oSelectedRecords = oMapLayer.SearchShape(mousePosition, SearchMethodConstants.moAreaIntersect, "");

                if (oSelectedRecords.EOF)
                {
                    continue;
                }

                oSelectedRecords.MoveFirst();

                oFeatureInfos = new FeatureInformations();
                oFeatureInfos.CurrentLayerInfos = oLayerInfos;
                oFeatureInfos.Geometry          = oSelectedRecords.Fields.Item("shape").Value;

                TableDesc oTableDesc = oSelectedRecords.TableDesc;
                oFeatureInfos.FieldsAndValuesCollection = new Dictionary <string, string>();
                int    iFieldsCount = oTableDesc.FieldCount;
                string sFieldName   = "";
                string sValue       = "";

                for (short i = 0; i < iFieldsCount; i++)
                {
                    sFieldName = oTableDesc.get_FieldName(i);
                    sValue     = oSelectedRecords.Fields.Item(sFieldName).ValueAsString;
                    oFeatureInfos.FieldsAndValuesCollection.Add(sFieldName, sValue);
                }

                break;
            }

            return(oFeatureInfos);
        }
Exemple #6
0
        /// <summary>
        /// ����ͼ�㼯��
        /// </summary>
        /// <param name="layerPaths">ͼ��·������</param>
        /// <param name="map">��ͼ����</param>
        public void LoadLayers(List<string> layerPaths,MapStruct mapInfoCollection, AxMapObjects2.AxMap mapControl)
        {
            BaseHandler.MapManager oMapManager = new BaseHandler.MapManager();
            ProjectSerialization oProjectSerilization = new ProjectSerialization();

            foreach (string sLayerPath in layerPaths)
            {
                string sFileExtent = System.IO.Path.GetExtension(sLayerPath);
                LayerTypeConstants oLayerType = oMapManager.GetLayerTypeByFileExtent(sFileExtent);

                if (oLayerType == LayerTypeConstants.moMapLayer)
                {
                    MapLayer oMapLayer = oMapManager.GetSingleVectorLayer(sLayerPath);
                    oMapLayer.Tag = "0-0";
                    mapControl.Layers.Add(oMapLayer);

                    MapLayerInfoStruct oMapLayerStruct = oProjectSerilization.LoadLayerInfos(oMapLayer, sLayerPath, -1, -1);
                    mapInfoCollection.Layers.Insert(0,oMapLayerStruct);
                }
                else if (oLayerType == LayerTypeConstants.moImageLayer)
                {
                    ImageLayer oImageLayer = oMapManager.GetSingleImageLayer(sLayerPath);
                    oImageLayer.Tag =  "0-0";
                    mapControl.Layers.Add(oImageLayer);

                    ImageLayerInfoStruct oImageLayerStruct = oProjectSerilization.LoadLayerInfos(oImageLayer, sLayerPath, -1, -1);
                    mapInfoCollection.Layers.Insert(0,oImageLayerStruct);
                }
            }
        }