问题1:当点击某一条数据时将实现地图定位功能,但要如何才能控制定位的缩放呢,按几何对象的大小缩放不是很好,今天特意去观察了下百度,发现百度地图中不管几何对象都大,定位时都是控制了地图的缩放的,故本人实现如下
1 /// <summary> 2 /// 使用矩形对象获取定位矩形对象 3 /// </summary> 4 /// <param name="enveLope">矩形实例</param> 5 /// <param name="dScale">定位时,定位信息X、Y最大最小值所占屏幕宽度比例,取值范围为0-1(不包含0包含1,否则将返回原矩形对象) </param> 6 /// <param name="mindistance">如果矩形实例中xy的最大差值小于这个值,定位将采用这个默认的xy差值进行缩放,默认值为60.0</param> 7 /// <returns></returns> 8 public static Geometry GetZoomToGeometry(Envelope enveLope, double dScale, double mindistance) 9 { 10 if (mindistance <= 0.0) mindistance = 60.0; 11 if (dScale <= 0.0 || dScale > 1.0) return enveLope; 12 double widthX = enveLope.XMax - enveLope.XMin, hightY = enveLope.YMax - enveLope.YMin; 13 if (widthX < mindistance && hightY < mindistance) 14 { 15 MapPoint minPoint = new MapPoint(enveLope.GetCenter().X - mindistance, enveLope.GetCenter().Y - mindistance); 16 MapPoint maxPoint = new MapPoint(enveLope.GetCenter().X + mindistance, enveLope.GetCenter().Y + mindistance); 17 return new Envelope(minPoint, maxPoint); 18 } 19 else 20 { 21 double xVaue = (widthX / 2.0) / dScale; double yValue = (hightY / 2.0) /dScale; 22 MapPoint minPoint = new MapPoint(enveLope.GetCenter().X - xVaue, enveLope.GetCenter().Y - yValue); 23 MapPoint maxPoint = new MapPoint(enveLope.GetCenter().X + xVaue, enveLope.GetCenter().Y + yValue); 24 return new Envelope(minPoint, maxPoint); 25 } 26 }