예제 #1
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);
        }
예제 #2
0
        public MapForm1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            // Set table search path to value sampledatasearch registry key
            string s = Environment.CurrentDirectory;

            Microsoft.Win32.RegistryKey keySamp = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(@"SOFTWARE\MapInfo\MapXtreme\6.6");
            if ((keySamp != null) && (keySamp.GetValue("SampleDataSearchPath") != null))
            {
                s = (string)keySamp.GetValue("SampleDataSearchPath");
                if (s.EndsWith("\\") == false)
                {
                    s += "\\";
                }
                keySamp.Close();
            }
            Session.Current.TableSearchPath.Path = s;

            // Add the USA table to the map
            mapControl1.Map.Load(new MapTableLoader("usa.tab"));

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

            // Create a ranged theme on the USA layer.
            Map          map = mapControl1.Map;
            FeatureLayer lyr = map.Layers["usa"] as MapInfo.Mapping.FeatureLayer;
            RangedTheme  thm = new MapInfo.Mapping.Thematics.RangedTheme(
                lyr,
                "Round(MI_Area(Obj, 'sq mi', 'Spherical'), 1)",
                "Area (square miles)",
                5,
                MapInfo.Mapping.Thematics.DistributionMethod.EqualCountPerRange);

            lyr.Modifiers.Append(thm);

            // Change the default fill colors from Red->Gray to White->Blue
            AreaStyle ars;
            // Get the style from our first bin
            CompositeStyle cs = thm.Bins[0].Style;

            // Get the region -- Area -- style
            ars = cs.AreaStyle;
            // Change the fill color
            ars.Interior = StockStyles.WhiteFillStyle();
            // Update the CompositeStyle with the new region color
            cs.AreaStyle = ars;
            // Update the bin with the new CompositeStyle settings
            thm.Bins[0].Style = cs;

            // Change the style settings on the last bin
            int nLastBin = thm.Bins.Count - 1;

            cs                       = thm.Bins[nLastBin].Style;
            ars                      = cs.AreaStyle;
            ars.Interior             = StockStyles.BlueFillStyle();
            thm.Bins[nLastBin].Style = cs;

            // Tell the theme how to fill in the other bins
            thm.SpreadBy      = SpreadByPart.Color;
            thm.ColorSpreadBy = ColorSpreadMethod.Rgb;
            thm.RecomputeStyles();

            // Create a legend
            legend        = map.Legends.CreateLegend(new Size(5, 5));
            legend.Border = true;
            ThemeLegendFrame frame = LegendFrameFactory.CreateThemeLegendFrame("Area", "Area", thm);

            legend.Frames.Append(frame);
            frame.Title = "Area (sq. mi.)";
            map.Adornments.Append(legend);
            // Set the initial legend location to be the lower right corner of the map control.
            System.Drawing.Point pt = new System.Drawing.Point(0, 0);
            pt.X            = mapControl1.Size.Width - legend.Size.Width;
            pt.Y            = mapControl1.Size.Height - legend.Size.Height;
            legend.Location = pt;
        }
예제 #3
0
        public MapForm1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            // Set table search path to value sampledatasearch registry key
            string s = Environment.CurrentDirectory;

            Microsoft.Win32.RegistryKey keySamp = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(@"SOFTWARE\MapInfo\MapXtreme\6.6");
            if ((keySamp != null) && (keySamp.GetValue("SampleDataSearchPath") != null))
            {
                s = (string)keySamp.GetValue("SampleDataSearchPath");
                if (s.EndsWith("\\") == false)
                {
                    s += "\\";
                }
                keySamp.Close();
            }
            Session.Current.TableSearchPath.Path = s;

            // Add the USA table to the map
            mapControl1.Map.Load(new MapTableLoader("usa.tab"));

            // Listen to the appropriate map event to allow the status bar to be updated
            mapControl1.Map.ViewChangedEvent += new ViewChangedEventHandler(Map_ViewChanged);

            // Create a ranged theme on the USA layer.
            Map          map = mapControl1.Map;
            FeatureLayer lyr = map.Layers["usa"] as MapInfo.Mapping.FeatureLayer;
            RangedTheme  thm = new MapInfo.Mapping.Thematics.RangedTheme(
                lyr,
                "Round(MI_Area(Obj, 'sq mi', 'Spherical'), 1)",
                "Area (square miles)",
                5,
                MapInfo.Mapping.Thematics.DistributionMethod.EqualCountPerRange);

            lyr.Modifiers.Append(thm);

            // Create a legend
            Legend legend = map.Legends.CreateLegend(new Size(5, 5));
            // Create a LegendFrame that contains the theme and add that frame to the Legend.
            ThemeLegendFrame frame = LegendFrameFactory.CreateThemeLegendFrame("Area", "Area", thm);

            legend.Frames.Append(frame);
            frame.Title = "Area (sq. mi.)";

            // Create a LegendExport and export the legend to a bitmap file.
            MapInfo.Mapping.LegendExport legendExport = new MapInfo.Mapping.LegendExport(map, legend);
            legendExport.Format     = ExportFormat.Bmp;
            legendExport.ExportSize = new ExportSize(300, 200);
            legendExport.Export("legend.bmp");

            // Display the legend in a window.
            System.Windows.Forms.Form legendForm = new LegendForm();
            legendForm.BackgroundImage = System.Drawing.Image.FromFile("legend.bmp");
            legendForm.Size            = new Size(300, 200);
            legendForm.Show();

            // Alternatively, you can add the legend as a child window of the map
            //  by appending it to the Adornments collection.  In this case, most likely
            //  a smaller size should be used when the Legend object is created.
            //
            //legend.Border = true;
            //map.Adornments.Append(legend);

            // Set the initial legend location to be the upper left corner of the map control.
            //legend.Location = new System.Drawing.Point(mapControl1.Left, mapControl1.Top);
        }