MapGuide公共静态方法

using  System;
using  System.Data;
using  System.Configuration;
using  System.Web;
using  System.Web.Security;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  System.Web.UI.WebControls.WebParts;
using  System.Web.UI.HtmlControls;
using  OSGeo.MapGuide;
using  System.Collections.Specialized;

/**/ /// <summary>
/// Shared 的摘要说明
/// </summary>

public   class  MapGuideShared
{
    
/**//// <summary>
    
/// 
    
/// </summary>

    public MapGuideShared()
    
{
        
//
        
// TODO: 在此处添加构造函数逻辑
        
//
    }

    
/**//// <summary>
    
/// 
    
/// </summary>
    
/// <param name="res"></param>
    
/// <param name="commands"></param>

    public static void ReleaseReader(MgPropertyCollection res, ref MgFeatureCommandCollection commands)
    
{
        
if (res == null)
            
return;

        
for (int i = 0; i < res.GetCount(); i++)
        
{
            MgFeatureCommand cmd 
= commands.GetItem(i);
            
if (cmd is MgInsertFeatures)
            
{
                MgFeatureProperty resProp 
= (MgFeatureProperty)res.GetItem(i);
                
if (resProp != null)
                
{
                    MgFeatureReader reader 
= (MgFeatureReader)resProp.GetValue();
                    
if (reader == null)
                        
return;
                    reader.Close();
                }

            }

        }

    }

    
/**//// <summary>
    
/// 更改图层
    
/// </summary>
    
/// <param name="sCondition">条件</param>
    
/// <param name="map">地图</param>
    
/// <param name="gsLayer">图层</param>
    
/// <param name="properties">修改属性集</param>
    
/// <param name="resourceService">资源服务</param>
    
/// <param name="featureService">要素服务</param>

    public static void UpdateLayer(string sCondition, MgMap map, MgLayer gsLayer, MgPropertyCollection properties,ref MgResourceService resourceService, ref MgFeatureService featureService)
    
{
        
if (sCondition != "")
        
{
            MgResourceIdentifier layerFeatureResource 
= new MgResourceIdentifier(gsLayer.GetFeatureSourceId());
            MgFeatureCommandCollection blueMarkerCommands 
= new MgFeatureCommandCollection();
            SetResourceReadOnly(layerFeatureResource, resourceService);
            MgUpdateFeatures updateCommand 
= new MgUpdateFeatures(gsLayer.Name, properties, sCondition);
            blueMarkerCommands.Add(updateCommand);
            
//execute blue marker command    
            if (blueMarkerCommands.GetCount() >= 1)
            
{
                ReleaseReader(featureService.UpdateFeatures(layerFeatureResource, blueMarkerCommands, 
false), ref blueMarkerCommands);
            }

            gsLayer.SetVisible(
true);
            gsLayer.ForceRefresh();
            map.Save(resourceService);
        }

    }

    
/**//// <summary>
    
/// 更改图层
    
/// </summary>
    
/// <param name="sCondition">条件</param>
    
/// <param name="map">地图</param>
    
/// <param name="nLayerIndex">图层序号</param>
    
/// <param name="properties">修改属性集</param>
    
/// <param name="resourceService">资源服务</param>
    
/// <param name="featureService">要素服务</param>

    public static void UpdateLayer(string sCondition, MgMap map, int nLayerIndex, MgPropertyCollection properties, ref MgResourceService resourceService,ref  MgFeatureService featureService)
    
{
        MgLayer gsLayer 
= map.GetLayers().GetItem(nLayerIndex) as MgLayer;
        UpdateLayer(sCondition, map, gsLayer, properties, 
ref resourceService, ref featureService);
    }

    
/**//// <summary>
    
/// 更改图层
    
/// </summary>
    
/// <param name="sCondition">条件</param>
    
/// <param name="map">地图</param>
    
/// <param name="sLayerName">图层名称</param>
    
/// <param name="properties">修改属性集</param>
    
/// <param name="resourceService">资源服务</param>
    
/// <param name="featureService">要素服务</param>

    public static void UpdateLayer(string sCondition, MgMap map, string sLayerName, MgPropertyCollection properties, ref MgResourceService resourceService, ref MgFeatureService featureService)
    
{
        MgLayer gsLayer 
= map.GetLayers().GetItem(sLayerName) as MgLayer;
        UpdateLayer(sCondition, map, gsLayer, properties, 
ref resourceService, ref featureService);
    }

    
/**//// <summary>
    
/// 
    
/// </summary>
    
/// <param name="map"></param>
    
/// <param name="featureService"></param>
    
/// <param name="resourceService"></param>
    
/// <param name="page"></param>

    public static void OpenMap(ref MgMap map, ref MgFeatureService featureService, ref MgResourceService resourceService, Page page)
    
{
        MgSiteConnection siteConnection 
= new MgSiteConnection();

        NameValueCollection requestParams 
= page.Request.HttpMethod == "GET" ? page.Request.QueryString : page.Request.Form;
        String mgSessionId 
= requestParams["SESSION"];
        String mgLocale 
= requestParams["LOCALE"];
        String mgMapName 
= requestParams["MAPNAME"];
        String configPath 
= page.Request.ServerVariables["APPL_PHYSICAL_PATH"+ "..\\webconfig.ini";

        MapGuideApi.MgInitializeWebTier(configPath);
        MgUserInformation userInfo 
= new MgUserInformation(mgSessionId);
        siteConnection.Open(userInfo);

        
//创建资源服务
        resourceService = (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);
        
//创建要素服务
        featureService = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService);

        map.Open(resourceService, mgMapName);
    }

    
/**//// <summary>
    
/// 
    
/// </summary>
    
/// <param name="resoureId"></param>
    
/// <param name="resourceService"></param>

    private static void SetResourceReadOnly(MgResourceIdentifier resoureId, MgResourceService resourceService)
    
{
        String buffer;
        buffer 
= resourceService.GetResourceContent(resoureId).ToString();
        
if (buffer.Contains("<Value>TRUE</Value>"))
        
{
            buffer 
= buffer.Replace("<Value>TRUE</Value>""<Value>FALSE</Value>");
            Byte[] buf_Byte 
= System.Text.Encoding.Default.GetBytes(buffer);
            MgByteSource byteSource 
= new MgByteSource(buf_Byte, buf_Byte.Length);
            resourceService.SetResource(resoureId, byteSource.GetReader(), 
null);
        }

    }

}

转载于:https://www.cnblogs.com/tonyboy/archive/2008/03/04/1089600.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值