MapObject地图显示速度优化

MapObjects2.ImageLayer.OpenCatalog方法可以构建一个图片层,然后添加到AxMapObjects2.AxMap地图组件中,以实现采用位图的方式显示地图背景,达到地图更加美观和信息全的效果。

 

在比例尺相对较大时,如果把当前比例尺所有瓦片地图全部一次性加载到图层中时,速度就成了一个头疼的问题

 

在这里,采用加载当前窗口大小区域的图片来达到速度的优化

 

代码如下

 

/// <summary> /// 添加图片层 /// </summary> /// <param name="tableName"></param> /// <param name="layerName"></param> public void AddImageLayer(string tableName, string layerName) { double left = _map.Extent.Left; double rigth = _map.Extent.Right; double top = _map.Extent.Top; double bottom = _map.Extent.Bottom; double width = 0; double height = 0; MapObjects2.Point pt = _map.ToMapPoint(map_center_x, map_center_y); switch (level) { case 1: width = pic_width * res1; height = pic_height * res1; break; case 2: width = pic_width * res2; height = pic_height * res2; break; case 3: width = pic_width * res3; height = pic_height * res3; break; case 4: width = pic_width * res4; height = pic_height * res4; break; case 5: width = pic_width * res5; height = pic_height * res5; break; } string connStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Windows.Forms.Application.StartupPath + "//map.mdb;Persist Security Info=False"; ADODB.Connection conn = new ADODB.ConnectionClass(); conn.ConnectionString = connStr; conn.Open(connStr, "", "", 0); ADODB.Command comm = new ADODB.CommandClass(); comm.ActiveConnection = conn; string sql = ""; if (level != 1 && !isFromResource) { sql = "select * from " + tableName; sql += " where xmin>=" + (left - width); sql += " and xmax<=" + (rigth + width); sql += " and ymin>=" + (bottom - height); sql += " and ymax<=" + (top + height); } else { sql = "select * from " + tableName; } comm.CommandText = sql; MapObjects2.Table t = new MapObjects2.TableClass(); t.Command = comm; MapObjects2.ImageLayer imgLyr = new MapObjects2.ImageLayerClass(); try { imgLyr.OpenCatalog(t, @"", MapObjects2.ImageCatalogConstants.moOpenImagesInDisplay); } catch (Exception ex) { } _map.Layers.Add(imgLyr); } 

 

代码中res1-res5代表一个像素显示的经度,也就是各个比例尺下经度的不同表示,pic_width和pic_height表示瓦片地图的图像宽度和高度。_map就是AxMapObjects2.AxMap组件。

 

值得注意的是当第一次加载图片时,_map.Extend因为还没有根据加载的图片进行初始化,所以第一次加载时采用全部加载图片,因为当比例尺小图片的数量比较少,对速度没有影响。

 

如果有任何问题或者建议,欢迎讨论

你可能感兴趣的:(sql,优化,exception,String,Security)