Ejemplo n.º 1
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);
        }
Ejemplo n.º 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 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);
        }