MapControl

MapControl.ascx

None.gif <% @ Control Language = " c# "  AutoEventWireup = " false "  Codebehind = " MapControl.ascx.cs "  Inherits = " MapPoint.MapControl "  TargetSchema = " http://schemas.microsoft.com/intellisense/ie5 " %>
None.gif
< script language = " javascript " >
None.gif
None.gifvar xmlhttp
= null ;
None.gif
None.giffunction GetMap(x,y,zoom)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
//Create a valid url with user typed place value
InBlock.gif
    var url = "Handler.aspx?x=" + x + "&y=" + y + "&zoom=" + zoom + "&ramdon=" + Math.random();
InBlock.gif
InBlock.gif    
//Create an instance of xmlHttp
InBlock.gif
    xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
InBlock.gif    
if(xmlhttp)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
//Now open a request and assign callback
InBlock.gif
        xmlhttp.open("GET",url,true);
InBlock.gif        xmlhttp.onreadystatechange
=SetMap;
InBlock.gif        
//Send the request
InBlock.gif
        xmlhttp.send(null);
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
None.giffunction SetMap()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
if(xmlhttp)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
if(xmlhttp.readyState==4&&xmlhttp.responseText)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//Get the response content
InBlock.gif
            var placecontent = xmlhttp.responseText;
InBlock.gif            
//Just execute the response content
InBlock.gif
            if(placecontent != "")
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif                
/**//*
InBlock.gif                var img = document.getElementById('Map_imgMap');
InBlock.gif                img.src=placecontent;
InBlock.gif                img.onreadystatechange = RepositionDiv;
ExpandedSubBlockEnd.gif                
*/

InBlock.gif                
InBlock.gif                RepositionDiv(placecontent);
ExpandedSubBlockEnd.gif            }

InBlock.gif            xmlhttp 
= null;
InBlock.gif            
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
None.giffunction RepositionDiv(placecontent)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    var innerDiv 
= document.getElementById("innerDiv");
InBlock.gif    
InBlock.gif    
if(stripPx(innerDiv.style.top) != 0 || stripPx(innerDiv.style.left) != 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        var img 
= document.getElementById('Map_imgMap');
InBlock.gif        innerDiv.removeChild(img);
InBlock.gif        var img 
= document.createElement("img");
InBlock.gif        img.src 
=placecontent;
InBlock.gif        img.setAttribute(
"id""Map_imgMap");
InBlock.gif        innerDiv.style.top 
= 0;
InBlock.gif        innerDiv.style.left 
= 0;
InBlock.gif        innerDiv.appendChild(img);
InBlock.gif
ExpandedSubBlockEnd.gif    }

InBlock.gif    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        var img 
= document.getElementById('Map_imgMap');
InBlock.gif        img.src
=placecontent;
InBlock.gif        
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedBlockEnd.gif}

ExpandedBlockStart.gifContractedBlock.gif
/**/ /*
InBlock.gif
InBlock.giffunction RepositionDiv()
InBlock.gif{
InBlock.gif    var innerDiv = document.getElementById("innerDiv");
InBlock.gif    
InBlock.gif    if(stripPx(innerDiv.style.top) != 0 || stripPx(innerDiv.style.left) != 0)
InBlock.gif    {
InBlock.gif        var img = document.getElementById('Map_imgMap');
InBlock.gif        if(img.readyState == "complete")
InBlock.gif        {
InBlock.gif            innerDiv.style.top = 0;
InBlock.gif            innerDiv.style.left = 0;
InBlock.gif        }
InBlock.gif    }
InBlock.gif
InBlock.gif}
InBlock.gif
ExpandedBlockEnd.gif
*/

