MapXtreme 2005学习(7):Web页面中实现鼠标中键缩放

在MapXtreme 2005中,在Windows应用程序中自带鼠标中键缩放的功能,而有Web应用程序中却没有,如果能够实现会显得更加人性化。在百度里面一搜,还真有位高人实现了,于是借鉴了一下,作了一些修改,在这里和大家共享一下,你可能通过修改程序代码,控制每次缩放的比例,也可以选择等差或等比的方式进行缩放,代码比较简单,只要稍作修改就可以实现。

 

(1)在页面的</form>之前添加如下JavaScript代码:

 

< script type = " text/javascript " >        
var  Img  =  document.getElementById( " MapControl1_Image " );
if (Img  !=   null )
ExpandedBlockStart.gifContractedBlock.gif
{
   Img.attachEvent(
'onmousewheel', GetMouseWheelEvent);
}

function  GetMouseWheelEvent()
ExpandedBlockStart.gifContractedBlock.gif
{
    
var mapImage = document.getElementById("MapControl1_Image");
    
var url = "MapController.ashx?Command=WheelZoom&Width=" + mapImage.width +"&Height=" + mapImage.height
     
+ "&ExportFormat=" + mapImage.exportFormat + "&Ran=" + Math.random() + "&wheelvalue=" + event.wheelDelta;
    
if (mapImage.mapAlias) 
        url 
+=  "&MapAlias=" + mapImage.mapAlias;    
    
try 
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        mapImage.src 
= url;
    }

    
catch(e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    

        alert(
"Error!");
    }

}

< / script>

 

(2)在后台代码中,如自定义命令的文件CustomerCommands.cs中的添加如下类:

 

    [Serializable]
    
public   class  WheelZoom : MapBaseCommand
ExpandedBlockStart.gifContractedBlock.gif    
{
        
public WheelZoom()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            Name 
= "WheelZoom";
        }


        
public override void Process()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
int wheelvalue = int.Parse(System.Convert.ToString(HttpContext.Current.Request["wheelvalue"]));
          
            MapControlModel model 
= MapControlModel.GetModelFromSession();
            model.SetMapSize(MapAlias, MapWidth, MapHeight);
            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                MapInfo.Mapping.Map map 
= model.GetMapObj(MapAlias);

                MapInfo.Geometry.Distance d;
                
if (wheelvalue > 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    d 
= new MapInfo.Geometry.Distance(map.Zoom.Value * 0.5, map.Zoom.Unit);
                }

                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    d 
= new MapInfo.Geometry.Distance(map.Zoom.Value * 2, map.Zoom.Unit);
                }

                map.Zoom 
= d;
            }

            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                System.IO.MemoryStream ms 
= model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);
                StreamImageToClient(ms);
            }

        }

    }

 

(3)在页面加载处注册Command:

 

if (Session.IsNewSession)
ExpandedBlockStart.gifContractedBlock.gif
{
    MapControlModel model 
= MapControlModel.SetDefaultModelInSession();
    model.Commands.Add(
new WheelZoom());
}

 

完毕,运行在页面地图上滚动鼠标中间键即可看到效果。

转载于:https://www.cnblogs.com/glacierh/archive/2008/08/07/1263118.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值