Пример #1
0
 private bool HasVisibleParent(MgLayerGroup grp)
 {
     var current = grp.Group;
     if (current != null)
         return current.IsVisible();
     return true;
 }
Пример #2
0
 //----------------------------------------------------------------------------------------
 // �� �ܣ� ��Ӳ㵽���飬������鲻���ڣ��򴴽�
 //
 // �� �ߣ�
 //
 //
 // �� �ڣ�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);
 }
Пример #3
0
        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);
        }
Пример #4
0
 public LocalRuntimeMapGroup(LocalRuntimeMap parent, MgLayerGroup group)
     : base(parent, "")
 {
     _parent = parent;
     _impl = group;
     _disableChangeTracking = false;
 }
Пример #5
0
 public GroupNodeMetadata(MgLayerGroup group)
 {
     base.IsGroup = true;
     this.Group = group;
     this.Checkable = true;
 }
Пример #6
0
        public override Mapping.RuntimeMapGroup CreateMapGroup(Mapping.RuntimeMap parent, string name)
        {
            var impl = parent as LocalRuntimeMap;
            if (impl == null)
                throw new ArgumentException("Instance is not a LocalRuntimeMap", "map"); //LOCALIZEME

            var group = new MgLayerGroup(name);
            return new LocalRuntimeMapGroup(impl, group);
        }
Пример #7
0
 private TreeNode CreateGroupNode(MgLayerGroup group)
 {
     var node = new TreeNode();
     node.Name = group.GetObjectId();
     node.Text = group.GetLegendLabel();
     node.Checked = group.IsVisible();
     node.SelectedImageKey = node.ImageKey = IMG_GROUP;
     var meta = new GroupNodeMetadata(group);
     node.Tag = meta;
     _groups[group.GetObjectId()] = meta;
     //node.ContextMenuStrip = _legend.GroupContextMenu;
     return node;
 }
Пример #8
0
        public override Mapping.RuntimeMapGroup CreateMapGroup(Mapping.RuntimeMap parent, ObjectModels.MapDefinition.IBaseMapGroup group)
        {
            var impl = parent as LocalRuntimeMap;
            if (impl == null)
                throw new ArgumentException("Instance is not a LocalRuntimeMap", "map"); //LOCALIZEME

            var rtGroup = new MgLayerGroup(group.Name);
            rtGroup.DisplayInLegend = group.ShowInLegend;
            MgdMap.SetGroupExpandInLegend(rtGroup, group.ExpandInLegend);
            //MgdMap.SetLayerGroupType(rtGroup, MgLayerGroupType.BaseMap);
            rtGroup.LegendLabel = group.LegendLabel;
            rtGroup.Visible = group.Visible;

            return new LocalRuntimeMapGroup(impl, rtGroup);
        }
Пример #9
0
        public override Mapping.RuntimeMapGroup CreateMapGroup(Mapping.RuntimeMap parent, ObjectModels.MapDefinition.IMapLayerGroup group)
        {
            var impl = parent as LocalRuntimeMap;
            if (impl == null)
                throw new ArgumentException("Instance is not a LocalRuntimeMap", "map"); //LOCALIZEME

            var rtGroup = new MgLayerGroup(group.Name);
            rtGroup.DisplayInLegend = group.ShowInLegend;
            MgdMap.SetGroupExpandInLegend(rtGroup, group.ExpandInLegend);
            rtGroup.LegendLabel = group.LegendLabel;
            rtGroup.Visible = group.Visible;

            var implMap = impl.GetWrappedInstance();
            var groups = implMap.GetLayerGroups();
            if (!string.IsNullOrEmpty(group.Group))
            {
                int idx = groups.IndexOf(group.Group);
                if (idx >= 0)
                {
                    var parentGrp = groups.GetItem(idx);
                    rtGroup.Group = parentGrp;
                }
            }

            return new LocalRuntimeMapGroup(impl, rtGroup);
        }
