Ejemplo n.º 1
0
        public override void Process()
        {
            MapControlModel model = MapControlModel.GetModelFromSession();

            model.SetMapSize(MapAlias, MapWidth, MapHeight);
            MapInfo.Mapping.Map map = model.GetMapObj(MapAlias);
            if (map == null)
            {
                return;
            }
            System.Drawing.Point[] points = this.ExtractPoints(this.DataString);

            double x    = points[0].X / 10000;
            double y    = points[0].Y / 10000;
            double zoom = Double.Parse(HttpContext.Current.Request["Zoom"]);

            if (zoom == -1)
            {
                zoom = map.Zoom.Value;
            }
            UserMap.Center(map, x, y, zoom);
            MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);

            StreamImageToClient(ms);
            return;
        }
Ejemplo n.º 2
0
		// Handler function called when the active map's view changes
		private void Map_ViewChanged(object o, ViewChangedEventArgs e) {
			// Get the map
			MapInfo.Mapping.Map map = (MapInfo.Mapping.Map) o;
			// Display the zoom level
			Double dblZoom = System.Convert.ToDouble(String.Format("{0:E2}", mapControl1.Map.Zoom.Value));
			statusBar1.Text = "Zoom: " + dblZoom.ToString() + " " + mapControl1.Map.Zoom.Unit.ToString();
		}
Ejemplo n.º 3
0
        private void FillDropDown(string tableName, string colName)
        {
            MapInfo.Mapping.Map map = null;

            // Get the map
            if (MapInfo.Engine.Session.Current.MapFactory.Count == 0 ||
                (map = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias]) == null)
            {
                return;
            }

            DropDownList1.Items.Clear();
            MapInfo.Mapping.FeatureLayer fl = (MapInfo.Mapping.FeatureLayer)map.Layers[tableName];
            MapInfo.Data.Table           t  = fl.Table;
            MIDataReader tr;
            MIConnection con = new MIConnection();
            MICommand    tc  = con.CreateCommand();

            tc.CommandText = "select " + colName + " from " + t.Alias;
            con.Open();
            tr = tc.ExecuteReader();
            while (tr.Read())
            {
                DropDownList1.Items.Add(tr.GetString(0));
            }
            tc.Cancel();
            tc.Dispose();
            tr.Close();
            con.Close();
            //t.Close();
        }
