Exemple #1
0
 private void initMap123(IMapLayers pMapLayer, DevComponents.AdvTree.Node advN)
 {
     if (!advN.HasChildNodes && advN.Checked)
     {
         string tag = advN.Tag as string;
         if (tag == "Layer")
         {
             //获取xml节点
             if (advN.DataKey != null)
             {
                 XmlNode layerNode = advN.DataKey as XmlNode;
                 string  nodeKey   = "";
                 if ((layerNode as XmlElement).HasAttribute("NodeKey"))
                 {
                     nodeKey = layerNode.Attributes["NodeKey"].Value;
                 }
                 ILayer addLayer = ModGetData.GetLayerByNodeKey(pAxMapControl.Map, nodeKey);
                 pMapLayer.InsertLayer(addLayer, false, pMapLayer.LayerCount);
             }
         }
         else if (tag == "OutLayer")
         {
         }
         return;
     }
     else if (advN.HasChildNodes)
     {
         foreach (DevComponents.AdvTree.Node avN in advN.Nodes)
         {
             initMap(pMapLayer, avN);
         }
     }
 }
Exemple #2
0
 private void initMap(IMapLayers pMapLayer, DevComponents.AdvTree.Node advN)
 {
     if (!advN.HasChildNodes && advN.Checked)
     {
         string tag = advN.Tag as string;
         if (tag == "Layer")
         {
             //获取xml节点
             if (advN.DataKey != null)
             {
                 XmlNode layerNode = advN.DataKey as XmlNode;
                 string  nodeKey   = "";
                 if ((layerNode as XmlElement).HasAttribute("NodeKey"))
                 {
                     nodeKey = layerNode.Attributes["NodeKey"].Value;
                 }
                 ILayer addLayer = ModGetData.GetLayerByNodeKey(pAxMapControl.Map, nodeKey);
                 pMapLayer.InsertLayer(addLayer, false, pMapLayer.LayerCount);
             }
         }
         else if (tag == "OutLayer")
         {
         }
         return;
     }
     else if (advN.HasChildNodes)
     {
         List <string> lstName = getXZQMC();
         foreach (DevComponents.AdvTree.Node avN in advN.Nodes)
         {
             if (lstName.Contains(avN.Text.Split('_')[0]))
             {
                 ILayer pLyr = getLayer(avN);
                 if (pLyr != null)
                 {
                     pMapLayer.InsertLayer(pLyr, false, pMapLayer.LayerCount);
                 }
             }
         }
     }
 }
Exemple #3
0
        //由专题类型构造制图页面的地图图层-----多了个专题名称针对DOM
        public static void AddMapOfNoneXZQ(IMap inMap, string inType, string LyrNT, IMap inSourceMap)
        {
            IMapLayers inMapLayers = inMap as IMapLayers;

            if (!File.Exists(LayerXMLpath))
            {
                return;
            }
            XmlDocument cXmlDoc = new XmlDocument();

            cXmlDoc.Load(LayerXMLpath);
            if (cXmlDoc == null)
            {
                return;
            }
            XmlNode xn = cXmlDoc.SelectSingleNode("//DIR[@DIRType='" + inType + "']");

            if (xn == null)
            {
                return;
            }
            inMap.Name = xn.Attributes["NodeText"].Value;//设置地图名称
            IGroupLayer gLayer = new GroupLayerClass();

            gLayer.Name = xn.Attributes["NodeText"].Value;
            XmlNodeList xnl = xn.SelectNodes(".//Layer[@NodeText='" + LyrNT + "']");

            foreach (XmlNode pxn in xnl)
            {
                string nodeKey = pxn.Attributes["NodeKey"].Value;
                ILayer pLayer  = GetLayerByNodeKey(inSourceMap, nodeKey);
                if (pLayer != null)
                {
                    gLayer.Add(pLayer);
                }
            }
            inMapLayers.InsertLayer(gLayer as ILayer, false, inMapLayers.LayerCount);
            cXmlDoc = null;
        }
