Inheritance: Caliburn.Micro.PropertyChangedBase
示例#1
0
 public void ToggleOpacity(sLayer layer)
 {
     if (layer == null) return;
     layer.Layer.Opacity = (layer.Layer.Opacity > 0.1) ? 0 : 1;
 }
示例#2
0
 private static IEnumerable<MenuItem> GetMenuItems(sLayer layer)
 {
     var r = new List<MenuItem>();
     var menuLayer = layer.Layer as IMenuLayer;
     if (menuLayer == null) return r;
     var mi = menuLayer.GetMenuItems();
     if (mi != null)
         r.AddRange(mi);
     return r;
 }
示例#3
0
        public void LayerMenu(sLayer layer, FrameworkElement element)
        {
            if (layer == null) return;

            var menu = new MenuPopupViewModel
            {
                RelativeElement = element,
                RelativePosition = new Point(25, 0),
                TimeOut = new TimeSpan(0, 0, 0, 5),
                VerticalAlignment = VerticalAlignment.Bottom,
                DisplayProperty = string.Empty
            };

            menu.Items.AddRange(GetMenuItems(layer));

            if (menu.Items.Any()) AppState.Popups.Add(menu);
        }
示例#4
0
 private static void LayerStructureAsString(int pLevel, sLayer pLayer, ref StringBuilder pLog)
 {
     pLog.AppendLine(Indent(pLevel * 3) + $"* {GetLayerType(pLayer)} '{pLayer.Title}'");
     foreach (var child in pLayer.Children)
     {
         LayerStructureAsString(pLevel + 1, child, ref pLog);
     }
 }
示例#5
0
 private static string GetLayerType(sLayer pLayer)
 {
     if (pLayer.Layer == null) return "Unknown layer type";
     if (pLayer.Layer is GroupLayer) return "Group layer";
     return pLayer.Layer.GetType().Name;
 }
示例#6
0
        public void CleanUpLayers(ref sLayer l)
        {
            var tbr = new List<sLayer>();

            for (var i = 0; i < l.Children.Count; i++)
            {
                var c = l.Children[i];

                c.HasMenu = GetMenuItems(c).Any();

                if (c.Children == null || c.Children.Count > 0) continue; //
                
                if (l.Layer is IStartStopLayer && !((IStartStopLayer)l.Layer).IsStarted)
                {
                    tbr.Add(c);
                }

                if (c.Layer is IStartStopLayer && !((IStartStopLayer) c.Layer).IsStarted)
                {
                    c.Children.Clear();
                }

                if (c.Layer is GraphicsLayer && !((GraphicsLayer)c.Layer).Graphics.Any())
                {
                    tbr.Add(c);
                }

                if (c.Layer is GraphicsLayer && l.Children.Count == 1 && l.Title == c.Title)
                {
                    tbr.Add(c);
                }

                //if (c.Layer is IStartStopLayer && c.Children != null && c.Children.Count == 1 && c.Children[0].Title == c.Title)
                //{
                //    l.Children.Add(c);

                //    c.Children.Clear();
                //    tbr.Add(c);
                //}
                //else 
                if (c.Children == null || !c.Children.Any()) continue;
                l.Children.Add(c.Children[0]);
                c.Children.Clear();
                tbr.Add(c);
            }
            
            foreach (var c in tbr)
            {
                l.Children.Remove(c);
            }
            foreach (var t in l.Children)
            {
                var c = t;
                CleanUpLayers(ref c);
            }
            if (l.Path != null && expandedStates.ContainsKey(l.Path)) l.IsExpanded = expandedStates[l.Path];
        }
示例#7
0
        public void UpdateLayers()
        {
            if (updating) return;
            
            try
            {
                updating = true;
                LogCs.LogMessage("(Re)build viewmodel for GIS layers.");
                var startLayer = new sLayer();
                ParseLayers(AppState.ViewDef.AcceleratedLayers, ref startLayer, "AcceleratedLayers", false);
                ParseLayers(AppState.ViewDef.Layers, ref startLayer, "Layers", false);
                ParseLayers(AppState.ViewDef.BaseLayers, ref startLayer, "BaseLayers", true);                
                CleanUpLayers(ref startLayer);
                if (AppState.ViewDef.EsriLayers != null) // When is EsriLayers set??
                {
                    ParseLayers(AppState.ViewDef.EsriLayers, ref startLayer, "BaseLayers", true);
                }
                StartLayer = startLayer; // Override with new layout
                if (view != null)
                {
                    //view.tvLayers.ItemsSource = StartLayer.Children;
                    view.tvStartLayer.ItemsSource = StartLayer.Children;
                }

                var layerStructure = LayerStructureAsString();
                LogCs.LogMessage("GIS layers:\n" + layerStructure);
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                updating = false;
            }
        }
示例#8
0
 public void Zoom(sLayer l)
 {
     try
     {
         MapViewDef.ZoomTo(l.Layer);
     }
     catch (Exception)
     {
         AppState.TriggerNotification("There is not a valid zoom level for " + l.Layer.ID);
     }
 }
