阅读:1067回复:0
[求助][讨论]mapxtreme2005 web 划线问题
<P>谁能给看一下这个在webGis上画线的代码,每当我画完双击后地图消失</P>
<P> [Serializable]<BR> public class Line : MapInfo.WebControls.MapBaseCommand<BR> {<BR> public Line()<BR> {<BR> Name = "Line";<BR> }</P> <P> public override void Process()<BR> {<BR> MapControlModel model = MapControlModel.GetModelFromSession();<BR> model.SetMapSize(MapAlias, MapWidth, MapHeight);</P> <P> //extract points from url of client side.<BR> System.Drawing.Point[] points = ExtractPoints(DataString);</P> <P> MapInfo.Mapping.Map map = model.GetMapObj(MapAlias);<BR> MapInfo.Mapping.FeatureLayer workLayer = (MapInfo.Mapping.FeatureLayer)map.Layers["行政区"];<BR> MapInfo.Data.Table tblTemp = MapInfo.Engine.Session.Current.Catalog.GetTable("行政区");<BR> <BR> for (int i = 0; i <points.Length-1; i++)<BR> {<BR> DPoint startPoint;<BR> DPoint endPoint;<BR> map.DisplayTransform.FromDisplay(points, out startPoint);<BR> map.DisplayTransform.FromDisplay(points[i + 1], out endPoint);<BR> </P> <P> FeatureGeometry lfg = MultiCurve.CreateLine(workLayer.CoordSys, startPoint, endPoint);<BR> MapInfo.Styles.SimpleLineStyle lstyle = new MapInfo.Styles.SimpleLineStyle(<BR> new MapInfo.Styles.LineWidth(3, MapInfo.Styles.LineWidthUnit.Pixel), 2, System.Drawing.Color.OrangeRed);<BR> MapInfo.Styles.CompositeStyle cstyle = new MapInfo.Styles.CompositeStyle(lstyle);<BR> MapInfo.Data.Feature lft = new MapInfo.Data.Feature(tblTemp.TableInfo.Columns);<BR> lft.Geometry = lfg;<BR> lft.Style = cstyle;<BR> lft["index"] = i;<BR> workLayer.Table.InsertFeature(lft);<BR> }</P> <P> System.IO.MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);<BR> StreamImageToClient(ms);</P> <P> }</P> <P><BR> }<BR>在页面上拖放一个自定义控件WebTool,对其样式进行设置,有几个属性需要选择:</P> <P>ID:LineTool1</P> <P>ClientCommand:MapCommand</P> <P>ClientInteraction:PolylineInteraction</P> <P>Command:Line</P> <P>在页面加载中添加Line的命令注册。代码如下:</P> <DIV class=cnblogs_code><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>if (Session.IsNewSession)<BR>{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>MapControlModel model = MapControlModel.SetDefaultModelInSession();<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>model.Commands.Add(new Line());<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</DIV> |
|