以下两个类对MapXtrme2004 asp.net鹰眼功能进行了完全的封装。
用法:
1 private void Page_Load(object sender, System.EventArgs e)
2 {
3 // 在此处放置用户代码以初始化页面
4 Overview oc = new Overview(MapControl1,MapControl2);
5
6 if(!IsPostBack)
7 {
8
9
10 }
11 }
2 {
3 // 在此处放置用户代码以初始化页面
4 Overview oc = new Overview(MapControl1,MapControl2);
5
6 if(!IsPostBack)
7 {
8
9
10 }
11 }
1/* 作者:xiexiaokui
2 * 时间:2005-10-18
3 * 功能:asp.net鹰眼
4 */
5using System;
6using MapInfo.Web.UI.WebControls;
7using MapInfo.Geometry;
8using MapInfo.Styles;
9using System.Drawing;
10using MapInfo.Data;
11
12 /// <summary>
13 /// OverviewTool 的摘要说明。
14 /// </summary>
15public class OverviewMapToolEventArgs:System.EventArgs
16{
17 System.Drawing.Point[] m_points;
18 public OverviewMapToolEventArgs(System.Drawing.Point[] points)
19 {
20 this.m_points = points;
21 }
22
23 public System.Drawing.Point[] Points
24 {
25 get
26 {
27 return m_points;
28 }
29 set
30 {
31 m_points = value;
32 }
33 }
34
35}
36
37public delegate void OverviewMapToolEventHandler(object sender,OverviewMapToolEventArgs e);
38
39
40public class OverviewMapTool:MapTool
41{
42 public static readonly string Toolname = "MapInfoWebOverview";
43 // public DPoint Point1,Point2;
44
45 string m_clientCodeSource;
46 string m_clientStartMethod;
47 string m_clientStopMethod;
48 string m_cursorUrl;
49 string m_name;
50
51
52 public event OverviewMapToolEventHandler OverviewMapToolStop;
53
54 protected void OnOverviewMapToolStop(OverviewMapToolEventArgs e)
55 {
56 if(this.OverviewMapToolStop != null)
57 this.OverviewMapToolStop(this,e);
58 }
59
60 public OverviewMapTool()
61 {
62 this.ClientStartMethod = "MapInfoWebRectangleStart";
63 this.ClientStopMethod = "MapInfoWebRectangleStop";
64 this.Name = Toolname;
65 }
66 public override string ClientCodeSource
67 {
68 get
69 {
70 return m_clientCodeSource;
71 }
72 set
73 {
74 m_clientCodeSource = value;
75 }
76 }
77
78 public override string ClientStartMethod
79 {
80 get
81 {
82 return m_clientStartMethod;
83 }
84 set
85 {
86 m_clientStartMethod = value;
87 }
88 }
89 public override string ClientStopMethod
90 {
91 get
92 {
93 return m_clientStopMethod;
94 }
95 set
96 {
97 m_clientStopMethod = value;
98 }
99 }
100 public override string CursorUrl
101 {
102 get
103 {
104 return m_cursorUrl;
105 }
106 set
107 {
108 m_cursorUrl = value;
109 }
110 }
111 public override string Name
112 {
113 get
114 {
115 return m_name;
116 }
117 set
118 {
119 m_name = value;
120 }
121 }
122
123
124 public override void Execute(string dataString, System.Collections.ArrayList selLayers, MapInfo.Mapping.Map map)
125 {
126
127 // DPoint dp1,dp2;
128 System.Drawing.Point[] points = base.ExtractPoints(dataString);
129 // map.DisplayTransform.FromDisplay(points[0],out dp1);
130 // map.DisplayTransform.FromDisplay(points[1],out dp2);
131
132
133 this.OnOverviewMapToolStop(new OverviewMapToolEventArgs(points));
134 // OverviewMapTool omt = (OverviewMapTool)this.MapControl2.MapTools[MapControl2.MapTools.Count-1];
135 // MapInfo.Geometry.DPoint dp1 = omt.Point1;
136 // MapInfo.Geometry.DPoint dp2 = omt.Point2;
137 // System.Drawing.Point p1,p2;
138
139 // MapControl2.Map.DisplayTransform.ToDisplay(dp1,out p1);
140 // MapControl2.Map.DisplayTransform.ToDisplay(dp2,out p2);
141// if(Math.Min(Math.Abs(points[0].X-points[1].X),Math.Abs(points[0].Y-points[1].Y))<5)
142// {
143// m_mainMapControl.Map.Center = dp1;
144// }
145// else
146// {
147// MapInfo.Geometry.DRect rect = new DRect(dp1,dp2);
148// m_mainMapControl.Map.SetView(rect,m_mainMapControl.Map.GetDisplayCoordSys());
149// }
150
151 }
152
153
154}
155class Overview
156{
157
158 MapInfo.Web.UI.WebControls.MapControl m_mainMapControl;
159 MapInfo.Web.UI.WebControls.MapControl m_overviewMapControl;
160 public Overview(MapInfo.Web.UI.WebControls.MapControl mainMapControl,MapInfo.Web.UI.WebControls.MapControl overviewMapControl)
161 {
162 MainMapControl = mainMapControl;
163 OverviewMapControl = overviewMapControl;
164 }
165
166 public MapInfo.Web.UI.WebControls.MapControl MainMapControl
167 {
168 get
169 {
170 return m_mainMapControl;
171 }
172 set
173 {
174 m_mainMapControl = value;
175 m_mainMapControl.PreRender += new EventHandler(MainMapControl_PreRender);
176 }
177 }
178 public MapInfo.Web.UI.WebControls.MapControl OverviewMapControl
179 {
180 get
181 {
182 return m_overviewMapControl;
183 }
184 set
185 {
186
187
188 MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.GetTable("temp_overview");
189 m_overviewMapControl = value;
190 OverviewMapTool omt = new OverviewMapTool();
191 omt.OverviewMapToolStop += new OverviewMapToolEventHandler(omt_OverviewMapToolStop);
192 this.m_overviewMapControl.MapTools.Add(omt);
193 this.m_overviewMapControl.MapTools.CurrentTool = omt.Name;
194 if(table == null)
195 {
196
197
198 this.m_overviewMapControl.Map.Load(new MapInfo.Mapping.MapTableLoader(m_mainMapControl.Map.Layers.GetTableEnumerator()));
199
200 MapInfo.Data.TableInfo ti = MapInfo.Data.TableInfoFactory.CreateTemp("temp_overview");
201 MapInfo.Data.TableSessionInfo tsi = new MapInfo.Data.TableSessionInfo();
202
203 table = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti);
204
205 MapInfo.Mapping.FeatureLayer fl = new MapInfo.Mapping.FeatureLayer(table);
206 m_overviewMapControl.Map.Layers.Insert(0,fl);
207 }
208
209 }
210 }
211 protected void MainMapControl_PreRender(object sender, EventArgs e)
212 {
213
214 DRect dr = this.m_mainMapControl.Map.Bounds;
215 FeatureGeometry fg = new MapInfo.Geometry.Rectangle(m_mainMapControl.Map.GetDisplayCoordSys(),dr);
216 MapInfo.Styles.SimpleLineStyle sls = new MapInfo.Styles.SimpleLineStyle(new LineWidth(1,LineWidthUnit.Pixel),2,Color.Red);
217 MapInfo.Styles.SimpleInterior si = new MapInfo.Styles.SimpleInterior(1);
218 MapInfo.Styles.AreaStyle arst = new MapInfo.Styles.AreaStyle(sls,si);
219 // MapInfo.Styles.CompositeStyle cs = new MapInfo.Styles.CompositeStyle(arst,null,null,null);
220 MapInfo.Styles.CompositeStyle cs = new MapInfo.Styles.CompositeStyle(arst);
221 MapInfo.Data.Feature f = new Feature(fg,arst);
222
223 MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.GetTable("temp_overview");
224 (table as ITableFeatureCollection).Clear();
225 table.InsertFeature(f);
226
227 m_overviewMapControl.Map.Layers["temp_overview"].Invalidate();
228 //table.Refresh();
229
230 }
231
232 private void omt_OverviewMapToolStop(object sender, OverviewMapToolEventArgs e)
233 {
234 DPoint dp1,dp2;
235 System.Drawing.Point[] points = e.Points;
236 m_overviewMapControl.Map.DisplayTransform.FromDisplay(points[0],out dp1);
237 m_overviewMapControl.Map.DisplayTransform.FromDisplay(points[1],out dp2);
238 // OverviewMapTool omt = (OverviewMapTool)this.MapControl2.MapTools[MapControl2.MapTools.Count-1];
239 // MapInfo.Geometry.DPoint dp1 = omt.Point1;
240 // MapInfo.Geometry.DPoint dp2 = omt.Point2;
241 // System.Drawing.Point p1,p2;
242
243 // MapControl2.Map.DisplayTransform.ToDisplay(dp1,out p1);
244 // MapControl2.Map.DisplayTransform.ToDisplay(dp2,out p2);
245 if(Math.Min(Math.Abs(points[0].X-points[1].X),Math.Abs(points[0].Y-points[1].Y))<5)
246 {
247 m_mainMapControl.Map.Center = dp1;
248 }
249 else
250 {
251 MapInfo.Geometry.DRect rect = new DRect(dp1,dp2);
252 m_mainMapControl.Map.SetView(rect,m_mainMapControl.Map.GetDisplayCoordSys());
253 }
254 }
255
256}
257
258
2 * 时间:2005-10-18
3 * 功能:asp.net鹰眼
4 */
5using System;
6using MapInfo.Web.UI.WebControls;
7using MapInfo.Geometry;
8using MapInfo.Styles;
9using System.Drawing;
10using MapInfo.Data;
11
12 /// <summary>
13 /// OverviewTool 的摘要说明。
14 /// </summary>
15public class OverviewMapToolEventArgs:System.EventArgs
16{
17 System.Drawing.Point[] m_points;
18 public OverviewMapToolEventArgs(System.Drawing.Point[] points)
19 {
20 this.m_points = points;
21 }
22
23 public System.Drawing.Point[] Points
24 {
25 get
26 {
27 return m_points;
28 }
29 set
30 {
31 m_points = value;
32 }
33 }
34
35}
36
37public delegate void OverviewMapToolEventHandler(object sender,OverviewMapToolEventArgs e);
38
39
40public class OverviewMapTool:MapTool
41{
42 public static readonly string Toolname = "MapInfoWebOverview";
43 // public DPoint Point1,Point2;
44
45 string m_clientCodeSource;
46 string m_clientStartMethod;
47 string m_clientStopMethod;
48 string m_cursorUrl;
49 string m_name;
50
51
52 public event OverviewMapToolEventHandler OverviewMapToolStop;
53
54 protected void OnOverviewMapToolStop(OverviewMapToolEventArgs e)
55 {
56 if(this.OverviewMapToolStop != null)
57 this.OverviewMapToolStop(this,e);
58 }
59
60 public OverviewMapTool()
61 {
62 this.ClientStartMethod = "MapInfoWebRectangleStart";
63 this.ClientStopMethod = "MapInfoWebRectangleStop";
64 this.Name = Toolname;
65 }
66 public override string ClientCodeSource
67 {
68 get
69 {
70 return m_clientCodeSource;
71 }
72 set
73 {
74 m_clientCodeSource = value;
75 }
76 }
77
78 public override string ClientStartMethod
79 {
80 get
81 {
82 return m_clientStartMethod;
83 }
84 set
85 {
86 m_clientStartMethod = value;
87 }
88 }
89 public override string ClientStopMethod
90 {
91 get
92 {
93 return m_clientStopMethod;
94 }
95 set
96 {
97 m_clientStopMethod = value;
98 }
99 }
100 public override string CursorUrl
101 {
102 get
103 {
104 return m_cursorUrl;
105 }
106 set
107 {
108 m_cursorUrl = value;
109 }
110 }
111 public override string Name
112 {
113 get
114 {
115 return m_name;
116 }
117 set
118 {
119 m_name = value;
120 }
121 }
122
123
124 public override void Execute(string dataString, System.Collections.ArrayList selLayers, MapInfo.Mapping.Map map)
125 {
126
127 // DPoint dp1,dp2;
128 System.Drawing.Point[] points = base.ExtractPoints(dataString);
129 // map.DisplayTransform.FromDisplay(points[0],out dp1);
130 // map.DisplayTransform.FromDisplay(points[1],out dp2);
131
132
133 this.OnOverviewMapToolStop(new OverviewMapToolEventArgs(points));
134 // OverviewMapTool omt = (OverviewMapTool)this.MapControl2.MapTools[MapControl2.MapTools.Count-1];
135 // MapInfo.Geometry.DPoint dp1 = omt.Point1;
136 // MapInfo.Geometry.DPoint dp2 = omt.Point2;
137 // System.Drawing.Point p1,p2;
138
139 // MapControl2.Map.DisplayTransform.ToDisplay(dp1,out p1);
140 // MapControl2.Map.DisplayTransform.ToDisplay(dp2,out p2);
141// if(Math.Min(Math.Abs(points[0].X-points[1].X),Math.Abs(points[0].Y-points[1].Y))<5)
142// {
143// m_mainMapControl.Map.Center = dp1;
144// }
145// else
146// {
147// MapInfo.Geometry.DRect rect = new DRect(dp1,dp2);
148// m_mainMapControl.Map.SetView(rect,m_mainMapControl.Map.GetDisplayCoordSys());
149// }
150
151 }
152
153
154}
155class Overview
156{
157
158 MapInfo.Web.UI.WebControls.MapControl m_mainMapControl;
159 MapInfo.Web.UI.WebControls.MapControl m_overviewMapControl;
160 public Overview(MapInfo.Web.UI.WebControls.MapControl mainMapControl,MapInfo.Web.UI.WebControls.MapControl overviewMapControl)
161 {
162 MainMapControl = mainMapControl;
163 OverviewMapControl = overviewMapControl;
164 }
165
166 public MapInfo.Web.UI.WebControls.MapControl MainMapControl
167 {
168 get
169 {
170 return m_mainMapControl;
171 }
172 set
173 {
174 m_mainMapControl = value;
175 m_mainMapControl.PreRender += new EventHandler(MainMapControl_PreRender);
176 }
177 }
178 public MapInfo.Web.UI.WebControls.MapControl OverviewMapControl
179 {
180 get
181 {
182 return m_overviewMapControl;
183 }
184 set
185 {
186
187
188 MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.GetTable("temp_overview");
189 m_overviewMapControl = value;
190 OverviewMapTool omt = new OverviewMapTool();
191 omt.OverviewMapToolStop += new OverviewMapToolEventHandler(omt_OverviewMapToolStop);
192 this.m_overviewMapControl.MapTools.Add(omt);
193 this.m_overviewMapControl.MapTools.CurrentTool = omt.Name;
194 if(table == null)
195 {
196
197
198 this.m_overviewMapControl.Map.Load(new MapInfo.Mapping.MapTableLoader(m_mainMapControl.Map.Layers.GetTableEnumerator()));
199
200 MapInfo.Data.TableInfo ti = MapInfo.Data.TableInfoFactory.CreateTemp("temp_overview");
201 MapInfo.Data.TableSessionInfo tsi = new MapInfo.Data.TableSessionInfo();
202
203 table = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti);
204
205 MapInfo.Mapping.FeatureLayer fl = new MapInfo.Mapping.FeatureLayer(table);
206 m_overviewMapControl.Map.Layers.Insert(0,fl);
207 }
208
209 }
210 }
211 protected void MainMapControl_PreRender(object sender, EventArgs e)
212 {
213
214 DRect dr = this.m_mainMapControl.Map.Bounds;
215 FeatureGeometry fg = new MapInfo.Geometry.Rectangle(m_mainMapControl.Map.GetDisplayCoordSys(),dr);
216 MapInfo.Styles.SimpleLineStyle sls = new MapInfo.Styles.SimpleLineStyle(new LineWidth(1,LineWidthUnit.Pixel),2,Color.Red);
217 MapInfo.Styles.SimpleInterior si = new MapInfo.Styles.SimpleInterior(1);
218 MapInfo.Styles.AreaStyle arst = new MapInfo.Styles.AreaStyle(sls,si);
219 // MapInfo.Styles.CompositeStyle cs = new MapInfo.Styles.CompositeStyle(arst,null,null,null);
220 MapInfo.Styles.CompositeStyle cs = new MapInfo.Styles.CompositeStyle(arst);
221 MapInfo.Data.Feature f = new Feature(fg,arst);
222
223 MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.GetTable("temp_overview");
224 (table as ITableFeatureCollection).Clear();
225 table.InsertFeature(f);
226
227 m_overviewMapControl.Map.Layers["temp_overview"].Invalidate();
228 //table.Refresh();
229
230 }
231
232 private void omt_OverviewMapToolStop(object sender, OverviewMapToolEventArgs e)
233 {
234 DPoint dp1,dp2;
235 System.Drawing.Point[] points = e.Points;
236 m_overviewMapControl.Map.DisplayTransform.FromDisplay(points[0],out dp1);
237 m_overviewMapControl.Map.DisplayTransform.FromDisplay(points[1],out dp2);
238 // OverviewMapTool omt = (OverviewMapTool)this.MapControl2.MapTools[MapControl2.MapTools.Count-1];
239 // MapInfo.Geometry.DPoint dp1 = omt.Point1;
240 // MapInfo.Geometry.DPoint dp2 = omt.Point2;
241 // System.Drawing.Point p1,p2;
242
243 // MapControl2.Map.DisplayTransform.ToDisplay(dp1,out p1);
244 // MapControl2.Map.DisplayTransform.ToDisplay(dp2,out p2);
245 if(Math.Min(Math.Abs(points[0].X-points[1].X),Math.Abs(points[0].Y-points[1].Y))<5)
246 {
247 m_mainMapControl.Map.Center = dp1;
248 }
249 else
250 {
251 MapInfo.Geometry.DRect rect = new DRect(dp1,dp2);
252 m_mainMapControl.Map.SetView(rect,m_mainMapControl.Map.GetDisplayCoordSys());
253 }
254 }
255
256}
257
258