コード例 #1
0
ファイル: MgLayer.cs プロジェクト: zhangxin8105/vgwpf
        public MgLayer cloneLayer()
        {
            global::System.IntPtr cPtr = touchvgPINVOKE.MgLayer_cloneLayer(swigCPtr);
            MgLayer ret = (cPtr == global::System.IntPtr.Zero) ? null : new MgLayer(cPtr, false);

            return(ret);
        }
コード例 #2
0
        public MgLayer getCurrentLayer()
        {
            global::System.IntPtr cPtr = touchvgPINVOKE.MgShapeDoc_getCurrentLayer(swigCPtr);
            MgLayer ret = (cPtr == global::System.IntPtr.Zero) ? null : new MgLayer(cPtr, false);

            return(ret);
        }
コード例 #3
0
ファイル: MgLayer.cs プロジェクト: zhangxin8105/vgwpf
        public static MgLayer create(MgShapeDoc doc, int index)
        {
            global::System.IntPtr cPtr = touchvgPINVOKE.MgLayer_create(MgShapeDoc.getCPtr(doc), index);
            MgLayer ret = (cPtr == global::System.IntPtr.Zero) ? null : new MgLayer(cPtr, false);

            return(ret);
        }
コード例 #4
0
 // Methods
 public HtzMaintenanceHelper(HtzMgHelper helper, MgLayer parentLayer, string uidKey)
 {
     this.ModuleAllowed = true;
     this.InitDefaultInfraTypes();
     this._helper = helper;
     this._uidKey = string.IsNullOrEmpty(uidKey) ? "UID" : uidKey;
     this._parentLayer = parentLayer;
     //if (this._helper.Configuration != null)
     //{
     //    this._config = this._helper.Configuration.GetProperties("FeatureCard");
     //    Dictionary<string, string> tmp = new Dictionary<string, string>();
     //    foreach (KeyValuePair<string, string> item in this._infraTypes)
     //    {
     //        if (!this._config.ContainsKey("ShowMaintFor" + item.Key))
     //        {
     //            this._helper.Configuration.RegisterPropertyDefinition("FeatureCard", "ShowMaintFor" + item.Key, item.Value, ConfigPropertyType.Boolean, "תחזוקה - הצגת שכבות", false);
     //        }
     //        else if ((bool)this._config["ShowMaintFor" + item.Key].Value)
     //        {
     //            tmp.Add(item.Key, item.Value);
     //        }
     //    }
     //    this._infraTypes = tmp;
     //}
     string mapPath = this._helper.Map.MapDefinition.Path;
     if (mapPath.LastIndexOf("/Maps") < 0)
     {
         this.ModuleAllowed = false;
     }
     else
     {
         this._maintenancePath = mapPath.Substring(0, mapPath.IndexOf("/Maps"));
         this._sdfResId = new MgResourceIdentifier(string.Format("Library://{0}/Maintenance/Data/Maintenance.FeatureSource", this._maintenancePath));
         this._layersResId = new List<MgResourceIdentifier>();
         if (!this._helper.ResourceService.ResourceExists(this._sdfResId))
         {
             this.CreateSdf(this._sdfResId);
         }
         foreach (KeyValuePair<string, string> item in this._infraTypes)
         {
             MgResourceIdentifier resId = new MgResourceIdentifier(string.Format("Library://{0}/Maintenance/Layers/Maint_{1}.LayerDefinition", this._maintenancePath, item.Key));
             this._layersResId.Add(resId);
             if (!this._helper.ResourceService.ResourceExists(resId))
             {
                 this.CreateLayer(resId, string.Format("InfrastructureType='{0}'", item.Value));
             }
         }
         this.AttachLayers();
         this._infraTypes.Add("none", "בחר מרשימה");
     }
 }
コード例 #5
0
 public void Activate(HtzMgHelper helper, string uidKey, int uid, MgLayer parentLayer)
 {
     if (helper != null)
     {
         this._helper = helper;
         this._uid = uid;
         this._parentLayer = parentLayer;
         this._maintHelper = new HtzMaintenanceHelper(this._helper, parentLayer, uidKey);
         this._activated = this._maintHelper.ModuleAllowed;
     }
     else
     {
         this._activated = false;
     }
 }
コード例 #6
0
        public FeatPropertyCollection(SiteUtilities siteUtilities, string layerName, string Filter)
        {
            mSiteUtilities = siteUtilities;
            mLayer = mSiteUtilities.Map.GetLayers().GetItem(layerName) as MgLayer;
            mPropertiesCollection = new Dictionary<string, FeatProperty>();
            GetPropertiesFields();
            GetAdditionalValues();
            FillValues(Filter);

            var sorted = from p in PropertiesCollection
                         orderby p.Value.Alias
                         select p;
            Dictionary<string, FeatProperty> SortedProperties = new Dictionary<string, FeatProperty>();
            foreach (var item in sorted)
            {
                SortedProperties.Add(item.Key, item.Value);
            }
            mPropertiesCollection = SortedProperties;
            mDataSet = GenerateDataSet();
        }
コード例 #7
0
ファイル: UtilityClass.cs プロジェクト: guchanghai/Cut
 //----------------------------------------------------------------------------------------
 // �� �ܣ� ��Ӳ㵽���飬������鲻���ڣ��򴴽�
 //
 // �� �ߣ�
 //
 //
 // �� �ڣ�2007.05.#
 //
 //-----------------------------------------------------------------------------------------
 public void AddLayerToGroup(MgLayer layer, string layerGroupName, string layerGroupLegendLabel, MgMap map)
 {
     // ��ȡ����
     MgLayerGroupCollection layerGroupCollection = map.GetLayerGroups();
     MgLayerGroup layerGroup = null;
     if (layerGroupCollection.Contains(layerGroupName))
     {
         layerGroup = layerGroupCollection.GetItem(layerGroupName);
     }
     else
     {
         // ���û�д��ڣ��򴴽�����
         layerGroup = new MgLayerGroup(layerGroupName);
         layerGroup.SetVisible(true);
         layerGroup.SetDisplayInLegend(true);
         layerGroup.SetLegendLabel(layerGroupLegendLabel);
         layerGroupCollection.Add(layerGroup);
     }
     layerGroup.SetDisplayInLegend(true);
     // ��Ӳ㵽����
     layer.SetGroup(layerGroup);
 }