Exemple #4
0
        //区分行政区
        public static void AddMapOfByXZQ(IMap inMap, string inType, string ZTMC, IMap inSourceMap, string inXZQMC)
        {
            IMapLayers inMapLayers = inMap as IMapLayers;

            if (!File.Exists(LayerXMLpath))
            {
                return;
            }
            XmlDocument cXmlDoc = new XmlDocument();

            cXmlDoc.Load(LayerXMLpath);
            if (cXmlDoc == null)
            {
                return;
            }
            string xpath = "";

            if (ZTMC == "")//规划不分年度
            {
                xpath = "//DIR[@DIRType='" + inType + "']";
            }
            else//现状分年度专题
            {
                xpath = "//DIR[@DIRType='" + inType + "' and @NodeText='" + ZTMC + "']";
            }
            XmlNode xn = cXmlDoc.SelectSingleNode(xpath);

            if (xn == null)
            {
                return;
            }
            inMap.Name = xn.Attributes["NodeText"].Value; //设置地图名称
            string xzqmc = getXIAN(inXZQMC);              //从不同级别的行政区获得县名称,以获得数据

            if (xzqmc == null)
            {
                return;
            }
            if (ZTMC != "")//区分现状和规划
            {
                string nxzq = ModGetData.AttrValueByXpath("//SpecialXZQ[@ZTMC='" + ZTMC + "']", "New");
                if (nxzq != "")
                {
                    if (nxzq.Contains(xzqmc))
                    {
                        xzqmc = ModGetData.AttrValueByXpath("//SpecialXZQ[@ZTMC='" + ZTMC + "']", "Old");
                    }

                    if (xzqmc == "")
                    {
                        return;
                    }
                }
            }
            XmlNode xnXZQ = xn.SelectSingleNode(".//DataDIR[contains(@NodeText,'" + xzqmc + "')]");

            if (xnXZQ == null)
            {
                return;
            }
            IGroupLayer gLayer = new GroupLayerClass();

            gLayer.Name = xnXZQ.Attributes["NodeText"].Value;
            XmlNodeList xnl = xnXZQ.SelectNodes(".//Layer");

            foreach (XmlNode pxn in xnl)
            {
                string nodeKey = pxn.Attributes["NodeKey"].Value;
                ILayer pLayer  = GetLayerByNodeKey(inSourceMap, nodeKey);
                if (pLayer != null)
                {
                    gLayer.Add(pLayer);
                }
            }
            if ((gLayer as ICompositeLayer).Count != 0)
            {
                if (!isExistGpLyr(inMap, gLayer.Name))
                {
                    inMapLayers.InsertLayer(gLayer as ILayer, false, inMapLayers.LayerCount);
                }
            }
            cXmlDoc = null;
        }
