Example #1
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
            if (Session.IsNewSession)
            {
                //get default mapcontrol model from session
                MapInfo.WebControls.MapControlModel controlModel = MapControlModel.SetDefaultModelInSession();

                //add custom commands to map control model
                controlModel.Commands.Add(new CreateTheme());
                controlModel.Commands.Add(new RemoveTheme());
                controlModel.Commands.Add(new GetLegend());

                //instanciate AppStateManager class
                AppStateManager myStateManager = new AppStateManager();

                //put current map alias to state manager dictionary
                myStateManager.ParamsDictionary[StateManager.ActiveMapAliasKey] = this.MapControl1.MapAlias;

                //put state manager to session
                StateManager.PutStateManagerInSession(myStateManager);
            }

            // Now Restore State
            StateManager.GetStateManagerFromSession().RestoreState();
        }
Example #2
0
        /// <summary>
        /// This method gets the map object from the mapfactory with the given mapalias and exports it to the memory stream and streams it back to client.
        /// </summary>
        /// <remarks>None</remarks>
        public override void Process()
        {
            MapControlModel model = MapControlModel.GetModelFromSession();
            MemoryStream    ms    = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);

            StreamImageToClient(ms);
        }
Example #3
0
        /// <summary>
        /// Sets the given model in the ASP.NET session
        /// </summary>
        /// <remarks>If a custom model is used, this method can be used to set the model in the session that will be used instead</remarks>
        /// <param name="model">The model to be set in the ASP.NET session.</param>
        public static void SetModelInSession(MapControlModel model)
        {
            HttpContext context = HttpContext.Current;
            string      key     = string.Format("{0}_MapModel", context.Session.SessionID);

            context.Session[key] = model;
        }
Example #4
0
        /// <summary>
        /// Renders the control by setting the source of the image to a URL containing all information to get the right map.
        /// </summary>
        /// <remarks>This method renders the controls HTML by writing an HTML IMG tag setting its source to the URL.
        /// </remarks>
        /// <param name="output">The HTML writer object to write HTML to.</param>
        protected override void RenderContents(HtmlTextWriter output)
        {
            // Get the model out of ASP.NET and get the stream
            MapControlModel model = MapControlModel.GetModelFromSession();

            if (model == null)
            {
                model = MapControlModel.SetDefaultModelInSession();
            }
            MemoryStream ms = null;

            try{
                ms = model.GetMap(MapAlias, (int)Width.Value, (int)Height.Value, ExportFormat.ToString());
            } catch (Exception ex) {
                output.WriteLine(ex.Message);
                output.WriteLine("<br>");
                output.WriteLine(L10NUtils.Resources.GetString("MapNotFoundErrorString"));
                HttpContext.Current.Server.ClearError();
                return;
            }

            // Insert the image stream to Cache with key imageid and timeout in 2 mintues.
            string imageid = ImageHelper.GetUniqueID();

            ImageHelper.SetImageToCache(imageid, ms, 2);
            string url = ImageHelper.GetImageURL(imageid, ExportFormat.ToString());

            //Write the IMG tag and set the mapalias.
            output.AddAttribute(HtmlTextWriterAttribute.Width, Width.ToString());
            output.AddAttribute(HtmlTextWriterAttribute.Height, Height.ToString());
//			output.AddAttribute("exportFormat", ExportFormat.ToString());
            //		output.AddAttribute("mapAlias", MapAlias);
            if (IMGUseMap != null)
            {
                if (IMGUseMap.Length > 0)
                {
                    output.AddAttribute("USEMAP", IMGUseMap);
                }
            }
            if (CssClass != null)
            {
                output.AddAttribute(HtmlTextWriterAttribute.Class, CssClass);
            }
            output.AddAttribute(HtmlTextWriterAttribute.Alt, "");
            output.AddAttribute(HtmlTextWriterAttribute.Src, url);
            output.AddAttribute(HtmlTextWriterAttribute.Id, UniqueID + "_Image");
            output.RenderBeginTag(HtmlTextWriterTag.Img);
            output.RenderEndTag();
            output.Flush();

            // Now set the alias and format manually by getting the image element.
            output.AddAttribute("language", "javascript");
            output.AddAttribute(HtmlTextWriterAttribute.Type, "text/javascript");
            output.RenderBeginTag(HtmlTextWriterTag.Script);
            output.WriteLine(string.Format("var {0}Me = document.getElementById('{0}_Image');", UniqueID));
            output.WriteLine(string.Format("{0}Me.mapAlias= '{1}';", UniqueID, MapAlias));
            output.WriteLine(string.Format("{0}Me.exportFormat= '{1}';", UniqueID, ExportFormat));
            output.RenderEndTag();
        }
Example #5
0
        /// <summary>
        /// Executes commands and delegates the execution of the command to the model.
        /// </summary>
        /// <remarks>The model extracts the command and calls the appropriate method to perform the operation.
        /// See description of the class for more details.</remarks>
        /// <param name="context">Current context</param>
        public void ProcessRequest(HttpContext context)
        {
            MapControlModel mapModel = MapControlModel.SetDefaultModelInSession();

            if (mapModel != null)
            {
                mapModel.InvokeCommand();
            }
        }