示例#9
0
 public void ToggleTab(sLayer l)
 {
     if (l == null) return;
     var tl = (ITabLayer)l.Layer;
     if (tl.IsTabActive)
         tl.OpenTab();
     else tl.CloseTab();
 }
示例#10
0
 public void Config(sLayer l)
 {
     var layer = l.Layer as ISettingsLayer;
     if (layer != null) layer.StartSettings();
 }
示例#11
0
 // Called when layer is deactivated (called from XAML)
 internal void DeactivateGisLayer(sLayer l)
 {
     if (l == null || l.Path==null) return;
     expandedStates[l.Path] = l.IsExpanded;
     var wmsLayer = l as sWmsLayer;
     if (wmsLayer != null) UpdateWmsLayer(wmsLayer.BaseLayer);
     var ls = l.Layer as IStartStopLayer;
     if (ls != null && ls.IsStarted && ls.CanStop)
     {
         ls.Stop();
         return;
     }
     var gl = l.Layer as GraphicsLayer;
     if (gl != null) {
         gl.Opacity = 0;
         return;
     }
     // Since we couldn't stop it, turn the visibility back on.
     l.Visible = true;
 }
示例#12
0
 // Called when layer is activated (called from XAML)
 internal void ActivateGisLayer(sLayer l)
 {
     if (l == null || l.Path==null) return;
     expandedStates[l.Path] = l.IsExpanded;
     var wmsLayer = l as sWmsLayer;
     if (wmsLayer != null) UpdateWmsLayer(wmsLayer.BaseLayer);
     var gl = l.Layer as GraphicsLayer;
     if (gl != null)
     {
         gl.Opacity = 1;
         return;
     }
     var ls = l.Layer as IStartStopLayer;
     if (ls == null) return;
     if (!ls.IsStarted)
         //ThreadPool.QueueUserWorkItem(delegate { 
         ls.Start();
     //});
 }
示例#13
0
 public void UpdateExpandState(sLayer l)
 {
     if (l == null || l.Path==null) return;
     expandedStates[l.Path] = l.IsExpanded;
 }
示例#14
0
        public void ParseEsriLayers(Layer layer, ref sLayer parent, string relativePath, bool include = true)
        {
            try
            {
                if (layer is IIgnoreLayer) return;
                var nl = parent;
                if (include)
                {
                    var wmsLayer = layer as WmsLayer;
                    if (wmsLayer != null)
                    {
                        wmsLayer.Initialized -= w_Initialized;
                        wmsLayer.Initialized += w_Initialized;

                        var wms = new sWmsLayer
                        {
                            Layer = layer,
                            Title = layer.ID,
                            Parent = parent,
                            IsTabAvailable = layer is ITabLayer,
                            IsConfigAvailable = layer is ISettingsLayer
                        };
                        wms.BaseLayer = wms;
                        parent.Children.Add(wms);
                        wms.Path = relativePath + "\\" + wmsLayer.ID;
                        if (wmsLayer.LayerList.Count > 0)
                        {
                            foreach (var sl in wmsLayer.LayerList.OrderBy(l => l.Name))
                            {
                                ParseWmsLayers(layer, sl, ref wms);
                            }
                        }
                    }
                    else
                    {
                        nl = new sLayer
                        {
                            Layer = layer,
                            Title = layer.ID,
                            IsTabAvailable = layer is ITabLayer,
                            IsConfigAvailable = layer is ISettingsLayer,
                            IsService = layer is IStartStopLayer,
                            Parent = parent,
                            Path = relativePath + "\\" + layer.ID
                        };
                        var nl1 = nl;
                        layer.PropertyChanged += (s, f) =>
                        {
                            if (f.PropertyName == "Visible")
                                nl1.Visible = layer.Visible;
                        };
                        var onlineLayer = layer as IOnlineLayer;
                        if (onlineLayer != null)
                        {
                            nl.IsOnline = onlineLayer.IsOnline;
                            nl.IsShared = onlineLayer.IsShared;
                        }
                        parent.Children.Add(nl);
                    }
                }

                var gl = layer as GroupLayer;
                if (gl == null) return;
                foreach (var cl in gl.ChildLayers.OrderBy(l => l.ID))
                {
                    //sLayer sl = new sLayer() {Layer = cl};
                    //nl.Children.Add(sl);
                    ParseLayers(cl, ref nl, relativePath + "\\" + cl.ID);
                }

                var children = layer as ILayerWithMoreChildren;
                if (children != null)
                {
                    foreach (var cl in children.Children.OrderBy(l => l.ID))
                    {
                        //sLayer sl = new sLayer() {Layer = cl};
                        //nl.Children.Add(sl);
                        ParseLayers(cl, ref nl, relativePath + "\\" + cl.ID);
                    }
                }
                gl.ChildLayers.CollectionChanged -= MakeDirty;
                gl.ChildLayers.CollectionChanged += MakeDirty;
            }
            catch (Exception e)
            {
                LogCs.LogException("ParseLayer", e);
            }
        }