ThinkGeo.com    |     Documentation    |     Premium Support

Adding text to a ShapeFileFeatureLayer

 


 This is Robinson.  We are evaluating Mapsuite Desktop edition 3.0 and come across some issues.


I have two queries;



1. I have written the following code for adding text   :- 



   InMemoryFeatureLayer  txtLayer = new InMemoryFeatureLayer();

    LayerOverlay staticOverlay1 = new LayerOverlay();

    txtLayer.ZoomLevelSet.


   ZoomLevel01.DefaultTextStyle = new TextStyle("Temp", new GeoFont("Arial", 7), new GeoSolidBrush(GeoColor.  SimpleColors.Red));

    txtLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

    staticOverlay1.Layers.Add(txtLayer);

    winformsMap1.Overlays.Add(staticOverlay1);

    txtLayer.Open();

    txtLayer.Columns.Add(new FeatureSourceColumn("Temp"));

    for (int i = 0; i < dt.Rows.Count; i++)

    {

        winformsMap1.MapUnit = GeographyUnit.DecimalDegree;

        PointShape ptShape = new PointShape(Convert.ToDouble(dt.Rows[0].ToString()), Convert.ToDouble(dt.Rows[1].ToString()));

        Feature feature = new Feature(ptShape);      

        feature.ColumnValues.Add("Temp",dt.Rows[5].ToString());

        txtLayer.InternalFeatures.Add("T" + i.ToString(), feature);

    }

    txtLayer.Close();

    winformsMap1.Refresh();



    I added some values to all lat, and lon. But values will be displayed randomly. It will display perfectly, if I add a unique values.     Could you please go through and let   me know the error ?





2. When I make a pdf file, I m adding all layer to pdfCanvas. But text will not be exported into pdf. could please shed some light on this ?

 




Thanks in advance.

Robinson C P



Robinson,


Thanks for your interests in MapSuite Desktop product and welcome you to the discussion forum.
 
Hope my following answers can give you some helps.
1)      There is some properties to control the overlapping labels and duplicate labels for the text style, so please try to change the code as following:

InMemoryFeatureLayer txtLayer = new InMemoryFeatureLayer();
LayerOverlay staticOverlay1 = new LayerOverlay();
TextStyle textStyle = new TextStyle("Temp", new GeoFont("Arial", 7), new GeoSolidBrush(GeoColor.SimpleColors.Red));
textStyle.OverlappingRule = LabelOverlappingRule.AllowOverlapping;
textStyle.DuplicateRule = LabelDuplicateRule.UnlimitedDuplicateLabels;

txtLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = textStyle;
txtLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
staticOverlay1.Layers.Add(txtLayer);
winformsMap1.Overlays.Add(staticOverlay1);
txtLayer.Open();
txtLayer.Columns.Add(new FeatureSourceColumn("Temp"));
for (int i = 0; i < dt.Rows.Count; i++)
{
    winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
    PointShape ptShape = new PointShape(Convert.ToDouble(dt.Rows[0].ToString()), Convert.ToDouble(dt.Rows[1].ToString()));
    Feature feature = new Feature(ptShape);
    feature.ColumnValues.Add("Temp", dt.Rows[5].ToString());
    txtLayer.InternalFeatures.Add("T" + i.ToString(), feature);
}
txtLayer.Close();
winformsMap1.Refresh();

 
2)      This is a bug in the PDF extension; we have fixed it in recently version. So, please get the latest version to get rid of this issue. Could you let me know which version you are using now? You could get the version information by following API:

string version = WinformsMap.GetVersion();

 
Any more questions just feel free to let me know.
 
Thanks.
 
Yale

Thank you Yale for your immediate response .


Its resolved.


And I am using following versions :-


MapSuiteCore:3.1.299


DesktopEdition:3.1.299


Here I attach my code, Please review.


 


            PdfDocument document = new PdfDocument();

            PdfPage page = document.AddPage();

            PdfGeoCanvas pdfGeoCanvas = new PdfGeoCanvas();

            Collection<SimpleCandidate> labelsInLayers = new Collection<SimpleCandidate>();

            foreach (LayerOverlay layeroverlay in winformsMap1.Overlays)

            {

                foreach (Layer layer in layeroverlay.Layers)

                {

                    pdfGeoCanvas.BeginDrawing(page, ExtentHelper.GetDrawingExtent(winformsMap1.CurrentExtent, (float)(page.Width.Point), (float)(page.Height.Point)), GeographyUnit.DecimalDegree);

                    layer.Open();

                    layer.Draw(pdfGeoCanvas, labelsInLayers);

                    layer.Close();

                    pdfGeoCanvas.EndDrawing();

                }

            }

            string filename = "MapSuite.pdf";

            document.Save(filename);

            Process.Start(filename);


 


Thanks in advance.


Robinson



Robinson, 
  
 Thanks for your post and question. 
  
 I think your code is exactly right and the version 3.1.299 should have resolved the labeling disappearing problem. 
  
 I am not exactly sure if your problem has been solved. If not, just feel free to let me know. 
  
 Thanks. 
  
 Yale 


Yale ,


Thank you for your support.


I drew lines, circles, polygons on a shape. And writtern text on the same shape as well.


everything is perfect on shape now.


Text will not be displayed on pdf, when I make pdf .


