本文主要是介绍SuperMap iObjects .NET 实现聚合显示详解,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
随着百度、谷歌等在线地图中出现点聚合显示,即用少量的点或图标来表示地图中的所有点,让地图显示更清晰明朗。有人会问了,SuperMap iObjects .NET可以实现这一可视化吗?回答当然是可以的,下面就跟着我一步一步的来看看具体是如何实现的吧。
一:前期准备:
数据准备:首先需要准备需要聚合的点数据,以及地图底图:
确定聚合算法:本聚合显示采用的是基于网格算法。
二:实现步骤
1、为了方便存放在程序过程中生成的一些显示数据,所以新建了一个内存数据源"mdata"来存放数据;
DatasourceConnectionInfo datasourceConnnectionInfo = new DatasourceConnectionInfo();
datasourceConnnectionInfo.EngineType = EngineType.UDB;
datasourceConnnectionInfo.Server = ":memory:"
datasourceConnnectionInfo.Alias = "mdata";
2、由于本次使用的是基于网格的算法,所以首先要根据地图窗口的可视范围新建一个地图网格数据,将生成的网格数据添加到新建的数据源中"mapgrid";
生成代码如下:
DatasetVector datasetvectorgrid = workspace.Datasources["mdata"].Datasets["mapgrid"] as DatasetVector;Recordset recordset = datasetvectorgrid.GetRecordset(false, CursorType.Dynamic);Rectangle2D maprectangle = new Rectangle2D();maprectangle = mapcontrol.Map.ViewBounds;double distancex = (maprectangle.Right - maprectangle.Left) / 10;double distancey = (maprectangle.Top - maprectangle.Bottom) / 9;Point2D point2d = new Point2D();rectangles = new Rectangle2D[100];Array .Clear (rectangles ,0, rectangles .Length );int count = 0;For (int j = 0; j <= 8; j++){for (int i = 0; i <= 9; i++){point2d.X = maprectangle.Left + distancex * i;point2d.Y = maprectangle.Bottom + distancey * j;Rectangle2D rectangle = new Rectangle2D(point2d, distancex, distancey);rectangles[count] = rectangle;count++;GeoRectangle georectangle = new GeoRectangle(rectangle, 0);GeoStyle style = Setgeostyle();georectangle.Style = style;recordset.AddNew(georectangle);recordset.Update();}}
3、计算每一个网格里面有多少个点,并且将将聚合点聚合在当前网格内点对象的中心,将聚合点对象添加到内存数据源“point”,将聚合点数以字段的方式存储,对于在网格线上的点则做优先选择处理,
实现代码如下:
//检查是否包含;private void IsCanContain(){//聚合点数据集;DatasetVector datasetvectorgrid = workspace.Datasources["mdata"].Datasets["point"] as DatasetVector;Recordset recordsetpoint = datasetvectorgrid.GetRecordset(false, CursorType.Dynamic);//原始点数据集;DatasetVector datasetvectorpoint = workspace.Datasources[0].Datasets["POIP"] as DatasetVector; Recordset recordset = datasetvectorpoint.GetRecordset(false, CursorType.Static);//临时单个聚合对象点DatasetVector datasetvetortpoint = workspace .Datasources ["mdata"].Datasets ["tpoint"] as DatasetVector ;recordsetpoint.DeleteAll();Point2D[] point2ds = new Point2D[recordset.RecordCount];int pointitem = 0;for (int i = 0; i < 100; i++){int count = 0;Rectangle2D rectangle = rectangles[i]; recordset.MoveFirst();Recordset rectangleitemrecordset = datasetvetortpoint.GetRecordset(false, CursorType.Dynamic);for (int j = 0; j < recordset.RecordCount; j++){Geometry geometry = recordset.GetGeometry(); GeoPoint geopoint = geometry as GeoPoint ;Point2D point2d = new Point2D (geopoint .X ,geopoint .Y );if (rectangle .Contains (point2d )){if (Array.IndexOf(point2ds, point2d) == -1){count++;point2ds[pointitem] = point2d;pointitem++;GeoPoint itemgeopoint = new GeoPoint(point2d);rectangleitemrecordset.AddNew(itemgeopoint);rectangleitemrecordset.Update();}}recordset.MoveNext();}
4、聚合完成后则进行显示聚合点,对上一步骤中生成的聚合点数据集point做分段专题图,进行2—20;20—50;50+进行分段显示不同图标的聚合点,并且将每个聚合点的聚合点数添加到跟中图层进行显示,效果如下:
5、实现选中聚合点的时候将地图中聚合点所表示的分散点显示出来,并且聚合点和聚合点处标签隐藏。实现思路如下:获取选中聚合点处的网格,通过循环判断当前聚合点的分散点有哪些,将分散点的ID存储在数组中,通过图层的过滤显示将分散点显示出来,通过以上步骤,我们的聚合显示就完成啦,效果图如下:
这篇关于SuperMap iObjects .NET 实现聚合显示详解的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!