Пример #10
0
        private void btnShowBuildings_Click(object sender, EventArgs e)
        {
            MgMapViewerProvider provider = _viewer.GetProvider();
            MgResourceService resourceService = (MgResourceService)provider.CreateService(MgServiceType.ResourceService);

            string layerName = "RecentlyBuilt";
            string legendLabel = "Built after 1980";
            string groupName = "Analysis";

            MgMapBase map = _viewer.GetMap();
            MgLayerCollection layers = map.GetLayers();
            MgLayerGroupCollection groups = map.GetLayerGroups();

            if (layers.IndexOf(layerName) >= 0)
            {
                MessageBox.Show("Layer (" + layerName + ") already created");
                return;
            }

            //NOTE: mg-desktop has no formal concept of a session repository, but we still
            //support session-based resources as a form of temporary resource (for the duration
            //of the application). Session ids in mg-desktop can be any arbitrary string
            string sessionId = Guid.NewGuid().ToString();

            XmlDocument domDocument = new XmlDocument();
            domDocument.LoadXml(Layers.RecentlyBuilt);

            // Get a list of all the <AreaRule><Filter> elements in
            // the XML.
            XmlNodeList nodes = domDocument.SelectNodes("//AreaRule/Filter");
            // Find the correct node and change it
            foreach (XmlNode node in nodes)
            {
                if (node.InnerText == "YRBUILT > 1950")
                {
                    node.InnerText = "YRBUILT > 1980";
                }
            }

            // Get a list of all the <LegendLabel> elements in the
            // XML.
            nodes = domDocument.SelectNodes("//LegendLabel");
            // Find the correct node and change it
            foreach (XmlNode node in nodes)
            {
                if (node.InnerText == "Built after 1950")
                {
                    node.InnerText = "Built after 1980";
                }
            }

            //Add the layer to the map
            // TODO: Should probably validate this XML content
            using (MemoryStream ms = new MemoryStream())
            {
                domDocument.Save(ms);
                ms.Position = 0L;
                //Note we do this to ensure our XML content is free of any BOM characters
                byte[] layerDefinition = ms.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 resourceID = new MgResourceIdentifier("Session:" + sessionId + "//" + layerName + ".LayerDefinition");
                resourceService.SetResource(resourceID, byteSource.GetReader(), null);

                //Insert this layer to our map
                MgdLayer newLayer = new MgdLayer(resourceID, resourceService);
                newLayer.Name = layerName;
                newLayer.LegendLabel = legendLabel;
                newLayer.DisplayInLegend = true;
                newLayer.SetVisible(true);
                layers.Insert(0, newLayer);

                //Create analysis group if not already created
                if (groups.IndexOf(groupName) < 0)
                {
                    MgLayerGroup group = new MgLayerGroup(groupName);
                    group.LegendLabel = groupName;
                    group.DisplayInLegend = true;
                    groups.Add(group);
                    newLayer.Group = group;
                }

                //Turn off square footage if it exists
                if (layers.IndexOf("SquareFootage") >= 0)
                {
                    MgLayerBase layer = layers.GetItem("SquareFootage");
                    layer.SetVisible(false);
                }

                MessageBox.Show("Layer (" + layerName + ") created");
                _viewer.RefreshMap();
                IMapLegend legend = Shell.Instance.Legend;
                if (legend != null)
                    legend.RefreshLegend();
            }
        }