Ejemplo n.º 4
0
        // Save the state
        public override void SaveState()
        {
            string mapAlias = this.ParamsDictionary[AppStateManager.ActiveMapAliasKey] as String;

            MapInfo.Mapping.Map map = GetMapObj(mapAlias);

            if (map != null)
            {
                ManualSerializer.SaveMapXtremeObjectIntoHttpSession(MapInfo.Engine.Session.Current.Selections.DefaultSelection, StateManager.GetKey("Selection"));

                MapInfo.WebControls.StateManager.SaveZoomCenterState(map);

                // Needs this because StateManger doens't have proper function to save them.
                if (StateManager.IsManualState())
                {
                    // this TempLayer should be always there, otherwise there is a chance to get other customer's TempLayer.
                    MapInfo.Mapping.IMapLayer lyr = map.Layers[SampleConstants.TempLayerAlias];
                    if (lyr != null)
                    {
                        MapInfo.Mapping.FeatureLayer fLyr = lyr as MapInfo.Mapping.FeatureLayer;
                        // Need to serialize the temp table first since the temp layer is based on it.
                        ManualSerializer.SaveMapXtremeObjectIntoHttpSession(fLyr.Table, "tempTable");
                        ManualSerializer.SaveMapXtremeObjectIntoHttpSession(fLyr, "tempLayer");
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public override void Process()
        {
            MapControlModel model = MapControlModel.GetModelFromSession();

            //get map object from map model
            MapInfo.Mapping.Map map = model.GetMapObj(MapAlias);

            if (map.Legends.Count == 0)
            {
                return;
            }

            Legend legend = map.Legends[0];

            LegendExport legendExp = new LegendExport(map, legend);

            legendExp.Format = (MapInfo.Mapping.ExportFormat)MapInfo.Mapping.ExportFormat.Parse(typeof(ExportFormat), LegendExportFormat, true);

            //export Legend to memorystream
            MemoryStream stream = new MemoryStream();

            legendExp.Export(stream);
            stream.Position = 0;
            legendExp.Dispose();

            //stream legend image back to client
            StreamImageToClient(stream);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// This method gets the map object out of the mapfactory with given mapalias and
        /// Adds a point feature into a temp layer, exports it to memory stream and streams it back to client.
        /// </summary>
        /// <remarks>None</remarks>
        public override void Process()
        {
            // Extract points from the string
            System.Drawing.Point [] points = this.ExtractPoints(this.DataString);

            MapControlModel model = MapControlModel.GetModelFromSession();

            model.SetMapSize(MapAlias, MapWidth, MapHeight);

            MapInfo.Mapping.Map map = model.GetMapObj(MapAlias);
            if (map == null)
            {
                return;
            }

            // There will be only one point, convert it to spatial
            MapInfo.Geometry.DPoint point;
            map.DisplayTransform.FromDisplay(points[0], out point);

            IMapLayer lyr = map.Layers[SampleConstants.TempLayerAlias];

            if (lyr == null)
            {
                TableInfoMemTable ti = new TableInfoMemTable(SampleConstants.TempTableAlias);
                // Make the table mappable
                ti.Columns.Add(ColumnFactory.CreateFeatureGeometryColumn(map.GetDisplayCoordSys()));
                ti.Columns.Add(ColumnFactory.CreateStyleColumn());

                Table table = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti);
                map.Layers.Insert(0, new FeatureLayer(table, "templayer", SampleConstants.TempLayerAlias));
            }
            lyr = map.Layers[SampleConstants.TempLayerAlias];
            if (lyr == null)
            {
                return;
            }
            FeatureLayer fLyr = lyr as FeatureLayer;

            MapInfo.Geometry.Point geoPoint = new MapInfo.Geometry.Point(map.GetDisplayCoordSys(), point);
            // Create a Point style which is a red pin point.
            SimpleVectorPointStyle vs = new SimpleVectorPointStyle();

            vs.Code       = 67;
            vs.Color      = Color.Red;
            vs.PointSize  = Convert.ToInt16(24);
            vs.Attributes = StyleAttributes.PointAttributes.BaseAll;
            vs.SetApplyAll();

            // Create a Feature which contains a Point geometry and insert it into temp table.
            Feature pntFeature = new Feature(geoPoint, vs);

            MapInfo.Data.Key key = fLyr.Table.InsertFeature(pntFeature);

            // Send contents back to client.
            MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);

            StreamImageToClient(ms);
        }
Ejemplo n.º 7
0
 private MapInfo.Mapping.GroupLayer GetTheGroupLayer()
 {
     MapInfo.Mapping.Map myMap = this.GetMapObj();
     if (myMap.Layers[SampleConstants.GroupLayerAlias] == null)
     {
         myMap.Layers.InsertGroup(0, "grouplayer", SampleConstants.GroupLayerAlias);
     }
     return(myMap.Layers[SampleConstants.GroupLayerAlias] as MapInfo.Mapping.GroupLayer);
 }
Ejemplo n.º 8
0
 private MapInfo.Mapping.Map GetMapObj()
 {
     MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias];
     if (myMap == null)
     {
         myMap = MapInfo.Engine.Session.Current.MapFactory[0];
     }
     return(myMap);
 }
Ejemplo n.º 9
0
        public override void Process()
        {
            MapControlModel model = MapControlModel.GetModelFromSession();

            //get map object from map model
            MapInfo.Mapping.Map map = model.GetMapObj(MapAlias);
            string zoomStr          = map.Zoom.ToString();

            HttpContext.Current.Response.Output.Write(zoomStr);
        }
Ejemplo n.º 10
0
        private void InitState()
        {
            MapInfo.Mapping.Map myMap = this.GetMapObj();

            // We need to put original state of applicatin into HttpApplicationState.
            if (Application.Get("DataAccessWeb") == null)
            {
                System.Collections.IEnumerator iEnum = MapInfo.Engine.Session.Current.MapFactory.GetEnumerator();
                // Put maps into byte[] objects and keep them in HttpApplicationState
                while (iEnum.MoveNext())
                {
                    MapInfo.Mapping.Map tempMap = iEnum.Current as MapInfo.Mapping.Map;
                    byte[] mapBits = MapInfo.WebControls.ManualSerializer.BinaryStreamFromObject(tempMap);
                    Application.Add(tempMap.Alias, mapBits);
                }

                // Load Named connections into catalog.
                if (MapInfo.Engine.Session.Current.Catalog.NamedConnections.Count == 0)
                {
                    System.Web.HttpServerUtility util = HttpContext.Current.Server;
                    string path     = util.MapPath(string.Format(""));
                    string fileName = System.IO.Path.Combine(path, "namedconnection.xml");
                    MapInfo.Engine.Session.Current.Catalog.NamedConnections.Load(fileName);
                }

                // Put Catalog into a byte[] and keep it in HttpApplicationState
                byte[] catalogBits = MapInfo.WebControls.ManualSerializer.BinaryStreamFromObject(MapInfo.Engine.Session.Current.Catalog);
                Application.Add("Catalog", catalogBits);

                // Put a marker key/value.
                Application.Add("DataAccessWeb", "Here");
            }
            else
            {
                // Apply original Catalog state.
                Object obj = Application.Get("Catalog");
                if (obj != null)
                {
                    Object tempObj = MapInfo.WebControls.ManualSerializer.ObjectFromBinaryStream(obj as byte[]);
                }

                // Apply original Map object state.
                obj = Application.Get(MapControl1.MapAlias);
                if (obj != null)
                {
                    Object tempObj = MapInfo.WebControls.ManualSerializer.ObjectFromBinaryStream(obj as byte[]);
                }
            }

            // Set the initial zoom, center and size of the map
            // 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, DistanceUnit.Mile);
            myMap.Center = new DPoint(27775.805792979896, -147481.33999999985);
            myMap.Size   = new System.Drawing.Size((int)this.MapControl1.Width.Value, (int)this.MapControl1.Height.Value);
        }
Ejemplo n.º 11
0
    /// <summary>
    /// Get the current map object
    /// </summary>
    /// <returns></returns>
    private MapInfo.Mapping.Map GetMapObj()
    {
        string strAlias = (string)StateManager.GetStateManagerFromSession().ParamsDictionary[StateManager.ActiveMapAliasKey];

        MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory[strAlias];
        if (myMap == null)
        {
            myMap = MapInfo.Engine.Session.Current.MapFactory[0];
        }
        return(myMap);
    }
Ejemplo n.º 12
0
        private void FindCity()
        {
            Find find = null;

            try
            {
                MapInfo.Mapping.Map map = null;

                // Get the map
                if (MapInfo.Engine.Session.Current.MapFactory.Count == 0 ||
                    (map = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias]) == null)
                {
                    return;
                }

                // Do the find
                MapInfo.Mapping.FeatureLayer findLayer = (MapInfo.Mapping.FeatureLayer)map.Layers[_findLayerName];
                find = new Find(findLayer.Table, findLayer.Table.TableInfo.Columns[_findColumnName]);
                FindResult result = find.Search(DropDownList1.SelectedItem.Text);
                if (result.ExactMatch)
                {
                    // Create a Feature (point) for the location we found
                    CoordSys        csys = findLayer.CoordSys;
                    FeatureGeometry g    = new MapInfo.Geometry.Point(csys, result.FoundPoint.X, result.FoundPoint.Y);
                    Feature         f    = new Feature(g, new MapInfo.Styles.SimpleVectorPointStyle(52, System.Drawing.Color.DarkGreen, 32));

                    // Delete the existing find object and add the new one
                    MapInfo.Mapping.FeatureLayer workingLayer = (MapInfo.Mapping.FeatureLayer)map.Layers[_workingLayerName];
                    if (workingLayer != null)
                    {
                        (workingLayer.Table as ITableFeatureCollection).Clear();
                        workingLayer.Table.InsertFeature(f);
                    }

                    // Set the map's center and zooom
                    map.Center = new DPoint(result.FoundPoint.X, result.FoundPoint.Y);
                    MapInfo.Geometry.Distance d = new MapInfo.Geometry.Distance(1000, map.Zoom.Unit);
                    map.Zoom = d;
                }
                else
                {
                    this.Label3.Text = ("Cannot find the country");
                }
                find.Dispose();
            }
            catch (Exception)
            {
                if (find != null)
                {
                    find.Dispose();
                }
            }
        }
Ejemplo n.º 13
0
        private bool InitWorkingLayer()
        {
            MapInfo.Mapping.Map map = null;

            // Get the map
            if (MapInfo.Engine.Session.Current.MapFactory.Count == 0 ||
                (map = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias]) == null)
            {
                return(false);
            }

            // Make sure the Find layer's MemTable exists
            MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.GetTable(_workingLayerName);
            if (table == null)
            {
                TableInfoMemTable ti = new TableInfoMemTable(_workingLayerName);
                ti.Temporary = true;
                // Add the Geometry column
                Column col = new MapInfo.Data.GeometryColumn(map.GetDisplayCoordSys());
                col.Alias    = "obj";
                col.DataType = MIDbType.FeatureGeometry;
                ti.Columns.Add(col);
                // Add the Style column
                col          = new MapInfo.Data.Column();
                col.Alias    = "MI_Style";
                col.DataType = MIDbType.Style;
                ti.Columns.Add(col);
                table = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti);
            }
            if (table == null)
            {
                return(false);
            }

            // Make sure the Find layer exists
            MapInfo.Mapping.FeatureLayer layer = (MapInfo.Mapping.FeatureLayer)map.Layers[_workingLayerName];
            if (layer == null)
            {
                layer = new MapInfo.Mapping.FeatureLayer(table, _workingLayerName, _workingLayerName);
                map.Layers.Insert(0, layer);
            }
            if (layer == null)
            {
                return(false);
            }

            // Delete the find object.  There should only be one object in this table.
            (layer.Table as ITableFeatureCollection).Clear();

            return(true);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Get a MultiFeatureCollection containing features in all layers falling into the tolerance of the point.
        /// </summary>
        /// <param name="points">points array</param>
        /// <param name="pixelTolerance">pixel tolerance used when searching</param>
        /// <returns>Returns a MultiResultSetFeatureCollection object</returns>
        protected MultiResultSetFeatureCollection RetrieveInfo(Point[] points, int pixelTolerance)
        {
            if (points.Length != 1)
            {
                return(null);
            }

            MapControlModel model = MapControlModel.GetModelFromSession();

            //get map object from map model
            MapInfo.Mapping.Map map = model.GetMapObj(MapAlias);

            if (map == null)
            {
                return(null);
            }

            //creat a layer filter to include normal visible layers for searching
            IMapLayerFilter layerFilter = MapLayerFilterFactory.FilterForTools(
                map, MapLayerFilterFactory.FilterByLayerType(LayerType.Normal), MapLayerFilterFactory.FilterVisibleLayers(true),
                "MapInfo.Tools.MapToolsDefault.SelectLayers", null);

            ITableEnumerator tableEnum = map.Layers.GetTableEnumerator(layerFilter);

            //return if there is no valid layer to search
            if (tableEnum == null)
            {
                return(null);
            }

            System.Drawing.Point center = points[0];

            //create a SearchInfo with a point and tolerance
            SearchInfo si = MapInfo.Mapping.SearchInfoFactory.SearchNearest(map, center, pixelTolerance);

            (si.SearchResultProcessor as ClosestSearchResultProcessor).Options = ClosestSearchOptions.StopAtFirstMatch;
            //retrieve all columns
            si.QueryDefinition.Columns = null;

            MapInfo.Geometry.Distance d = MapInfo.Mapping.SearchInfoFactory.ScreenToMapDistance(map, pixelTolerance);
            (si.SearchResultProcessor as ClosestSearchResultProcessor).DistanceUnit = d.Unit;
            (si.SearchResultProcessor as ClosestSearchResultProcessor).MaxDistance  = d.Value;


            //do search
            MultiResultSetFeatureCollection mrfc = MapInfo.Engine.Session.Current.Catalog.Search(tableEnum, si);

            return(mrfc);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// This method gets the map object out of the mapfactory with given mapalias
        /// and This method delete the pin point features added by AddPinPointCommand in a given point
        /// and then streams the image back to client.
        /// </summary>
        /// <remarks>None</remarks>
        public override void Process()
        {
            System.Drawing.Point[] points = ExtractPoints(DataString);
            MapControlModel        model  = MapControlModel.GetModelFromSession();

            model.SetMapSize(MapAlias, MapWidth, MapHeight);
            MapInfo.Mapping.Map map = model.GetMapObj(MapAlias);
            if (map == null)
            {
                return;
            }
            PointDeletion(map, points[0]);
            MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);

            StreamImageToClient(ms);
        }