Please have look at the attached Shape.jpg and the pdf.jpg


You may get the source code from previous post, same topic.


pls review the same.


 


Thanks in advance


Robinson



Robinson, 
  
 I am sorry I did not see your attachment screenshots. 
  
 Could you have a try on the HowDoI samples\Extending MapSuite\Use PDFExtension to see the labels is on PDF file? We have tested against version 3.1.299 and it should work perfectly. 
  
 Any more questions just feel free to let me know. 
  
 Thanks. 
  
 Yale 


Yale, 


I have gone through HowDoI samples\Extending MapSuite\Use PDFExtension, which load the text as shape files, where as I am adding text on a shape file as a feature. Both the codes are there(Adding text and making pdf) on previous post in the same topic. Please review and let me know , am I doing in the right way or not.  we would like to kill this issue ASAP. Please help me out in this issue.


 


Thanks with regards, 


Robinson



Robinson,


I cannot fully test your case because your code cannot compile for missing the DataTable dt.
 
Following code is my whole test code using InmemoryFeatureLayer. Also, I attached the final PDF result.


        private void AddFeaturesFromAFeatureLayer_Load(object sender, EventArgs e)
        {
            winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
 
            winformsMap1.CurrentExtent = new RectangleShape(0, 100, 100, 0);
            winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.StandardColors.White);
 
 
            FeatureSourceColumn column = new FeatureSourceColumn("Temp", "string", 50);
            Collection<FeatureSourceColumn> columns = new Collection<FeatureSourceColumn>();
            columns.Add(column);
 
            InMemoryFeatureLayer inMemoryLayer = new InMemoryFeatureLayer(columns, new Collection<Feature>());
 
            Feature feature1 = new Feature(BaseShape.CreateShapeFromWellKnownData("POLYGON((10 60,40 70,30 85, 10 60))"));
            feature1.ColumnValues.Add("Temp", "PolygonShape");
 
            Feature feature2 = new Feature(BaseShape.CreateShapeFromWellKnownData("MULTIPOINT(10 20, 30 20,40 20, 10 30, 30 30, 40 30)"));
            feature2.ColumnValues.Add("Temp", "Multipoint");
 
            inMemoryLayer.InternalFeatures.Add("Polygon", feature1);
            inMemoryLayer.InternalFeatures.Add("Multipoint", feature2);
 
            TextStyle textStyle = new TextStyle("Temp", new GeoFont("Arial", 7), new GeoSolidBrush(GeoColor.SimpleColors.Red));
            inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = textStyle;
 
            inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillSolidBrush.Color = GeoColor.FromArgb(100, GeoColor.StandardColors.RoyalBlue);
            inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen.Color = GeoColor.StandardColors.Blue;
            inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.OuterPen = new GeoPen(GeoColor.FromArgb(200, GeoColor.StandardColors.Red), 5);
            inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.SymbolPen = new GeoPen(GeoColor.FromArgb(255, GeoColor.StandardColors.Green), 8);
            inMemoryLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
 
            LayerOverlay staticOverlay = new LayerOverlay();
            staticOverlay.Layers.Add("InMemoryFeatureLayer", inMemoryLayer);
            winformsMap1.Overlays.Add("InMemoryOverlay", staticOverlay);
 
            winformsMap1.Refresh();
        }
 
        private void PrintToPDF(object sender, EventArgs e)
        {
            PdfDocument document = new PdfDocument();
            PdfPage page = document.AddPage();
            PdfGeoCanvas pdfGeoCanvas = new PdfGeoCanvas();
            Collection<SimpleCandidate> labelsInLayers = new Collection<SimpleCandidate>();
            foreach (LayerOverlay layeroverlay in winformsMap1.Overlays)
            {
                foreach (Layer layer in layeroverlay.Layers)
                {
                    pdfGeoCanvas.BeginDrawing(page, ExtentHelper.GetDrawingExtent(winformsMap1.CurrentExtent, (float)(page.Width.Point), (float)(page.Height.Point)), GeographyUnit.DecimalDegree);
                    layer.Open();
                    layer.Draw(pdfGeoCanvas, labelsInLayers);
                    layer.Close();
                    pdfGeoCanvas.EndDrawing();
                }
            }
            string filename = "MapSuite.pdf";
            document.Save(filename);
            Process.Start(filename);
        }

 
Any more questions just feel free to let me know.
 
Thanks.
 
Yale

Robinson,


Sorry, I missed the final PDF screenshot file.
 
Here it goes.
 


Thanks.
 
Yale

1559-MapSuite.pdf (6.14 KB)

Yale,


I used the same code, which you have writtern on the post. 


But still text is not there in the pdf file.


polygon and points are printed.


I dont know, what wrong.


is there any version issue ?


MapSuiteCore:3.1.299


DesktopEdition:3.1.299


these are the versions, which I use.


 


with regards,


Robinson


 



Robinson, 
  
 That is much wired than I expected; did you install the previous version before? If so, could you let me know which version you have tried before going to version 3.1.299? 
  
 Could you verify that the DLL PdfExtension.dll is the version 3.1.299 which was made in Date 11/16/2009? 
  
 Also, could you let me know what kind of OS you are running against? Do you have any chance to change to other OS to see it works? 
  
 Thanks. 
  
 Yale