public void LoadMapDocument(string filename) { if (_doc == null || filename == "") { return; } _docFilename = filename; System.IO.FileInfo fi = new System.IO.FileInfo(filename); if (!fi.Exists) { return; } if (fi.Extension.ToLower() != ".axl") { RemoveAllDataViews(); if (_appWindow != null) { _appWindow.RemoveAllToolbars(); } _activeDataView = null; } XmlStream stream = new XmlStream(""); if (fi.Extension.ToLower() == ".rdm") { StreamReader sr = new StreamReader(filename); byte[] bytes = new byte[fi.Length]; BinaryReader br = new BinaryReader(sr.BaseStream); br.Read(bytes, 0, bytes.Length); sr.Close(); bytes = Crypto.Decrypt(bytes, _cryptoKey); MemoryStream ms = new MemoryStream(bytes); stream.ReadStream(ms); ms.Close(); } else if (fi.Extension.ToLower() == ".axl") { IMap map = _doc.Maps[0]; PlugInManager pman = new PlugInManager(); #region AXL XmlDocument axl = new XmlDocument(); axl.Load(fi.FullName); #region Extent XmlNode envNode = axl.SelectSingleNode("ARCXML/CONFIG/MAP/PROPERTIES/ENVELOPE[@minx and @maxx and @miny and @miny]"); if (envNode != null) { Envelope env = new Envelope(envNode); map.Display.Limit = new Envelope(env); map.Display.ZoomTo(env); } #endregion #region Workspaces Dictionary <string, IDataset> _workspaces = new Dictionary <string, IDataset>(); foreach (XmlNode workspaceNode in axl.SelectNodes("ARCXML/CONFIG/MAP/WORKSPACES/*")) { switch (workspaceNode.Name) { case "SDEWORKSPACE": string connectionString = "server=" + workspaceNode.Attributes["server"].Value; if (workspaceNode.Attributes["instance"] != null) { connectionString += ";instance=" + workspaceNode.Attributes["instance"].Value; } if (workspaceNode.Attributes["database"] != null) { connectionString += ";database=" + workspaceNode.Attributes["database"].Value; } if (workspaceNode.Attributes["user"] != null) { connectionString += ";user="******"user"].Value; } if (workspaceNode.Attributes["password"] != null) { connectionString += ";password="******"password"].Value; } IDataset sdeDataset = pman.CreateInstance(new Guid("CE42218B-6962-48c9-9BAC-39E4C5003AE5")) as IDataset; if (sdeDataset == null) { continue; } sdeDataset.ConnectionString = connectionString; if (!sdeDataset.Open()) { continue; } _workspaces.Add(workspaceNode.Attributes["name"].Value, sdeDataset); break; case "SHAPEWORKSPACE": IDataset shapeDataset = pman.CreateInstance(new Guid("80F48262-D412-41fb-BF43-2D611A2ABF42")) as IDataset; if (shapeDataset == null) { continue; } shapeDataset.ConnectionString = workspaceNode.Attributes["directory"].Value; if (!shapeDataset.Open()) { continue; } _workspaces.Add(workspaceNode.Attributes["name"].Value, shapeDataset); break; case "IMAGEWORKSPACE": IDataset rasterDataset = pman.CreateInstance(new Guid("43DFABF1-3D19-438c-84DA-F8BA0B266592")) as IDataset; _workspaces.Add(workspaceNode.Attributes["name"].Value, rasterDataset); break; } } #endregion #region Layers XmlNodeList layerNodes = axl.SelectNodes("ARCXML/CONFIG/MAP/LAYER[@name and @id and @type]"); if (layerNodes == null) { return; } for (int i = layerNodes.Count - 1; i >= 0; i--) { XmlNode layerNode = layerNodes[i]; if (layerNode.Attributes["type"].Value == "featureclass") { XmlNode datasetNode = layerNode.SelectSingleNode("DATASET[@name and @workspace]"); if (datasetNode == null) { continue; } if (!_workspaces.ContainsKey(datasetNode.Attributes["workspace"].Value)) { continue; } IDataset dataset = _workspaces[datasetNode.Attributes["workspace"].Value]; IDatasetElement dsElement = dataset[datasetNode.Attributes["name"].Value]; if (dsElement == null || dsElement.Class == null) { continue; } IFeatureLayer layer = (IFeatureLayer)LayerFactory.Create(dsElement.Class); if (layerNode.Attributes["visible"] != null) { layer.Visible = layerNode.Attributes["visible"].Value == "true"; } layer.SID = layerNode.Attributes["id"].Value; map.AddLayer(layer); SetLayernameAndScales(layerNode, layer); SetRenderers(layerNode, layer); XmlNode queryNode = layerNode.SelectSingleNode("QUERY[@where]"); if (queryNode != null) { layer.FilterQuery = new QueryFilter(); layer.FilterQuery.WhereClause = queryNode.Attributes["where"].Value; } } else if (layerNode.Attributes["type"].Value == "image") { XmlNode datasetNode = layerNode.SelectSingleNode("DATASET[@name and @workspace]"); if (datasetNode == null) { continue; } if (!_workspaces.ContainsKey(datasetNode.Attributes["workspace"].Value)) { continue; } IRasterFileDataset dataset = _workspaces[datasetNode.Attributes["workspace"].Value] as IRasterFileDataset; if (dataset == null) { continue; } XmlNode workspaceNode = axl.SelectSingleNode("ARCXML/CONFIG/MAP/WORKSPACES/IMAGEWORKSPACE[@name='" + datasetNode.Attributes["workspace"].Value + "' and @directory]"); if (workspaceNode == null) { continue; } IRasterLayer rLayer = dataset.AddRasterFile(workspaceNode.Attributes["directory"].Value + @"\" + datasetNode.Attributes["name"].Value); if (rLayer == null) { continue; } if (layerNode.Attributes["visible"] != null) { rLayer.Visible = layerNode.Attributes["visible"].Value == "true"; } rLayer.SID = layerNode.Attributes["id"].Value; map.AddLayer(rLayer); SetLayernameAndScales(layerNode, rLayer); } } #endregion ValidateUI(); IsDirty = false; _appWindow.Title = "gView.Carto " + fi.Name; if (AfterLoadMapDocument != null) { AfterLoadMapDocument(_doc); } return; #endregion } else { stream.ReadStream(filename); } while (_doc.Maps.Count > 0) { _doc.RemoveMap(_doc.Maps[0]); } _dataViews.Clear(); stream.Load("MapDocument", null, _doc); // Load DataViews... DataView dv; while ((dv = (DataView)stream.Load("DataView", null, new DataView(_doc.Maps))) != null) { if (!(dv.Map is Map)) { continue; } DataView dataView = _appWindow.AddDataView((Map)dv.Map); if (dataView == null) { continue; } dataView.Envelope = dv.Envelope; dataView.TOC = dv.TOC; dataView.DisplayRotation = dv.DisplayRotation; if (_activeDataView == null) { _activeDataView = dataView; } } if (_dataViews.Count == 0 && _doc.Maps.Count > 0) { //_appWindow.AddDataView((Map)_doc.Maps[0]); _activeDataView = _dataViews[0]; } if (_activeDataView != null && _activeDataView.MapView != null) { _activeDataView.MapView.Tool = this.ActiveTool; } ValidateUI(); IsDirty = false; _appWindow.Title = "gView.Carto " + fi.Name; _readonly = (fi.Extension.ToLower() == ".rdm"); if (AfterLoadMapDocument != null) { AfterLoadMapDocument(_doc); } }