Ejemplo n.º 16
0
        // Open a new table or use existing one.
        protected void OpenTableButton_Click(object sender, System.EventArgs e)
        {
            if (CheckBoxList1.SelectedValue == null || CheckBoxList1.SelectedValue.Length <= 0)
            {
                return;
            }
            WarningLabel.Visible = false;
            if (OpenTableTextBox.Text != null && OpenTableTextBox.Text.Trim().Length != 0)
            {
                string             tableName = OpenTableTextBox.Text.Trim();
                MapInfo.Data.Table table     = null;
                try
                {
                    table = this.OpenTable(CheckBoxList1.SelectedValue, tableName);
                    if (table != null)
                    {
                        string lyrAlias           = "alias_flyr_" + table.Alias;
                        MapInfo.Mapping.Map myMap = GetMapObj();
                        if (myMap == null)
                        {
                            return;
                        }
                        if (myMap.Layers[lyrAlias] != null)
                        {
                            myMap.Layers.Remove(lyrAlias);
                        }
                        FeatureLayer fLyr = new FeatureLayer(table, "LayerName_" + tableName, lyrAlias);
                        myMap.Layers.Insert(0, fLyr);

                        // Need to rebind again since a new table got opened.
                        BindOpenedTablesAliasToRepeater();
                    }
                    else
                    {
                        WarningLabel.Visible = true;
                    }
                }
                catch (Exception)
                {
                    WarningLabel.Visible = true;
                    if (table != null)
                    {
                        table.Close();
                    }
                }
            }
        }