コード例 #8
0
ファイル: MgLayer.cs プロジェクト: rhcad/vgwpf
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(MgLayer obj)
 {
     return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
 }
コード例 #9
0
    // Create a temporary Layer to display geocode results.
    public MgLayer CreateLocationMarkerLayer(MgResourceService resourceService, MgResourceIdentifier locationMarkerDataResId, String sessionId)
    {
        // Load the AddressMarker layer definition template into
        // a ASPX XML object, find the "ResourceId" element, and
        // modify it's content to reference the temporary
        // feature source.

        XmlDocument doc = new XmlDocument();
        doc.PreserveWhitespace = true;
        string path =HttpContext.Current.Request.ServerVariables["APPL_PHYSICAL_PATH"] + "Extensions/findlocation/templates/locationmarker.xml";
        doc.Load(path);
        XmlNode featureSourceNode = doc.GetElementsByTagName("ResourceId").Item(0);
        XmlNode resContent = doc.CreateTextNode(locationMarkerDataResId.ToString());
        featureSourceNode.AppendChild(resContent);

        // Get the updated layer definition from the DOM object
        // and save it to the session repository using the
        // ResourceService object.
        MemoryStream xmlStream = new MemoryStream();
        doc.Save(xmlStream);
        byte[] layerDefinition = xmlStream.ToArray();
        Encoding utf8 = Encoding.UTF8;
        String layerDefStr = new String(utf8.GetChars(layerDefinition));
        layerDefinition = new byte[layerDefStr.Length - 1];
        int byteCount = utf8.GetBytes(layerDefStr, 1, layerDefStr.Length - 1, layerDefinition, 0);
        MgByteSource byteSource = new MgByteSource(layerDefinition, layerDefinition.Length);
        byteSource.SetMimeType(MgMimeType.Xml);

        MgResourceIdentifier tempLayerResId = new MgResourceIdentifier("Session:" + sessionId + "//LocationMarker.LayerDefinition");
        //MgResourceIdentifier tempLayerResId = new MgResourceIdentifier("Library://findLocation/" + sessionId + "/LocationMarker.LayerDefinition");
        resourceService.SetResource(tempLayerResId, byteSource.GetReader(), null);

        // Create an MgLayer object based on the new layer definition
        // and return it to the caller.

        MgLayer locationLayer = new MgLayer(tempLayerResId, resourceService);
        locationLayer.SetName("LocationMarker");
        locationLayer.SetLegendLabel("LocationMarker");
        locationLayer.SetDisplayInLegend(false);
        locationLayer.SetSelectable(false);

        return locationLayer;
    }
コード例 #10
0
ファイル: HtzMgHelper.cs プロジェクト: ranyaof/Meuhedet
 public Dictionary<string, string> GetPropertiesList(MgLayer layer)
 {
     Dictionary<string, string> properties = new Dictionary<string, string>();
     MgByteReader reader = this.ResourceService.GetResourceContent(layer.LayerDefinition);
     string xmlSchema = reader.ToString();
     reader.Dispose();
     XmlDocument xmlDoc = new XmlDocument();
     xmlDoc.LoadXml(xmlSchema);
     XmlNodeList xmlProperties = xmlDoc.GetElementsByTagName("PropertyMapping");
     foreach (XmlNode node in xmlProperties)
     {
         string name = node.SelectSingleNode("Name").InnerText;
         string alias = node.SelectSingleNode("Value").InnerText;
         properties.Add(name, alias);
     }
     return properties;
 }
コード例 #11
0
ファイル: HtzMgHelper.cs プロジェクト: ranyaof/Meuhedet
 public object GetValueByForeignKey(MgLayer layer, string propertyName, object value)
 {
     string schemaName = layer.FeatureClassName.Split(new char[] { ':' })[0];
     string className = propertyName.Split(new char[] { '_' })[1];
     MgResourceIdentifier resourceId = new MgResourceIdentifier(layer.FeatureSourceId);
     if (this.FeatureService.GetClasses(resourceId, schemaName).Contains(string.Format("{0}:{1}", schemaName, className)))
     {
         MgClassDefinition classDefinition = this.FeatureService.GetClassDefinition(resourceId, schemaName, className);
         MgPropertyDefinitionCollection properties = classDefinition.GetProperties();
         MgDataPropertyDefinition keyProperty = classDefinition.GetIdentityProperties()[0] as MgDataPropertyDefinition;
         MgDataPropertyDefinition valProperty = null;
         foreach (MgDataPropertyDefinition dpd in properties.OfType<MgDataPropertyDefinition>())
         {
             if (dpd.Name.Equals("code", StringComparison.InvariantCultureIgnoreCase))
             {
                 keyProperty = dpd;
             }
             else if (dpd.DataType == 9)
             {
                 valProperty = dpd;
             }
         }
         if ((keyProperty != null) && (valProperty != null))
         {
             MgFeatureQueryOptions opt = new MgFeatureQueryOptions();
             opt.SetFilter(string.Format("{0}={1}", keyProperty.Name, value));
             MgFeatureReader reader = this.FeatureService.SelectFeatures(resourceId, string.Format("{0}:{1}", schemaName, className), opt);
             if (reader.ReadNext())
             {
                 value = this.GetFeaturePropertyValue(reader, valProperty.Name);
             }
         }
     }
     return value;
 }
