Zoom steps

Topics: SharpMap Project, SharpMap v0.9 / v1.x
Jun 18, 2009 at 9:29 AM

Is there a parametre or an attribute where one can fix, this with draw from geometrical figures the line width depending on the zoom step is?

So, the further I zoom in, the thicker becomes the line.

Jun 18, 2009 at 10:00 AM
Edited Jun 18, 2009 at 10:01 AM

Hi MightyPanther, you can do this by creating a class which holds a reference to the map and has a method which matches the GetStyleMethod delegate. This method would use the scale of the map to construct the appropriate VectorStyle object.

then you would instantiate the class and pass a delegate to the method into the constructor of a CustomTheme which you would add to the vector layer


///Incomplete Psudo code!
///the class responsible for creating the style

public class MyScaleBasedThemer
	private Map _map;
	public MyScaleBasedThemer(Map map)
		_map = map;

	public IStyle GetStyle(FeatureDataRow feature)
		VectorStyle style = .......
		// do something with the style

		return style;


///usage of class
VectorLayer layer = .........
Map map = .....
MyScaleBasedThemer themer = new MyScaleBasedThemer(map);
layer.Theme =  new CustomTheme(themer.GetStyle);
hth jd
Jun 18, 2009 at 1:04 PM

Cool. I will test it immediately sometimes. Thank you!

Jun 18, 2009 at 2:11 PM
Edited Jun 18, 2009 at 2:21 PM

With test to the class I got following error message.

"Attribute data is not supported by the GeometryProvider."

If it can be due to the fact that I use no database or shape file as a data source, but an simple geometrical figure.
Besides, it concerns a line which exists of a listing of points.

// Part of the code

public void AddLine(List<SharpMap.Geometries.Point> listPoints)
    //Create a layer

    SharpMap.Layers.VectorLayer layer = new SharpMap.Layers.VectorLayer("GeometryLine");

    //Add datasource
    SharpMap.Geometries.LineString line = new SharpMap.Geometries.LineString(listPoints);
    layer.DataSource = new SharpMap.Data.Providers.GeometryProvider(line);    

    // Custom Style
    MyScaleBasedThemer themer = new MyScaleBasedThemer(map);
    layer.Theme = new CustomTheme(this.themer.GetStyle);

    // Add layer to map


Jun 18, 2009 at 2:58 PM

Use a GeometryFeatureProvider instead of a GeometryProvider

Jun 18, 2009 at 3:56 PM

First, thanks for your quick support.

From which version is implemented GeometryFeatureProvider
In version 0.9, which I use, there is not.

Jun 18, 2009 at 4:09 PM

do not use the dlls from the Downloads tab - instead build the trunk downloaded from the Source Code tab and use that instead - it contains many bugfixes and functionality.. cheers jd