This project has moved and is read-only. For the latest updates, please go here.

Repeating default symbols

Topics: Algorithms
Mar 21, 2012 at 11:27 AM

Dear all!

I am using Sharpmap v0.9. When loading a map from the database so I have defined a new Symbol to replace the Symbol default but when click on it to query the MapQueried event does not occur. Here is my code:


SharpMap.Layers.VectorLayer layTBA = new SharpMap.Layers.VectorLayer("TBA");
            layTBA.DataSource = new SharpMap.Data.Providers.PostGIS(PostGisConnectionString, "TBA", "pd", "oid");            
            layTBA.Style.Symbol = new System.Drawing.Bitmap("GeoData/Tram_24.png");
            //label for TBA layer
            SharpMap.Layers.LabelLayer layTBALabel = new SharpMap.Layers.LabelLayer("TBA labels")
                DataSource = layTBA.DataSource,
                Enabled = true,
                LabelColumn = "oid",
                TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias,
                SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias,
                LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection,
                Style = new SharpMap.Styles.LabelStyle()
                    ForeColor = Color.Blue,
                    Font = new Font(FontFamily.GenericSerif, 11),
                    //MaxVisible = layLabel.MinVisible,
                    HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left,
                    VerticalAlignment = SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Bottom,
                    Offset = new PointF(3, 3),
                    Halo = new Pen(Color.Black, 2),
                    CollisionDetection = true
help me!



Mar 21, 2012 at 12:28 PM

You need to

  1. set the MapBox.QueryLayerIndex right.
  2. Increase the MapBox.QueryGrowFactor

Hth FObermaier

Mar 22, 2012 at 4:25 AM
Edited Mar 22, 2012 at 4:39 AM

nice reply, thanks. 

I want to load the map will zoom to a certain level and position how do I do? (when closing the form I will save the current zoom and position for the next opening will reopen program)

Mar 22, 2012 at 8:55 AM

All you need to do is store the MapBox.Map.Envelope values and then, when reopening the form enforce the map to be zoomed (Map.ZoomToBox(box)) to that envelope.

Hth FObermaier

Mar 23, 2012 at 8:35 AM

I tried without success. Here my code:


string path = Application.StartupPath;
            if (!File.Exists(path + "\\setting.ini"))
                IniFile ini = new IniFile();
                ini.AddSection(keyname).AddKey("Left").Value = DisplayMap.Map.Envelope.Left.ToString();
                ini.AddSection(keyname).AddKey("Bottom").Value = DisplayMap.Map.Envelope.Bottom.ToString();
                ini.AddSection(keyname).AddKey("Right").Value = DisplayMap.Map.Envelope.Right.ToString();
                ini.AddSection(keyname).AddKey("Top").Value = DisplayMap.Map.Envelope.Top.ToString();                
                ini.Save(path + "\\setting.ini");                
                IniFile ini = new IniFile();
                ini.SetKeyValue(keyname, "Left", DisplayMap.Map.Envelope.Left.ToString());
                ini.SetKeyValue(keyname, "Bottom", DisplayMap.Map.Envelope.Bottom.ToString());
                ini.SetKeyValue(keyname, "Right", DisplayMap.Map.Envelope.Right.ToString());
                ini.SetKeyValue(keyname, "Top", DisplayMap.Map.Envelope.Top.ToString());
                ini.Save(path + "\\setting.ini");

form load:

string path = Application.StartupPath;
            if (File.Exists(path + "\\setting.ini"))
                IniFile ini = new IniFile();
                ini.Load(path + "\\setting.ini");

                SharpMap.Geometries.BoundingBox bbox = new SharpMap.Geometries.BoundingBox(Convert.ToDouble(ini.GetSection(keyname).GetKey("Left").Value),
                    Convert.ToDouble(ini.GetSection(keyname).GetKey("Right").Value), Convert.ToDouble(ini.GetSection(keyname).GetKey("Top").Value));                
result was the same as used Map.ZoomToExtents. Why? Help me.

Mar 23, 2012 at 12:33 PM

The code looks ok, maybe you closed the map with the full map displayed?

I'll try to set-up a test-case.

Hth FObermaier

Mar 24, 2012 at 2:03 AM

No, only a small part of the map.

Mar 26, 2012 at 6:51 AM
  • Is there a call to ZoomToExtents() afterwards?
  • What are the values storede in the ini-file
  • Are the values read correctly from the ini file (NumberFormatInfo.InvariantInfo)
  • What is the envelope of the map right after you call ZoomToBox?
Mar 26, 2012 at 10:45 AM
Edited Mar 26, 2012 at 10:49 AM

Thanks for your answer. I solved the problem.