Example #1
0
 /// <summary>
 /// Adds the specified layer
 /// </summary>
 /// <param name="layer"></param>
 public void Add(RuntimeMapLayer layer)
 {
     if (!Contains(layer))
     {
         var sel = new LayerSelection(layer);
         Add(sel);
     }
 }
Example #2
0
 /// <summary>
 /// Internal helper to construct a LayerSelection
 /// </summary>
 /// <param name="layer">The layer that the selection belongs to</param>
 /// <param name="ids">A list of xml &lt;ID&gt; nodes</param>
 internal LayerSelection(RuntimeMapLayer layer, XmlNodeList ids)
     : this(layer)
 {
     foreach (XmlNode n in ids)
     {
         Add(ParseIDString(n.InnerXml));
     }
 }
Example #3
0
        /// <summary>
        /// Gets the parent group
        /// </summary>
        /// <param name="layer"></param>
        /// <returns></returns>
        public static RuntimeMapGroup GetParentGroup(this RuntimeMapLayer layer)
        {
            Check.ArgumentNotNull(layer, nameof(layer));

            if (string.IsNullOrEmpty(layer.Group))
            {
                return(null);
            }

            return(layer.Parent.Groups[layer.Group]);
        }
Example #4
0
        /// <summary>
        /// Returns the index of the given layer
        /// </summary>
        /// <param name="layer">The layer.</param>
        /// <returns>
        /// The index of the layer, or -1 if the layer is not in the collection
        /// </returns>
        public int IndexOf(RuntimeMapLayer layer)
        {
            for (int i = 0; i < _layers.Count; i++)
            {
                if (_layers[i].Layer.ObjectId == layer.ObjectId)
                {
                    return(i);
                }
            }

            return(-1);
        }
Example #5
0
            /// <summary>
            /// Constructs a new LayerSelection with a number of selected featured
            /// </summary>
            /// <param name="layer">The layer to represent</param>
            public LayerSelection(RuntimeMapLayer layer)
            {
                if (layer == null)
                {
                    throw new ArgumentNullException(nameof(layer)); //NOXLATE
                }
                if (layer.IdentityProperties.Length == 0 && layer.Parent.StrictSelection)
                {
                    throw new Exception(Strings.ErrorLayerHasNoPk);
                }

                m_layer = layer;
            }
Example #6
0
 public int IndexOfLayer(RuntimeMapLayer layer)
 {
     return this.Layers.IndexOf(layer);
 }
Example #7
0
 public RuntimeMapLayer CreateLayer(string layerDefinitionId, RuntimeMapGroup group)
 {
     ILayerDefinition ldf = GetLayerDefinition(layerDefinitionId);
     var layer = new RuntimeMapLayer(this, ldf, true);
     if (group != null)
         layer.Group = group.Name;
     return layer;
 }
Example #8
0
 private void OnLayerSelected(RuntimeMapLayer layer)
 {
     var h = this.LayerSelected;
     if (h != null)
         h(this, layer);
 }
 private void drawOrderCtrl_LayerDeleted(object sender, RuntimeMapLayer layer)
 {
     if (layer == propGrid.SelectedObject)
         propGrid.SelectedObject = null;
 }
Example #10
0
 internal bool GetVisibilityFlag(RuntimeMapLayer layer)
 {
     return layer.IsVisibleAtScale(_map.ViewScale);
 }
Example #11
0
 public void RemoveLayer(RuntimeMapLayer layer)
 {
     Check.NotNull(layer, "layer"); //NOXLATE
     this.Layers.Remove(layer);
 }
Example #12
0
 /// <summary>
 /// Inserts a selection layer into the collection
 /// </summary>
 /// <param name="index">The index to place the item at</param>
 /// <param name="layer">The layer.</param>
 public void Insert(int index, RuntimeMapLayer layer) => _layers.Insert(index, new LayerSelection(layer));