Example #6
0
        /// <summary>
        /// Gets the map object out of the Mapfactory with a given MapAlias, zooms it using the given zoomfactor,
        /// and streams the image back to client.
        /// </summary>
        /// <remarks>None</remarks>
        public override void Process()
        {
            MapControlModel model = MapControlModel.GetModelFromSession();

            ZoomLevel = System.Convert.ToDouble(HttpContext.Current.Request["ZoomLevel"]);
            model.Zoom(MapAlias, -1.0, ZoomLevel);
            MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);

            StreamImageToClient(ms);
        }
Example #7
0
        /// <summary>
        /// Gets the map object out of the MapFactory with a given MapAlias, searches for all features whose centroids are within
        /// the given polygon, updates the default selection, and streams the image back to client.
        /// </summary>
        /// <remarks>None</remarks>
        public override void Process()
        {
            MapControlModel model = MapControlModel.GetModelFromSession();

            model.SetMapSize(MapAlias, MapWidth, MapHeight);
            System.Drawing.Point[] points = ExtractPoints(DataString);
            model.PolygonSelection(MapAlias, points);
            MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);

            StreamImageToClient(ms);
        }
Example #8
0
        /// <summary>
        /// Gets the model from the ASP.NET session.
        /// </summary>
        /// <remarks>This method will return null if the model is not found.</remarks>
        /// <returns>MapControlModel</returns>
        public static MapControlModel GetModelFromSession()
        {
            HttpContext     context = HttpContext.Current;
            string          key     = string.Format("{0}_MapModel", context.Session.SessionID);
            MapControlModel model   = null;

            if (context.Session[key] != null)
            {
                model = context.Session[key] as MapControlModel;
            }
            return(model);
        }
Example #9
0
        /// <summary>
        /// Creates the default model provided by MapXtreme and sets the object in the ASP.NET session.
        /// </summary>
        /// <remarks>This method tries to extract the model for the MapControl from the ASP.NET session. If a model is not found, a default will be created and places there.
        /// This is a safe method and always returns the model. This method can be used when the model does not exist in the session.</remarks>
        /// <returns>MapControlMode from session.</returns>
        public static MapControlModel SetDefaultModelInSession()
        {
            HttpContext     context = HttpContext.Current;
            MapControlModel model   = GetModelFromSession();

            if (model == null)
            {
                model = new MapControlModel();
                SetModelInSession(model);
            }
            return(model);
        }
Example #10
0
        /// <summary>
        /// Gets the map object out of the MapFactory with a given MapAlias, sets the visibility of the given layer,
        /// and streams the image back to the client.
        /// </summary>
        /// <remarks>
        /// This command is executed from the LayerControl. The LayerControl is set up when the visibility checkbox is checked, it
        /// uses an XMLHttp object to make a call to the server with a given layername and visibility.
        /// There is no submit button for the LayerControl. Therefore, every trip to the server contains one layername.
        /// </remarks>
        public override void Process()
        {
            MapControlModel model      = MapControlModel.GetModelFromSession();
            string          layerAlias = HttpContext.Current.Request["LayerAlias"];
            string          layerType  = HttpContext.Current.Request["LayerType"];
            bool            visible    = (HttpContext.Current.Request["Visible"] == "true");

            model.SetLayerVisibility(MapAlias, layerAlias, layerType, visible);
            MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);

            StreamImageToClient(ms);
        }
Example #11
0
        /// <summary>
        /// Gets the map object out of the MapFactory with a given MapAlias, searches all features near a
        /// given point in all visible and selectable layers, updates the default selection, and streams the image back to client.
        /// </summary>
        /// <remarks>None</remarks>
        public override void Process()
        {
            int             pixelTolerance = System.Convert.ToInt32(HttpContext.Current.Request[PixelToleranceKey]);
            MapControlModel model          = MapControlModel.GetModelFromSession();

            model.SetMapSize(MapAlias, MapWidth, MapHeight);
            System.Drawing.Point[] points = ExtractPoints(DataString);
            model.PointSelection(MapAlias, points[0], pixelTolerance);
            MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);

            StreamImageToClient(ms);
        }
