/// <summary>
        /// Parses a Map from a MapDocument
        /// </summary>
        /// <param name="s">Instance of <see cref="Stream"/></param>
        /// <returns>Map Document accodring to the MapDocument</returns>
        public static Map LoadMapFromStream(Stream s)
        {
            XmlSerializer ser = new XmlSerializer(typeof(MapDefinition));
            MapDefinition md = (MapDefinition)ser.Deserialize(s);

            Map m = new Map();

            if (md.Extent != null)
                m.ZoomToBox(new GeoAPI.Geometries.Envelope(md.Extent.Xmin, md.Extent.Xmax, md.Extent.Ymin, md.Extent.Ymax));

            if (!string.IsNullOrEmpty(md.BackGroundColor))
            {
                m.BackColor = ColorTranslator.FromHtml(md.BackGroundColor);
            }

            m.SRID = md.SRID;

            foreach (var l in md.Layers)
            {
                SharpMap.Layers.ILayer lay = null;
                //WMSLayer?
                if (l is WmsLayer)
                {
                    ICredentials cred = null;
                    if (!string.IsNullOrEmpty((l as WmsLayer).WmsUser))
                        cred = new NetworkCredential((l as WmsLayer).WmsUser, (l as WmsLayer).WmsPassword);

                    SharpMap.Layers.WmsLayer wmsl = new Layers.WmsLayer(l.Name, (l as WmsLayer).OnlineURL, TimeSpan.MaxValue, WebRequest.DefaultWebProxy, cred);
                    if ((l as WmsLayer).WmsLayers != null)
                    {
                        string[] layers = (l as WmsLayer).WmsLayers.Split(',');
                        foreach (var wl in layers)
                        {
                            wmsl.AddLayer(wl);
                        }
                    }
                    else
                    {
                        wmsl.AddChildLayers(wmsl.RootLayer,true);
                    }
                    lay = wmsl;
                }
                //And some simple tiled layers
                else if (l is OsmLayer)
                {
                    lay = new Layers.TileLayer(new BruTile.Web.OsmTileSource(), l.Name);
                }
                else if (l is GoogleLayer)
                {
                    lay = new Layers.TileLayer(new BruTile.Web.GoogleTileSource(BruTile.Web.GoogleMapType.GoogleMap), l.Name);
                }
                else if (l is GoogleSatLayer)
                {
                    lay = new Layers.TileLayer(new BruTile.Web.GoogleTileSource(BruTile.Web.GoogleMapType.GoogleSatellite), l.Name);
                }
                else if (l is GoogleTerrainLayer)
                {
                    lay = new Layers.TileLayer(new BruTile.Web.GoogleTileSource(BruTile.Web.GoogleMapType.GoogleTerrain), l.Name);
                }

                if (lay != null)
                {
                    lay.MinVisible = l.MinVisible;
                    lay.MaxVisible = l.MaxVisible;
                    m.Layers.Add(lay);
                }

            }

            return m;
        }
Exemple #2
0
        /// <summary>
        /// Parses a Map from a MapDocument
        /// </summary>
        /// <param name="s">Instance of <see cref="Stream"/></param>
        /// <returns>Map Document accodring to the MapDocument</returns>
        public static Map LoadMapFromStream(Stream s)
        {
            XmlSerializer ser = new XmlSerializer(typeof(MapDefinition));
            MapDefinition md  = (MapDefinition)ser.Deserialize(s);

            Map m = new Map();

            if (md.Extent != null)
            {
                m.ZoomToBox(new GeoAPI.Geometries.Envelope(md.Extent.Xmin, md.Extent.Xmax, md.Extent.Ymin, md.Extent.Ymax));
            }

            if (!string.IsNullOrEmpty(md.BackGroundColor))
            {
                m.BackColor = ColorTranslator.FromHtml(md.BackGroundColor);
            }

            m.SRID = md.SRID;

            foreach (var l in md.Layers)
            {
                SharpMap.Layers.ILayer lay = null;
                //WMSLayer?
                if (l is WmsLayer)
                {
                    ICredentials cred = null;
                    if (!string.IsNullOrEmpty((l as WmsLayer).WmsUser))
                    {
                        cred = new NetworkCredential((l as WmsLayer).WmsUser, (l as WmsLayer).WmsPassword);
                    }

                    SharpMap.Layers.WmsLayer wmsl = new Layers.WmsLayer(l.Name, (l as WmsLayer).OnlineURL, TimeSpan.MaxValue, WebRequest.DefaultWebProxy, cred);
                    if ((l as WmsLayer).WmsLayers != null)
                    {
                        string[] layers = (l as WmsLayer).WmsLayers.Split(',');
                        foreach (var wl in layers)
                        {
                            wmsl.AddLayer(wl);
                        }
                    }
                    else
                    {
                        wmsl.AddChildLayers(wmsl.RootLayer, true);
                    }
                    lay = wmsl;
                }
                //And some simple tiled layers
                else if (l is OsmLayer)
                {
                    lay = new Layers.TileLayer(new BruTile.Web.OsmTileSource(), l.Name);
                }
                else if (l is GoogleLayer)
                {
                    lay = new Layers.TileLayer(new BruTile.Web.GoogleTileSource(BruTile.Web.GoogleMapType.GoogleMap), l.Name);
                }
                else if (l is GoogleSatLayer)
                {
                    lay = new Layers.TileLayer(new BruTile.Web.GoogleTileSource(BruTile.Web.GoogleMapType.GoogleSatellite), l.Name);
                }
                else if (l is GoogleTerrainLayer)
                {
                    lay = new Layers.TileLayer(new BruTile.Web.GoogleTileSource(BruTile.Web.GoogleMapType.GoogleTerrain), l.Name);
                }

                if (lay != null)
                {
                    lay.MinVisible = l.MinVisible;
                    lay.MaxVisible = l.MaxVisible;
                    m.Layers.Add(lay);
                }
            }


            return(m);
        }