None.gifvar dragging 
=   false ;
None.gifvar top;
None.gifvar left;
None.gifvar dragStartTop;
None.gifvar dragStartLeft;
None.gif
ExpandedBlockStart.gifContractedBlock.giffunction init() 
dot.gif {
InBlock.gif    
// wire up the mouse listeners to do dragging
InBlock.gif
    var outerDiv = document.getElementById("outerDiv");
InBlock.gif    outerDiv.onmousedown 
= startMove;
InBlock.gif    
//outerDiv.onmousemove = processMove;
InBlock.gif    
//outerDiv.onmouseup = stopMove;
InBlock.gif
    document.onmousemove = processMove;    
InBlock.gif    document.onmouseup 
= stopMove;
InBlock.gif    
// necessary to enable dragging on IE
ExpandedSubBlockStart.gifContractedSubBlock.gif
    outerDiv.ondragstart = function() dot.gifreturn false; }
ExpandedBlockEnd.gif}

ExpandedBlockStart.gifContractedBlock.giffunction startMove(
event dot.gif {
InBlock.gif    
// necessary for IE
InBlock.gif
    if (!eventevent = window.event;
InBlock.gif    dragStartLeft 
= event.clientX;
InBlock.gif    dragStartTop 
= event.clientY;
InBlock.gif    var innerDiv 
= document.getElementById("innerDiv");
InBlock.gif    innerDiv.style.cursor 
= "hand";//"-moz-grab";
InBlock.gif
    top = stripPx(innerDiv.style.top);
InBlock.gif    left 
= stripPx(innerDiv.style.left);
InBlock.gif    dragging 
= true;
InBlock.gif    
return false;
ExpandedBlockEnd.gif}

ExpandedBlockStart.gifContractedBlock.giffunction processMove(
event dot.gif {
InBlock.gif    
if (!eventevent = window.event// for IE
InBlock.gif
    var innerDiv = document.getElementById("innerDiv");
ExpandedSubBlockStart.gifContractedSubBlock.gif    
if (dragging) dot.gif{
InBlock.gif        innerDiv.style.top 
= top + (event.clientY - dragStartTop);
InBlock.gif        innerDiv.style.left 
= left + (event.clientX - dragStartLeft);
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

ExpandedBlockStart.gifContractedBlock.giffunction stopMove() 
dot.gif {
InBlock.gif    
if(dragging)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        var innerDiv 
= document.getElementById("innerDiv");
InBlock.gif        innerDiv.style.cursor 
= "";
InBlock.gif        dragging 
= false;
InBlock.gif        var panx 
= (left - stripPx(innerDiv.style.left))/500;
InBlock.gif        var pany 
= (stripPx(innerDiv.style.top) - top)/500;
InBlock.gif        GetMap(panx,pany,
0);
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

ExpandedBlockStart.gifContractedBlock.giffunction stripPx(value) 
dot.gif {
InBlock.gif    
if (value == ""return 0;
InBlock.gif    
return parseFloat(value.substring(0, value.length - 2));
ExpandedBlockEnd.gif}

None.gif
</ script >
None.gif
< style >
ExpandedBlockStart.gifContractedBlock.gif    #outerDiv 
dot.gif { BORDER-RIGHT: black 1px solid; BORDER-TOP: black 1px solid; OVERFLOW: hidden; BORDER-LEFT: black 1px solid; WIDTH: 500px; BORDER-BOTTOM: black 1px solid; POSITION: relative; HEIGHT: 500px }
ExpandedBlockStart.gifContractedBlock.gif    #innerDiv 
dot.gif { LEFT: 0px; POSITION: relative; TOP: 0px }
None.gif
</ style >
None.gif
< div id = " divMap "  runat = " server " >
None.gif    
< TABLE id = " Table1 "  cellSpacing = " 1 "  cellPadding = " 1 "
None.gif        width
= " 480 "  border = " 1 " >
None.gif        
< TR >
None.gif            
< TD align = " center "  colspan = " 2 " >
None.gif                
< INPUT type = " button "  value = " N "  onclick = " GetMap(0,.25,0); " >   < INPUT type = " button "  value = " S "  onclick = " GetMap(0,-.25,0); " >
None.gif                
< INPUT type = " button "  value = " E "  onclick = " GetMap(.25,0,0); " >   < INPUT type = " button "  value = " W "  onclick = " GetMap(-.25,0,0); " >
None.gif                
< INPUT type = " button "  value = " + "  onclick = " GetMap(0,0,.25); " >   < INPUT type = " button "  value = " - "  onclick = " GetMap(0,0,-.25); " >
None.gif            
</ TD >
None.gif        
</ TR >
None.gif        
< TR >
None.gif            
< TD ></ TD >
None.gif            
< TD ></ TD >
None.gif        
</ TR >
None.gif    
</ TABLE >
None.gif    
< div id = " outerDiv " >
None.gif        
< div id = " innerDiv " >< asp:Image ID = " imgMap "  Runat = " server "  Visible = " False "  Height = " 500px "  Width = " 500px "   ></ asp:Image ></ div >
None.gif    
</ div >
None.gif
</ div >
None.gif
CodeBehind of MapControl.ascx
None.gif namespace  MapPoint
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
using System;
InBlock.gif    
using System.Data;
InBlock.gif    
using System.Drawing;
InBlock.gif    
using System.Web;
InBlock.gif    
using System.Web.UI.WebControls;
InBlock.gif    
using System.Web.UI.HtmlControls;
InBlock.gif    
using MapPointService;
InBlock.gif    
using MapPointService.MapPointService;
InBlock.gif    
using System.Web.Services.Protocols;
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
///        Summary description for MapControl.
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class MapControl : System.Web.UI.UserControl
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
protected System.Web.UI.WebControls.Image imgMap;
InBlock.gif        
protected System.Web.UI.HtmlControls.HtmlGenericControl divMap;
InBlock.gif
InBlock.gif
//        private readonly double PAN_ADJUSTMENT = 0.25;
InBlock.gif
//        private readonly double ZOOM_VALUE = 0.25;
InBlock.gif
    
InBlock.gif
InBlock.gif        
public SchoolLocator SchoolLocator
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//return _mapSpecification;
InBlock.gif
                return (SchoolLocator)Session["SchoolLocator"];
InBlock.gif
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//_mapSpecification = value;
InBlock.gif
                Session["SchoolLocator"= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
public void RenderMap()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            RenderMap(
0,0,0);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
private void Page_Load(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
// Put user code to initialize the page here
InBlock.gif
            this.divMap.Visible = false;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
void RenderMap(double myPanHorizontalAdjustment, double myPanVerticalAdjustment, double myZoomValue) 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif
InBlock.gif            
InBlock.gif            
//Get the latest map specification object
InBlock.gif
            if(SchoolLocator == null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.divMap.Visible = false;
InBlock.gif                
return;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.divMap.Visible = true;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
//Pan or zoom the map as appropriate
InBlock.gif

InBlock.gif
InBlock.gif            
string url = SchoolLocator.GetMapURL(myPanHorizontalAdjustment, myPanVerticalAdjustment, myZoomValue);
InBlock.gif
InBlock.gif            
//Assign the Map Url
InBlock.gif
            if(url.Length > 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.imgMap.ImageUrl = url;
InBlock.gif                
this.imgMap.Visible = true;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
InBlock.gif                
this.divMap.Visible = false;
InBlock.gif
InBlock.gif            Page.RegisterStartupScript(
"Init","<script language='JavaScript'>init();</script>");
InBlock.gif
InBlock.gif        
ExpandedSubBlockEnd.gif        }

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
Web Form Designer generated code#region Web Form Designer generated code
InBlock.gif        
override protected void OnInit(EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
InBlock.gif            
//
InBlock.gif
            InitializeComponent();
InBlock.gif            
base.OnInit(e);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
///        Required method for Designer support - do not modify
InBlock.gif        
///        the contents of this method with the code editor.
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private void InitializeComponent()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.Load += new System.EventHandler(this.Page_Load);
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

转载于:https://www.cnblogs.com/4netfriend/archive/2006/09/05/495017.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值