コード例 #12
0
ファイル: MgLayer.cs プロジェクト: zhangxin8105/vgwpf
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(MgLayer obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
コード例 #13
0
ファイル: UtilityClass.cs プロジェクト: guchanghai/Cut
 //----------------------------------------------------------------------------------------
 // �� �ܣ� ��Ӳ㵽���飬������鲻���ڣ��򴴽�
 //
 // �� �ߣ�
 //
 //
 // �� �ڣ�2007.05.#
 //
 //-----------------------------------------------------------------------------------------
 public MgLayer CreateLayerResource(MgResourceIdentifier layerResourceID, MgResourceService resourceService, string layerName, string layerLegendLabel, MgMap map)
 {
     MgLayer newLayer = new MgLayer(layerResourceID, resourceService);
     //  �����㲢��Ӽҵ���ͼ��
     newLayer.SetName(layerName);
     newLayer.SetVisible(true);
     newLayer.SetLegendLabel(layerLegendLabel);
     newLayer.SetDisplayInLegend(true);
     MgLayerCollection layerCollection = map.GetLayers();
     if (!layerCollection.Contains(layerName))
     {
         // ��Insert��������㣬�´����IJ�λ�ڻ��ƴ�������
         layerCollection.Insert(0, newLayer);
     }
     newLayer.SetDisplayInLegend(true);
     return newLayer;
 }
コード例 #14
0
ファイル: HtzMgHelper.cs プロジェクト: ranyaof/Meuhedet
 public string GetDefaultGeometryPropertyName(MgLayer layer)
 {
     return this.FeatureService.GetClassDefinition(new MgResourceIdentifier(layer.FeatureSourceId), layer.FeatureClassName.Split(new char[] { ':' })[0], layer.FeatureClassName.Split(new char[] { ':' })[1]).GetDefaultGeometryPropertyName();
 }
コード例 #15
0
 private void AttachLayers()
 {
     MgLayerCollection layers = this._helper.Map.GetLayers();
     for (int i = this._layersResId.Count - 1; i >= 0; i--)
     {
         if (!layers.Contains(this._layersResId[i].Name))
         {
             string legendLable = this._infraTypes[this._layersResId[i].GetName().Split(new char[] { '_' })[1]];
             MgLayer layer = new MgLayer(this._layersResId[i], this._helper.ResourceService);
             layer.SetName(this._layersResId[i].Name);
             layer.SetLegendLabel(legendLable);
             layer.SetDisplayInLegend(false);
             layer.SetSelectable(false);
             this._helper.Map.GetLayers().Insert(0, layer);
             this._helper.Map.Save(this._helper.ResourceService);
             this._newLayerAttached = true;
         }
     }
     this.ModuleAllowed = true;
     this.UpdateMap();
 }
コード例 #16
0
ファイル: MarkupManager.cs プロジェクト: ranyaof/Meuhedet
        public void OpenMarkup()
        {
            MgResourceService resourceService = (MgResourceService)this.site.CreateService(MgServiceType.ResourceService);

            MgMap map = new MgMap();
            map.Open(resourceService, GetParameter(this.args, "MAPNAME"));

            // Create the Layer Groups

            MgLayerGroup markupGroup = null;
            MgLayerGroupCollection layerGroups = map.GetLayerGroups();
            if (layerGroups.Contains("_Markup"))
            {
                markupGroup = layerGroups.GetItem("_Markup");
            }
            else
            {
                markupGroup = new MgLayerGroup("_Markup");
                markupGroup.SetVisible(true);
                markupGroup.SetLegendLabel("Markup");
                markupGroup.SetDisplayInLegend(false);
                layerGroups.Add(markupGroup);
            }

            // Add the Markup Layer

            MgResourceIdentifier markupLayerResId = new MgResourceIdentifier(GetParameter(this.args, "MARKUPLAYER"));
            MgLayer markupLayer = new MgLayer(markupLayerResId, resourceService);
            markupLayer.SetName("_" + markupLayerResId.GetName());
            markupLayer.SetLegendLabel(markupLayerResId.GetName());
            markupLayer.SetDisplayInLegend(false);
            markupLayer.SetSelectable(true);
            markupLayer.SetGroup(markupGroup);
            map.GetLayers().Insert(0, markupLayer);

            map.Save(resourceService);
        }
コード例 #17
0
ファイル: HtzMgHelper.cs プロジェクト: ranyaof/Meuhedet
 public bool PropertyIsString(MgLayer layer, string propertyName)
 {
     MgDataPropertyDefinition streetCode1Property = this.FeatureService.GetClassDefinition(new MgResourceIdentifier(layer.FeatureSourceId), layer.FeatureClassName.Split(new char[] { ':' })[0], layer.FeatureClassName.Split(new char[] { ':' })[1]).GetProperties().GetItem(propertyName) as MgDataPropertyDefinition;
     return (streetCode1Property.DataType == 9);
 }
コード例 #18
0
ファイル: GService.asmx.cs プロジェクト: ranyaof/Meuhedet
        public string AddNaaz(double X, double Y, string MapSession, string mapName)
        {
            try
            {
                string dataSource = "Session:" + MapSession + "//RedlineSymbol.FeatureSource";
                string layerDef = "Session:" + MapSession + "//RedlineSymbol.LayerDefinition";
                //  MgSiteConnection site = MGMapObject.GetMgSite(MapSession);

                MgUserInformation userInfo = new MgUserInformation(MapSession);
                MgSiteConnection siteConnection = new MgSiteConnection();
                siteConnection.Open(userInfo);

                // Create a ReserviceService object and use it to open the Map
                // object from the sessions repository. Use the Map object to
                // determine if the "AddressMarker" layer is visible.

                MgResourceService resourceService = siteConnection.CreateService(MgServiceType.ResourceService) as MgResourceService;
                MgMap map = new MgMap();
                map.Open(resourceService, mapName);
              //  MgLayer locationLayer = GetLayerByName(map, "LocationMarker");

                if (siteConnection == null)
                {
                    return "יש לרענן את האתר , לחיצה על כפתור הבית בפינה השמאלית עליונה";
                }
                MgFeatureService featureSrvc = siteConnection.CreateService(2) as MgFeatureService;
                MgResourceService resourceSrvc = siteConnection.CreateService(0) as MgResourceService;
                MgResourceIdentifier dataSourceId = new MgResourceIdentifier(dataSource);
                MgResourceIdentifier layerDefId = new MgResourceIdentifier(layerDef);
                //MgMap map = MGMapObject.GetMgMap(resourceSrvc, mapName);
                MgGeometryFactory geomFactory = new MgGeometryFactory();
                MgPoint geom = geomFactory.CreatePoint(geomFactory.CreateCoordinateXY(X, Y));
                if (DataSourceExists(resourceSrvc, dataSourceId))
                {
                    resourceSrvc.DeleteResource(dataSourceId);
                }
                MgClassDefinition classDef = CreateFeatureClass("RedlineSymbol", "RedlineSymbol");
                AddFeatureClassProperty(classDef, "KEY", 7, true);
                SetGeometryProp(classDef);
                MgFeatureSchema schema = CreateSchema(classDef, "RedlineSymbolShema", "RedlineSymbolShema");
                MgCreateSdfParams parameters = new MgCreateSdfParams("ArbitraryXY", GetMapSrs(map), schema);
                featureSrvc.CreateFeatureSource(dataSourceId, parameters);
                MgLayerCollection layers = map.GetLayers();
                MgLayer layer = FindLayer(layers, layerDef);
                LayerDefinitionFactory LayerDeffactory = new LayerDefinitionFactory();
                if ((layer == null) && LayerDeffactory.CreateLayerDef("SymbolLayerDef_Cell", dataSource, "RedlineSymbol", ""))
                {
                    resourceSrvc.SetResource(layerDefId, LayerDeffactory.layerDefContent, null);
                    layer = new MgLayer(layerDefId, resourceSrvc);
                    layer.SetDisplayInLegend(false);
                    layer.SetSelectable(false);
                    layer.SetVisible(true);
                    layer.SetLegendLabel("ZoomSymbol");
                    layers.Insert(0, layer);
                }
                MgPropertyCollection featureProps = new MgPropertyCollection();
                AddPointFeature("RedlineSymbol", featureProps, geom, featureSrvc, dataSourceId);
                if (layer != null)
                {
                    layer.ForceRefresh();
                }
                map.Save(resourceSrvc);
                siteConnection = null;
                map = null;
                dataSourceId = null;
                layerDefId = null;
                featureSrvc = null;
                resourceSrvc = null;
                geomFactory = null;
                geom = null;
                classDef = null;
                schema = null;
                featureProps = null;
                parameters = null;
                layers = null;
                layer = null;
                LayerDeffactory = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
                return "Ok";
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
コード例 #19
0
        public string getPlanMapImageAsBase64String(string planID, string imageWidth, string imageHeight)
        {
            try
            {
                MgUserInformation userInfo = null;
                string mapWebTierInit = ConfigurationManager.AppSettings["MGWebTierInit"].ToString();
                MapGuideApi.MgInitializeWebTier(mapWebTierInit);

                // Om kartsession finns för applikationssession använd den annars skapa ny kartssitesession
                string mapSiteSessionID = null;
                if (Session["MapSiteSessionID"] != null)
                {
                    mapSiteSessionID = Session["MapSiteSessionID"].ToString();
                    userInfo = new MgUserInformation(mapSiteSessionID);
                }
                else
                {
                    // Initierar kartsite och kartsession
                    string mapUserName = ConfigurationManager.AppSettings["MGUserName"].ToString();
                    string mapUserPass = ConfigurationManager.AppSettings["MGUserPass"].ToString();

                    userInfo = new MgUserInformation(mapUserName, mapUserPass);
                    MgSite mapSite = new MgSite();
                    mapSite.Open(userInfo);

                    userInfo.Dispose();

                    mapSiteSessionID = mapSite.CreateSession();

                    //mapSite.Close();

                    Session["MapSiteSessionID"] = mapSiteSessionID;

                    userInfo = new MgUserInformation(mapSiteSessionID);
                }

                //bool test = resSvc.ResourceExists(mapResId);

                string mapSurfaceFactor = ConfigurationManager.AppSettings["MGMapSurfaceFactor"].ToString();
                string mapRes = ConfigurationManager.AppSettings["MGMapResource"].ToString();
                string planRes = ConfigurationManager.AppSettings["MGPlanytorResource"].ToString();
                string planClassName = ConfigurationManager.AppSettings["MGPlanytorClassName"].ToString();
                string planFilterColumn = ConfigurationManager.AppSettings["MGPlanytorFilterColumn"].ToString();
                string planGeometryColumn = ConfigurationManager.AppSettings["MGPlanytorGeometryColumn"].ToString();
                string planytorStrokeRgbaColor = ConfigurationManager.AppSettings["MGPlanytorStrokeRgbaColor"].ToString();
                string planytorForegroundRgbaColor = ConfigurationManager.AppSettings["MGPlanytorForegroundRgbaColor"].ToString();

                string mapImageSizeFromServer = ConfigurationManager.AppSettings["MGMapImageSizeFromServer"].ToString();

                // Standardvärde för storlek på kartbild, används om värde ej finns i Settings.config eller skickas in som parametrar i webbmetod
                string mapImageWidthPixel = "400";
                string mapImageHeightPixel = "300";
                // Väljer bredd och höjd på kartbild om värde ska finnas i Settings.config samt indikeras att de ska användas
                // annars förväntas värde skickas med i webbmetod
                if (mapImageSizeFromServer.ToLower() == "true")
                {
                    mapImageWidthPixel = ConfigurationManager.AppSettings["MGMapImageWidth"].ToString();
                    mapImageHeightPixel = ConfigurationManager.AppSettings["MGMapImageHeight"].ToString();
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(imageWidth) && !string.IsNullOrWhiteSpace(imageHeight))
                    {
                        mapImageWidthPixel = imageWidth;
                        mapImageHeightPixel = imageHeight;
                    }
                }

                MgSiteConnection siteConnection = new MgSiteConnection();
                siteConnection.Open(userInfo);

                MgResourceService resSvc = (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);
                MgResourceIdentifier mapResId = new MgResourceIdentifier(mapRes);
                MgFeatureService featSvc = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService);
                MgResourceIdentifier planResId = new MgResourceIdentifier(planRes);

                // Filter för planDoc efter planDoc-ID
                MgFeatureQueryOptions featureQuery = new MgFeatureQueryOptions();
                featureQuery.SetFilter(planFilterColumn + " = " + planID);

                MgFeatureReader featureReader = featSvc.SelectFeatures(planResId, planClassName, featureQuery);
                MgByteReader byteReaderGeometry = null;
                MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter();
                MgGeometryCollection geometryCollection = new MgGeometryCollection();
                int featureCount = 0;
                try
                {
                    while (featureReader.ReadNext())
                    {
                        byteReaderGeometry = featureReader.GetGeometry(planGeometryColumn);
                        MgGeometry districtGeometry = agfReaderWriter.Read(byteReaderGeometry);
                        geometryCollection.Add(districtGeometry);

                        featureCount++;
                    }
                }
                finally
                {
                    featureReader.Close();
                }

                MgGeometryFactory geometryFactory = new MgGeometryFactory();
                MgMultiGeometry multiGeometry = geometryFactory.CreateMultiGeometry(geometryCollection);

                MgMap map = new MgMap(siteConnection);

                MgEnvelope envelope = multiGeometry.Envelope();

                // Anpassar ev. punkt till komma i tal som hanteras som textsträng för kommande konvertering
                if (mapImageHeightPixel.IndexOf(".") != -1)
                {
                    mapImageHeightPixel = mapImageHeightPixel.Replace(".", ",");
                }
                if (mapImageWidthPixel.IndexOf(".") != -1)
                {
                    mapImageWidthPixel = mapImageWidthPixel.Replace(".", ",");
                }

                // Önskad bilds höjd och bredd i punkter
                double imageHeightPixel = Convert.ToDouble(mapImageHeightPixel);
                double imageWidthPixel = Convert.ToDouble(mapImageWidthPixel);

                map.DisplayDpi = 120;

                double heightEnvelopeN = envelope.Height;
                double widthEnvelopeE = envelope.Width;

                // Anpassar utbredningen på sökta planer (envelope) till bildens format för att bevara skalriktighet
                string mapFarthest = string.Empty;
                if (heightEnvelopeN > widthEnvelopeE)
                    mapFarthest = "height";
                else
                    mapFarthest = "width";

                string imageFarthest = string.Empty;
                if (imageHeightPixel > imageWidthPixel)
                    imageFarthest = "height";
                else
                    imageFarthest = "width";

                double scale = 1.0;
                const double inch = 2.54;

                // Ändring av kartans utbredning och addering av utrymme i kartans bild runt planavgränsningen
                // Map = avgränsning enligt planytan (utbredning i kartan), Image = önskad bild att skapa med kartan
                // Om: kartans höjd är längst & bildens bredd är längst
                if (mapFarthest == "height" && imageFarthest == "width")
                {
                    scale = imageWidthPixel / imageHeightPixel * inch;

                    widthEnvelopeE = imageWidthPixel / imageHeightPixel * heightEnvelopeN * scale;
                }
                // Om: kartans bredd är längst & bildens höjd är längst
                else if (mapFarthest == "width" && imageFarthest == "height")
                {
                    scale = imageHeightPixel / imageWidthPixel * inch;

                    heightEnvelopeN = imageHeightPixel / imageWidthPixel * widthEnvelopeE * scale;
                }
                // Om: kartans höjd är längst & bildens höjd är längst
                else if (mapFarthest == "height" && imageFarthest == "height")
                {
                    double compareSide = (heightEnvelopeN / (imageHeightPixel / imageWidthPixel));
                    bool isCompareSideFarthest = false;
                    if (compareSide > widthEnvelopeE)
                    {
                        isCompareSideFarthest = true;
                    }
                    else
                    {
                        isCompareSideFarthest = false;
                    }

                    scale = imageHeightPixel / imageWidthPixel * inch;

                    if (isCompareSideFarthest)
                    {
                        widthEnvelopeE = heightEnvelopeN / (imageHeightPixel / imageWidthPixel) * scale;
                    }
                    else
                    {
                        heightEnvelopeN = (imageHeightPixel / imageWidthPixel) * widthEnvelopeE * scale;
                    }
                }
                // Om(annars): kartans bredd är längst & bildens bredd är längst
                else
                {
                    double compareSide = (widthEnvelopeE / (imageWidthPixel / imageHeightPixel));
                    bool isCompareSideFarthest = false;
                    if (compareSide > heightEnvelopeN)
                    {
                        isCompareSideFarthest = true;
                    }
                    else
                    {
                        isCompareSideFarthest = false;
                    }

                    scale = imageWidthPixel / imageHeightPixel * inch;

                    if (isCompareSideFarthest)
                    {
                        heightEnvelopeN = widthEnvelopeE / (imageWidthPixel / imageHeightPixel) * scale;
                    }
                    else
                    {
                        widthEnvelopeE = heightEnvelopeN * (imageWidthPixel / imageHeightPixel) * scale;
                    }
                }

                double mapSurfaceFactorDbl = Convert.ToDouble(mapSurfaceFactor.Replace('.', ','));
                double newHeightN = heightEnvelopeN * mapSurfaceFactorDbl;
                double newWidthE = widthEnvelopeE * mapSurfaceFactorDbl;
                MgCoordinate lowerLeft = envelope.LowerLeftCoordinate;
                MgCoordinate upperRight = envelope.UpperRightCoordinate;
                envelope = new MgEnvelope(lowerLeft.X - (newWidthE - widthEnvelopeE) / 2,
                                          lowerLeft.Y - (newHeightN - heightEnvelopeN) / 2,
                                          upperRight.X + (newWidthE - widthEnvelopeE) / 2,
                                          upperRight.Y + (newHeightN - heightEnvelopeN) / 2);

                map.Create(resSvc, mapResId, mapResId.Name);

                // Skapa lagerdefinition i XML
                DefineAreaLayer areaLayer = new DefineAreaLayer();
                areaLayer.FeatureName = planClassName;
                areaLayer.FeatureSourceName = planRes;
                areaLayer.GeometryColumnName = planGeometryColumn;
                areaLayer.Filter = planFilterColumn + " = " + planID;

                LayerScaleRangeCollection lsrCollection = new LayerScaleRangeCollection();

                LayerScaleRange lsr = new LayerScaleRange();
                // MinScale applikations-default till 0 (inklusive) om utelämnat, MaxScale applikations-default till kartans maxskala (exklusive) om utelämnat
                //lsr.MinScale = "0";
                //lsr.MaxScale = "100000000";
                AreaTypeStyle ats = new AreaTypeStyle();

                AreaRuleCollection arCollection = new AreaRuleCollection();

                AreaRule ar = new AreaRule();
                //ar.Filter = planFilterColumn + " = " + planID;
                ar.LegendLabel = "Plan" + planID;
                AreaSymbolization2D symb2D = new AreaSymbolization2D();
                Fill fill = new Fill();
                fill.BackgroundColor = "FFFF0000";
                fill.FillPattern = "Solid";
                fill.ForegroundColor = convertRgbsToHexColor(planytorForegroundRgbaColor);
                Stroke stroke = new Stroke();
                stroke.Color = convertRgbsToHexColor(planytorStrokeRgbaColor);
                stroke.LineStyle = "Solid";
                stroke.Thickness = "1";
                stroke.Unit = "Points";
                symb2D.Fill = fill;
                symb2D.Stroke = stroke;
                ar.Symbolization2D = symb2D;
                arCollection.Add(ar);

                ats.AreaRules = arCollection;

                lsr.AreaTypeStyle = ats;

                lsrCollection.Add(lsr);

                areaLayer.LayerScaleRanges = lsrCollection;

                XmlDocument xmlFile = new XmlDocument();
                //XDocument xmlFile = new XDocument();
                // om returnerande av xml-dokument
                //xmlFile = areaLayer.CreateLayerDefinitionAsXmlDocument();
                // om returnerande av xml-sträng
                xmlFile.LoadXml(areaLayer.CreateLayerDefinitionAsXmlString());
                //xmlFile = areaLayer.CreateLayerDefinitionAsXDocument();
                //xmlFile.Save(Server.MapPath(this.Context.Request.ApplicationPath) + "XmlTestLayerDefinition.xml");

                using (MemoryStream msNewPlanLayer = new MemoryStream())
                {
                    xmlFile.Save(msNewPlanLayer);
                    msNewPlanLayer.Position = 0L;
                    //Note we do this to ensure our XML content is free of any BOM characters
                    byte[] layerDefinition = msNewPlanLayer.ToArray();
                    Encoding utf8 = Encoding.UTF8;
                    String layerDefStr = new String(utf8.GetChars(layerDefinition));
                    layerDefinition = new byte[layerDefStr.Length - 1];
                    int byteCount = utf8.GetBytes(layerDefStr, 1, layerDefStr.Length - 1, layerDefinition, 0);
                    // Save the new layer definition to the session repository
                    MgByteSource byteSource = new MgByteSource(layerDefinition, layerDefinition.Length);
                    MgResourceIdentifier layerResourceID = new MgResourceIdentifier("Session:" + mapSiteSessionID + "//" + "planytor" + ".LayerDefinition"); //"SearchedPlan" + planID + ".LayerDefinition");
                    resSvc.SetResource(layerResourceID, byteSource.GetReader(), null);

                    MgLayer newPlanLayer = new MgLayer(layerResourceID, resSvc);
                    newPlanLayer.SetName("Sökta planer");
                    newPlanLayer.SetVisible(true);
                    newPlanLayer.SetLegendLabel("Sökta planer");
                    newPlanLayer.SetDisplayInLegend(true);
                    MgLayerCollection layerCollection = map.GetLayers();
                    if (!layerCollection.Contains(newPlanLayer))
                    {
                        // Insert the new layer at position 0 so it is at the top
                        // of the drawing order
                        layerCollection.Insert(0, newPlanLayer);
                    }
                    else
                    {
                        layerCollection.Remove(newPlanLayer);
                        layerCollection.Insert(0, newPlanLayer);
                    }

                    map.Save();
                }

                double mapScale = map.ViewScale;

                // XML-dokument till ren text
                //StringWriter stringWriter = new StringWriter();
                //XmlWriter xmlTextWriter = XmlWriter.Create(stringWriter);
                //xmlFile.WriteTo(xmlTextWriter);
                //xmlTextWriter.Flush();
                string xmlSelection = string.Empty;
                //string xmlSelection = stringWriter.GetStringBuilder().ToString();

                MgSelection selection = null;
                if (!string.IsNullOrEmpty(xmlSelection))
                {
                    selection = new MgSelection(map, xmlSelection);
                }
                else
                {
                    selection = new MgSelection(map);
                }

                MgColor color = new MgColor("255,255,255");

                // Skapar bild av kartan
                MgRenderingService renderingService = (MgRenderingService)siteConnection.CreateService(MgServiceType.RenderingService);
                //MgByteReader byteReader = renderingService.RenderMap(map, selection, "PNG");
                MgByteReader byteReader = renderingService.RenderMap(map, selection, envelope, Convert.ToInt32(imageWidthPixel), Convert.ToInt32(imageHeightPixel), color, "PNG");
                MemoryStream ms = new MemoryStream();
                byte[] byteBuffer = new byte[1024];
                int numBytes = byteReader.Read(byteBuffer, 1024);
                while (numBytes > 0)
                {
                    ms.Write(byteBuffer, 0, numBytes);
                    numBytes = byteReader.Read(byteBuffer, 1024);
                }
                byte[] mapImageByte = ms.ToArray();
                string imageBase64String = Convert.ToBase64String(mapImageByte);

                map.Dispose();
                siteConnection.Dispose();

                DataTable dtResult = new DataTable();
                DataColumn dc = new DataColumn("MAPIMAGEBASE64");
                dtResult.Columns.Add(dc);
                dc = new DataColumn("WIDTH");
                dtResult.Columns.Add(dc);
                dc = new DataColumn("HEIGHT");
                dtResult.Columns.Add(dc);
                DataRow dr = dtResult.NewRow();
                dr["MAPIMAGEBASE64"] = imageBase64String;
                dr["WIDTH"] = imageWidthPixel;
                dr["HEIGHT"] = imageHeightPixel;
                dtResult.Rows.Add(dr);

                //TODO: MAP: Vad kan returneras, base64 eller länk där bild temporärt genereras på server
                //JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
                //return jsonSerializer.Serialize(imageBase64String);

                return getDatatableAsJson(dtResult);
            }
            catch (System.Exception ex)
            {
                UtilityException.LogException(ex, "Webbmetod : getPlanMapImageAsBase64String", true);
                return null;
            }
        }
コード例 #20
0
    public bool ShowSpatialFilter()
    {
        bool result = true;
        MgUserInformation userInfo = new MgUserInformation(Request["SESSION"]);
        MgSiteConnection siteConnection = new MgSiteConnection();
        siteConnection.Open(userInfo);

        MgResourceIdentifier sdfResId = new MgResourceIdentifier("Session:" + Request["SESSION"] + "//Filter.FeatureSource");

        MgResourceService resourceService = siteConnection.CreateService(MgServiceType.ResourceService) as MgResourceService;
        MgFeatureService featureService = siteConnection.CreateService(MgServiceType.FeatureService) as MgFeatureService;

        MgFeatureCommandCollection updateCommands = new MgFeatureCommandCollection();

        MgMap map = new MgMap();
        map.Open(resourceService, Request["MAPNAME"]);

        MgLayer layer = null;
        MgLayerCollection layers = map.GetLayers();
        if (layers.Contains("_QuerySpatialFilter"))
        {
            layer = (MgLayer)layers.GetItem("_QuerySpatialFilter");
            //updateCommands.Add(new MgDeleteFeatures("Filter", "ID > 0"));
        }
        else
        {
            // Create the Feature Source (SDF)

            MgFeatureSchema sdfSchema = this.CreateFilterSchema();
            MgCreateSdfParams sdfParams = new MgCreateSdfParams("MAPCS", map.GetMapSRS(), sdfSchema);
            featureService.CreateFeatureSource(sdfResId, sdfParams);

            // Create the Layer

            MgResourceIdentifier layerResId = new MgResourceIdentifier("Session:" + Request["SESSION"] + "//Filter.LayerDefinition");
            String layerDefinition = File.ReadAllText(GetQueryXmlTemplatePath());
            layerDefinition = layerDefinition.Replace("%s", sdfResId.ToString());

            MgByteReader reader = new MgByteReader(layerDefinition, "text/xml");
            resourceService.SetResource(layerResId, reader, null);

            layer = new MgLayer(layerResId, resourceService);

            layer.SetName("_QuerySpatialFilter");
            layer.SetLegendLabel("תחום זמני");
            layer.SetDisplayInLegend(true);
            layer.SetSelectable(true);
            layer.ForceRefresh();
            layer.NeedsRefresh();

            layers.Insert(0, layer);
        }

        // Make the layer visible

        layer.SetVisible(true);
        map.Save(resourceService);

        // Add the geometry to the filter feature source
        MgPolygon polygon = this.CreatePolygonFromGeomText(Request["GEOMTEXT"].ToString());
        MgAgfReaderWriter agfWriter = new MgAgfReaderWriter();
        MgByteReader byteReader = agfWriter.Write(polygon);

        MgPropertyCollection propertyValues = new MgPropertyCollection();
        propertyValues.Add(new MgGeometryProperty("Geometry", byteReader));
        try
        {
            updateCommands.Add(new MgInsertFeatures("Filter", propertyValues));

            featureService.UpdateFeatures(sdfResId, updateCommands, false);
        }
        catch { }

        return result;
    }
コード例 #21
0
ファイル: UtilityClass.cs プロジェクト: guchanghai/Cut
    //---------------------------------------------------------------------------------------
    //
    //        ���ܣ�����Ԥ�����XML������
    //
    //         ���ߣ�
    //
    //         ���ڣ� 2007.5.23
    //        
    //         �޸���ʷ����
    //        
    //---------------------------------------------------------------------------------------
    private MgLayer createTempParcelLayer(MgResourceService resService, MgResourceIdentifier resId, string sessionId)
    {
        MgLayer tempParcelLayer = null;

        // ����XML�ĵ�
        XmlDocument doc = new XmlDocument();
        doc.PreserveWhitespace = false;
        doc.Load(@"C:\inetpub\wwwroot\MapguideTutorial\CH05-2\tempParcels.xml");
        // ��XML�ĵ��е�ResourceId���滻Ϊ�������ԴID���˴�ӦΪ�������ĻỰ�ִ��е���ʱ��ԴID
        XmlNode featureSourceNode = doc.GetElementsByTagName("ResourceId").Item(0);
        XmlNode resContent = doc.CreateTextNode(resId.ToString());
        featureSourceNode.AppendChild(resContent);
        // ����XML
        MemoryStream xmlStream = new MemoryStream();
        doc.Save(xmlStream);
        byte[] layerDef = xmlStream.ToArray();
        Encoding utf8 = Encoding.UTF8;
        string layerDefStr = new string(utf8.GetChars(layerDef));
        layerDef = new byte[layerDefStr.Length - 1];
        int byteCount = utf8.GetBytes(layerDefStr, 1, layerDefStr.Length - 1, layerDef, 0);

        MgByteSource byteSource = new MgByteSource(layerDef, layerDef.Length);
        byteSource.SetMimeType(MgMimeType.Xml);
        // ������Դ
        MgResourceIdentifier tempParcelLayerId = new MgResourceIdentifier("Session:" + sessionId + "//TempParcel.LayerDefinition");
        resService.SetResource(tempParcelLayerId, byteSource.GetReader(), null);
        //������ʱ��
        tempParcelLayer = new MgLayer(tempParcelLayerId, resService);
        tempParcelLayer.SetName("TempParcels");
        tempParcelLayer.SetLegendLabel("New Parcels");
        tempParcelLayer.SetDisplayInLegend(true);
        tempParcelLayer.SetSelectable(false);

        return tempParcelLayer;
    }
コード例 #22
0
        LayerLegendInfo GetLayerContent(MgResourceService resourceService, MgLayer layer, double scale)
        {
            bool insertInToList = false;

            string[] styleTypes = new[] { "PointTypeStyle", "LineTypeStyle", "AreaTypeStyle", "CompositeTypeStyle" };
            string[] ruleNames = new[] { "PointRule", "LineRule", "AreaRule", "CompositeRule" };

            LayerLegendInfo layerInfo = new LayerLegendInfo { Name = layer.Name, Label = layer.LegendLabel, Path = layer.LayerDefinition.ToString() };

            string xmlContent = resourceService.GetResourceContent(layer.LayerDefinition).ToString();

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xmlContent);

            XmlNodeList scaleNodes = doc.GetElementsByTagName("VectorScaleRange");
            foreach (XmlElement scaleRange in scaleNodes)
            {
                double minScale = 0.0;
                double maxScale = 1000000000000.0;

                XmlNode minScaleNode = scaleRange.SelectSingleNode("MinScale");
                XmlNode maxScaleNode = scaleRange.SelectSingleNode("MaxScale");
                if (minScaleNode != null) minScale =Convert.ToDouble(minScaleNode.InnerText);
                if (maxScaleNode != null) maxScale = Convert.ToDouble(maxScaleNode.InnerText);
                if (scale > minScale && scale < maxScale)
                {

                    for (int stylesIndex = 0; stylesIndex < styleTypes.Length; stylesIndex++)
                    {
                        foreach (XmlElement element in (scaleRange).GetElementsByTagName(styleTypes[stylesIndex]))
                        {
                            int legendIndex = -1;
                            foreach (XmlElement rule in element.GetElementsByTagName(ruleNames[stylesIndex]))
                            {
                                string legendLabel = rule.SelectSingleNode("LegendLabel").InnerText;
                                if (string.IsNullOrEmpty(legendLabel)) continue;
                                LayerLegendInfo info = new LayerLegendInfo { Label = HttpUtility.HtmlAttributeEncode(legendLabel), Path = layerInfo.Path, GeomType = stylesIndex + 1, LegendIndex = ++legendIndex };
                                layerInfo.Children.Add(info);
                            }
                            insertInToList = true;
                        }
                    }
                    break;
                }
            }
            return insertInToList ? layerInfo : null;
            //return layerInfo;
        }
