Esempio n. 1
0
        private void toolStripUnloadGeometryRender_Click(object sender, EventArgs e)
        {
            myListNode    node  = selectNode as myListNode;
            IFeatureLayer layer = node.layer;

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

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

            if (trform.ShowDialog() == DialogResult.OK)
            {
                node.layer.SetTextRender(trform.newRender);
                IFeatureClass fc = layerFcMap[node.layer] as IFeatureClass;
                this.axRenderControl1.FeatureManager.RefreshFeatureClass(fc);
            }
        }
Esempio n. 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;
            }
        }
Esempio n. 4
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;
            //this.axRenderControl1.Camera.LookAtEnvelope(item.layer.Envelope);

            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;
            }
            this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle);
        }
Esempio n. 5
0
        private void importGeometryRenderToolStripMenuItem_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();

                    IGeometryRender gr       = this.axRenderControl1.ObjectManager.CreateGeometryRenderFromXML(xmlstring);
                    string          nodeName = selectNode.Text;
                    myListNode      node     = selectNode as myListNode;
                    IFeatureLayer   layer    = node.layer;
                    layer.SetGeometryRender(gr);
                }
            }
        }
Esempio n. 6
0
        private void exportGeometryRenderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string        nodeName  = selectNode.Text;
            myListNode    node      = selectNode as myListNode;
            IFeatureLayer layer     = node.layer;
            string        renderStr = layer.GetGeometryRender().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("导出成功");
            }
        }
Esempio n. 7
0
        private void toolStripSetGeometryRender_Click(object sender, EventArgs e)
        {
            string        nodeName = selectNode.Text;
            myListNode    node     = selectNode as myListNode;
            IFeatureLayer layer    = node.layer;
            // 获取注册了RenderIndex的字段名集合
            IFeatureClass fc = layerFcMap[node.layer] as IFeatureClass;
            ArrayList     fieldNamesWithRegisterRenderIndex = new ArrayList();

            fieldNamesWithRegisterRenderIndex.Add("");
            IFieldInfoCollection fields = fc.GetFields();

            for (int i = 0; i < fields.Count; i++)
            {
                if (fields.Get(i).RegisteredRenderIndex)
                {
                    fieldNamesWithRegisterRenderIndex.Add(fields.Get(i).Name);
                }
            }
            switch (nodeName.Split('_')[0])
            {
            case "ModelPoint":
            {
                ModelPointRenderForm trform = new ModelPointRenderForm(node.layer.GetGeometryRender(), fieldNamesWithRegisterRenderIndex.ToArray());
                if (trform.ShowDialog() == DialogResult.OK)
                {
                    node.layer.SetGeometryRender(trform.newRender);
                    this.axRenderControl1.FeatureManager.RefreshFeatureClass(fc);
                }
            }
            break;

            case "Point":
            {
                SelectPointStyleForm selectStyleForm = new SelectPointStyleForm();
                if (selectStyleForm.ShowDialog() == DialogResult.OK)
                {
                    PointRenderForm trform;
                    if (selectStyleForm.radioButtonSimplePoint.Checked)
                    {
                        trform = new PointRenderForm(node.layer.GetGeometryRender(), fieldNamesWithRegisterRenderIndex.ToArray(), true);
                    }
                    else
                    {
                        trform = new PointRenderForm(node.layer.GetGeometryRender(), fieldNamesWithRegisterRenderIndex.ToArray(), false);
                    }
                    if (trform.ShowDialog() == DialogResult.OK)
                    {
                        node.layer.SetGeometryRender(trform.newRender);
                        this.axRenderControl1.FeatureManager.RefreshFeatureClass(fc);
                    }
                }
            }
            break;

            case "Polyline":
            {
                PolylineRenderForm trform = new PolylineRenderForm(node.layer.GetGeometryRender(), fieldNamesWithRegisterRenderIndex.ToArray());
                if (trform.ShowDialog() == DialogResult.OK)
                {
                    node.layer.SetGeometryRender(trform.newRender);
                    this.axRenderControl1.FeatureManager.RefreshFeatureClass(fc);
                }
            }
            break;

            case "Polygon":
            {
                PolygonRenderForm trform = new PolygonRenderForm(node.layer.GetGeometryRender(), fieldNamesWithRegisterRenderIndex.ToArray());
                if (trform.ShowDialog() == DialogResult.OK)
                {
                    node.layer.SetGeometryRender(trform.newRender);
                    this.axRenderControl1.FeatureManager.RefreshFeatureClass(fc);
                }
            }
            break;
            }
        }
Esempio n. 8
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]);
                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);

                        // 设置featureLayer组可见
                        if (!geoRender.RenderGroupField.Equals(""))
                        {
                            SetGroupVisiable(dataset, featureLayer);
                        }

                        // 添加节点到界面控件上
                        myListNode item = new myListNode(string.Format("{0}_{1}_{2}", sourceName, fcInMap.Name, featureLayer.MaxVisibleDistance.ToString()), featureLayer);
                        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);
                            this.axRenderControl1.Camera.LookAt(env.Center, 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 (dsFactory != null)
                {
                    //Marshal.ReleaseComObject(dsFactory);
                    dsFactory = null;
                }
                if (ds != null)
                {
                    //Marshal.ReleaseComObject(ds);
                    ds = null;
                }
                if (dataset != null)
                {
                    //Marshal.ReleaseComObject(dataset);
                    dataset = null;
                }
                //if (fc != null)
                //{
                //    //Marshal.ReleaseComObject(fc);
                //    fc = null;
                //}
            }
        }