This project has moved. For the latest updates, please go here.

Map goes blanks when zooming in

Feb 12, 2007 at 1:40 PM
I tried using the code with some shape files for Clay county and everything works perfectly.
Then I tried using the same code but with shape files from Dallas and the original image is displayed just fine but when I try to zoom in or pan around the image goes blank. I stepped through the code but didn't see any exceptions being thrown anywhere so not sure what is going on. Just wondering if anyone has had this issue and could point me in the right direction.

Feb 20, 2007 at 10:54 PM

How do you zoom?
Do you use fixed zoom levels?

Feb 21, 2007 at 3:05 PM
Hello Christian, not sure what you mean by fixed zoom levels. I just click on the map and use whatever the default is.
Feb 21, 2007 at 3:19 PM

Please post some of your code.
Are you using both shape files in one map?
Do they have the same coordinate system?

Feb 21, 2007 at 4:30 PM
I just modified the Simple.cs file that the project came with. Here it is ...

using System;
using System.Data;
using System.Drawing;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing.Drawing2D;
public partial class Simple : System.Web.UI.Page
	private SharpMap.Map myMap;
    private int dbfColumn = 0;
    private Hashtable htPrecinctColors = null;
    private SharpMap.Styles.VectorStyle MyStyle(SharpMap.Data.FeatureDataRow row)
        SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle();
        string color = null;
        if (htPrecinctColors[row[dbfColumn].ToString()] != null)
            color = htPrecinctColors[row[dbfColumn].ToString()].ToString();
            color = "#FFFFFF";
        HatchBrush hb = new HatchBrush(HatchStyle.Percent90, ColorTranslator.FromHtml(color), ColorTranslator.FromHtml(color));
        style.Fill = hb;
        style.Outline = Pens.Black;
        style.EnableOutline = true;
        return style;
    private string LabelDelegate(SharpMap.Data.FeatureDataRow row)
        string precinct = row[dbfColumn].ToString();
        double area = 0;
        double scale = 0;
        if (row.Geometry.GetType() == typeof(SharpMap.Geometries.MultiPolygon) )
            area = (row.Geometry as SharpMap.Geometries.MultiPolygon).Area;
            area = (row.Geometry as SharpMap.Geometries.Polygon).Area;
        scale = 1 / myMap.Zoom * 100;
        area = area * scale;
        if ( area > .25 )
            return precinct;
            return string.Empty;
	protected void Page_Load(object sender, EventArgs e)
        htPrecinctColors = new Hashtable();
        htPrecinctColors.Add("100", "#FF0000");
        htPrecinctColors.Add("200", "#00FF00");
        SharpMap.Rendering.Thematics.CustomTheme myTheme = new SharpMap.Rendering.Thematics.CustomTheme(MyStyle);
        Size mapSize = new System.Drawing.Size((int)imgMap.Width.Value, (int)imgMap.Height.Value);
        myMap = new SharpMap.Map(mapSize);
        //Set up the countries layer
        SharpMap.Layers.VectorLayer layCounty = new SharpMap.Layers.VectorLayer("County");
        SharpMap.Data.Providers.IProvider provider = new SharpMap.Data.Providers.ShapeFile(HttpContext.Current.Server.MapPath(@"~\App_data\dallas.shp"), true);
        layCounty.DataSource = provider;
        layCounty.Theme = myTheme;
        layCounty.SRID = 4326;
        SharpMap.Layers.LabelLayer label = new SharpMap.Layers.LabelLayer("Label Layer");
        label.DataSource = layCounty.DataSource;
        label.Style.ForeColor = Color.Black;
        label.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
        label.LabelStringDelegate = LabelDelegate;
        //label.Style.Offset = new PointF(20, 20);
        label.MaxVisible = 200;
        //limit the zoom to 360 degrees width
        myMap.MaximumZoom = 360;
        myMap.BackColor = Color.LightBlue;
        myMap.Center = new SharpMap.Geometries.Point(0, 0);
        if (Page.IsPostBack) 
			//Page is post back. Restore center and zoom-values from viewstate
			myMap.Center = (SharpMap.Geometries.Point)ViewState["mapCenter"];
			myMap.Zoom = (double)ViewState["mapZoom"];
			//This is the initial view of the map. Zoom to the extents of the map:
			//or center on 0,0 and zoom to full earth (360 degrees)
			//myMap.Center = new SharpMap.Geometries.Point(0,0);
			//myMap.Zoom = 10;
			//Create the map
	protected void imgMap_Click(object sender, ImageClickEventArgs e)
		//Set center of the map to where the client clicked
		myMap.Center = myMap.ImageToWorld(new System.Drawing.Point(e.X, e.Y));
		//Set zoom value if any of the zoom tools were selected
		if (rblMapTools.SelectedValue == "0") //Zoom in
			myMap.Zoom = myMap.Zoom * 0.5;
		else if (rblMapTools.SelectedValue == "1") //Zoom out
			myMap.Zoom = myMap.Zoom * 2;
		//Create the map
	/// <summary>
	/// Creates the map, inserts it into the cache and sets the ImageButton Url
	/// </summary>
	private void GenerateMap()
		//Save the current mapcenter and zoom in the viewstate
		ViewState.Add("mapCenter", myMap.Center);
		ViewState.Add("mapZoom", myMap.Zoom);
		//Render map
		System.Drawing.Image img = myMap.GetMap();
		string imgID = SharpMap.Web.Caching.InsertIntoCache(1, img);
		imgMap.ImageUrl = "getmap.aspx?ID=" + HttpUtility.UrlEncode(imgID);