コード例 #1
0
        public static void PointsLabelingPlaced()
        {
            //ExStart: PointsLabelingPlaced
            using (var map = new Map(500, 200))
            {
                var symbol = new SimpleMarker
                {
                    FillColor   = Color.LightGray,
                    StrokeStyle = StrokeStyle.None
                };

                var labeling = new SimpleLabeling(labelAttribute: "name")
                {
                    HaloSize  = 1,
                    Placement = new PointLabelPlacement
                    {
                        VerticalAnchorPoint   = VerticalAnchor.Bottom,
                        HorizontalAnchorPoint = HorizontalAnchor.Left,
                        HorizontalOffset      = 2,
                        VerticalOffset        = 2,
                        Rotation = 10,
                    }
                };

                map.Add(VectorLayer.Open(dataDir + "points.geojson", Drivers.GeoJson), symbol, labeling);
                map.Padding = 50;
                map.Render(dataDir + "points_labeling_placed_out.svg", Renderers.Svg);
            }
            //ExEnd: PointsLabelingPlaced
        }
コード例 #2
0
        public static void PointsLabelingStyled()
        {
            //ExStart: PointsLabelingStyled
            using (var map = new Map(500, 200))
            {
                var symbol = new SimpleMarker
                {
                    FillColor   = Color.LightGray,
                    StrokeStyle = StrokeStyle.None
                };

                var labeling = new SimpleLabeling(labelAttribute: "name")
                {
                    HaloSize  = 2,
                    HaloColor = Color.LightGray,
                    FontSize  = 15,
                    FontStyle = FontStyle.Italic,
                };

                map.Add(VectorLayer.Open(dataDir + "points.geojson", Drivers.GeoJson), symbol, labeling);
                map.Padding = 50;
                map.Render(dataDir + "points_labeling_styled_out.svg", Renderers.Svg);
            }
            //ExEnd: PointsLabelingStyled
        }
コード例 #3
0
        public static void LinesLabelingCurvedWithOffset()
        {
            //ExStart: LinesLabelingCurvedWithOffset
            using (var map = new Map(1000, 634))
            {
                var symbolizer = new SimpleLine {
                    Width = 1.5, Color = Color.FromArgb(0xAE, 0xD9, 0xFD)
                };

                var labeling = new SimpleLabeling(labelAttribute: "name")
                {
                    HaloSize  = 1,
                    Placement = new LineLabelPlacement
                    {
                        Alignment = LineLabelAlignment.Curved,
                        Offset    = 5,
                    }
                };

                map.Add(VectorLayer.Open(dataDir + "lines.geojson", Drivers.GeoJson), symbolizer, labeling);
                map.Padding = 50;
                map.Render(dataDir + "lines_labeling_curved_offset_out.svg", Renderers.Svg);
            }
            //ExEnd: LinesLabelingCurvedWithOffset
        }
コード例 #4
0
        public static void LinesLabelingFeatureBased()
        {
            //ExStart: LinesLabelingFeatureBased
            using (var map = new Map(1000, 634))
            {
                var lineSymbolizer = new SimpleLine {
                    Width = 1.5, Color = Color.FromArgb(0xae, 0xd9, 0xfd)
                };
                lineSymbolizer.FeatureBasedConfiguration = (feature, symbolizer) =>
                {
                    if (feature.GetValue <string>("NAM") == "UNK")
                    {
                        symbolizer.Width = 1;
                        symbolizer.Style = StrokeStyle.Dash;
                    }
                };


                var lineLabeling = new SimpleLabeling(labelAttribute: "name")
                {
                    HaloSize  = 1,
                    Placement = new LineLabelPlacement
                    {
                        Alignment = LineLabelAlignment.Parallel,
                    },
                    FontSize = 20,
                    FeatureBasedConfiguration = (feature, labeling) =>
                    {
                        if (feature.GetValue <string>("NAM") == "UNK")
                        {
                            // change labeling properties for some features.
                            labeling.FontStyle = FontStyle.Italic;
                            labeling.FontSize  = 10;
                            labeling.Priority  = -1;

                            var placement = (LineLabelPlacement)labeling.Placement;
                            placement.Alignment = LineLabelAlignment.Curved;
                            placement.Offset    = 5;
                        }
                    }
                };

                map.Add(VectorLayer.Open(dataDir + "lines.geojson", Drivers.GeoJson), lineSymbolizer, lineLabeling);
                map.Padding = 50;
                map.Render(dataDir + "lines_labeling_feature_based_out.svg", Renderers.Svg);
            }
            //ExEnd: LinesLabelingFeatureBased
        }
コード例 #5
0
        public static void LinesLabeling()
        {
            //ExStart: LinesLabeling
            using (var map = new Map(1000, 634))
            {
                var symbolizer = new SimpleLine {
                    Width = 1.5, Color = Color.FromArgb(0xAE, 0xD9, 0xFD)
                };

                var labeling = new SimpleLabeling(labelAttribute: "name");

                map.Add(VectorLayer.Open(dataDir + "lines.geojson", Drivers.GeoJson), symbolizer, labeling);
                map.Padding = 50;
                map.Render(dataDir + "lines_labeling_out.svg", Renderers.Svg);
            }
            //ExEnd: LinesLabeling
        }
コード例 #6
0
        public static void PointsLabelingFeatureBased()
        {
            //ExStart: PointsLabelingFeatureBased
            using (var map = new Map(500, 200))
            {
                var pointLabeling = new SimpleLabeling("name")
                {
                    HaloSize = 1,

                    Placement = new PointLabelPlacement
                    {
                        VerticalAnchorPoint   = VerticalAnchor.Bottom,
                        HorizontalAnchorPoint = HorizontalAnchor.Left,
                        VerticalOffset        = 4,
                        HorizontalOffset      = 4,
                    },

                    FeatureBasedConfiguration = (feature, labeling) =>
                    {
                        // Retrieve population from the feature.
                        var population = feature.GetValue <int>("population");
                        // Font size is computed and is based on the population.
                        labeling.FontSize = Math.Min(20, 5 * population / 1000);
                        // Priority of the label is also based on the population.
                        // The greater the priority is, the more likely label will appear on the output image.
                        labeling.Priority = population;
                    }
                };


                map.Add(VectorLayer.Open(dataDir + "points.geojson", Drivers.GeoJson), new SimpleMarker(), pointLabeling);
                map.Padding = 50;
                map.Render(dataDir + "points_labeling_feature_based_out.svg", Renderers.Svg);
            }
            //ExEnd: PointsLabelingFeatureBased
        }