using System; using System.IO; using System.Xml; using System.Collections.Generic; using System.Linq; using System.Text; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.WpfDesktopEdition; namespace MapLoader { class MapManager { public void loadMapFromXML(WpfMap wpfMap1, String _MapPath) { ShapeFileFeatureLayer[] ShpFileTable; ShapeFileFeatureLayer[] ShpLabelTable; ShpFileTable = new ShapeFileFeatureLayer[16]; ShpLabelTable = new ShapeFileFeatureLayer[16]; int ShpFindex = 0; string layerName = "Layer"; string labelName = "Label"; wpfMap1.Overlays.Clear(); // remove old map _MapPath = System.Configuration.ConfigurationManager.AppSettings["MapPath"]; if (_MapPath == null) _MapPath = string.Empty; StringBuilder output = new StringBuilder(); FileStream fs = new FileStream(_MapPath + "map.xml", FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read); XmlReader reader = XmlReader.Create(fs); XmlReaderSettings setttings = new XmlReaderSettings(); // using (reader) wpfMap1.MapUnit = GeographyUnit.DecimalDegree; LayerOverlay staticOverlay = new LayerOverlay(); GeoColor layerColor = new GeoColor(); while (reader.Read()) { reader.ReadToFollowing("Layer"); reader.MoveToFirstAttribute(); string filename = reader.Value; reader.MoveToNextAttribute(); string typename = reader.Value; // MessageBox.Show(filename,"FileName"); // MessageBox.Show(typename, "Type Name"); string path = _MapPath + filename; // ShpFileTable[ShpFindex] = new ShapeFileFeatureLayer(path); if (typename == "land") layerColor = GeoColor.SimpleColors.Black; else if (typename == "city") layerColor = GeoColor.SimpleColors.Red; else if (typename == "railroad") layerColor = GeoColor.SimpleColors.Blue; else if (typename == "water") layerColor = GeoColor.SimpleColors.DarkBlue; else if (typename == "street") layerColor = GeoColor.SimpleColors.DarkRed; else if (typename == "park") layerColor = GeoColor.SimpleColors.Copper; else if (typename == "maincity") layerColor = GeoColor.SimpleColors.DarkOrange; ShpFileTable[ShpFindex] = new ShapeFileFeatureLayer(path); if ((typename == "land") || (typename == "city") || (typename == "water") || (typename == "park") || (typename == "maincity")) ShpFileTable[ShpFindex].ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.FromArgb(100, layerColor)); else ShpFileTable[ShpFindex].ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(layerColor, 2, true); ShpFileTable[ShpFindex].ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; // ShpFileTable[ShpFindex].ZoomLevelSet.ZoomLevel01.DefaultTextStyle=TextStyles.CreateSimpleTextStyle("NAME","Arial",7, DrawingFontStyles.Bold, GeoColor.FromArgb(255, 91, 91, 91)); ShpFileTable[ShpFindex].DrawingMarginPercentage = 100; // Label layer ShpLabelTable[ShpFindex] = new ShapeFileFeatureLayer(path); // ShpLabelTable[ShpFindex].ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(layerColor, 5, true); ShpLabelTable[ShpFindex].ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; ShpLabelTable[ShpFindex].ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.CreateSimpleTextStyle("NAME", "Arial", 7, DrawingFontStyles.Bold, GeoColor.FromArgb(255, 91, 91, 91)); ShpLabelTable[ShpFindex].DrawingMarginPercentage = 100; labelName = "Label" + ShpFindex.ToString(); layerName = "Layer" + ShpFindex.ToString(); staticOverlay.Layers.Add(layerName, ShpFileTable[ShpFindex]); staticOverlay.Layers.Add(labelName, ShpLabelTable[ShpFindex]); // staticOverlay.Layers.Add("mylandLayer", mylandBaseRegion); ShpFindex = ShpFindex + 1; wpfMap1.Overlays.Add(staticOverlay); if ((!ShpFileTable[0].IsOpen == true) && (ShpFileTable[0] != null)) { ShpFileTable[0].Open(); } RectangleShape extBox = ShpFileTable[0].GetBoundingBox(); wpfMap1.CurrentExtent = extBox; wpfMap1.Refresh(); if (ShpFindex == 16) break; // MessageBox.Show(ShpFindex.ToString(), "Layer Number"); } ShpFileTable[0].Close(); return; } } }