Ejemplo n.º 17
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();
        }
Ejemplo n.º 18
0
        public override void Process()
        {
            MapControlModel model = MapControlModel.GetModelFromSession();

            model.SetMapSize(MapAlias, MapWidth, MapHeight);

            //get map object from map model
            MapInfo.Mapping.Map map  = model.GetMapObj(MapAlias);
            FeatureLayer        fLyr = map.Layers[ProjectConstants.ThemeLayerAlias] as FeatureLayer;

            fLyr.Modifiers.Clear();
            map.Legends.Clear();

            //create theme
            IndividualValueTheme iTheme = new IndividualValueTheme(fLyr, ProjectConstants.IndColumnName, ProjectConstants.ThemeAlias);

            fLyr.Modifiers.Insert(0, iTheme);

            //create legend based on the individual value theme
            Legend lg = map.Legends.CreateLegend(new Size(236, 282));

            //create legend frame
            ThemeLegendFrame lgFrame = LegendFrameFactory.CreateThemeLegendFrame(iTheme);

            lg.Frames.Append(lgFrame);

            //modify legend frame style
            lgFrame.BackgroundBrush = new SolidBrush(Color.AliceBlue);
            lgFrame.Title           = "World Country Legend";
            lgFrame.SubTitle        = " ";

            MapInfo.Styles.Font titleFont = new MapInfo.Styles.Font("Arial", 10);
            titleFont.ForeColor  = Color.DarkBlue;
            titleFont.FontWeight = FontWeight.Bold;

            lgFrame.TitleStyle = titleFont;

            MapInfo.Styles.Font rowTextStyle = new Font("Arial", 8);
            rowTextStyle.FontWeight = FontWeight.Bold;

            lgFrame.RowTextStyle = rowTextStyle;

            //stream map image back to client
            MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);

            StreamImageToClient(ms);
        }