Пример #11
0
        private void btnCreatePointsOfInterest_Click(object sender, EventArgs e)
        {
            string layerName = "Points";
            string legendLabel = "Points of Interest";
            string groupName = "Analysis";

            MgMapViewerProvider provider = _viewer.GetProvider();
            MgResourceService resourceService = (MgResourceService)provider.CreateService(MgServiceType.ResourceService);
            //We use MgdFeatureService instead of MgFeatureService as this sample demonstrates APIs unique to mg-desktop
            MgdFeatureService featureService = (MgdFeatureService)provider.CreateService(MgServiceType.FeatureService);

            MgMapBase map = _viewer.GetMap();
            MgLayerCollection layers = map.GetLayers();
            MgLayerGroupCollection groups = map.GetLayerGroups();

            //NOTE: mg-desktop has no formal concept of a session repository, but we still
            //support session-based resources as a form of temporary resource (for the duration
            //of the application). Session ids in mg-desktop can be any arbitrary string
            string sessionId = Guid.NewGuid().ToString();

            if (layers.IndexOf(layerName) >= 0)
            {
                MessageBox.Show("Layer (" + layerName + ") already created");
                return;
            }

            //---------------------------------------------------//
            // Create a feature source with point data.
            // (The Sheboygan sample data does not contain such data,
            // so we"ll create it.)

            // Create a feature class definition for the new feature source
            MgClassDefinition classDefinition = new MgClassDefinition();
            classDefinition.SetName("Points");
            classDefinition.SetDescription("Feature class with point data.");
            classDefinition.SetDefaultGeometryPropertyName("GEOM");

            MgPropertyDefinitionCollection idProps = classDefinition.GetIdentityProperties();
            MgPropertyDefinitionCollection clsProps = classDefinition.GetProperties();

            // Create an identify property
            MgDataPropertyDefinition identityProperty = new MgDataPropertyDefinition("KEY");
            identityProperty.SetDataType(MgPropertyType.Int32);
            identityProperty.SetAutoGeneration(true);
            identityProperty.SetReadOnly(true);
            // Add the identity property to the class definition
            clsProps.Add(identityProperty);
            idProps.Add(identityProperty);

            // Create a name property
            MgDataPropertyDefinition nameProperty = new MgDataPropertyDefinition("NAME");
            nameProperty.SetDataType(MgPropertyType.String);
            // Add the name property to the class definition
            clsProps.Add(nameProperty);

            // Create a geometry property
            MgGeometricPropertyDefinition geometryProperty = new MgGeometricPropertyDefinition("GEOM");
            geometryProperty.SetGeometryTypes(MgFeatureGeometricType.Point);
            // Add the geometry property to the class definition
            clsProps.Add(geometryProperty);

            // Create a feature schema
            MgFeatureSchema featureSchema = new MgFeatureSchema("PointSchema", "Point schema");
            MgClassDefinitionCollection classes = featureSchema.GetClasses();
            // Add the feature schema to the class definition
            classes.Add(classDefinition);

            // Create the feature source
            String featureSourceName = "Library://Samples/DevGuide/Data/points.FeatureSource";
            MgResourceIdentifier resourceIdentifier = new MgResourceIdentifier(featureSourceName);
            //wkt = "LOCALCS[\"*XY-MT*\",LOCAL_DATUM[\"*X-Y*\",10000],UNIT[\"Meter\", 1],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH]]";
            String wkt = "GEOGCS[\"LL84\",DATUM[\"WGS84\",SPHEROID[\"WGS84\",6378137.000,298.25722293]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.01745329251994]]";
            MgCreateSdfParams sdfParams = new MgCreateSdfParams("LatLong", wkt, featureSchema);
            featureService.CreateFeatureSource(resourceIdentifier, sdfParams);

            // We need to add some data to the sdf before using it.  The spatial context
            // reader must have an extent.
            MgBatchPropertyCollection batchPropertyCollection = new MgBatchPropertyCollection();
            MgWktReaderWriter wktReaderWriter = new MgWktReaderWriter();
            MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter();
            MgGeometryFactory geometryFactory = new MgGeometryFactory();

            // Make four points
            batchPropertyCollection.Add(MakePoint("Point A", -87.727, 43.748, wktReaderWriter, agfReaderWriter));

            batchPropertyCollection.Add(MakePoint("Point B", -87.728, 43.730, wktReaderWriter, agfReaderWriter));

            batchPropertyCollection.Add(MakePoint("Point C", -87.726, 43.750, wktReaderWriter, agfReaderWriter));

            batchPropertyCollection.Add(MakePoint("Point D", -87.728, 43.750, wktReaderWriter, agfReaderWriter));

            // Old way commented out
            
            /*
            // Add the batch property collection to the feature source
            MgInsertFeatures cmd = new MgInsertFeatures("Points", batchPropertyCollection);
            MgFeatureCommandCollection featureCommandCollection = new MgFeatureCommandCollection();
            featureCommandCollection.Add(cmd);

            // Execute the "add" commands
            featureService.UpdateFeatures(resourceIdentifier, featureCommandCollection, false);
            */

            // Here's the mg-desktop way
            MgPropertyCollection insertResult = featureService.InsertFeatures(resourceIdentifier, "Points", batchPropertyCollection);
            for (int i = 0; i < insertResult.GetCount(); i++)
            {
                MgFeatureProperty fp = insertResult.GetItem(i) as MgFeatureProperty;
                if (fp != null)
                {
                    MgFeatureReader fr = fp.GetValue();
                    fr.Close();
                }
            }

            // ...
            //---------------------------------------------------//
            // Create a new layer

            LayerDefinitionFactory factory = new LayerDefinitionFactory();

            // Create a mark symbol
            String resourceId = "Library://Samples/Sheboygan/Symbols/BasicSymbols.SymbolLibrary";
            String symbolName = "PushPin";
            String width = "24";  // unit = points
            String height = "24"; // unit = points
            String color = "FFFF0000";
            String markSymbol = factory.CreateMarkSymbol(resourceId, symbolName, width, height, color);

            // Create a text symbol
            String text = "ID";
            String fontHeight = "12";
            String foregroundColor = "FF000000";
            String textSymbol = factory.CreateTextSymbol(text, fontHeight, foregroundColor);

            // Create a point rule.
            String ruleLegendLabel = "trees";
            String filter = "";
            String pointRule = factory.CreatePointRule(ruleLegendLabel, filter, textSymbol, markSymbol);

            // Create a point type style.
            String pointTypeStyle = factory.CreatePointTypeStyle(pointRule);

            // Create a scale range.
            String minScale = "0";
            String maxScale = "1000000000000";
            String pointScaleRange = factory.CreateScaleRange(minScale, maxScale, pointTypeStyle);

            // Create the layer definiton.
            String featureName = "PointSchema:Points";
            String geometry = "GEOM";
            String layerDefinition = factory.CreateLayerDefinition(featureSourceName, featureName, geometry, pointScaleRange);
            //---------------------------------------------------//
            // ...

            XmlDocument domDocument = new XmlDocument();
            domDocument.LoadXml(layerDefinition);

            //Add the layer to the map
            // TODO: Should probably validate this XML content
            using (MemoryStream ms = new MemoryStream())
            {
                domDocument.Save(ms);
                ms.Position = 0L;
                //Note we do this to ensure our XML content is free of any BOM characters
                byte[] ldfBytes = ms.ToArray();
                Encoding utf8 = Encoding.UTF8;
                String layerDefStr = new String(utf8.GetChars(ldfBytes));
                ldfBytes = new byte[layerDefStr.Length - 1];
                int byteCount = utf8.GetBytes(layerDefStr, 1, layerDefStr.Length - 1, ldfBytes, 0);
                // Save the new layer definition to the session repository  
                MgByteSource byteSource = new MgByteSource(ldfBytes, ldfBytes.Length);
                MgResourceIdentifier resourceID = new MgResourceIdentifier("Session:" + sessionId + "//" + layerName + ".LayerDefinition");
                resourceService.SetResource(resourceID, byteSource.GetReader(), null);

                //Insert this layer to our map
                MgdLayer newLayer = new MgdLayer(resourceID, resourceService);
                newLayer.Name = layerName;
                newLayer.LegendLabel = legendLabel;
                newLayer.DisplayInLegend = true;
                newLayer.SetVisible(true);
                layers.Insert(0, newLayer);

                //Create analysis group if not already created
                if (groups.IndexOf(groupName) < 0)
                {
                    MgLayerGroup group = new MgLayerGroup(groupName);
                    group.LegendLabel = groupName;
                    group.DisplayInLegend = true;
                    groups.Add(group);
                    newLayer.Group = group;
                }

                MessageBox.Show("Layer (" + layerName + ") created");
                _viewer.RefreshMap();
                IMapLegend legend = Shell.Instance.Legend;
                if (legend != null)
                    legend.RefreshLegend();
            }
        }