Exemple #5
0
        private static void AddRasterLayer(Raster gRaster, IRasterRenderer rasterRenderer, string sRasterName, IGroupLayer pGrpLyr, string sHeader = null, short fTransparency = -1, bool ExpandLegend = true)
        {
            if (pGrpLyr != null)
            {
                IRasterLayer pResultLayer = ArcMapUtilities.IsRasterLayerInGroupLayer(gRaster.GISFileInfo, pGrpLyr);
                if (pResultLayer is ILayer)
                {
                    return;
                }
            }

            IRasterLayer   rasterLayer = new RasterLayer();
            IRasterDataset pRDS        = ArcMapUtilities.GetRasterDataset(gRaster);

            rasterLayer.CreateFromDataset(pRDS);
            if (rasterRenderer != null)
            {
                rasterLayer.Renderer = rasterRenderer;
            }

            if (rasterLayer != null)
            {
                IMapLayers pMapLayers = (IMapLayers)ArcMap.Document.FocusMap;
                if (!string.IsNullOrEmpty(sRasterName))
                {
                    rasterLayer.Name = sRasterName;
                }

                if (!string.IsNullOrEmpty(sHeader))
                {
                    ESRI.ArcGIS.Carto.ILegendInfo pLegend = (ESRI.ArcGIS.Carto.ILegendInfo)rasterLayer;
                    pLegend.LegendGroup[0].Heading = sHeader;
                }

                if (fTransparency >= 0)
                {
                    ILayerEffects pLayerEffects = (ILayerEffects)rasterLayer;
                    pLayerEffects.Transparency = fTransparency;
                }

                if (pGrpLyr == null)
                {
                    pMapLayers.InsertLayer(rasterLayer, false, 0);
                }
                else
                {
                    pMapLayers.InsertLayerInGroup(pGrpLyr, rasterLayer, false, 0);
                }

                // Collapse or expand the legend in the ToC (e.g. Hillshade should be collapsed)
                ((ILegendGroup)((ILegendInfo)rasterLayer).LegendGroup[0]).Visible = ExpandLegend;
            }

            int refsLeft = 0;

            do
            {
                refsLeft = System.Runtime.InteropServices.Marshal.ReleaseComObject(pRDS);
            }while (refsLeft > 0);

            refsLeft = 0;
            do
            {
                refsLeft = System.Runtime.InteropServices.Marshal.ReleaseComObject(rasterLayer);
            }while (refsLeft > 0);
        }
        public static void AddToMapVector(FileInfo sSource, string sDisplayName, IGroupLayer pGrpLyr, string displayField, IFeatureRenderer pRenderer, string queryFilter, string labelField, short fTransparency = -1)
        {
            if (string.IsNullOrEmpty(sDisplayName))
            {
                throw new ArgumentNullException("Display Name", "Null or empty display Name");
            }

            IFeatureLayer pResultLayer = IsFeatureLayerInGroupLayer(sSource.FullName, pGrpLyr);


            IFeatureWorkspace pWS = (IFeatureWorkspace)ArcMapUtilities.GetWorkspace(sSource);
            IFeatureClass     pFC = pWS.OpenFeatureClass(Path.GetFileNameWithoutExtension(sSource.FullName));

            pResultLayer = new FeatureLayer();
            pResultLayer.FeatureClass = pFC;
            if (fTransparency >= 0)
            {
                ILayerEffects pLayerEffects = (ILayerEffects)pResultLayer;
                pLayerEffects.Transparency = fTransparency;
            }

            if (!string.IsNullOrEmpty(sDisplayName))
            {
                pResultLayer.Name = sDisplayName;
            }

            IMapLayers pMapLayers = (IMapLayers)ArcMap.Document.FocusMap;

            if (pGrpLyr == null)
            {
                pMapLayers.InsertLayer(pResultLayer, true, 0);
            }
            else
            {
                pMapLayers.InsertLayerInGroup(pGrpLyr, pResultLayer, true, 0);
            }

            if (pRenderer != null)
            {
                ((IGeoFeatureLayer)pResultLayer).Renderer = pRenderer;
            }

            if (!string.IsNullOrEmpty(labelField))
            {
                IGeoFeatureLayer pGFL = pResultLayer as IGeoFeatureLayer;

                // This first attempt seems to set the label field, but doesn't
                // cause the labeling to refresh and take effect
                //IDisplayString displayString = pGFL as IDisplayString;
                //IDisplayExpressionProperties properties = displayString.ExpressionProperties;
                //properties.Expression = string.Format("[{0}]", labelField);

                // This second attempt takes more effort but actually works
                // https://community.esri.com/thread/19005
                IAnnotateLayerPropertiesCollection labelPropsCollection = pGFL.AnnotationProperties;
                labelPropsCollection.Clear();

                //IBasicOverposterLayerProperties pBOLayerProps = new BasicOverposterLayerProperties();
                //pBOLayerProps.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolygon
                //pBOLayerProps.NumLabelsOption = esriBasicNumLabelsOption.esriOneLabelPerShape
                //pBOLayerProps.FeatureWeight = esriBasicOverposterWeight.esriNoWeight
                //pBOLayerProps.LabelWeight = esriBasicOverposterWeight.esriLowWeight

                //Dim tSym As ITextSymbol
                //Set tSym = New TextSymbol
                //Dim font As IFontDisp
                //Set font = tSym.font
                //font.Bold = False
                //font.size = 6
                //tSym.font = font

                ILabelEngineLayerProperties aLELayerProps = (ILabelEngineLayerProperties) new LabelEngineLayerProperties();
                aLELayerProps.Expression = string.Format("[{0}]", labelField);

                //Set aLELayerProps.Symbol = tSym
                //Set aLELayerProps.BasicOverposterLayerProperties = pBOLayerProps
                IAnnotateLayerProperties lProps = aLELayerProps as IAnnotateLayerProperties;
                lProps.Class = "Any Name";
                labelPropsCollection.Add(lProps);

                pGFL.DisplayAnnotation = true;
            }

            if (pRenderer is IUniqueValueRenderer)
            {
                // If you didn't use a color ramp that was predefined in a style,
                // you need to use "Custom" here, otherwise use the name of the color ramp you chose.
                ((IGeoFeatureLayer)pResultLayer).DisplayField = displayField;

                // This makes the layer properties symbology tab show the correct interface
                IUID pUID = new UIDClass();
                pUID.Value = "{683C994E-A17B-11D1-8816-080009EC732A}";
                ((IGeoFeatureLayer)pResultLayer).RendererPropertyPageClassID = pUID as UIDClass;
            }

            if (!string.IsNullOrEmpty(queryFilter))
            {
                ((IFeatureLayerDefinition)pResultLayer).DefinitionExpression = queryFilter;
            }

            int refsLeft = 0;

            do
            {
                refsLeft = System.Runtime.InteropServices.Marshal.ReleaseComObject(pFC);
            }while (refsLeft > 0);

            do
            {
                refsLeft = System.Runtime.InteropServices.Marshal.ReleaseComObject(pResultLayer);
            }while (refsLeft > 0);

            ArcMap.Document.UpdateContents();
            ArcMap.Document.ActiveView.Refresh();
            ArcMap.Document.CurrentContentsView.Refresh(null);
        }