Ejemplo n.º 19
0
        public override void Process()
        {
            MapControlModel model = MapControlModel.GetModelFromSession();

            model.SetMapSize(MapAlias, MapWidth, MapHeight);

            //get map object from map model
            MapInfo.Mapping.Map map  = model.GetMapObj(MapAlias);
            FeatureLayer        fLyr = map.Layers[ProjectConstants.ThemeLayerAlias] as FeatureLayer;

            fLyr.Modifiers.Clear();
            map.Legends.Clear();

            MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);

            StreamImageToClient(ms);
        }
Ejemplo n.º 20
0
        public override void Process()
        {
            MapControlModel model = MapControlModel.GetModelFromSession();

            model.SetMapSize(MapAlias, MapWidth, MapHeight);
            MapInfo.Mapping.Map map = model.GetMapObj(MapAlias);

            if (map == null)
            {
                return;
            }
            UserMap.ZoomAll(map);
            MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);

            StreamImageToClient(ms);
            return;
        }
Ejemplo n.º 21
0
        // Save the state
        public override void SaveState()
        {
            string mapAlias = this.ParamsDictionary[AppStateManager.ActiveMapAliasKey] as String;

            MapInfo.Mapping.Map map = GetMapObj(mapAlias);

            if (map == null)
            {
                return;
            }
            // 1. Only if the MapInfo.Engine.Session.State is set to "Manual" in the web.config,
            // We manually save objects below.
            // 2. The MapInfo Session object will be automatically saved and you need to do nothing,
            // if the MapInfo.Engine.Session.State is set to HttpSessionState.
            AppStateManager.SaveZoomCenterState(map);
            ManualSerializer.SaveMapXtremeObjectIntoHttpSession(MapInfo.Engine.Session.Current.Catalog, "Catalog");
            ManualSerializer.SaveMapXtremeObjectIntoHttpSession(map.Layers, "Layers");
        }