Пример #12
0
        private void btnCreateHydroLine_Click(object sender, EventArgs e)
        {
            string layerName = "Hydro";
            string legendLabel = "Hydro";
            string groupName = "Analysis";

            MgMapViewerProvider provider = _viewer.GetProvider();
            MgResourceService resourceService = (MgResourceService)provider.CreateService(MgServiceType.ResourceService);

            MgMapBase map = _viewer.GetMap();
            MgLayerCollection layers = map.GetLayers();
            MgLayerGroupCollection groups = map.GetLayerGroups();

            //NOTE: mg-desktop has no formal concept of a session repository, but we still
            //support session-based resources as a form of temporary resource (for the duration
            //of the application). Session ids in mg-desktop can be any arbitrary string
            string sessionId = Guid.NewGuid().ToString();

            if (layers.IndexOf(layerName) >= 0)
            {
                MessageBox.Show("Layer (" + layerName + ") already created");
                return;
            }

            //---------------------------------------------------//
            // Create a new layer

            LayerDefinitionFactory factory = new LayerDefinitionFactory();

            // Create a line rule.
            String ruleLegendLabel = "";
            String filter = "";
            String color = "FF0000FF";
            String lineRule = factory.CreateLineRule(ruleLegendLabel, filter, color);

            // Create a line type style.
            String lineTypeStyle = factory.CreateLineTypeStyle(lineRule);

            // Create a scale range.
            String minScale = "0";
            String maxScale = "1000000000000";
            String lineScaleRange = factory.CreateScaleRange(minScale, maxScale, lineTypeStyle);

            // Create the layer definiton.
            String featureClass = "Library://Samples/Sheboygan/Data/HydrographicLines.FeatureSource";
            String featureName = "SHP_Schema:HydrographicLines";
            String geometry = "SHPGEOM";
            String layerDefinition = factory.CreateLayerDefinition(featureClass, featureName, geometry, lineScaleRange);

            //---------------------------------------------------//
            // ...

            XmlDocument domDocument = new XmlDocument();
            domDocument.LoadXml(layerDefinition);

            //Add the layer to the map
            // TODO: Should probably validate this XML content
            using (MemoryStream ms = new MemoryStream())
            {
                domDocument.Save(ms);
                ms.Position = 0L;
                //Note we do this to ensure our XML content is free of any BOM characters
                byte[] ldfBytes = ms.ToArray();
                Encoding utf8 = Encoding.UTF8;
                String layerDefStr = new String(utf8.GetChars(ldfBytes));
                ldfBytes = new byte[layerDefStr.Length - 1];
                int byteCount = utf8.GetBytes(layerDefStr, 1, layerDefStr.Length - 1, ldfBytes, 0);
                // Save the new layer definition to the session repository  
                MgByteSource byteSource = new MgByteSource(ldfBytes, ldfBytes.Length);
                MgResourceIdentifier resourceID = new MgResourceIdentifier("Session:" + sessionId + "//" + layerName + ".LayerDefinition");
                resourceService.SetResource(resourceID, byteSource.GetReader(), null);

                //Insert this layer to our map
                MgdLayer newLayer = new MgdLayer(resourceID, resourceService);
                newLayer.Name = layerName;
                newLayer.LegendLabel = legendLabel;
                newLayer.DisplayInLegend = true;
                newLayer.SetVisible(true);
                layers.Insert(0, newLayer);

                //Create analysis group if not already created
                if (groups.IndexOf(groupName) < 0)
                {
                    MgLayerGroup group = new MgLayerGroup(groupName);
                    group.LegendLabel = groupName;
                    group.DisplayInLegend = true;
                    groups.Add(group);
                    newLayer.Group = group;
                }

                MessageBox.Show("Layer (" + layerName + ") created");
                _viewer.RefreshMap();
                IMapLegend legend = Shell.Instance.Legend;
                if (legend != null)
                    legend.RefreshLegend();
            }
        }
