ArcGIS Mobile 自定义图层在绘制面时节点未绘制完全,如下图:
面的绘制代码如下:
public void Draw(Display dis, Pen p1, Pen p2,Pen p3 ,SolidBrush b1,Map map) { Envelope env = map.GetExtent(); if (_mapPoints.Count >= 2) { for (int i = 0; i < _mapPoints.Count - 1; i++) { if (env.Contains(_mapPoints[i].Coor)) _mapPoints[i].Draw(dis, p1, b1,map); if (env.Contains(_mapPoints[i].Coor) || env.Contains(_mapPoints[i + 1].Coor)) dis.DrawLine(p2, _mapPoints[i].Coor, _mapPoints[i + 1].Coor); } if (env.Contains(_mapPoints[_mapPoints.Count - 1].Coor)) _mapPoints[_mapPoints.Count - 1].Draw(dis, p1, b1,map); if (env.Contains(_mapPoints[_mapPoints.Count - 1].Coor) || env.Contains(_mapPoints[0].Coor)) dis.DrawLine(p3, _mapPoints[0].Coor, _mapPoints[_mapPoints.Count - 1].Coor); } else if (_mapPoints.Count == 1) { _mapPoints[0].Draw(dis, p1, b1,map); } else if (_mapPoints.Count <= 0) { return; } }
其中,节点的绘制代码如下:
public void Draw(Display dis, Pen pen, SolidBrush brush,Map map) { System.Drawing.Point p = map.ToClient(_coor); System.Drawing.Point pbl = new System.Drawing.Point(p.X - 3 * 2 / CGbParas.per, p.Y + 3 * 2 / CGbParas.per); System.Drawing.Point prt = new System.Drawing.Point(p.X + 3 * 2 / CGbParas.per, p.Y - 3 * 2 / CGbParas.per); dis.DrawEllipse(pen, brush, new Envelope(map.ToMap(pbl), map.ToMap(prt))); }
节点不显示,应该从地图刷新的地方找问题。检查代码发现Map_MouseDown中添加节点时的地图刷新使用的是Map.Invalidate(Envelope)方法,代码如下:
_polygon.AddMapPoint(_coorMouseDown); map1.Invalidate(_polygon.GetExtent(true));
问题就是出在map1.Invalidate(_polygon.GetExtent(true))。该行代码指定map只刷新面状地物的数据框区域,导致绘制到数据框外面的节点没有显示出来,因此只需要将刷新的数据框扩大一些即可。
Envelope env = _polygon.GetExtent(true); env.XMax = env.XMax * 1.01; env.XMin = env.XMin * 0.99; env.YMax = env.YMax * 1.01; env.YMin = env.YMin * 0.99; map1.Invalidate(env);
上面只是一种方式,也可以使用Envelope.Resize方法调整Envelope。