Example #13
0
 internal void OnLayerDefinitionChanged(RuntimeMapLayer layer)
 {
     TrackChange(layer.ObjectId, true, Change.ChangeType.definitionChanged, string.Empty);
 }
Example #14
0
 internal void OnLayerDisplayInLegendChanged(RuntimeMapLayer layer, string displayInLegendState)
 {
     TrackChange(layer.ObjectId, true, Change.ChangeType.displayInLegendChanged, displayInLegendState);
 }
Example #15
0
        internal void OnLayerAdded(RuntimeMapLayer layer)
        {
            var h = this.LayerAdded;
            if (h != null)
                h(this, layer);
            //Fix the draw order of this layer that was added

            //???

            TrackChange(layer.ObjectId, true, Change.ChangeType.added, string.Empty);
        }
Example #16
0
 internal void AddLayer(RuntimeMapLayer layer)
 {
     this.Layers.Add(layer);
 }
Example #17
0
 public void SetLayerIndex(int index, RuntimeMapLayer layer)
 {
     this.Layers[index] = layer;
 }
Example #18
0
        private TreeNode CreateLayerNode(RuntimeMapLayer layer)
        {
            var node = new TreeNode();
            node.Name = layer.ObjectId;
            node.Text = layer.LegendLabel;
            node.Checked = layer.Visible;
            //node.ContextMenuStrip = _legend.LayerContextMenu;
            var lt = layer.Type;
            var fsId = layer.FeatureSourceID;

            LayerNodeMetadata layerMeta = null;
            if (fsId.EndsWith("DrawingSource"))
            {
                node.SelectedImageKey = node.ImageKey = IMG_DWF;
                bool bInitiallySelectable = layer.Selectable;
                if (_layers.ContainsKey(layer.ObjectId))
                {
                    layerMeta = _layers[layer.ObjectId];
                    bInitiallySelectable = layerMeta.WasInitiallySelectable;
                }
                else //If not in the dictionary, assume it is a dynamically added layer
                {
                    RuntimeMapGroup group = null;
                    if (!string.IsNullOrEmpty(layer.Group))
                        group = _map.Groups[layer.Group];
                    layerMeta = new LayerNodeMetadata(layer, bInitiallySelectable);
                    _layers[layer.ObjectId] = layerMeta;
                }
                node.Tag = layerMeta;
                node.ToolTipText = string.Format(Properties.Resources.DrawingLayerTooltip, Environment.NewLine, layer.Name, layer.FeatureSourceID);
            }
            else //Vector or Grid layer
            {
                var ldfId = layer.LayerDefinitionID;
                if (_layers.ContainsKey(layer.ObjectId))
                {
                    layerMeta = _layers[layer.ObjectId];
                }
                else
                {
                    RuntimeMapGroup group = null;
                    if (!string.IsNullOrEmpty(layer.Group))
                        group = _map.Groups[layer.Group];
                    layerMeta = new LayerNodeMetadata(layer, layer.Selectable);
                    _layers[layer.ObjectId] = layerMeta;
                }
                if (string.IsNullOrEmpty(layerMeta.LayerDefinitionContent))
                    return null;

                node.Tag = layerMeta;

                const int LAYER_VECTOR = 0;
                const int LAYER_RASTER = 1;
                const int LAYER_DWF = 2;

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(layerMeta.LayerDefinitionContent);
                int type = LAYER_VECTOR;
                XmlNodeList scaleRanges = doc.GetElementsByTagName("VectorScaleRange");
                if (scaleRanges.Count == 0)
                {
                    scaleRanges = doc.GetElementsByTagName("GridScaleRange");
                    if (scaleRanges.Count == 0)
                    {
                        scaleRanges = doc.GetElementsByTagName("DrawingLayerDefinition");
                        if (scaleRanges.Count == 0)
                            return null;
                        type = LAYER_DWF;
                    }
                    else
                        type = LAYER_RASTER;
                }

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

                node.ToolTipText = string.Format(Properties.Resources.DefaultLayerTooltip, Environment.NewLine, layer.Name, layer.FeatureSourceID, layer.QualifiedClassName);
                //Do this if not cached already from a previous run
                if (!layerMeta.HasTheme() || !layerMeta.HasDefaultIcons())
                {
                    for (int sc = 0; sc < scaleRanges.Count; sc++)
                    {
                        XmlElement scaleRange = (XmlElement)scaleRanges[sc];
                        XmlNodeList minElt = scaleRange.GetElementsByTagName("MinScale");
                        XmlNodeList maxElt = scaleRange.GetElementsByTagName("MaxScale");
                        String minScale, maxScale;
                        minScale = "0";
                        maxScale = "1000000000000.0";   // as MDF's VectorScaleRange::MAX_MAP_SCALE
                        if (minElt.Count > 0)
                            minScale = minElt[0].ChildNodes[0].Value;
                        if (maxElt.Count > 0)
                            maxScale = maxElt[0].ChildNodes[0].Value;

                        if (type != LAYER_VECTOR)
                            break;

                        bool bComposite = false;

                        //Check TS count. Give precedence to composite type styles
                        List<XmlNode> typeStyleCol = new List<XmlNode>();
                        XmlNodeList styleNodes = scaleRange.GetElementsByTagName(typeStyles[3]);
                        List<RuleData> rules = new List<RuleData>();
                        if (styleNodes.Count > 0)
                        {
                            foreach (XmlNode n in styleNodes)
                            {
                                // We will check if this typestyle is going to be shown in the legend
                                XmlNodeList showInLegend = ((XmlElement)n).GetElementsByTagName("ShowInLegend"); //NOXLATE
                                if (showInLegend.Count > 0)
                                    if (!bool.Parse(showInLegend[0].ChildNodes[0].Value))
                                        continue;   // This typestyle does not need to be shown in the legend

                                typeStyleCol.Add(n);

                                var ruleData = new RuleData();
                                ruleData.GeomType = 3;
                                ruleData.RuleNodes = ((XmlElement)n).GetElementsByTagName(ruleNames[3]);
                                if (ruleData.RuleNodes.Count > 0)
                                    rules.Add(ruleData);
                            }

                            bComposite = true;
                        }
                        else
                        {
                            for (int t = 0; t < 3; t++)
                            {
                                styleNodes = scaleRange.GetElementsByTagName(typeStyles[t]);
                                foreach (XmlNode n in styleNodes)
                                {
                                    // We will check if this typestyle is going to be shown in the legend
                                    XmlNodeList showInLegend = ((XmlElement)n).GetElementsByTagName("ShowInLegend"); //NOXLATE
                                    if (showInLegend.Count > 0)
                                        if (!bool.Parse(showInLegend[0].ChildNodes[0].Value))
                                            continue;   // This typestyle does not need to be shown in the legend

                                    typeStyleCol.Add(n);

                                    var ruleData = new RuleData();
                                    ruleData.GeomType = t;
                                    ruleData.RuleNodes = ((XmlElement)n).GetElementsByTagName(ruleNames[t]);
                                    if (ruleData.RuleNodes.Count > 0)
                                        rules.Add(ruleData);
                                }
                            }
                        }

                        //No type styles. Skip
                        if (typeStyleCol.Count == 0)
                            continue;

                        //Determine if this is themed or not
                        int nTotalRules = 0;
                        foreach (RuleData r in rules)
                        {
                            nTotalRules += r.RuleNodes.Count;
                        }
                        bool bThemed = nTotalRules > 1;
                        if (bThemed)
                        {
                            int catIndex = 0;
                            for (int i = 0; i < rules.Count; i++)
                            {
                                RuleData theRule = rules[i];
                                ThemeCategory themeCat = new ThemeCategory()
                                {
                                    MinScale = minScale,
                                    MaxScale = maxScale,
                                    GeometryType = theRule.GeomType
                                };

                                //Non-composite styles must be processed once
                                if (layerMeta.CategoryExists(themeCat) && theRule.GeomType != 3)
                                    continue;

                                layerMeta.SetDefaultIcon(themeCat, Properties.Resources.lc_theme);
                                node.ToolTipText = string.Format(Properties.Resources.ThemedLayerTooltip, Environment.NewLine, layer.Name, layer.FeatureSourceID, layer.QualifiedClassName, nTotalRules);

                                if (_legend.ThemeCompressionLimit > 0 && theRule.RuleNodes.Count > _legend.ThemeCompressionLimit)
                                {
                                    AddThemeRuleNode(layerMeta, themeCat, node, theRule.GeomType, catIndex, theRule.RuleNodes, 0);
                                    node.Nodes.Add(CreateCompressedThemeNode(layerMeta, themeCat, theRule.RuleNodes.Count - 2));
                                    AddThemeRuleNode(layerMeta, themeCat, node, theRule.GeomType, (catIndex + (theRule.RuleNodes.Count - 1)), theRule.RuleNodes, theRule.RuleNodes.Count - 1);
                                }
                                else
                                {
                                    for (int r = 0; r < theRule.RuleNodes.Count; r++)
                                    {
                                        AddThemeRuleNode(layerMeta, themeCat, node, theRule.GeomType, (catIndex + r), theRule.RuleNodes, r);
                                    }
                                }
                                //Only bump catIndex if composite, as category indexes for composite styles are handled differently
                                if (bComposite)
                                    catIndex += theRule.RuleNodes.Count;
                            }
                        }
                        else
                        {
                            Trace.Assert(rules.Count == 1);
                            Trace.Assert(rules[0].RuleNodes.Count == 1);
                            RuleData theRule = rules[0];

                            ThemeCategory themeCat = new ThemeCategory()
                            {
                                MinScale = minScale,
                                MaxScale = maxScale,
                                GeometryType = theRule.GeomType
                            };

                            if (layerMeta.CategoryExists(themeCat))
                                continue;

                            if (LayerNodeMetadata.ScaleIsApplicable(_map.ViewScale, themeCat))
                            {
                                if (!layerMeta.HasDefaultIconsAt(_map.ViewScale))
                                {
                                    try
                                    {
                                        var img = _map.GetLegendImage(layer.LayerDefinitionID,
                                                                                _map.ViewScale,
                                                                                16,
                                                                                16,
                                                                                "PNG",
                                                                                (theRule.GeomType + 1),
                                                                                -1);
                                        legendCallCount++;
                                        layerMeta.SetDefaultIcon(themeCat, img);
                                        node.ToolTipText = string.Format(Properties.Resources.DefaultLayerTooltip, Environment.NewLine, layer.Name, layer.FeatureSourceID, layer.QualifiedClassName);
                                    }
                                    catch
                                    {
                                        //layerMeta.SetDefaultIcon(themeCat, Properties.Resources.lc_broken);
                                    }
                                }
                            }
                        }

                        //for (int geomType = 0; geomType < typeStyles.Length; geomType++)
                        //{
                        //    ThemeCategory themeCat = new ThemeCategory()
                        //    {
                        //        MinScale = minScale,
                        //        MaxScale = maxScale,
                        //        GeometryType = geomType
                        //    };

                        //    if (layerMeta.CategoryExists(themeCat))
                        //        continue;

                        //    int catIndex = 0;
                        //    XmlNodeList typeStyle = scaleRange.GetElementsByTagName(typeStyles[geomType]);
                        //    for (int st = 0; st < typeStyle.Count; st++)
                        //    {
                        //        // We will check if this typestyle is going to be shown in the legend
                        //        XmlNodeList showInLegend = ((XmlElement)typeStyle[st]).GetElementsByTagName("ShowInLegend");
                        //        if (showInLegend.Count > 0)
                        //            if (!bool.Parse(showInLegend[0].ChildNodes[0].Value))
                        //                continue;   // This typestyle does not need to be shown in the legend

                        //        XmlNodeList rules = ((XmlElement)typeStyle[st]).GetElementsByTagName(ruleNames[geomType]);
                        //        if (rules.Count > 1)
                        //        {
                        //            layerMeta.SetDefaultIcon(themeCat, Properties.Resources.lc_theme);
                        //            node.ToolTipText = string.Format(Properties.Resources.ThemedLayerTooltip, Environment.NewLine, layer.Name, layer.FeatureSourceID, layer.QualifiedClassName, rules.Count);

                        //            if (_legend.ThemeCompressionLimit > 0 && rules.Count > _legend.ThemeCompressionLimit)
                        //            {
                        //                AddThemeRuleNode(layerMeta, themeCat, node, geomType, 0, rules, 0);
                        //                node.Nodes.Add(CreateCompressedThemeNode(layerMeta, themeCat, rules.Count - 2));
                        //                AddThemeRuleNode(layerMeta, themeCat, node, geomType, rules.Count - 1, rules, rules.Count - 1);
                        //            }
                        //            else
                        //            {
                        //                for (int r = 0; r < rules.Count; r++)
                        //                {
                        //                    AddThemeRuleNode(layerMeta, themeCat, node, geomType, catIndex++, rules, r);
                        //                }
                        //            }
                        //        }
                        //        else
                        //        {
                        //            if (LayerNodeMetadata.ScaleIsApplicable(_map.ViewScale, themeCat))
                        //            {
                        //                if (!layerMeta.HasDefaultIconsAt(_map.ViewScale))
                        //                {
                        //                    try
                        //                    {
                        //                        var img = _map.GetLegendImage(layer.LayerDefinitionID,
                        //                                                                _map.ViewScale,
                        //                                                                16,
                        //                                                                16,
                        //                                                                "PNG",
                        //                                                                -1,
                        //                                                                -1);
                        //                        legendCallCount++;
                        //                        layerMeta.SetDefaultIcon(themeCat, img);
                        //                        node.ToolTipText = string.Format(Properties.Resources.DefaultLayerTooltip, Environment.NewLine, layer.Name, layer.FeatureSourceID, layer.QualifiedClassName);
                        //                    }
                        //                    catch
                        //                    {
                        //                        //layerMeta.SetDefaultIcon(themeCat, Properties.Resources.lc_broken);
                        //                    }
                        //                }
                        //            }
                        //        }
                        //    }
                        //}
                    }
                }
                else //Already cached
                {
                    Trace.TraceInformation("Icons already cached for: " + layer.Name);
                    node.Nodes.AddRange(layerMeta.CreateThemeNodesFromCachedMetadata(_map.ViewScale));
                }
            }

            return node;
        }