Ejemplo n.º 22
0
        private void InitState()
        {
            MapInfo.Mapping.Map myMap = GetMapObj();

            #region Store and Restore the orignal state of the map.
            //***************************************************************************//
            //*   Store and Restore the original state of the map.                      *//
            //*   Store   - if no one puts the map into HttpSessionState yet,           *//
            //*             the map is clean, store it.                                 *//
            //*   Restore - if there is the map stored in HttpSessionState,             *//
            //*             deserialize it and apply the state of the map automatically *//
            //***************************************************************************//
            string originalMap = "original_map";
            if (this.Application[originalMap] != null)
            {
                byte[] bytes = this.Application[originalMap] as byte[];
                // This step will deserialize myMap object back and all original states will be put back to
                // myMap if myMap has same alias name as the one stored in HttpApplicationState.
                Object obj = MapInfo.WebControls.ManualSerializer.ObjectFromBinaryStream(bytes);
            }
            else
            {
                // Set the initial zoom and center for the map
                myMap.Zoom   = new MapInfo.Geometry.Distance(25000, DistanceUnit.Mile);
                myMap.Center = new DPoint(27775.805792979896, -147481.33999999985);
                // adjust the map.Size to mapcontrol's size
                myMap.Size = new System.Drawing.Size((int)MapControl1.Width.Value, (int)MapControl1.Height.Value);

                // Serialize myMap into a byte[] and store the original state of the map if no one stores it in HttpApplicationState yet.
                this.Application[originalMap] = MapInfo.WebControls.ManualSerializer.BinaryStreamFromObject(myMap);
            }
            #endregion

            // Create a GroupLayer to hold temp created label layer and object theme layer.
            // We are going to put this group layer into HttpSessionState, and it will get restored
            // when requets come in with the same asp.net sessionID.
            if (myMap.Layers[SampleConstants.GroupLayerAlias] != null)
            {
                myMap.Layers.Remove(SampleConstants.GroupLayerAlias);
            }
            // put the GroupLayer on the top of Layers collection, so contents within it could get displayed.
            myMap.Layers.InsertGroup(0, "grouplayer", SampleConstants.GroupLayerAlias);
        }
Ejemplo n.º 23
0
        public MapForm1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            // Listen to some map events
            mapControl1.Map.ViewChangedEvent += new ViewChangedEventHandler(Map_ViewChanged);

            // Set table search path to value sampledatasearch registry key
            // if not found, then just use the app's current directory
            Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(@"SOFTWARE\MapInfo\MapXtreme\6.6");
            string s = (string)key.GetValue("SampleDataSearchPath");

            if (s != null && s.Length > 0)
            {
                if (s.EndsWith("\\") == false)
                {
                    s += "\\";
                }
            }
            else
            {
                s = Environment.CurrentDirectory;
            }
            key.Close();

            Session.Current.TableSearchPath.Path = s;

            // load some layers, set csys and default view
            _map = mapControl1.Map;
            try {
                _map.Load(new MapTableLoader("florida.tab"));
            }       catch (Exception ex)     {
                MessageBox.Show(this, "Unable to load tables. Sample Data may not be installed.\r\n" + ex.Message);
                this.Close();
                return;
            }

            SetUpRasterLayer();
        }
Ejemplo n.º 24
0
        public override void Process()
        {
            MapControlModel model = MapControlModel.GetModelFromSession();

            model.SetMapSize(MapAlias, MapWidth, MapHeight);
            MapInfo.Mapping.Map map = model.GetMapObj(MapAlias);
            if (map == null)
            {
                return;
            }
            MapInfo.Geometry.Distance savezoom = map.Zoom;
            map.Zoom = new MapInfo.Geometry.Distance(savezoom.Value * 4, savezoom.Unit);

            if (ExportFormat == "undefined")
            {
                ExportFormat = "Gif";
            }
            System.IO.MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);
            StreamImageToClient(ms);
            map.Zoom = savezoom;

            /*
             * MapControlModel model = MapControlModel.GetModelFromSession();
             * Map oMap = model.GetMapObj(MapAlias);
             * if (oMap == null)
             * {
             *  return;
             * }
             *
             * MapInfo.Geometry.Distance zoom = oMap.Zoom;
             * zoom = new MapInfo.Geometry.Distance(zoom.Value * 4, zoom.Unit );
             * oMap.Zoom = zoom;
             * if (ExportFormat == "undefined" )
             * {
             *  ExportFormat = "Gif";
             * }
             * System.IO.MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);
             * StreamImageToClient(ms);
             * zoom = new MapInfo.Geometry.Distance(zoom.Value / 4, zoom.Unit);
             * oMap.Zoom = zoom;
             */
        }