Example #12
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            MapInfo.Mapping.Map myMap = GetMapObj();
            if (Session.IsNewSession)
            {
                AppStateManager stateManager = new AppStateManager();
                stateManager.ParamsDictionary[AppStateManager.ActiveMapAliasKey] = this.MapControl1.MapAlias;
                MapInfo.WebControls.StateManager.PutStateManagerInSession(stateManager);

                // Add customized web tools
                // Below line will put controlModel into HttpSessionState.
                MapInfo.WebControls.MapControlModel controlModel = MapControlModel.SetDefaultModelInSession();
                controlModel.Commands.Add(new AddPinPointCommand());
                controlModel.Commands.Add(new ClearPinPointCommand());
                controlModel.Commands.Add(new ModifiedRadiusSelectionCommand());

                /****** Set the initial state of the map  *************/
                // Clear up the temp layer left by other customer requests.
                if (myMap != null)
                {
                    if (myMap.Layers[SampleConstants.TempLayerAlias] != null)
                    {
                        myMap.Layers.Remove(SampleConstants.TempLayerAlias);
                    }
                }
                // Need to clean up "dirty" temp table left by other customer requests.
                MapInfo.Engine.Session.Current.Catalog.CloseTable(SampleConstants.TempTableAlias);
                // Need to clear the DefautlSelection.
                MapInfo.Engine.Session.Current.Selections.DefaultSelection.Clear();

                // Creat a temp table and AddPintPointCommand will add features into it.
                MapInfo.Data.TableInfoMemTable ti = new MapInfo.Data.TableInfoMemTable(SampleConstants.TempTableAlias);
                // Make the table mappable
                ti.Columns.Add(MapInfo.Data.ColumnFactory.CreateFeatureGeometryColumn(myMap.GetDisplayCoordSys()));
                ti.Columns.Add(MapInfo.Data.ColumnFactory.CreateStyleColumn());

                MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti);
                // Create a new FeatureLayer based on the temp table, so we can see the temp table on the map.
                myMap.Layers.Insert(0, new FeatureLayer(table, "templayer", SampleConstants.TempLayerAlias));

                // This step is needed because you may get a dirty map from mapinfo Session.Current which is retrived from session pool.
                myMap.Zoom   = new MapInfo.Geometry.Distance(25000, MapInfo.Geometry.DistanceUnit.Mile);
                myMap.Center = new MapInfo.Geometry.DPoint(27775.805792979896, -147481.33999999985);
            }

            MapInfo.WebControls.StateManager.GetStateManagerFromSession().RestoreState();
        }
Example #13
0
        /// <summary>
        /// Gets the map object out of the MapFactory with a given MapAlias, searches for all features whose centroids are within
        /// the given rectangle, updates the default selection, and streams the image back to client.
        /// </summary>
        /// <remarks>None</remarks>
        public override void Process()
        {
            MapControlModel model = MapControlModel.GetModelFromSession();

            model.SetMapSize(MapAlias, MapWidth, MapHeight);
            System.Drawing.Point[] points = ExtractPoints(DataString);
            if (points.Length == 1 || points[0] == points[1])
            {
                model.PointSelection(MapAlias, points[0]);
            }
            else
            {
                model.RectangleSelection(MapAlias, points[0], points[1]);
            }
            MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);

            StreamImageToClient(ms);
        }
Example #14
0
        /// <summary>
        /// Gets the map object out of the MapFactory with a given MapAlias, calculates the total distance between the given points,
        /// and writes the double value to the response object.
        /// </summary>
        /// <remarks>This command is different, it does not update the map, but returns information. The user interface
        /// used to display the value has to be decided by the javascript which receives it. The distance command from the client
        /// side uses an XMLHttp object to make a call to the server to calculate the distance.
        /// </remarks>
        public override void Process()
        {
            string          distanceType = System.Convert.ToString(HttpContext.Current.Request[DistanceTypeKey]);
            string          distanceUnit = System.Convert.ToString(HttpContext.Current.Request[DistanceUnitKey]);
            MapControlModel model        = MapControlModel.GetModelFromSession();

            model.SetMapSize(MapAlias, MapWidth, MapHeight);
            System.Drawing.Point[] points = ExtractPoints(DataString);
            double dist = 0.0;

            try {
                dist = model.Distance(MapAlias, points, distanceType, distanceUnit);
            } catch (Exception e) {
                HttpContext.Current.Response.Output.Write(e.Message);
                return;
            }
            HttpContext.Current.Response.Output.Write(dist);
        }
Example #15
0
        /// <summary>
        /// Gets the map object out of the MapFactory with a given MapAlias, pans either by specified map units or percentage of
        /// the map on the screen, and streams the image back to client.
        /// </summary>
        /// <remarks>The map is panned using this method and North and East offsets.</remarks>
        public override void Process()
        {
            MapControlModel model = MapControlModel.GetModelFromSession();

            model.SetMapSize(MapAlias, MapWidth, MapHeight);
            double north  = System.Convert.ToDouble(HttpContext.Current.Request["North"]);
            double east   = System.Convert.ToDouble(HttpContext.Current.Request["East"]);
            string method = HttpContext.Current.Request["Method"];

            if (method.Equals("ByUnit"))
            {
                model.Pan(MapAlias, north, east);
            }
            else if (method.Equals("ByPercentage"))
            {
                int xoffset = (int)(east * 0.01 * MapWidth);
                int yoffset = (int)(north * 0.01 * MapHeight);
                model.Pan(MapAlias, xoffset, yoffset);
            }
            MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);

            StreamImageToClient(ms);
        }