Example #19
0
 private bool HasVisibleParent(RuntimeMapLayer layer)
 {
     var current = layer.Group;
     if (current != null)
     {
         var parent = _map.Groups[current];
         if (parent != null)
         {
             return parent.Visible;
         }
     }
     return true;
 }
Example #20
0
 /// <summary>
 /// Constructs a new LayerSelection with a number of selected featured
 /// </summary>
 /// <param name="layer">The layer to represent</param>
 /// <param name="ids">The list of composite IDs that the layer supports</param>
 public LayerSelection(RuntimeMapLayer layer, IEnumerable <object[]> ids)
     : this(layer)
 {
     AddRange(ids);
 }
Example #21
0
 void OnMapLayerAdded(object sender, RuntimeMapLayer layer)
 {
     if (_bComputeLayerCsAndExtentOnFirstLayerAdded && _mapEditor.Map.Layers.Count == 1)
     {
         Debug.WriteLine("Computing map extents and CS based on first layer added");
         try
         {
             ILayerDefinition layerDef = (ILayerDefinition)_conn.ResourceService.GetResource(layer.LayerDefinitionID);
             string wkt;
             IEnvelope env = layerDef.GetSpatialExtent(true, out wkt);
             if (SupportsMutableMapProperties(_mapEditor.Map))
             {
                 _mapEditor.Map.MapExtent = env;
                 _mapEditor.Map.CoordinateSystem = wkt;
                 if (CsHelper.DefaultCalculator != null)
                 {
                     _mapEditor.Map.MetersPerUnit = CsHelper.DefaultCalculator.Calculate(wkt, 1.0);
                 }
                 else
                 {
                     var calc = _mapEditor.Map.CurrentConnection.GetCalculator();
                     _mapEditor.Map.MetersPerUnit = calc.Calculate(wkt, 1.0);
                 }
                 _mapEditor.ReloadViewer();
             }
             else
             {
                 //We have to tear down the current runtime map, update the shadow copy
                 //map definition and then rebuild a new runtime map
                 _mapEditor.SyncMap();
                 IMapDefinition mdf = _mapEditor.GetMapDefinition();
                 mdf.Extents = env;
                 mdf.CoordinateSystem = wkt;
                 CleanupExistingMap();
                 //If local, we'd be rebuilding off of the resource ID and not its in-memory
                 //object representation so flush
                 _mapEditor.EditorService.SyncSessionCopy();
                 _mapEditor.RebuildRuntimeMap();
                 _mapEditor.ReloadViewer();
             }
             Debug.WriteLine("Computed map extents and CS");
         }
         catch (Exception ex)
         {
             Debug.WriteLine("Uh-Oh: " + ex.ToString());
         }
     }
 }
