ITeye博客

MapXtreme 2005 鹰眼源代码

seven7680 · 2009-03-30 16:13 · MapXtreme · UI · F# · Security · XHTML · Web · Markdown

研究了一段时间的MapXtreme2005 v6.6, 实现了个简单的鹰眼,放出来与大家分享,转载请注明出处。设计思路为设置两个MapControl ,map1和map2,map1为主地图,map2为索引图,将map1.Bounds的矩形在map2上转换为System.Drawing.Rectangle,之后将这个Rectangle的左上坐标和width,height传到客户端,应用JS在客户端绘图。 同理移动客户端索引图上的Rectangle,则将Rectangle的中心坐标传回转换后设置map1的中心坐标。 一、打开VS2005新建一个网站,选择“MapXtreme 6.6 Web Application”模板(当然也可以建一个空模板,然后自己拖控件,配置web..config); 二、把界面的上MapControl1命名为MainMap,MapAlias为Map1,再拖一个MapContol到界面上(自己排版),命名为IndexMap(作为导航地图),MapAlias为Map2; 三、下面为源码: MapForm.aspx 复制内容到剪贴板 代码: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="MapForm.aspx.cs" Inherits="IndexMap.IndexPage" %> <%@ Register Assembly="MapInfo.WebControls, Version=4.0.0.428, Culture=neutral, PublicKeyToken=0a9556cc66c0af57" Namespace="MapInfo.WebControls" TagPrefix="cc1" %> Untitled Page

MapInfo MapXtreme

MapForm.cs 复制内容到剪贴板 代码: using System; using System.Data; using System.Configuration; 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 MapInfo.WebControls; using ApplicationStateManager; namespace IndexMap { public partial class IndexPage : System.Web.UI.Page { private void Page_Load(object sender, System.EventArgs e) { // If the StateManager doesn't exist in the session put it else get it. if (StateManager.GetStateManagerFromSession() == null) StateManager.PutStateManagerInSession(new AppStateManager()); if (!IsPostBack) { MapControlModel model = MapControlModel.SetDefaultModelInSession(); model.Commands.Add(new IndexMap.ZoomValue()); model.Commands.Add(new IndexMap.MoveMainMap()); } // Now Restore State StateManager.GetStateManagerFromSession().ParamsDictionary[StateManager.ActiveMapAliasKey] = MainMap.MapAlias; StateManager.GetStateManagerFromSession().RestoreState(); } // At the time of unloading the page, save the state private void Page_UnLoad(object sender, System.EventArgs e) { StateManager.GetStateManagerFromSession().SaveState(); } protected MapInfo.Mapping.Map GetMapObj(string mapAlias) { MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory[mapAlias]; if(myMap == null) { myMap = MapInfo.Engine.Session.Current.MapFactory[0]; } return myMap; } } } CustomerCommand.cs 复制内容到剪贴板 代码: using System; using System.Data; using System.IO; using System.Drawing; using System.Configuration; 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 MapInfo.Web; using MapInfo.WebControls; using MapInfo.Data; using MapInfo.Geometry; namespace IndexMap { [Serializable] public class ZoomValue : MapInfo.WebControls.MapBaseCommand { public ZoomValue() { Name = "ZoomValue"; } public override void Process() { MapControlModel model = MapControlModel.GetModelFromSession(); MapInfo.Mapping.Map map1 = model.GetMapObj("Map1"); MapInfo.Mapping.Map map2 = model.GetMapObj("Map2"); System.Drawing.Rectangle rectNew; map2.DisplayTransform.ToDisplay(map1.Bounds, out rectNew); HttpContext.Current.Response.Output.Write(rectNew.X + "," + rectNew.Y + "," + rectNew.Height + "," + rectNew.Width); } } [Serializable] public class MoveMainMap : MapInfo.WebControls.MapBaseCommand { public MoveMainMap() { Name = "MoveMainMap"; } public override void Process() { int x = System.Convert.ToInt32(HttpContext.Current.Request["CenterX"]); int y = System.Convert.ToInt32(HttpContext.Current.Request["CenterY"]); MapControlModel model = MapControlModel.GetModelFromSession(); MapInfo.Mapping.Map map1 = model.GetMapObj("Map1"); MapInfo.Mapping.Map map2 = model.GetMapObj("Map2"); System.Drawing.Point spoint = new System.Drawing.Point(x,y); MapInfo.Geometry.DPoint point; map2.DisplayTransform.FromDisplay(spoint, out point); map1.Center = point; MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat); StreamImageToClient(ms); } } } JScript.js 复制内容到剪贴板 代码: // JScript 文件 function getZoomValue() { var MapImage = document.getElementById("MainMap_Image"); var url = "MapController.ashx?Command=ZoomValue&Width=" + MapImage.width + "&height=" + MapImage.height + "&ExportFormat=" + MapImage.exportFormat + "&Ran=" + Math.random(); if(MapImage.mapAlias) url += "&MapAlias" + MapImage.mapAlias; var xmlHttp = CreateXMLHttp(); xmlHttp.open("GET",url,false); xmlHttp.send(null); var result = xmlHttp.responseText; var htmlContent = new Array(); htmlContent = result.split(','); var div = document.getElementById("indexDiv"); var left = 1*htmlContent[0] ; var top = 1*htmlContent[1] ; var height = 1*htmlContent[2] ; var width = 1*htmlContent[3] ; if (left < 0) left = 0; if (top < 0) top = 0; if (width > 200) width = 200; if (height > 200) height = 200; div.innerHTML="

"; } function MoveMainMap() { var mapImage = document.getElementById("MainMap_Image"); var indexRect = document.getElementById("indexRect"); var w = indexRect.clientWidth /2; var h = indexRect.clientHeight /2; var x = parseInt((parseInt(indexRect.style.left) + w)); var y = parseInt((parseInt(indexRect.style.top) + h)); var url = "MapController.ashx?Command=MoveMainMap&Width=" + mapImage.width + "&Height=" + mapImage.height + "&ExportFormat=" + mapImage.exportFormat + "&Ran=" + Math.random(); url += "&CenterX=" + x; url += "&CenterY=" + y; if (mapImage.mapAlias) url += "&MapAlias=" + mapImage.mapAlias; var xmlHttp = CreateXMLHttp(); xmlHttp.open("GET", url, false); xmlHttp.send(null); try { mapImage.src = url; } catch(e){ alert("ll"); } } 注意在配置文件中,要加载2个工作空间。 如下:

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。