Ejemplo n.º 25
0
        public override void Process()
        {
            MapControlModel model = MapControlModel.GetModelFromSession();

            model.SetMapSize(MapAlias, MapWidth, MapHeight);
            MapInfo.Mapping.Map map = model.GetMapObj(MapAlias);
            if (map == null)
            {
                return;
            }

            string strUID = HttpContext.Current.Request["uid"];

            UserMap.DeleteFeature(map, Constants.TempLayerAlias, strUID);

            MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);

            StreamImageToClient(ms);
            return;
        }
Ejemplo n.º 26
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            // The first time in
            if (Session.IsNewSession)
            {
                //******************************************************************************//
                //*   You need to follow below lines in your own application in order to       *//
                //*   save state manually.                                                     *//
                //*   You don't need this state manager if the "MapInfo.Engine.Session.State"  *//
                //*   in the web.config is not set to "Manual"                                 *//
                //******************************************************************************//
                if (AppStateManager.IsManualState())
                {
                    AppStateManager stateManager = new AppStateManager();
                    // tell the state manager which map alias you want to use.
                    // You could also add your own key/value pairs, the value should be serializable.
                    stateManager.ParamsDictionary[AppStateManager.ActiveMapAliasKey] = this.MapControl1.MapAlias;

                    // Add workingLayerName into State manager's ParamsDictionary.
                    stateManager.ParamsDictionary["WorkingLayerName"] = _workingLayerName;

                    // Put state manager into HttpSession, so we could get it later on.
                    AppStateManager.PutStateManagerInSession(stateManager);
                }

                InitWorkingLayer();

                MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory[this.MapControl1.MapAlias];
                // Set the initial zoom, center and size of the map
                // 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, DistanceUnit.Mile);
                myMap.Center = new DPoint(27775.805792979896, -147481.33999999985);
                myMap.Size   = new System.Drawing.Size((int)this.MapControl1.Width.Value, (int)this.MapControl1.Height.Value);
            }

            // Restore state.
            if (MapInfo.WebControls.StateManager.IsManualState())
            {
                MapInfo.WebControls.StateManager.GetStateManagerFromSession().RestoreState();
            }
        }
Ejemplo n.º 27
0
        private void InitState()
        {
            MapInfo.Mapping.Map myMap = this.GetMapObj();

            if (Application.Get("HelloWorldWeb") == null)
            {
                System.Collections.IEnumerator iEnum = MapInfo.Engine.Session.Current.MapFactory.GetEnumerator();
                // Put each map's Layers into a byte[] and keep them in HttpApplicationState for the original layers state.
                while (iEnum.MoveNext())
                {
                    MapInfo.Mapping.Map tempMap = iEnum.Current as MapInfo.Mapping.Map;
                    byte[] lyrsBits             = MapInfo.WebControls.ManualSerializer.BinaryStreamFromObject(tempMap.Layers);
                    Application.Add(tempMap.Alias + "_layers", lyrsBits);
                }
                // this is a marker key/value only.
                Application.Add("HelloWorldWeb", "Here");
            }
            else
            {
                // Set the initial Layers of the map because below reasons:
                // 1. There is a LayerControl in the web form.
                // 2. Pooled MapInfo Session objects.
                // 3. Settings of IMapLayer of the map which is from Pooled Session may not be the one you want.
                // 4. There is Layers collection with initial state stored in Application level with byte[] format.
                Object obj = Context.Application[myMap.Alias + "_layers"];

                // if we found out there is correct Layers collection stored in Application level.
                if (obj != null)
                {
                    // deserialization applys "original layers setting" to the one in the current map.
                    // "Object tempObj" is only for compiling purpose, otherwise it is useless,
                    // because MapXtreme object's deserialization process will put MapXtreme object back to the place it belongs to.
                    Object tempObj = MapInfo.WebControls.ManualSerializer.ObjectFromBinaryStream(obj as byte[]);
                }
            }

            // Set the initial state of the map
            // 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, DistanceUnit.Mile);
            myMap.Center = new DPoint(27775.805792979896, -147481.33999999985);
        }
Ejemplo n.º 28
0
        public override void Process()
        {
            MapControlModel model = MapControlModel.GetModelFromSession();

            model.SetMapSize(MapAlias, MapWidth, MapHeight);
            MapInfo.Mapping.Map map = model.GetMapObj(MapAlias);
            if (map == null)
            {
                return;
            }
            int wheelvalue = int.Parse(System.Convert.ToString(HttpContext.Current.Request["wheelvalue"]));

            try
            {
                double db;
                if (wheelvalue > 0)
                {
                    db = map.Zoom.Value * 0.5;
                }
                else
                {
                    db = map.Zoom.Value * 2;
                }
                if (db > Constants.MINZOOMVALUE)
                {
                    db = Constants.MINZOOMVALUE;
                }
                else if (db < Constants.MAXZOOMVALUE)
                {
                    db = Constants.MAXZOOMVALUE;
                }
                map.Zoom = new MapInfo.Geometry.Distance(db, map.Zoom.Unit);
            }
            finally
            {
                System.IO.MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);
                StreamImageToClient(ms);
            }
        }
