Represents a map workspace.

Instances of this class is used to store map settings like a list of layers; data sources, colors, fonts, visible area, the scale of the map etc.

Ejemplo n.º 1
0
 private void SetSpecialScaleStyles(MapWorkspace mapWs, double scale)
 {
 }
Ejemplo n.º 2
0
        public void ProcessRequest(HttpContext context)
        {
            httpContext = context;
            var WorkspaceFilePath = System.IO.Path.Combine(httpContext.Server.MapPath("~"), "workspace.xml");
            MapFolder = System.IO.Path.Combine(httpContext.Server.MapPath("~"), "..", "..", "data");
            string mapId = "";
            


            
                mapWs = new MapWorkspace();
                mapWs.XmlRepresentation = File.ReadAllText(WorkspaceFilePath);
                mapWs.Map.RenderingSettings.AntiAliasGeometry = true;
                mapWs.Map.RenderingSettings.AntiAliasText = true;
          

            //    mapWs.Map.CoodrinateSystemWKT = "PROJCS[\"CS_WGS_1984_Major_Auxiliary_Sphere\",GEOGCS[\"WGS_1984_Major_Auxiliary_Sphere\",DATUM[\"WGS_1984_Major_Auxiliary_Sphere\",SPHEROID[\"WGS84\", 6378137, 0]],PRIMEM[\"Greenwich\", 0],UNIT[\"Degree\", 0.0174532925199433]],PROJECTION[\"Mercator\"],PARAMETER[\"latitude_of_origin\", 0],PARAMETER[\"central_meridian\", 0],PARAMETER[\"false_easting\", 0],PARAMETER[\"false_northing\", 0],UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]],AXIS[\"East\", EAST], AXIS[\"North\", NORTH],AUTHORITY[\"EPSG\", \"102100\"]];";

            foreach (LayerBase l in mapWs.Map.Layers)
            {
               
                    FeatureLayer fl = l as FeatureLayer;
                    if (fl != null)
                    {
                        fl.DataSourceNeeded += LayerDataSourceNeeded;
                        fl.DataSourceReadyToRelease += LayerDataSourceReadyToRelease;                       

                        if (!fl.AreFeaturesAutoLoadable)
                            fl.LoadFeatures();
                    }

                   
               
            }

            mapWs.Map.FeatureRenderer.SelectionColor = ColorTranslator.FromHtml("#0000FF");
            BoundingRectangle bbox = new BoundingRectangle();
            if (context.Request.Params.AllKeys.Contains("BBOX",StringComparer.InvariantCultureIgnoreCase))
            {
                bbox = QueryStringDataExtractor.GetBBox(httpContext.Request.QueryString["BBOX"]);
            }
            Size displaySize;
            double mapScale = 0;
            if (context.Request.Params.AllKeys.Contains("WIDTH", StringComparer.InvariantCultureIgnoreCase) && context.Request.Params.AllKeys.Contains("HEIGHT", StringComparer.InvariantCultureIgnoreCase))
            {
                displaySize = QueryStringDataExtractor.GetDisplaySize(httpContext.Request.QueryString["WIDTH"], httpContext.Request.QueryString["HEIGHT"]);
                mapScale = displaySize.Width / bbox.Width;
            }



            if (context.Request.Params.AllKeys.Contains("LAYERS", StringComparer.InvariantCultureIgnoreCase))
            {
                string[] layersAliases = context.Request.Params["LAYERS"].Split(',');
                foreach (LayerBase l in mapWs.Map.Layers)
                    l.Visible = layersAliases.Contains(l.Alias);
            }

            

            SetSpecialScaleStyles(mapWs, mapScale);

            IMapServer server = new WMSServer(new WmsServiceDescription("MapAround Demo", ""));
            server.ImageQuality = 95;        
            server.Map = mapWs.Map;
            server.GutterSize = 180;
            server.BeforeRenderNewImage += server_BeforeRenderNewImage;


           
               
                FileTileCacheAccessor tileCacheAccessor =
                    new FileTileCacheAccessor(Path.Combine(HttpContext.Current.Server.MapPath("~"), "map\\cache"));
                tileCacheAccessor.Prefix = TileCacheKeyPrefix;
                //  tileCacheAccessor.IsHierarchic = true;
                server.TileCacheAccessor = tileCacheAccessor;


            string mime = string.Empty;
            context.Response.Clear();

            server.GetResponse(context.Request.Params, context.Response.OutputStream, out mime);


            context.Response.ContentType = mime;
            context.Response.Cache.SetCacheability(HttpCacheability.Public);
            context.Response.Cache.SetMaxAge(new TimeSpan(24, 0, 0));

           
         
            server.BeforeRenderNewImage -= server_BeforeRenderNewImage;

            context.Response.End();
        }
Ejemplo n.º 3
0
        private void setWorkspace(MapWorkspace workspace)
        {
            int MapWidth = (int)Width.Value;
            int MapHeight = (int)Height.Value;

            Context.Session[WorkspaceUniqString] = workspace;

            if (workspace.Map != null)
            {
                foreach (LayerBase l in workspace.Map.Layers)
                {
                    FeatureLayer fl = l as FeatureLayer;
                    if (fl != null)
                    {
                        fl.DataSourceNeeded += dataSourceNeeded;
                        fl.DataSourceReadyToRelease += dataSourceReadyToRelease;
                        fl.BeforePointRender += beforePointRender;
                        fl.BeforePolylineRender += beforePolylineRender;
                        fl.BeforePolygonRender += beforePolygonRender;
                        if (!fl.AreFeaturesAutoLoadable)
                            fl.LoadFeatures();
                    }
                }
            }

            // the aspect ratio of the viewport maps may not match the aspect ratio of viewbox, read from the workspace.
            // to correct it.

            double dx = 0, dy = 0;

            if (workspace.ViewBox.IsEmpty())
                throw new InvalidOperationException("View box should be set in the workspace.");

            if (MapWidth / MapHeight > workspace.ViewBox.Width / workspace.ViewBox.Height)
                dy = -(workspace.ViewBox.Height - (double)MapHeight / (double)MapWidth * workspace.ViewBox.Width);
            else
                dx = -(workspace.ViewBox.Width - (double)MapWidth / (double)MapHeight * workspace.ViewBox.Height);

            workspace.ViewBox = new BoundingRectangle(workspace.ViewBox.MinX,
                                                      workspace.ViewBox.MinY,
                                                      workspace.ViewBox.MaxX + dx,
                                                      workspace.ViewBox.MaxY + dy);
        }