コード例 #23
0
    MgGeometry MultiGeometryFromSelection(MgFeatureService featureSrvc, MgMap map, String selText)
    {
        MgSelection sel = new MgSelection(map);

        sel.FromXml(selText);
        MgReadOnlyLayerCollection selLayers = sel.GetLayers();

        if (selLayers == null)
        {
            return(null);
        }
        MgGeometryCollection geomColl = new MgGeometryCollection();
        MgAgfReaderWriter    agfRW    = new MgAgfReaderWriter();
        bool polyOnly = true;

        for (int i = 0; i < selLayers.GetCount(); i++)
        {
            MgLayer layer = (MgLayer)selLayers.GetItem(i);

            // TODO:  How to get selectionSize?
            //int selectionSize = 20;
            string filter = sel.GenerateFilter(layer, layer.GetFeatureClassName());

            if (filter == "")
            {
                continue;
            }

            MgFeatureQueryOptions query = new MgFeatureQueryOptions();
            query.SetFilter(filter);
            MgResourceIdentifier featureSource = new MgResourceIdentifier(layer.GetFeatureSourceId());
            MgFeatureReader      features      = featureSrvc.SelectFeatures(featureSource, layer.GetFeatureClassName(), query);

            if (features != null)
            {
                MgClassDefinition classDef     = features.GetClassDefinition();
                String            geomPropName = classDef.GetDefaultGeometryPropertyName();
                int j = 0;
                //bool isPoly = true;
                while (features.ReadNext())
                {
                    MgByteReader geomReader = features.GetGeometry(geomPropName);
                    MgGeometry   geom       = agfRW.Read(geomReader);
                    if (j++ == 0)
                    {
                        int type = geom.GetGeometryType();
                        if (type == MgGeometryType.MultiPolygon || type == MgGeometryType.CurvePolygon || type == MgGeometryType.MultiCurvePolygon)
                        {
                            //isPoly = false;
                            polyOnly = false;
                        }
                        else if (type != MgGeometryType.Polygon)
                        {
                            break;
                        }
                    }
                    geomColl.Add(geom);
                }
                features.Close();
                features.Dispose();
            }
        }

        if (geomColl.GetCount() == 0)
        {
            return(null);
        }

        MgGeometryFactory gf = new MgGeometryFactory();

        if (polyOnly)
        {
            MgPolygonCollection polyColl = new MgPolygonCollection();
            for (int j = 0; j < geomColl.GetCount(); j++)
            {
                polyColl.Add((MgPolygon)geomColl.GetItem(j));
            }
            return(gf.CreateMultiPolygon(polyColl));
        }
        else
        {
            return(gf.CreateMultiGeometry(geomColl));
        }
    }