Example #22
0
 internal void OnLayerLegendLabelChanged(RuntimeMapLayer layer, string legendLabel)
 {
     TrackChange(layer.ObjectId, true, Change.ChangeType.legendLabelChanged, legendLabel);
 }
Example #23
0
 public void InsertLayer(int index, RuntimeMapLayer layer)
 {
     this.Layers.Insert(index, layer);
 }
Example #24
0
 /// <summary>
 /// Gets the selection layer at a given index
 /// </summary>
 /// <param name="index">The index to get or set the item for</param>
 /// <returns>The item at the given index</returns>
 public LayerSelection this[RuntimeMapLayer index] => _layers[IndexOf(index)];
Example #25
0
 internal void OnLayerParentChanged(RuntimeMapLayer layer, string parentId)
 {
     TrackChange(layer.ObjectId, true, Change.ChangeType.parentChanged, parentId);
 }
Example #26
0
 /// <summary>
 /// Gets whether this selection contains the specified layer
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public bool Contains(RuntimeMapLayer item) => IndexOf(item) >= 0;
Example #27
0
 internal void OnLayerRemoved(RuntimeMapLayer layer)
 {
     //???
     TrackChange(layer.ObjectId, true, Change.ChangeType.removed, string.Empty);
 }
Example #28
0
 internal void OnLayerSelectabilityChanged(RuntimeMapLayer layer, string selectability)
 {
     TrackChange(layer.ObjectId, true, Change.ChangeType.selectabilityChanged, selectability);
 }
Example #29
0
        internal void OnLayerVisibilityChanged(RuntimeMapLayer layer, string visibility)
        {
            //???

            TrackChange(layer.ObjectId, true, Change.ChangeType.visibilityChanged, visibility);
        }
Example #30
0
        private bool HasVisibleParent(RuntimeMapLayer layer)
        {
            if (string.IsNullOrEmpty(layer.Group))
                return true;

            var current = _map.Groups[layer.Group];
            if (current != null)
                return current.Visible;

            return true;
        }
Example #31
0
 private RuntimeMapLayer DeserializeLayer(MgBinaryDeserializer d)
 {
     //TODO: Review when we split to specific implementations
     RuntimeMapLayer t = new RuntimeMapLayer(this);
     t.Deserialize(d);
     return t;
 }
 private void drawOrderCtrl_LayerSelected(object sender, RuntimeMapLayer layer)
 {
     propGrid.SelectedObject = new LayerNodeMetadata(layer);
 }
Example #33
0
        private static bool IsRasterLayer(RuntimeMapLayer layer)
        {
            var cls = layer.GetClassDefinition();

            return IsRasterClass(cls);
        }