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);
        }

    }

}

posted on 2008-03-04 09:16  tonyYe  阅读(801)  评论(0编辑  收藏  举报