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

Rough time get zoom and selection working together

Feb 22, 2010 at 4:24 PM

I'm having a very rough time getting this simple app of mine to be able to zoom and click.

When a zoom is triggered, the MapHandler gets a valid zoom amount and all is well.

When I go down the path of a Click, the maphander always just has the default zoom-to-extents value passed to it.

In other words, I can zoom in and out all I want, but when I got to click/select and enter the Maphandler, I'm inevitably

resetting the zoom value to a default.  Not what the user would expect.  What am I missing?

Feb 22, 2010 at 6:30 PM

any chance you can post an example? jd

Feb 22, 2010 at 8:20 PM
	Radio buttons for mode switching in main page:
<asp:RadioButtonList ID="rblMapTools" runat="server" RepeatDirection="Horizontal" 
            BorderStyle="None" Font-Names="Arial" Height="24px" Width="109px" 
		<asp:ListItem Value="0" 
            onClick="ctl00_MainContent_ajaxMapObj.disableClickEvent(); ctl00_MainContent_ajaxMapObj.zoomAmount = 3;">Zoom</asp:ListItem>
		<asp:ListItem Value="2" 
            onClick="ctl00_MainContent_ajaxMapObj.enableClickEvent(); ctl00_MainContent_ajaxMapObj.zoomAmount = 1.3;" 

	SharpMap map:
	<smap:AjaxMapControl width="100%" height="400px" id="ajaxMap" runat="server"
	OnClickEvent="MapClickedRoadMap" OnViewChange="ViewChanged" 
        OnViewChanging="ViewChanging" ForeColor="Black" style="color: #000000" />
For click: 
<asp:Button ID="Button2" runat="server" Text="Button" onclick="Button2_Click" CausesValidation="False"/>
    function MapClickedRoadMap(event, obj) {
        var btnName = $get("<%=Button2.ClientID%>").name;
        __doPostBack(btnName, "");

Key code in main page:
    protected void Page_Load(object sender, EventArgs e)
        // Create the map


    private void CreateMap()

        ajaxMap.Map = MapHelper.InitializeMap(new Size(10, 10), RegionDropDownList.SelectedValue, -1, -1);

        if (!Page.IsPostBack && !Page.IsCallback)
            //Set up the map. We use the method in the App_Code folder for initializing the map
            ajaxMap.Map.Center = new Point(0, 0);
            ajaxMap.FadeSpeed = 10;
            ajaxMap.ZoomSpeed = 10;

        ajaxMap.ResponseFormat = "maphandler.ashx?MAP=SimpleWorld&Width=[WIDTH]&Height=[HEIGHT]" +
            "&Zoom=[ZOOM]&X=[X]&Y=[Y]&R=" + RegionDropDownList.SelectedValue;


        // We want to be in Select mode always
        Literal ThisLit = new Literal();
        ThisLit.Text = "<script>ctl00_MainContent_ajaxMapObj.enableClickEvent(); ctl00_MainContent_ajaxMapObj.zoomAmount = 1.001;</script>";


    protected void Button2_Click(object sender, EventArgs e)


Map Handler:
	Identical to ajax example, setting zoom
Map Helper:
	Defines InitializeMap, where data is loaded into map

Feb 23, 2010 at 11:54 AM

I suspect that the way you are triggering a postback is causing the whole screen to be rebuilt and the map reinitialized. I guess you need to ensure the postback is trapped by an UpdatePanel leaving the map intact. hth jd