// Save the state public override void SaveState() { string mapAlias = ParamsDictionary[ActiveMapAliasKey] as string; Map map = GetMapObj(mapAlias); if (map == null) { return; } SaveZoomCenterState(map); //ManualSerializer.SaveMapXtremeObjectIntoHttpSession(map.Layers, "Layers"); ManualSerializer.SaveMapXtremeObjectIntoHttpSession(MapInfo.Engine.Session.Current.Selections.DefaultSelection, GetKey("Selection")); // Needs this because StateManger doens't have proper function to save them. // Need to serialize the temp table first since the temp layer is based on it. if (StateManager.IsManualState()) { MapInfo.Mapping.FeatureLayer fLyr = (MapInfo.Mapping.FeatureLayer)map.Layers[Constants.TempLayerAlias]; MapInfo.Data.Table tbl = (fLyr != null) ? fLyr.Table : null; if (fLyr != null) { ManualSerializer.SaveMapXtremeObjectIntoHttpSession(tbl, "tempTable"); ManualSerializer.SaveMapXtremeObjectIntoHttpSession(fLyr, "tempLayer"); } } }
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(); }
// 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"); } } } }
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(); } } }
// Creates a simple theme using the default values private void SimpleTheme(Map map) { // Get table from the feature layer MapInfo.Mapping.FeatureLayer mexicoLayer = map.Layers["mexico"] as MapInfo.Mapping.FeatureLayer; MapInfo.Data.Table mexicoTable = mexicoLayer.Table; // Create the theme GraduatedSymbolTheme theme = new GraduatedSymbolTheme(mexicoTable, "Pop_90"); // Create the theme layer ObjectThemeLayer themeLayer = new ObjectThemeLayer("Population1990", "Population1990", theme); // Add theme layer to the map map.Layers.Add(themeLayer); }
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); }
// Creates a theme with a non-default symbol private void CustomPositiveSymbolTheme(Map map) { // Get table from the feature layer MapInfo.Mapping.FeatureLayer mexicoLayer = map.Layers["mexico"] as MapInfo.Mapping.FeatureLayer; MapInfo.Data.Table mexicoTable = mexicoLayer.Table; // Create the theme GraduatedSymbolTheme theme = new GraduatedSymbolTheme(mexicoTable, "Pop_90"); // Replace the default symbol of the theme theme.PositiveSymbol = new MapInfo.Styles.SimpleVectorPointStyle(35, Color.Blue, 36); // Create the theme layer ObjectThemeLayer themeLayer = new ObjectThemeLayer("Population1990", "Population1990", theme); // Add theme layer to the map map.Layers.Add(themeLayer); }
// Creates a theme with a custom DataValueAtSize property private void DataValueAtSizeTheme(Map map) { // Get table from the feature layer MapInfo.Mapping.FeatureLayer mexicoLayer = map.Layers["mexico"] as MapInfo.Mapping.FeatureLayer; MapInfo.Data.Table mexicoTable = mexicoLayer.Table; // Create the theme GraduatedSymbolTheme theme = new GraduatedSymbolTheme(mexicoTable, "Pop_90"); // Decreasing DataValueAtSize value will increase the size of the symbols. theme.DataValueAtSize /= 4; // Create the theme layer ObjectThemeLayer themeLayer = new ObjectThemeLayer("Population1990", "Population1990", theme); // Add theme layer to the map map.Layers.Add(themeLayer); }
// Creates a theme whose symbol sizes are graduated logarithmically private void GraduateByLogTheme(Map map) { // Get table from the feature layer MapInfo.Mapping.FeatureLayer mexicoLayer = map.Layers["mexico"] as MapInfo.Mapping.FeatureLayer; MapInfo.Data.Table mexicoTable = mexicoLayer.Table; // Create the theme GraduatedSymbolTheme theme = new GraduatedSymbolTheme(mexicoTable, "Pop_90"); // Graduate the size logarithmically theme.GraduateSizeBy = GraduateSizeBy.Log; // Create the theme layer ObjectThemeLayer themeLayer = new ObjectThemeLayer("Population1990", "Population1990", theme); // Add theme layer to the map map.Layers.Add(themeLayer); }
// 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"); }
// Creates a theme that shows symbols for negative values. // Also uses the NumericNull property to hide the symbol of // the greatest theme value. private void NegativeValueTheme(Map map) { // Get table from the feature layer MapInfo.Mapping.FeatureLayer mexicoLayer = map.Layers["mexico"] as MapInfo.Mapping.FeatureLayer; MapInfo.Data.Table mexicoTable = mexicoLayer.Table; // Add a temporary column to the mexico table, // calulating the difference between Pop_90 and Pop_80 MapInfo.Data.Columns tempColumns = new MapInfo.Data.Columns(); tempColumns.Add(new MapInfo.Data.Column("CarsMinusTrucks", "(Cars_91-Trucks_91)")); mexicoTable.AddColumns(tempColumns); // Create the theme GraduatedSymbolTheme theme = new GraduatedSymbolTheme(mexicoTable, "CarsMinusTrucks"); // Show Negative symbols theme.ShowNegativeSymbol = true; // Setup symbols theme.PositiveSymbol = new MapInfo.Styles.SimpleVectorPointStyle(35, Color.Blue, 18); theme.NegativeSymbol = new MapInfo.Styles.SimpleVectorPointStyle(35, Color.Red, 36); // Get the larget value in the theme column MapInfo.Data.MIDataReader reader = mexicoTable.ExecuteReader("MAX(CarsMinusTrucks)"); reader.MoveNext(); double maxValue = reader.GetDouble(0); reader.Dispose(); // Setup the numeric null value to exclude the largest value theme.NumericNull = maxValue; theme.HasNumericNull = true; // These end up being small values, so use the DataValueAtSize // property to increase the size of the symbols theme.DataValueAtSize = 50000; // Create the theme layer ObjectThemeLayer themeLayer = new ObjectThemeLayer("CarOrTruck", "CarOrTruck", theme); // Add theme layer to the map map.Layers.Add(themeLayer); }
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; }