How to implement the function :AddDrawingLabel()

Dec 29, 2010 at 6:13 AM

I want to add some string to a layer ,not to the map, what should I do?? Its's like this:how to implement the function of map4's AddDrawingLabel() in the DotSpatial ?

Dec 29, 2010 at 3:41 PM
Edited Dec 29, 2010 at 3:47 PM

i am currently using this code and works fine

        'add a label layer for the points layer
        Dim LabelLayer As New MapLabelLayer
        Dim category As ILabelCategory = LabelLayer.Symbology.Categories(0)
        category.Expression = "[" & fieldName & "]"
        category.Symbolizer.Orientation = ContentAlignment.BottomCenter
        pLayer.LabelLayer = LabelLayer
        pLayer.ShowLabels = True
        
Developer
Dec 29, 2010 at 8:22 PM

To the layer but not the map?  I'm not sure I understand exactly what you want, but agelospanagiotaki's code will add labels that depend on layer attributes.  Technically the label can say anything you want, but it is usually attribute specific.  If you are trying to draw content onto the map surface, but which has nothing to do with the geographic referencing, then you can handle the Map.Paint event and use e.Graphics.DrawString. 

Ted

 

Dec 30, 2010 at 1:33 AM
shade1974 wrote:

To the layer but not the map?  I'm not sure I understand exactly what you want, but agelospanagiotaki's code will add labels that depend on layer attributes.  Technically the label can say anything you want, but it is usually attribute specific.  If you are trying to draw content onto the map surface, but which has nothing to do with the geographic referencing, then you can handle the Map.Paint event and use e.Graphics.DrawString. 

Ted

 

 Thanks.

To the layer,not to the map control. I am not trying to draw content onto the map surface,but to a layer.

Example:

           IFeatureSet polyFeatureSet = new FeatureSet(FeatureType.Polygon);

            Coordinate c1 = new Coordinate(0, 0);
            Coordinate c2 = new Coordinate(200, 0);
            Coordinate c3 = new Coordinate(200, 200);

            List<Coordinate> coorList = new List<Coordinate>();
            coorList.Add(c1);
            coorList.Add(c2);
            coorList.Add(c3);

            IFeature polyFeature = new Feature(FeatureType.Polygon, coorList.ToArray());

            polyFeatureSet.Features.Add(polyFeature);

            IMapFeatureLayer polyLayer = this.map1.Layers.Add(polygonFeatureSet);

Now I want to draw some lines and string to the polyLayer,it's like add a Auxiliary drawing layer. If I use the Map.Paint event and e.Graphics.DrawString, the lines and string I have drawn always in the top of the map1,the other layers(Such as anothor polygon layer) can not cover the lines and string live.

I am so sorry my English is poor,that we could't communicate smoothly.

Developer
Dec 30, 2010 at 1:09 PM

Ok, so I think one option that is not very easy to use would be to add drawing content as a layer and then you could specify that the layer does not appear in the legend.  however, as people re-order the legend, this might cause problems for you.  you could create a custom IPattern, which can be added to the symbolizer where you handle your drawing logic.  Unfortunately, for the moment you are not handed in an FID index or any information about which feature is being drawn, which makes it difficult to implement custom labeling according to that feature, and the algorithm would be called separately for each instance of your pattern on the screen.  If you just want to draw content on the layer one time one method might be to start with the MapPolygonLayer and inherit from this class.  These are not sealed or anything so you can simply inherit from the default MapPolygonLayer class, and override the OnDrawRegions() method.   Then, in your method call base.OnDrawRegions(..) passing in the original parameters so that you correctly draw all the content from that layer onto the buffer.  At this point, you should have the Graphics object as an event argument.  You can now draw whatever you like to this, and it will draw immediately after the basic layer content has drawn, but before the content for layers above the layer is drawn.  Hopefully that will help.  Since your layer is still technically a MapPolygonLayer, it should work as usual.  you will not be able to simply add a featureset to the map, however.  You will have to create a new instance of your CustomMapPolygonLayer, passing in your featureset.  Then you can add your custom layer to the map.

Ted