private void InitDocument()
        {
            document.Layers.RemoveAllChildren();
            document.Style.StrokeStyle      = new NStrokeStyle(1, Color.FromArgb(68, 90, 108));
            document.RoutingManager.Enabled = false;
            document.BridgeManager.Enabled  = false;
            document.Bounds = new NRectangleF(0, 0, 10000, 10000);
            document.BackgroundStyle.FillStyle = new NColorFillStyle(Color.LightBlue);

            m_MapImporter           = new NEsriMapImporter();
            m_MapImporter.MapBounds = NMapBounds.World;

            // Configure and add a shapefile
            NEsriShapefile countries = new NEsriShapefile(Path.Combine(Application.StartupPath, COUNTRIES));

            countries.NameColumn = "CNTRY_NAME";
            countries.TextColumn = "CNTRY_NAME";
            m_MapImporter.AddLayer(countries);

            // Read the map data
            m_MapImporter.Read();

            // Create a data binding source
            NMapOleDbDataBindingSource source = new NMapOleDbDataBindingSource(string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}\..\..\Resources\Maps\Sales.mdb", Application.StartupPath));

            source.SelectQuery = "SELECT * FROM Sales";

            // Create a data binding context
            NMapDataBindingContext context = new NMapDataBindingContext();

            context.AddColumnMatching("CNTRY_NAME", "Country");
            context.ColumnsToImport.Add("Sales");

            // Perform the data binding
            countries.DataBind(source, context);

            // Create and apply a fill rule
            NMapFillRuleRange fillRule = new NMapFillRuleRange("Sales", Color.White, Color.DarkGreen, 8);

            fillRule.DataGrouping = m_DataGrouping;
            countries.FillRule    = fillRule;

            m_MapImporter.ShapeCreatedListener = new NCustomShapeCreatedListener();
            m_MapImporter.ShapeImporter.ImportInMultipleLayers = true;
            m_MapImporter.Import(document, document.Bounds);

            // Generate the legend
            NMapLegendRange mapLegend = (NMapLegendRange)m_MapImporter.GetLegend(fillRule);

            mapLegend.Title             = "Sales";
            mapLegend.RangeFormatString = "{0:N0} - {1:N0} million dollars";
            mapLegend.LastFormatString  = "{0:N0} million dollars and more";

            if (pMapLegend == null)
            {
                pMapLegend          = new Panel();
                pMapLegend.Location = new Point(btnRecreateMap.Left, btnRecreateMap.Bottom + 10);
                pMapLegend.Width    = btnRecreateMap.Width;
                pMapLegend.Anchor   = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
                this.Controls.Add(pMapLegend);
            }

            mapLegend.Create(pMapLegend);

            // Size document to content
            document.SizeToContent(new NSizeF(0, 0), new Nevron.Diagram.NMargins(0));
        }
Beispiel #2
0
        private void InitDocument()
        {
            document.Layers.RemoveAllChildren();

            // Configure the drawing document
            document.Style.StrokeStyle      = new NStrokeStyle(1, Color.FromArgb(68, 90, 108));
            document.RoutingManager.Enabled = false;
            document.BridgeManager.Enabled  = false;
            document.Bounds = new NRectangleF(0, 0, 10000, 10000);
            document.BackgroundStyle.FillStyle = new NColorFillStyle(Color.LightBlue);

            // Add a style sheet
            NStyleSheet styleSheet = new NStyleSheet(WhiteTextStyleSheetName);
            NTextStyle  textStyle  = (NTextStyle)document.ComposeTextStyle().Clone();

            textStyle.FillStyle = new NColorFillStyle(KnownArgbColorValue.White);
            NStyle.SetTextStyle(styleSheet, textStyle);
            document.StyleSheets.AddChild(styleSheet);

            // Create a map importer
            m_MapImporter           = new NEsriMapImporter();
            m_MapImporter.MapBounds = NMapBounds.World;

            // Add a shapefile
            NEsriShapefile countries = new NEsriShapefile(Path.Combine(Application.StartupPath, Countries));

            countries.NameColumn = "CNTRY_NAME";
            countries.TextColumn = "CNTRY_NAME";
            m_MapImporter.AddLayer(countries);

            // Read the map data
            m_MapImporter.Read();

            // Create a fill rule
            NMapFillRuleRange fillRule = new NMapFillRuleRange("POP_CNTRY", Color.White, Color.Black, 12);

            fillRule.DataGrouping = m_DataGrouping;
            countries.FillRule    = fillRule;

            // Associate a shape created listener and import the map data
            m_MapImporter.ShapeCreatedListener = new NCustomShapeCreatedListener();
            m_MapImporter.Import(document, document.Bounds);

            // Generate a legend
            NMapLegendRange mapLegend = (NMapLegendRange)m_MapImporter.GetLegend(fillRule);

            mapLegend.Title             = "Population";
            mapLegend.RangeFormatString = "{0:N0} - {1:N0} people";
            mapLegend.LastFormatString  = "{0:N0} people and more";

            if (pMapLegend == null)
            {
                pMapLegend          = new Panel();
                pMapLegend.Location = new Point(btnRecreateMap.Left, btnRecreateMap.Bottom + 10);
                pMapLegend.Width    = btnRecreateMap.Width;
                pMapLegend.Anchor   = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
                this.Controls.Add(pMapLegend);
            }

            mapLegend.Create(pMapLegend);
        }