Ejemplo n.º 29
0
        // Save the state
        public override void SaveState()
        {
            string mapAlias = this.ParamsDictionary[AppStateManager.ActiveMapAliasKey] as String;

            MapInfo.Mapping.Map map = GetMapObj(mapAlias);

            if (map != null)
            {
                MapInfo.WebControls.StateManager.SaveZoomCenterState(map);
                // Note: Please be aware of the order of assigning below objects to HttpContext.Current.Session.
                // The order matters in this case since theme_table contains some temp columns constructed from mdb_table.
                // and some themes/modifiers in the theme_layer are based on the theme_table.
                ManualSerializer.SaveMapXtremeObjectIntoHttpSession(MapInfo.Engine.Session.Current.Catalog[SampleConstants.EWorldAlias], "mdb_table");
                //HttpContext.Current.Session["mdb_table"] = MapInfo.Engine.Session.Current.Catalog[SampleConstants.EWorldAlias];
                ManualSerializer.SaveMapXtremeObjectIntoHttpSession(MapInfo.Engine.Session.Current.Catalog[SampleConstants.ThemeTableAlias], "theme_table");
                //HttpContext.Current.Session["theme_table"] = MapInfo.Engine.Session.Current.Catalog[SampleConstants.ThemeTableAlias];
                ManualSerializer.SaveMapXtremeObjectIntoHttpSession(map.Layers[SampleConstants.ThemeLayerAlias], "theme_layer");
                //HttpContext.Current.Session["theme_layer"] = map.Layers[SampleConstants.ThemeLayerAlias];
                // Group Layer holds temp object theme or label layers which varies with requests.
                ManualSerializer.SaveMapXtremeObjectIntoHttpSession(map.Layers[SampleConstants.GroupLayerAlias], "group_layer");
                //HttpContext.Current.Session["group_layer"] = map.Layers[SampleConstants.GroupLayerAlias];
            }
        }
Ejemplo n.º 30
0
        // Save the state
        public override void SaveState()
        {
            string mapAlias = this.ParamsDictionary[AppStateManager.ActiveMapAliasKey] as String;

            MapInfo.Mapping.Map myMap = GetMapObj(mapAlias);

            if (myMap == null)
            {
                return;
            }

            // Note: for performance reasons, only save the map's center and zoom.
            AppStateManager.SaveZoomCenterState(myMap);

            // Get the workingLayerName saved in WebForm1.aspx page_load.
            string workingLayerName = this.ParamsDictionary["WorkingLayerName"] as String;

            // Save the map's Working table and layer
            MapInfo.Mapping.FeatureLayer workingLayer = (MapInfo.Mapping.FeatureLayer)myMap.Layers[workingLayerName];
            MapInfo.Data.Table           workingTable = workingLayer != null ? workingLayer.Table : null;
            ManualSerializer.SaveMapXtremeObjectIntoHttpSession(workingTable, "WorkingTable");
            ManualSerializer.SaveMapXtremeObjectIntoHttpSession(workingLayer, "WorkingLayer");
        }
Ejemplo n.º 31
0
        public MapForm1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            // Listen to some map events
            mapControl1.Map.ViewChangedEvent += new ViewChangedEventHandler(Map_ViewChanged);

            // Set table search path to value sampledatasearch registry key
            // if not found, then just use the app's current directory
            Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(@"SOFTWARE\MapInfo\MapXtreme\6.6");
            string s = (string)key.GetValue("SampleDataSearchPath");
            if (s != null && s.Length > 0) 	{
                if (s.EndsWith("\\")==false) {
                    s += "\\";
                }
            }	else 	{
                s = Environment.CurrentDirectory;
            }
            key.Close();

            Session.Current.TableSearchPath.Path = s;

            // load some layers, set csys and default view
            _map = mapControl1.Map;
            try {
                _map.Load(new MapTableLoader( "florida.tab"));
            }	catch(Exception ex)	{
                MessageBox.Show(this, "Unable to load tables. Sample Data may not be installed.\r\n" +  ex.Message);
                this.Close();
                return;
            }

            SetUpRasterLayer();
        }