Exemplo n.º 1
0
        /// <summary>
        /// Initializes this map viewer and constructs the user interface based on the
        /// given AppLayout document
        /// </summary>
        /// <param name="layout"></param>
        /// <param name="provider"></param>
        public void Initialize(AppLayout layout, MgMapViewerProvider provider)
        {
            this.Text = layout.Title;

            if (!string.IsNullOrEmpty(layout.Language))
            {
                try
                {
                    var ci = CultureInfo.GetCultureInfo(layout.Language);
                    System.Threading.Thread.CurrentThread.CurrentUICulture 
                        = System.Threading.Thread.CurrentThread.CurrentCulture
                        = ci;
                    SetLanguage(ci);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, Strings.SetLanguage);
                }
            }

            _menuInvoker = new MgMenuItemComponentInvoker();
            _toolInvoker = new MgToolButtonComponentInvoker();

            ValidateMapNames(layout);

            InitializeComponentSet(layout);
            InitializeMenu(layout.Menu);
            InitializeToolbar(layout.Toolbar);
            InitializeContextMenu(layout.ContextMenu);
            InitializeTaskPaneMenu(layout.TaskPane.TaskMenu);

            _layout = layout;
            if (!string.IsNullOrEmpty(_layout.Icon) && System.IO.File.Exists(_layout.Icon))
            {
                this.Icon = new System.Drawing.Icon(_layout.Icon);
            }

            SetInfoPaneWidth(_layout.InfoPane.Width);
            SetInfoPaneVisible(_layout.InfoPane.IsVisible);
            if (_layout.InfoPane.IsVisible)
            {
                SetLegendVisbility(_layout.InfoPane.Legend.Visible);
                legend.ShowTooltips = _layout.InfoPane.Legend.ShowTooltips;
                if (_layout.InfoPane.Legend.ThemeCompressionLimit.HasValue)
                    legend.ThemeCompressionLimit = _layout.InfoPane.Legend.ThemeCompressionLimit.Value;
                SetPropertyPaneVisbility(_layout.InfoPane.PropertyPane.Visible);
            }
            SetTaskPaneWidth(_layout.TaskPane.Width);
            if (!string.IsNullOrEmpty(_layout.TaskPane.InitialComponentID))
            {
                var cmp = GetComponent(_layout.TaskPane.InitialComponentID) as MgViewerComponent;
                if (cmp != null)
                    taskPane.SetInitialComponent(cmp);
                else
                    MessageBox.Show(string.Format(Strings.WarnInitialTaskComponentNotFound, _layout.TaskPane.InitialComponentID));
            }

            _provider = provider;
            mapViewer.PropertyChanged += new PropertyChangedEventHandler(OnMapViewerPropertyChanged);
        }
