在Arcgis Engine中使用Arcgis Server的切片地图的一点心得

 

最近写一个基于Arcgis Engine(AE)的程序,因为显示的地物特别多且复杂,并且有很多数据需要不停的刷新闪烁,所以打算使用动态显示加缓存来写,但不知道为什么,每次程序重新启动时都无法连接到原来的缓存目录.代码如下:

        private void SetDynamicDisplay()
        {
            IDynamicMap iDMap = m_mapControl.Map as IDynamicMap;

            if (m_bDynamicDisplay == true)
            {
                iDMap.DynamicMapEnabled = false;
                m_bDynamicDisplay = false;

                return;
            }

            iDMap.DynamicMapEnabled = true;
            iDMap.DynamicDrawRate = 15;
            m_bDynamicDisplay = true;

            string strStartupPath = Application.StartupPath;

            string strCachePath = strStartupPath + @"\Cache";
            bool bFirstrun = !System.IO.Directory.Exists(strCachePath);
            if (bFirstrun)
            {
                System.IO.Directory.CreateDirectory(strCachePath);
            }
            IDynamicCacheLayerManager pDynamicCacheLayerManager = new DynamicCacheLayerManagerClass();
            for (int iIndex = 0; iIndex < m_mapControl.LayerCount; iIndex++)
            {
                ILayer layer = m_mapControl.get_Layer(iIndex);
                if (!(layer is IDynamicLayer))
                {
                    layer.Cached = true;
                    pDynamicCacheLayerManager.Init(m_mapControl.Map, layer);
                    bool bCacheable = pDynamicCacheLayerManager.Cacheable;

                    if (bCacheable)
                    {
                        string sCacheFolderName = pDynamicCacheLayerManager.FolderName;
                        if (bFirstrun)
                        {
                            pDynamicCacheLayerManager.FolderPath = strCachePath;
                            pDynamicCacheLayerManager.DetailsThreshold = 100;
                            pDynamicCacheLayerManager.Format = "PNG";
                            if (layer is ICompositeLayer) pDynamicCacheLayerManager.ConsolidatedGroupLayer = true;
                            pDynamicCacheLayerManager.StrictOnDemandMode = false;
                        }
                        if (!bFirstrun)
                        {
                            pDynamicCacheLayerManager.Connect(strCachePath, sCacheFolderName);
                        }
                    }
                }
            }
        }

搜了好几天,又在ESRI中国的论坛发贴询问原因,却始终得不到答案.如果有高手看到这里,请指教.

解决不了上面的问题,于是转而向ARCGIS SERVER求解.因为Arcgis Server自带了切片的功能,而这正是动态显示的原型.

在Arcgis Server中将地图发布为服务后,设置切片.然后在程序加载的时候,连接到AS的地图服务,并加入到当前的地图控件中.试了一下,显示效果相当不错,但是有一点问题,就是当比例改变的时候,无法控制地图控件载入哪一个切片层(Tiles).这样经常会造成当前的比例下显示的地图很小,无法看清.类似于将一张很大的图片以50%的比例显示出来.即使在MapControl的AfterExtentChanged事件中控制地图的比例与想要显示的切片比例一样也不行.经过多次的尝试,终于发现,AE在下载AS的地图的时候,是以当前地图的比例向下靠拢AS的比例,也就是说,当当前MAPCONTROL的比例为200,000时,AS的切片有220,000和100,000两层,它会优先选择100,000的切片.于是我修改了AfterExtentChanged事件中的代码,控制MAPCONTROL的比例稍大于我想要显示的切片比例,也就是说,当我想显示220,000的切片时,把MapControl.MapScale设置为230,000,这样,即使拉出来的切片被稍微拉伸了一点,显示效果也远远好于它自己选择.

代码如下:

        private void ExtentUpdated()
        {
            double dActiveMapScale = m_mapControl.MapScale;

            if (dActiveMapScale == m_dPrivScale)
                return;

            double dDangQian = 0.0f;
            double dShangYiJi = 0.0f;

            double dShangYiJiCha = 0.0f;
            double dXiaYiJiCha = 0.0f;

            for (int i = 0; i < dLod.Length; i++)
            {
                dDangQian = dLod[i];
                if (dActiveMapScale <= dDangQian)
                {
                    dXiaYiJiCha = dDangQian - dActiveMapScale;
                    if ((dShangYiJiCha > 0 && dXiaYiJiCha <= dShangYiJiCha) || dShangYiJiCha == 0)
                    {
                        m_dPrivScale = dDangQian;
                        m_mapControl.MapScale = dDangQian;
                    }
                    else if (dXiaYiJiCha > dShangYiJiCha)
                    {
                        m_dPrivScale = dShangYiJi;
                        m_mapControl.MapScale = dShangYiJi;
                    }
                    cboRate.Text = string.Format("1:{0:n}", m_mapControl.MapScale);
                    return;
                }
                else
                {
                    dShangYiJiCha = dActiveMapScale - dDangQian;
                    dShangYiJi = dDangQian;
                }
            }
        }

这段代码可以实现当MapScale改变的时候,选择最合适(与当前的MapScale最接近)的一个比例.其中dLod是一个数组,其中存放希望显示的一些比例.

 

转自:http://hi.baidu.com/hizsk/blog/item/60ee80b19d0a415c09230236.html

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值