示例#1
0
        private void toolStripUnloadTextRender_Click(object sender, EventArgs e)
        {
            myListNode    node  = selectNode as myListNode;
            IFeatureLayer layer = node.layer;

            layer.SetTextRender(null);
            IFeatureClass fc = layerFcMap[layer] as IFeatureClass;

            this.axRenderControl1.FeatureManager.RefreshFeatureClass(fc);
        }
示例#2
0
        private void toolStripSetTextRender_Click(object sender, EventArgs e)
        {
            myListNode     node   = selectNode as myListNode;
            TextRenderForm trform = new TextRenderForm(node.layer.GetTextRender(), node.fields);

            if (trform.ShowDialog() == DialogResult.OK)
            {
                node.layer.SetTextRender(trform.newRender);
                IFeatureClass fc = layerFcMap[node.layer] as IFeatureClass;
                this.axRenderControl1.FeatureManager.RefreshFeatureClass(fc);
            }
        }
示例#3
0
        private void listView1_ItemChecked(object sender, ItemCheckedEventArgs e)
        {
            myListNode item = (myListNode)e.Item;

            if (e.Item.Checked)
            {
                item.layer.VisibleMask = gviViewportMask.gviViewAllNormalView;
            }
            else
            {
                item.layer.VisibleMask = gviViewportMask.gviViewNone;
            }
        }
示例#4
0
        private void importTextRenderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog od = new OpenFileDialog();

            od.Filter           = "XML文件|*.xml";
            od.RestoreDirectory = true;
            if (od.ShowDialog() == DialogResult.OK)
            {
                if (File.Exists(od.FileName))
                {
                    StreamReader sr        = new StreamReader(od.FileName);
                    string       xmlstring = sr.ReadToEnd();
                    sr.Close();

                    ITextRender   tr       = this.axRenderControl1.ObjectManager.CreateTextRenderFromXML(xmlstring);
                    string        nodeName = selectNode.Text;
                    myListNode    node     = selectNode as myListNode;
                    IFeatureLayer layer    = node.layer;
                    layer.SetTextRender(tr);
                }
            }
        }
示例#5
0
        private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (this.listView1.SelectedItems.Count == 0)
            {
                return;
            }
            myListNode item = (myListNode)this.listView1.SelectedItems[0];

            item.Checked = true;

            IEnvelope env = (IEnvelope)layerEnvelopeMap[item.layer];

            if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 &&
                                env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0))
            {
                return;
            }
            IPoint pos = (new GeometryFactory()).CreatePoint(gviVertexAttribute.gviVertexAttributeZ);

            pos.SpatialCRS = crs;
            pos.Position   = env.Center;
            this.axRenderControl1.Camera.LookAt2(pos, 1000, angle);
        }
示例#6
0
        private void exportTextRenderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string        nodeName  = selectNode.Text;
            myListNode    node      = selectNode as myListNode;
            IFeatureLayer layer     = node.layer;
            string        renderStr = layer.GetTextRender().AsXml();

            SaveFileDialog sd = new SaveFileDialog();

            sd.AddExtension     = true;
            sd.DefaultExt       = "xml";
            sd.Filter           = "XML文件|*.xml";
            sd.RestoreDirectory = true;
            if (sd.ShowDialog() == DialogResult.OK)
            {
                String final = sd.FileName;
                if (sd.FileName.LastIndexOf(".xml") == -1)
                {
                    final = String.Format("{0}.xml", sd.FileName);
                }
                System.IO.File.WriteAllText(final, renderStr);
                MessageBox.Show("导出成功");
            }
        }
示例#7
0
        // 公共方法
        void FeatureLayerVisualize(IConnectionInfo ci, bool needfly, string sourceName,
                                   ITextRender textRender, IGeometryRender geoRender)
        {
            IDataSourceFactory dsFactory = null;
            IDataSource        ds        = null;
            IFeatureDataSet    dataset   = null;

            try
            {
                dsFactory = new DataSourceFactory();
                ds        = dsFactory.OpenDataSource(ci);
                string[] setnames = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                dataset = ds.OpenFeatureDataset(setnames[0]);
                crs     = dataset.SpatialReference;
                string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        geoNames.Add(fieldinfo.Name);
                    }
                    fcMap.Add(fc, geoNames);
                }

                // CreateFeautureLayer
                bool hasfly = !needfly;
                foreach (IFeatureClass fcInMap in fcMap.Keys)
                {
                    List <string> geoNames = (List <string>)fcMap[fcInMap];
                    foreach (string geoName in geoNames)
                    {
                        IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(
                            fcInMap, geoName, textRender, geoRender, rootId);

                        // 添加节点到界面控件上
                        object[]   registeredFields = GetRegisteredRenderIndexFields(fcInMap);
                        myListNode item             = new myListNode(string.Format("{0}_{1}_{2}", sourceName, fcInMap.Name, featureLayer.MaxVisibleDistance.ToString()), featureLayer, registeredFields);
                        item.Checked = true;
                        listView1.Items.Add(item);
                        layerFcMap.Add(featureLayer, fcInMap);

                        IFieldInfoCollection fieldinfos  = fcInMap.GetFields();
                        IFieldInfo           fieldinfo   = fieldinfos.Get(fieldinfos.IndexOf(geoName));
                        IGeometryDef         geometryDef = fieldinfo.GeometryDef;
                        IEnvelope            env         = geometryDef.Envelope;
                        layerEnvelopeMap.Add(featureLayer, env);
                        if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 &&
                                            env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0))
                        {
                            continue;
                        }

                        // 相机飞入
                        if (!hasfly)
                        {
                            angle.Set(0, -20, 0);
                            IPoint pos = (new GeometryFactory()).CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                            pos.SpatialCRS = crs;
                            pos.Position   = env.Center;
                            this.axRenderControl1.Camera.LookAt2(pos, 1000, angle);
                        }
                        hasfly = true;
                    }
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }
            catch (System.Exception e)
            {
                System.Diagnostics.Trace.WriteLine(e.Message);
                return;
            }
            finally
            {
                if (ds != null)
                {
                    ds.Dispose();
                    ds = null;
                }
                if (dataset != null)
                {
                    dataset.Dispose();
                    dataset = null;
                }
                //if (fc != null)
                //{
                //    fc.Dispose();
                //    fc = null;
                //}
            }
        }