Пример #13
0
 public override void SetGroupExpandInLegend(MgLayerGroup group, bool bExpanded)
 {
     MgdMap.SetGroupExpandInLegend(group, bExpanded);
 }
Пример #14
0
        public void LayerGroup()
        {
            MgLayerGroup lg = new MgLayerGroup("TestLayerGroupName");

            Assert.AreEqual("TestLayerGroupName", lg.Name);
            Assert.AreEqual(MgLayerGroupType.Normal, lg.LayerGroupType);

            lg.Group = new MgLayerGroup("AnotherTestLayerGroupName");
            Assert.AreEqual("AnotherTestLayerGroupName", lg.Group.Name);

            lg.Visible = true;
            Assert.IsTrue(lg.Visible);
            lg.Visible = false;
            Assert.IsFalse(lg.Visible);

            lg.DisplayInLegend = true;
            Assert.IsTrue(lg.DisplayInLegend);
            lg.DisplayInLegend = false;
            Assert.IsFalse(lg.DisplayInLegend);

            Assert.IsFalse(lg.ExpandInLegend);

            lg.LegendLabel = "TestLegendLabel";
            Assert.AreEqual("TestLegendLabel", lg.LegendLabel);
        }
Пример #15
0
 public abstract void SetGroupExpandInLegend(MgLayerGroup group, bool bExpanded);
Пример #16
0
 public abstract void MakeGroupNormal(MgLayerGroup group);