Exemplo n.º 2
0
        const string RESERVED_CHARS = "\\:*?\"<>|&'%=/"; //NOXLATE

        private static void ValidateMapNames(AppLayout layout)
        {
            string mapName = layout.Map.Name;

            if (mapName.Contains(" ")) //NOXLATE
            {
                throw new InvalidOperationException(string.Format(Strings.ErrorInvalidMapName, mapName));
            }

            foreach (char c in mapName)
            {
                if (RESERVED_CHARS.IndexOf(c) >= 0)
                {
                    throw new InvalidOperationException(string.Format(Strings.ErrorInvalidMapName, mapName));
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Creates a default AppLayout based on the given map definition
 /// </summary>
 /// <param name="title"></param>
 /// <param name="mapDefinition"></param>
 /// <returns></returns>
 public static AppLayout CreateDefault(string title, string mapDefinition)
 {
     var layout = new AppLayout();
     layout.Title = title;
     layout.Settings = new List<NameValue>()
     {
         new NameValue() { Name = "ConvertTiledGroupsToNonTiled", Value = "true" }, //NOXLATE
         new NameValue() { Name = "UseRenderMap", Value = "true" }, //NOXLATE
         new NameValue() { Name = "SelectionColor", Value = "color:" + Util.ToHtmlColorWithAlpha(System.Drawing.Color.Blue) }, //NOXLATE
         new NameValue() { Name = "ShowVertexCoordinatesWhenDigitizing", Value = "true" }, //NOXLATE
         new NameValue() { Name = "ZoomInFactor", Value = "0.5" }, //NOXLATE
         new NameValue() { Name = "ZoomOutFactor", Value = "2.0" }, //NOXLATE
         new NameValue() { Name = "PointPixelBuffer", Value = "3" } //NOXLATE
     };
     layout.InfoPane = new InfoPaneSettings()
     {
         Legend = new LegendSettings() 
         {
             Visible = true,
             ThemeCompressionLimit = 25
         },
         PropertyPane = new PropertyPaneSettings() 
         {
             Visible = true
         },
         Width = 200
     };
     layout.Map = new MapReference()
     {
         MapDefinition = mapDefinition
     };
     layout.Menu = new MenuDefinition()
     {
         Items = new List<ItemBase>()
         {
             new SubMenu(Strings.MenuFile) 
             {
                 Items = new List<ItemBase>()
                 {
                     new CommandItem("LoadMap"), //NOXLATE
                     new CommandItem("LoadPackage"), //NOXLATE
                     new SeparatorItem(),
                     new CommandItem("Quit") //NOXLATE
                 }
             },
             new SubMenu(Strings.MenuTools)
             {
                 Items = new List<ItemBase>()
                 {
                     new CommandItem("Buffer"), //NOXLATE
                     new CommandItem("Measure"), //NOXLATE
                     new CommandItem("Query"), //NOXLATE
                     new CommandItem("Theme"), //NOXLATE
                     new SeparatorItem(),
                     new CommandItem("ViewerOptions") //NOXLATE
                 }
             }
         }
     };
     layout.Toolbar = new ToolbarDefinition()
     {
         Items = new List<ItemBase>()
         {
             new CommandItem("PrintMap", false), //NOXLATE
             new SeparatorItem(),
             new CommandItem("CopyMap", false), //NOXLATE
             new SeparatorItem(),
             new CommandItem("ZoomIn", false), //NOXLATE
             new CommandItem("ZoomOut", false), //NOXLATE
             new CommandItem("InitialView", false), //NOXLATE
             new SeparatorItem(),
             new CommandItem("ZoomPrev", false), //NOXLATE
             new CommandItem("ZoomNext", false), //NOXLATE
             new SeparatorItem(),
             new CommandItem("Select", false), //NOXLATE
             new CommandItem("SelectRadius", false), //NOXLATE
             new CommandItem("SelectPolygon", false), //NOXLATE
             new CommandItem("Pan", false), //NOXLATE
             new SeparatorItem(),
             new CommandItem("ClearSelection", false), //NOXLATE
             new CommandItem("RefreshMap", false), //NOXLATE
             new SeparatorItem(),
             new CommandItem("TooltipToggle", true), //NOXLATE
             new SeparatorItem(),
             new SubMenu(Strings.MenuTools)
             {
                 Items = new List<ItemBase>()
                 {
                     new CommandItem("Buffer"), //NOXLATE
                     new CommandItem("Measure"), //NOXLATE
                     new CommandItem("Query"), //NOXLATE
                     new CommandItem("Theme"), //NOXLATE
                     new SeparatorItem(),
                     new CommandItem("ViewerOptions") //NOXLATE
                 }
             }
         }
     };
     layout.ContextMenu = new MenuDefinition()
     {
         Items = new List<ItemBase>()
         {
             new CommandItem("RefreshMap"), //NOXLATE
             new SeparatorItem(),
             new CommandItem("ZoomIn"), //NOXLATE
             new CommandItem("ZoomOut"), //NOXLATE
             new CommandItem("ZoomToSelection"), //NOXLATE
             new CommandItem("InitialView"), //NOXLATE
             new SeparatorItem(),
             new CommandItem("Pan"), //NOXLATE
             new CommandItem("Select"), //NOXLATE
             new CommandItem("ClearSelection"), //NOXLATE
             new SeparatorItem(),
             new SubMenu(Strings.MenuTools) 
             {
                 Items = new List<ItemBase>() 
                 {
                     new CommandItem("Buffer"), //NOXLATE
                     new CommandItem("Measure"), //NOXLATE
                     new CommandItem("Query"), //NOXLATE
                     new CommandItem("Theme") //NOXLATE
                 }
             },
             new SeparatorItem(),
             new CommandItem("ViewerOptions"), //NOXLATE
         }
     };
     layout.TaskPane = new TaskPaneDefinition()
     {
         Width = 250,
         TaskMenu = new MenuDefinition()
         {
             Items = new List<ItemBase>()
             {
                 new CommandItem("Buffer"), //NOXLATE
                 new CommandItem("Measure"), //NOXLATE
                 new CommandItem("Query"), //NOXLATE
                 new CommandItem("Theme") //NOXLATE
             }
         }
     };
     layout.Components = new List<ComponentDefinition>()
     {
         new ComponentDefinition()
         {
             ClassName = typeof(Viewer.MgBufferComponent).FullName,
             Assembly = null,
             ComponentID = "Buffer", //NOXLATE
             Properties = new List<NameValue>()
             {
                 new NameValue("DefaultLayerName", "BufferLayer"), //NOXLATE
                 new NameValue("DefaultBufferUnits", "enum:" + typeof(MeasurementUnit).FullName + ":" + MeasurementUnit.Meters.ToString()), //NOXLATE
                 new NameValue("Target", "enum:" + typeof(MgViewerTarget).FullName + ":" + MgViewerTarget.TaskPane), //NOXLATE
                 new NameValue("TaskPane", "taskpane:") //NOXLATE
             }
         },
         new ComponentDefinition(typeof(Viewer.MgCircleSelectComponent).FullName, "SelectRadius"), //NOXLATE
         new ComponentDefinition(typeof(Viewer.MgClearSelectionComponent).FullName, "ClearSelection"), //NOXLATE
         new ComponentDefinition(typeof(Viewer.MgCopyMapComponent).FullName, "CopyMap"), //NOXLATE
         new ComponentDefinition(typeof(Viewer.MgInitialViewComponent).FullName, "InitialView"), //NOXLATE
         new ComponentDefinition(typeof(Viewer.MgLoadMapComponent).FullName, "LoadMap") //NOXLATE
         {
             Properties = new List<NameValue>()
             {
                 new NameValue("MapDefinition", mapDefinition) //NOXLATE
             }
         },
         new ComponentDefinition(typeof(Viewer.MgLoadPackageComponent).FullName, "LoadPackage") //NOXLATE
         {
             Properties = new List<NameValue>()
             {
                 new NameValue("InvokeOnPackageLoad", "component:LoadMap") //NOXLATE
             }
         },
         new ComponentDefinition(typeof(Viewer.MgMeasureComponent).FullName, "Measure") //NOXLATE
         {
             Properties = new List<NameValue>()
             {
                 new NameValue("MeasureMode", "enum:" + typeof(MeasureMode).FullName + ":" + MeasureMode.Line.ToString()), //NOXLATE
                 new NameValue("PreferredUnits", "enum:" + typeof(MeasurementUnit).FullName + ":" + MeasurementUnit.Meters.ToString()), //NOXLATE
                 new NameValue("Target", "enum:" + typeof(MgViewerTarget).FullName + ":" + MgViewerTarget.TaskPane), //NOXLATE
                 new NameValue("TaskPane", "taskpane:") //NOXLATE
             }
         },
         new ComponentDefinition(typeof(Viewer.MgPanComponent).FullName, "Pan"), //NOXLATE
         new ComponentDefinition(typeof(Viewer.MgPolygonSelectComponent).FullName, "SelectPolygon"), //NOXLATE
         new ComponentDefinition(typeof(Viewer.MgPrintComponent).FullName, "PrintMap"), //NOXLATE
         new ComponentDefinition(typeof(Viewer.MgQueryComponent).FullName, "Query") //NOXLATE
         {
             Properties = new List<NameValue>()
             {
                 new NameValue("Target", "enum:" + typeof(MgViewerTarget).FullName + ":" + MgViewerTarget.TaskPane), //NOXLATE
                 new NameValue("TaskPane", "taskpane:") //NOXLATE
             }
         },
         new ComponentDefinition(typeof(Viewer.AppLayoutEngine.MgQuitComponent).FullName, "Quit"), //NOXLATE
         new ComponentDefinition(typeof(Viewer.MgRefreshMapComponent).FullName, "RefreshMap"), //NOXLATE
         new ComponentDefinition(typeof(Viewer.MgSelectComponent).FullName, "Select"), //NOXLATE
         new ComponentDefinition(typeof(Viewer.MgThemeComponent).FullName, "Theme") //NOXLATE
         {
             Properties = new List<NameValue>()
             {
                 new NameValue("Target", "enum:" + typeof(MgViewerTarget).FullName + ":" + MgViewerTarget.TaskPane), //NOXLATE
                 new NameValue("TaskPane", "taskpane:") //NOXLATE
             }
         },
         new ComponentDefinition(typeof(Viewer.MgTooltipToggleComponent).FullName, "TooltipToggle"), //NOXLATE
         new ComponentDefinition(typeof(Viewer.MgViewerOptionsComponent).FullName, "ViewerOptions"), //NOXLATE
         new ComponentDefinition(typeof(Viewer.MgZoomInComponent).FullName, "ZoomIn"), //NOXLATE
         new ComponentDefinition(typeof(Viewer.MgZoomNextComponent).FullName, "ZoomNext"), //NOXLATE
         new ComponentDefinition(typeof(Viewer.MgZoomOutComponent).FullName, "ZoomOut"), //NOXLATE
         new ComponentDefinition(typeof(Viewer.MgZoomPreviousComponent).FullName, "ZoomPrev"), //NOXLATE
         new ComponentDefinition(typeof(Viewer.MgZoomToSelectionComponent).FullName, "ZoomToSelection") //NOXLATE
     };
     return layout;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes this map viewer and constructs the user interface based on the
        /// given AppLayout document
        /// </summary>
        /// <param name="layout"></param>
        /// <param name="provider"></param>
        public void Initialize(AppLayout layout, MgMapViewerProvider provider)
        {
            this.Text = layout.Title;

            if (!string.IsNullOrEmpty(layout.Language))
            {
                try
                {
                    var ci = CultureInfo.GetCultureInfo(layout.Language);
                    System.Threading.Thread.CurrentThread.CurrentUICulture
                          = System.Threading.Thread.CurrentThread.CurrentCulture
                          = ci;
                    SetLanguage(ci);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, Strings.SetLanguage);
                }
            }

            _menuInvoker = new MgMenuItemComponentInvoker();
            _toolInvoker = new MgToolButtonComponentInvoker();

            ValidateMapNames(layout);

            InitializeComponentSet(layout);
            InitializeMenu(layout.Menu);
            InitializeToolbar(layout.Toolbar);
            InitializeContextMenu(layout.ContextMenu);
            InitializeTaskPaneMenu(layout.TaskPane.TaskMenu);

            _layout = layout;
            if (!string.IsNullOrEmpty(_layout.Icon) && System.IO.File.Exists(_layout.Icon))
            {
                this.Icon = new System.Drawing.Icon(_layout.Icon);
            }

            SetInfoPaneWidth(_layout.InfoPane.Width);
            SetInfoPaneVisible(_layout.InfoPane.IsVisible);
            if (_layout.InfoPane.IsVisible)
            {
                SetLegendVisbility(_layout.InfoPane.Legend.Visible);
                legend.ShowTooltips = _layout.InfoPane.Legend.ShowTooltips;
                if (_layout.InfoPane.Legend.ThemeCompressionLimit.HasValue)
                {
                    legend.ThemeCompressionLimit = _layout.InfoPane.Legend.ThemeCompressionLimit.Value;
                }
                SetPropertyPaneVisbility(_layout.InfoPane.PropertyPane.Visible);
            }
            SetTaskPaneWidth(_layout.TaskPane.Width);
            if (!string.IsNullOrEmpty(_layout.TaskPane.InitialComponentID))
            {
                var cmp = GetComponent(_layout.TaskPane.InitialComponentID) as MgViewerComponent;
                if (cmp != null)
                {
                    taskPane.SetInitialComponent(cmp);
                }
                else
                {
                    MessageBox.Show(string.Format(Strings.WarnInitialTaskComponentNotFound, _layout.TaskPane.InitialComponentID));
                }
            }

            _provider = provider;
            mapViewer.PropertyChanged += new PropertyChangedEventHandler(OnMapViewerPropertyChanged);
        }
Exemplo n.º 5
0
        private void InitializeComponentSet(AppLayout layout)
        {
            var thisAsm         = this.GetType().Assembly;
            var thisPublicTypes = thisAsm.GetExportedTypes();
            var assemblies      = new Dictionary <string, Assembly>();

            _components = new Dictionary <string, MgComponent>();

            // We do this in 4 passes:
            //
            // 1. Create the components in the component set
            // 2. Then set the properties of the instantiated components
            // 3. Assign the viewer to all these components
            // 4. Set the owner parent and Task Pane of any MgViewerComponent instances to this instance

            // 1st pass
            foreach (var compDef in layout.Components)
            {
                if (compDef.Assembly == null)
                {
                    foreach (var type in thisPublicTypes)
                    {
                        if (type.FullName == compDef.ClassName)
                        {
                            if (_components.ContainsKey(compDef.ComponentID))
                            {
                                throw new InvalidOperationException(string.Format(Strings.ErrorComponentAlreadyExists, compDef.ComponentID));
                            }
                            var comp = (MgComponent)Activator.CreateInstance(type);
                            _components[compDef.ComponentID] = comp;
                            //Override default label if specified
                            if (!string.IsNullOrEmpty(compDef.Label))
                            {
                                comp.Label = compDef.Label;
                            }
                            break;
                        }
                    }
                }
                else
                {
                    if (!assemblies.ContainsKey(compDef.Assembly))
                    {
                        assemblies[compDef.Assembly] = Assembly.LoadFrom(compDef.Assembly);
                    }

                    foreach (var type in assemblies[compDef.Assembly].GetExportedTypes())
                    {
                        if (type.FullName == compDef.ClassName)
                        {
                            if (_components.ContainsKey(compDef.ComponentID))
                            {
                                throw new InvalidOperationException(string.Format(Strings.ErrorComponentAlreadyExists, compDef.ComponentID));
                            }
                            var comp = (MgComponent)Activator.CreateInstance(type);
                            _components[compDef.ComponentID] = comp;
                            break;
                        }
                    }
                }
            }
            //2nd pass
            foreach (var compDef in layout.Components)
            {
                var comp = _components[compDef.ComponentID];
                if (compDef.Properties == null)
                {
                    continue;
                }

                foreach (var prop in compDef.Properties)
                {
                    if (prop.Value.StartsWith(StringPrefixes.MAPDEFINITION))
                    {
                        var mapName = prop.Value.Substring(StringPrefixes.MAPDEFINITION.Length);
                        //TODO: Update for multi-maps if/when we support it
                        if (layout.Map.Name == mapName)
                        {
                            comp.SetPropertyValue(prop.Name, layout.Map.MapDefinition);
                        }
                        else
                        {
                            throw new InvalidOperationException(string.Format(Strings.ErrorMapNotFound, mapName));
                        }
                    }
                    else if (prop.Value.StartsWith(StringPrefixes.COLOR))
                    {
                        var colorStr = prop.Value.Substring(StringPrefixes.COLOR.Length);
                        var color    = Util.FromHtmlColor(colorStr);
                        comp.SetPropertyValue(prop.Name, color);
                    }
                    else if (prop.Value.StartsWith(StringPrefixes.COMPONENTID))
                    {
                        var compID = prop.Value.Substring(StringPrefixes.COMPONENTID.Length);
                        if (!_components.ContainsKey(compID))
                        {
                            throw new InvalidOperationException(string.Format(Strings.ErrorComponentNotFound, compID));
                        }

                        comp.SetPropertyValue(prop.Name, _components[compID]);
                    }
                    else if (prop.Value.StartsWith(StringPrefixes.ENUM))
                    {
                        string [] tokens = prop.Value.Split(':'); //NOXLATE
                        if (tokens.Length != 3)
                        {
                            throw new InvalidOperationException(Strings.ErrorMalformedEnumString);
                        }
                        comp.SetPropertyValue(prop.Name, Enum.Parse(Type.GetType(tokens[1]), tokens[2]));
                    }
                    else if (prop.Value.StartsWith(StringPrefixes.STRINGARRAY))
                    {
                        var csvList = prop.Value.Substring(StringPrefixes.STRINGARRAY.Length);
                        var values  = csvList.Split(',');
                        comp.SetPropertyValue(prop.Name, values);
                    }
                    else if (prop.Value.StartsWith(StringPrefixes.TASKPANEID)) //NOTE: only one taskpane instance, but we're checking this as a forward-looking measure
                    {
                        comp.SetPropertyValue(prop.Name, taskPane);
                    }
                    else if (prop.Value.StartsWith(StringPrefixes.VIEWERID)) //NOTE: only one viewer instance, but we're checking this as a forward-looking measure
                    {
                        comp.SetPropertyValue(prop.Name, mapViewer);
                    }
                    else
                    {
                        comp.SetPropertyValue(prop.Name, prop.Value);
                    }
                }
            }

            //Apply viewer properties. We do this here because we want to respect the viewer options component
            //So we apply before the viewer options component gets its chance to
            foreach (var prop in layout.Settings)
            {
                //Special case
                if (prop.Name == "InvokeOnStartup") //NOXLATE
                {
                    _invokeComponentOnStartup = prop.Value.Substring(StringPrefixes.COMPONENTID.Length);
                    continue;
                }

                if (prop.Value.StartsWith(StringPrefixes.MAPDEFINITION))
                {
                    var mapName = prop.Value.Substring(StringPrefixes.MAPDEFINITION.Length);
                    //TODO: Update for multi-maps if/when we support it
                    if (layout.Map.Name == mapName)
                    {
                        mapViewer.SetPropertyValue(prop.Name, layout.Map.MapDefinition);
                    }
                    else
                    {
                        throw new InvalidOperationException(string.Format(Strings.ErrorMapNotFound, mapName));
                    }
                }
                else if (prop.Value.StartsWith(StringPrefixes.COLOR))
                {
                    var colorStr = prop.Value.Substring(StringPrefixes.COLOR.Length);
                    var color    = Util.FromHtmlColor(colorStr);
                    mapViewer.SetPropertyValue(prop.Name, color);
                }
                else if (prop.Value.StartsWith(StringPrefixes.COMPONENTID))
                {
                    var compID = prop.Value.Substring(StringPrefixes.COMPONENTID.Length);
                    if (!_components.ContainsKey(compID))
                    {
                        throw new InvalidOperationException(string.Format(Strings.ErrorComponentNotFound, compID));
                    }

                    mapViewer.SetPropertyValue(prop.Name, _components[compID]);
                }
                else if (prop.Value.StartsWith(StringPrefixes.ENUM))
                {
                    string[] tokens = prop.Value.Split(':'); //NOXLATE
                    if (tokens.Length != 3)
                    {
                        throw new InvalidOperationException(Strings.ErrorMalformedEnumString);
                    }
                    mapViewer.SetPropertyValue(prop.Name, Enum.Parse(Type.GetType(tokens[1]), tokens[2]));
                }
                else if (prop.Value.StartsWith(StringPrefixes.TASKPANEID)) //NOTE: only one taskpane instance, but we're checking this as a forward-looking measure
                {
                    mapViewer.SetPropertyValue(prop.Name, taskPane);
                }
                else if (prop.Value.StartsWith(StringPrefixes.VIEWERID)) //NOTE: only one viewer instance, but we're checking this as a forward-looking measure
                {
                    mapViewer.SetPropertyValue(prop.Name, mapViewer);
                }
                else
                {
                    mapViewer.SetPropertyValue(prop.Name, prop.Value);
                }
            }

            //3rd pass
            foreach (var compDef in layout.Components)
            {
                _components[compDef.ComponentID].Viewer = mapViewer;
            }

            //4th pass, set the owner parent and Task Pane of any MgViewerComponent instances
            //to this instance
            foreach (var comp in _components.Values)
            {
                var vc = comp as MgViewerComponent;
                if (vc != null)
                {
                    vc.OwnerParent = this;
                    if (vc.Target == MgViewerTarget.TaskPane)
                    {
                        vc.TaskPane = taskPane;
                    }
                }
            }
        }
Exemplo n.º 6
0
        private void InitializeComponentSet(AppLayout layout)
        {
            var thisAsm = this.GetType().Assembly;
            var thisPublicTypes = thisAsm.GetExportedTypes();
            var assemblies = new Dictionary<string, Assembly>();
            _components = new Dictionary<string, MgComponent>();

            // We do this in 4 passes:
            //
            // 1. Create the components in the component set
            // 2. Then set the properties of the instantiated components
            // 3. Assign the viewer to all these components
            // 4. Set the owner parent and Task Pane of any MgViewerComponent instances to this instance

            // 1st pass
            foreach (var compDef in layout.Components)
            {
                if (compDef.Assembly == null)
                {
                    foreach (var type in thisPublicTypes)
                    {
                        if (type.FullName == compDef.ClassName)
                        {
                            if (_components.ContainsKey(compDef.ComponentID))
                                throw new InvalidOperationException(string.Format(Strings.ErrorComponentAlreadyExists, compDef.ComponentID));
                            var comp = (MgComponent)Activator.CreateInstance(type);
                            _components[compDef.ComponentID] = comp;
                            //Override default label if specified
                            if (!string.IsNullOrEmpty(compDef.Label))
                                comp.Label = compDef.Label;
                            break;
                        }
                    }
                }
                else
                {
                    if (!assemblies.ContainsKey(compDef.Assembly))
                    {
                        assemblies[compDef.Assembly] = Assembly.LoadFrom(compDef.Assembly);
                    }

                    foreach (var type in assemblies[compDef.Assembly].GetExportedTypes())
                    {
                        if (type.FullName == compDef.ClassName)
                        {
                            if (_components.ContainsKey(compDef.ComponentID))
                                throw new InvalidOperationException(string.Format(Strings.ErrorComponentAlreadyExists, compDef.ComponentID));
                            var comp = (MgComponent)Activator.CreateInstance(type);
                            _components[compDef.ComponentID] = comp;
                            break;
                        }
                    }
                }
            }
            //2nd pass
            foreach (var compDef in layout.Components)
            {
                var comp = _components[compDef.ComponentID];
                if (compDef.Properties == null)
                    continue;

                foreach (var prop in compDef.Properties)
                {
                    if (prop.Value.StartsWith(StringPrefixes.MAPDEFINITION))
                    {
                        var mapName = prop.Value.Substring(StringPrefixes.MAPDEFINITION.Length);
                        //TODO: Update for multi-maps if/when we support it
                        if (layout.Map.Name == mapName)
                            comp.SetPropertyValue(prop.Name, layout.Map.MapDefinition);
                        else
                            throw new InvalidOperationException(string.Format(Strings.ErrorMapNotFound, mapName));
                    }
                    else if (prop.Value.StartsWith(StringPrefixes.COLOR))
                    {
                        var colorStr = prop.Value.Substring(StringPrefixes.COLOR.Length);
                        var color = Util.FromHtmlColor(colorStr);
                        comp.SetPropertyValue(prop.Name, color);
                    }
                    else if (prop.Value.StartsWith(StringPrefixes.COMPONENTID))
                    {
                        var compID = prop.Value.Substring(StringPrefixes.COMPONENTID.Length);
                        if (!_components.ContainsKey(compID))
                            throw new InvalidOperationException(string.Format(Strings.ErrorComponentNotFound, compID));

                        comp.SetPropertyValue(prop.Name, _components[compID]);
                    }
                    else if (prop.Value.StartsWith(StringPrefixes.ENUM))
                    {
                        string [] tokens = prop.Value.Split(':'); //NOXLATE
                        if (tokens.Length != 3)
                            throw new InvalidOperationException(Strings.ErrorMalformedEnumString);
                        comp.SetPropertyValue(prop.Name, Enum.Parse(Type.GetType(tokens[1]), tokens[2]));
                    }
                    else if (prop.Value.StartsWith(StringPrefixes.STRINGARRAY))
                    {
                        var csvList = prop.Value.Substring(StringPrefixes.STRINGARRAY.Length);
                        var values = csvList.Split(',');
                        comp.SetPropertyValue(prop.Name, values);
                    }
                    else if (prop.Value.StartsWith(StringPrefixes.TASKPANEID)) //NOTE: only one taskpane instance, but we're checking this as a forward-looking measure
                    {
                        comp.SetPropertyValue(prop.Name, taskPane);
                    }
                    else if (prop.Value.StartsWith(StringPrefixes.VIEWERID)) //NOTE: only one viewer instance, but we're checking this as a forward-looking measure
                    {
                        comp.SetPropertyValue(prop.Name, mapViewer);
                    }
                    else
                    {
                        comp.SetPropertyValue(prop.Name, prop.Value);
                    }
                }
            }

            //Apply viewer properties. We do this here because we want to respect the viewer options component
            //So we apply before the viewer options component gets its chance to
            foreach (var prop in layout.Settings)
            {
                //Special case
                if (prop.Name == "InvokeOnStartup") //NOXLATE
                {
                    _invokeComponentOnStartup = prop.Value.Substring(StringPrefixes.COMPONENTID.Length);
                    continue;
                }

                if (prop.Value.StartsWith(StringPrefixes.MAPDEFINITION))
                {
                    var mapName = prop.Value.Substring(StringPrefixes.MAPDEFINITION.Length);
                    //TODO: Update for multi-maps if/when we support it
                    if (layout.Map.Name == mapName)
                        mapViewer.SetPropertyValue(prop.Name, layout.Map.MapDefinition);
                    else
                        throw new InvalidOperationException(string.Format(Strings.ErrorMapNotFound, mapName));
                }
                else if (prop.Value.StartsWith(StringPrefixes.COLOR))
                {
                    var colorStr = prop.Value.Substring(StringPrefixes.COLOR.Length);
                    var color = Util.FromHtmlColor(colorStr);
                    mapViewer.SetPropertyValue(prop.Name, color);
                }
                else if (prop.Value.StartsWith(StringPrefixes.COMPONENTID))
                {
                    var compID = prop.Value.Substring(StringPrefixes.COMPONENTID.Length);
                    if (!_components.ContainsKey(compID))
                        throw new InvalidOperationException(string.Format(Strings.ErrorComponentNotFound, compID));

                    mapViewer.SetPropertyValue(prop.Name, _components[compID]);
                }
                else if (prop.Value.StartsWith(StringPrefixes.ENUM))
                {
                    string[] tokens = prop.Value.Split(':'); //NOXLATE
                    if (tokens.Length != 3)
                        throw new InvalidOperationException(Strings.ErrorMalformedEnumString);
                    mapViewer.SetPropertyValue(prop.Name, Enum.Parse(Type.GetType(tokens[1]), tokens[2]));
                }
                else if (prop.Value.StartsWith(StringPrefixes.TASKPANEID)) //NOTE: only one taskpane instance, but we're checking this as a forward-looking measure
                {
                    mapViewer.SetPropertyValue(prop.Name, taskPane);
                }
                else if (prop.Value.StartsWith(StringPrefixes.VIEWERID)) //NOTE: only one viewer instance, but we're checking this as a forward-looking measure
                {
                    mapViewer.SetPropertyValue(prop.Name, mapViewer);
                }
                else
                {
                    mapViewer.SetPropertyValue(prop.Name, prop.Value);
                }
            }

            //3rd pass
            foreach (var compDef in layout.Components)
            {
                _components[compDef.ComponentID].Viewer = mapViewer;
            }

            //4th pass, set the owner parent and Task Pane of any MgViewerComponent instances
            //to this instance
            foreach (var comp in _components.Values)
            {
                var vc = comp as MgViewerComponent;
                if (vc != null)
                {
                    vc.OwnerParent = this;
                    if (vc.Target == MgViewerTarget.TaskPane)
                        vc.TaskPane = taskPane;
                }
            }
        }
Exemplo n.º 7
0
        const string RESERVED_CHARS = "\\:*?\"<>|&'%=/"; //NOXLATE

        private static void ValidateMapNames(AppLayout layout)
        {
            string mapName = layout.Map.Name;
            if (mapName.Contains(" ")) //NOXLATE
                throw new InvalidOperationException(string.Format(Strings.ErrorInvalidMapName, mapName));

            foreach (char c in mapName)
            {
                if (RESERVED_CHARS.IndexOf(c) >= 0)
                    throw new InvalidOperationException(string.Format(Strings.ErrorInvalidMapName, mapName));
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates a default AppLayout based on the given map definition
        /// </summary>
        /// <param name="title"></param>
        /// <param name="mapDefinition"></param>
        /// <returns></returns>
        public static AppLayout CreateDefault(string title, string mapDefinition)
        {
            var layout = new AppLayout();

            layout.Title    = title;
            layout.Settings = new List <NameValue>()
            {
                new NameValue()
                {
                    Name = "ConvertTiledGroupsToNonTiled", Value = "true"
                },                                                                         //NOXLATE
                new NameValue()
                {
                    Name = "UseRenderMap", Value = "true"
                },                                                         //NOXLATE
                new NameValue()
                {
                    Name = "SelectionColor", Value = "color:" + Util.ToHtmlColorWithAlpha(System.Drawing.Color.Blue)
                },                                                                                                                    //NOXLATE
                new NameValue()
                {
                    Name = "ShowVertexCoordinatesWhenDigitizing", Value = "true"
                },                                                                                //NOXLATE
                new NameValue()
                {
                    Name = "ZoomInFactor", Value = "0.5"
                },                                                        //NOXLATE
                new NameValue()
                {
                    Name = "ZoomOutFactor", Value = "2.0"
                },                                                         //NOXLATE
                new NameValue()
                {
                    Name = "PointPixelBuffer", Value = "3"
                }                                                          //NOXLATE
            };
            layout.InfoPane = new InfoPaneSettings()
            {
                Legend = new LegendSettings()
                {
                    Visible = true,
                    ThemeCompressionLimit = 25
                },
                PropertyPane = new PropertyPaneSettings()
                {
                    Visible = true
                },
                Width = 200
            };
            layout.Map = new MapReference()
            {
                MapDefinition = mapDefinition
            };
            layout.Menu = new MenuDefinition()
            {
                Items = new List <ItemBase>()
                {
                    new SubMenu(Strings.MenuFile)
                    {
                        Items = new List <ItemBase>()
                        {
                            new CommandItem("LoadMap"),     //NOXLATE
                            new CommandItem("LoadPackage"), //NOXLATE
                            new SeparatorItem(),
                            new CommandItem("Quit")         //NOXLATE
                        }
                    },
                    new SubMenu(Strings.MenuTools)
                    {
                        Items = new List <ItemBase>()
                        {
                            new CommandItem("Buffer"),       //NOXLATE
                            new CommandItem("Measure"),      //NOXLATE
                            new CommandItem("Query"),        //NOXLATE
                            new CommandItem("Theme"),        //NOXLATE
                            new SeparatorItem(),
                            new CommandItem("ViewerOptions") //NOXLATE
                        }
                    }
                }
            };
            layout.Toolbar = new ToolbarDefinition()
            {
                Items = new List <ItemBase>()
                {
                    new CommandItem("PrintMap", false),       //NOXLATE
                    new SeparatorItem(),
                    new CommandItem("CopyMap", false),        //NOXLATE
                    new SeparatorItem(),
                    new CommandItem("ZoomIn", false),         //NOXLATE
                    new CommandItem("ZoomOut", false),        //NOXLATE
                    new CommandItem("InitialView", false),    //NOXLATE
                    new SeparatorItem(),
                    new CommandItem("ZoomPrev", false),       //NOXLATE
                    new CommandItem("ZoomNext", false),       //NOXLATE
                    new SeparatorItem(),
                    new CommandItem("Select", false),         //NOXLATE
                    new CommandItem("SelectRadius", false),   //NOXLATE
                    new CommandItem("SelectPolygon", false),  //NOXLATE
                    new CommandItem("Pan", false),            //NOXLATE
                    new SeparatorItem(),
                    new CommandItem("ClearSelection", false), //NOXLATE
                    new CommandItem("RefreshMap", false),     //NOXLATE
                    new SeparatorItem(),
                    new CommandItem("TooltipToggle", true),   //NOXLATE
                    new SeparatorItem(),
                    new SubMenu(Strings.MenuTools)
                    {
                        Items = new List <ItemBase>()
                        {
                            new CommandItem("Buffer"),       //NOXLATE
                            new CommandItem("Measure"),      //NOXLATE
                            new CommandItem("Query"),        //NOXLATE
                            new CommandItem("Theme"),        //NOXLATE
                            new SeparatorItem(),
                            new CommandItem("ViewerOptions") //NOXLATE
                        }
                    }
                }
            };
            layout.ContextMenu = new MenuDefinition()
            {
                Items = new List <ItemBase>()
                {
                    new CommandItem("RefreshMap"),      //NOXLATE
                    new SeparatorItem(),
                    new CommandItem("ZoomIn"),          //NOXLATE
                    new CommandItem("ZoomOut"),         //NOXLATE
                    new CommandItem("ZoomToSelection"), //NOXLATE
                    new CommandItem("InitialView"),     //NOXLATE
                    new SeparatorItem(),
                    new CommandItem("Pan"),             //NOXLATE
                    new CommandItem("Select"),          //NOXLATE
                    new CommandItem("ClearSelection"),  //NOXLATE
                    new SeparatorItem(),
                    new SubMenu(Strings.MenuTools)
                    {
                        Items = new List <ItemBase>()
                        {
                            new CommandItem("Buffer"),  //NOXLATE
                            new CommandItem("Measure"), //NOXLATE
                            new CommandItem("Query"),   //NOXLATE
                            new CommandItem("Theme")    //NOXLATE
                        }
                    },
                    new SeparatorItem(),
                    new CommandItem("ViewerOptions"), //NOXLATE
                }
            };
            layout.TaskPane = new TaskPaneDefinition()
            {
                Width    = 250,
                TaskMenu = new MenuDefinition()
                {
                    Items = new List <ItemBase>()
                    {
                        new CommandItem("Buffer"),  //NOXLATE
                        new CommandItem("Measure"), //NOXLATE
                        new CommandItem("Query"),   //NOXLATE
                        new CommandItem("Theme")    //NOXLATE
                    }
                }
            };
            layout.Components = new List <ComponentDefinition>()
            {
                new ComponentDefinition()
                {
                    ClassName   = typeof(Viewer.MgBufferComponent).FullName,
                    Assembly    = null,
                    ComponentID = "Buffer", //NOXLATE
                    Properties  = new List <NameValue>()
                    {
                        new NameValue("DefaultLayerName", "BufferLayer"),                                                                          //NOXLATE
                        new NameValue("DefaultBufferUnits", "enum:" + typeof(MeasurementUnit).FullName + ":" + MeasurementUnit.Meters.ToString()), //NOXLATE
                        new NameValue("Target", "enum:" + typeof(MgViewerTarget).FullName + ":" + MgViewerTarget.TaskPane),                        //NOXLATE
                        new NameValue("TaskPane", "taskpane:")                                                                                     //NOXLATE
                    }
                },
                new ComponentDefinition(typeof(Viewer.MgCircleSelectComponent).FullName, "SelectRadius"),     //NOXLATE
                new ComponentDefinition(typeof(Viewer.MgClearSelectionComponent).FullName, "ClearSelection"), //NOXLATE
                new ComponentDefinition(typeof(Viewer.MgCopyMapComponent).FullName, "CopyMap"),               //NOXLATE
                new ComponentDefinition(typeof(Viewer.MgInitialViewComponent).FullName, "InitialView"),       //NOXLATE
                new ComponentDefinition(typeof(Viewer.MgLoadMapComponent).FullName, "LoadMap")                //NOXLATE
                {
                    Properties = new List <NameValue>()
                    {
                        new NameValue("MapDefinition", mapDefinition) //NOXLATE
                    }
                },
                new ComponentDefinition(typeof(Viewer.MgLoadPackageComponent).FullName, "LoadPackage") //NOXLATE
                {
                    Properties = new List <NameValue>()
                    {
                        new NameValue("InvokeOnPackageLoad", "component:LoadMap") //NOXLATE
                    }
                },
                new ComponentDefinition(typeof(Viewer.MgMeasureComponent).FullName, "Measure") //NOXLATE
                {
                    Properties = new List <NameValue>()
                    {
                        new NameValue("MeasureMode", "enum:" + typeof(MeasureMode).FullName + ":" + MeasureMode.Line.ToString()),              //NOXLATE
                        new NameValue("PreferredUnits", "enum:" + typeof(MeasurementUnit).FullName + ":" + MeasurementUnit.Meters.ToString()), //NOXLATE
                        new NameValue("Target", "enum:" + typeof(MgViewerTarget).FullName + ":" + MgViewerTarget.TaskPane),                    //NOXLATE
                        new NameValue("TaskPane", "taskpane:")                                                                                 //NOXLATE
                    }
                },
                new ComponentDefinition(typeof(Viewer.MgPanComponent).FullName, "Pan"),                     //NOXLATE
                new ComponentDefinition(typeof(Viewer.MgPolygonSelectComponent).FullName, "SelectPolygon"), //NOXLATE
                new ComponentDefinition(typeof(Viewer.MgPrintComponent).FullName, "PrintMap"),              //NOXLATE
                new ComponentDefinition(typeof(Viewer.MgQueryComponent).FullName, "Query")                  //NOXLATE
                {
                    Properties = new List <NameValue>()
                    {
                        new NameValue("Target", "enum:" + typeof(MgViewerTarget).FullName + ":" + MgViewerTarget.TaskPane), //NOXLATE
                        new NameValue("TaskPane", "taskpane:")                                                              //NOXLATE
                    }
                },
                new ComponentDefinition(typeof(Viewer.AppLayoutEngine.MgQuitComponent).FullName, "Quit"), //NOXLATE
                new ComponentDefinition(typeof(Viewer.MgRefreshMapComponent).FullName, "RefreshMap"),     //NOXLATE
                new ComponentDefinition(typeof(Viewer.MgSelectComponent).FullName, "Select"),             //NOXLATE
                new ComponentDefinition(typeof(Viewer.MgThemeComponent).FullName, "Theme")                //NOXLATE
                {
                    Properties = new List <NameValue>()
                    {
                        new NameValue("Target", "enum:" + typeof(MgViewerTarget).FullName + ":" + MgViewerTarget.TaskPane), //NOXLATE
                        new NameValue("TaskPane", "taskpane:")                                                              //NOXLATE
                    }
                },
                new ComponentDefinition(typeof(Viewer.MgTooltipToggleComponent).FullName, "TooltipToggle"),    //NOXLATE
                new ComponentDefinition(typeof(Viewer.MgViewerOptionsComponent).FullName, "ViewerOptions"),    //NOXLATE
                new ComponentDefinition(typeof(Viewer.MgZoomInComponent).FullName, "ZoomIn"),                  //NOXLATE
                new ComponentDefinition(typeof(Viewer.MgZoomNextComponent).FullName, "ZoomNext"),              //NOXLATE
                new ComponentDefinition(typeof(Viewer.MgZoomOutComponent).FullName, "ZoomOut"),                //NOXLATE
                new ComponentDefinition(typeof(Viewer.MgZoomPreviousComponent).FullName, "ZoomPrev"),          //NOXLATE
                new ComponentDefinition(typeof(Viewer.MgZoomToSelectionComponent).FullName, "ZoomToSelection") //NOXLATE
            };
            return(layout);
        }