Example #1
0
 /// <summary>
 /// Creates the preview flex layout.
 /// </summary>
 /// <param name="owner">The owner.</param>
 /// <returns></returns>
 public static IApplicationDefinition CreatePreviewFlexLayout(IServerConnection owner)
 {
     Check.NotNull(owner, "owner"); //NOXLATE
     var appDef = new ApplicationDefinitionType()
     {
         CurrentConnection = owner,
         Title = OSGeo.MapGuide.MaestroAPI.Strings.TitlePreview,
         MapSet = new System.ComponentModel.BindingList<MapGroupType>(),
         WidgetSet = new System.ComponentModel.BindingList<WidgetSetType>()
     };
     appDef.TemplateUrl = "fusion/templates/mapguide/preview/index.html"; //NOXLATE
     return appDef;
 }
Example #2
0
        /// <summary>
        /// Creates a fusion flexible layout
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="templateName">The name of the template. See <see cref="FusionTemplateNames"/> for the common pre-defined names</param>
        /// <returns></returns>
        public static IApplicationDefinition CreateFlexibleLayout(IServerConnection owner, string templateName)
        {
            Check.NotNull(owner, "owner"); //NOXLATE

            /*
            Check.Precondition(Array.IndexOf(owner.Capabilities.SupportedServices, (int)ServiceType.Fusion) >= 0, "Required Fusion service not supported on this connection");

            var fusionSvc = (IFusionService)owner.GetService((int)ServiceType.Fusion);
            var templates = fusionSvc.GetApplicationTemplates();

            var appDef = DeserializeEmbeddedFlexLayout();
            //Find matching template.
            var tpl = templates.FindTemplate(templateName);
            if (tpl != null)
            {
                appDef.TemplateUrl = tpl.LocationUrl;
                appDef.Title = tpl.Name;
            }
            appDef.CurrentConnection = owner;
            return appDef;
            */

            Check.Precondition(Array.IndexOf(owner.Capabilities.SupportedServices, (int)ServiceType.Fusion) >= 0, "Required Fusion service not supported on this connection");

            IApplicationDefinition appDef = new ApplicationDefinitionType()
            {
                CurrentConnection = owner,
                MapSet = new System.ComponentModel.BindingList<MapGroupType>(),
                WidgetSet = new System.ComponentModel.BindingList<WidgetSetType>()
            };

            var fusionSvc = (IFusionService)owner.GetService((int)ServiceType.Fusion);
            var templates = fusionSvc.GetApplicationTemplates();
            var widgets = fusionSvc.GetApplicationWidgets();
            var containers = fusionSvc.GetApplicationContainers();

            //Find matching template. If it's a known template we should be able to
            //build it programatically, otherwise return a deserialized copy from our
            //embedded resource
            var tpl = templates.FindTemplate(templateName);
            if (tpl != null)
            {
                appDef.TemplateUrl = tpl.LocationUrl;
                appDef.Title = tpl.Name;
            }
            else
            {
                //NOTE: Depending on MapGuide Server version, this document may be
                //invalid (eg. References to widgets not available in that version)
                return DeserializeEmbeddedFlexLayout(owner);
            }

            //Toolbars, every template has them
            var toolbar = appDef.CreateContainer("Toolbar", containers.FindContainer("Toolbar")); //NOXLATE
            var secToolbar = appDef.CreateContainer("ToolbarSecondary", containers.FindContainer("Toolbar")); //NOXLATE
            var vertToolbar = appDef.CreateContainer("ToolbarVertical", containers.FindContainer("Toolbar")); //NOXLATE

            //Context menus, every template has them
            var mapContextMenu = appDef.CreateContainer("MapContextMenu", containers.FindContainer("ContextMenu")); //NOXLATE
            var taskPaneMenu = appDef.CreateContainer("TaskMenu", containers.FindContainer("ContextMenu")); //NOXLATE

            //Menu
            var menu = appDef.CreateContainer("FileMenu", containers.FindContainer("Toolbar")); //NOXLATE

            //Status bar
            var statusbar = appDef.CreateContainer("Statusbar", containers.FindContainer("Splitterbar")); //NOXLATE

            string mapId = "MainMap"; //NOXLATE
            //Set default map group
            appDef.AddMapGroup(mapId, true, string.Empty);

            //Create default widget set
            var widgetSet = appDef.CreateWidgetSet(appDef.CreateMapWidget(mapId, mapContextMenu.Name));
            appDef.AddWidgetSet(widgetSet);

            //Add all known non-parameterized widgets to this widget set
            foreach (var wgt in widgets.WidgetInfo)
            {
                if (Array.IndexOf(parameterizedWidgets, wgt.Type) < 0)
                {
                    var widget = appDef.CreateWidget(wgt.Type, wgt);
                    widgetSet.AddWidget(widget);
                }
            }

            //Add some parameterized ones

            //Zoom In
            var zoomIn = (IUIWidget)appDef.CreateWidget("ZoomIn", widgets.FindWidget(KnownWidgetNames.ZoomOnClick)); //NOXLATE
            zoomIn.SetValue("Factor", "2"); //NOXLATE
            zoomIn.StatusText = zoomIn.Tooltip = Strings.ADF_Widget_ZoomIn_Desc;
            zoomIn.Label = Strings.ADF_Widget_ZoomIn_Label;
            zoomIn.ImageUrl = "images/icons.png"; //NOXLATE
            zoomIn.ImageClass = "zoom-in-fixed"; //NOXLATE
            var vZoomIn = CreateVerticalWidget(zoomIn);

            //Zoom Out
            var zoomOut = (IUIWidget)appDef.CreateWidget("ZoomOut", widgets.FindWidget(KnownWidgetNames.ZoomOnClick)); //NOXLATE
            zoomOut.SetValue("Factor", "0.5"); //NOXLATE
            zoomOut.StatusText = zoomOut.Tooltip = Strings.ADF_Widget_ZoomOut_Desc;
            zoomOut.Label = Strings.ADF_Widget_ZoomOut_Label;
            zoomOut.ImageUrl = "images/icons.png"; //NOXLATE
            zoomOut.ImageClass = "zoom-out-fixed"; //NOXLATE
            var vZoomOut = CreateVerticalWidget(zoomOut);

            //Previous View
            var prevView = (IUIWidget)appDef.CreateWidget("PreviousView", widgets.FindWidget(KnownWidgetNames.ExtentHistory)); //NOXLATE
            prevView.SetValue("Direction", "previous"); //NOXLATE
            prevView.StatusText = prevView.Tooltip = Strings.ADF_Widget_PreviousView_Desc;
            prevView.Label = Strings.ADF_Widget_PreviousView_Label;
            prevView.ImageUrl = "images/icons.png"; //NOXLATE
            prevView.ImageClass = "view-back"; //NOXLATE
            var vPrevView = CreateVerticalWidget(prevView);

            //Next View
            var nextView = (IUIWidget)appDef.CreateWidget("NextView", widgets.FindWidget(KnownWidgetNames.ExtentHistory)); //NOXLATE
            nextView.SetValue("Direction", "next"); //NOXLATE
            nextView.StatusText = nextView.Tooltip = Strings.ADF_Widget_NextView_Desc;
            nextView.Label = Strings.ADF_Widget_NextView_Label;
            nextView.ImageUrl = "images/icons.png"; //NOXLATE
            nextView.ImageClass = "view-forward"; //NOXLATE
            var vNextView = CreateVerticalWidget(nextView);

            //Buffer
            var buffer = (IUIWidget)appDef.CreateWidget("tbBuffer", widgets.FindWidget(KnownWidgetNames.BufferPanel)); //NOXLATE
            //buffer.SetValue("Target", "TaskPane"); //NOXLATE
            buffer.StatusText = buffer.Tooltip = Strings.ADF_Widget_Buffer_Desc;
            buffer.Tooltip = Strings.ADF_Widget_Buffer_Label;

            //Measure
            var measure = (IUIWidget)appDef.CreateWidget("Measure", widgets.FindWidget(KnownWidgetNames.Measure)); //NOXLATE
            var measureParams = new NameValueCollection();
            measureParams["Type"] = "both"; //NOXLATE
            measureParams["MeasureTooltipContainer"] = "MeasureResult"; //NOXLATE
            measureParams["MeasureTooltipType"] = "dynamic"; //NOXLATE
            measureParams["DistancePrecision"] = "0"; //NOXLATE
            measureParams["AreaPrecision"] = "0"; //NOXLATE
            measureParams["Units"] = "meters"; //NOXLATE
            measureParams["Target"] = "TaskPane"; //NOXLATE
            measure.SetAllValues(measureParams);
            measure.StatusText = buffer.Tooltip = Strings.ADF_Widget_Measure_Desc;
            measure.Tooltip = Strings.ADF_Widget_Measure_Label;

            //Show Overview
            var showOverview = (IUIWidget)appDef.CreateWidget("showOverview", widgets.FindWidget(KnownWidgetNames.InvokeScript)); //NOXLATE
            showOverview.Label = "Show Overview"; //NOXLATE
            showOverview.SetValue("Script", "showOverviewMap()"); //NOXLATE

            //Show Task Pane
            var showTaskPane = (IUIWidget)appDef.CreateWidget("showTaskPane", widgets.FindWidget(KnownWidgetNames.InvokeScript)); //NOXLATE
            showTaskPane.Label = "Show Task Pane"; //NOXLATE
            showTaskPane.SetValue("Script", "showTaskPane()"); //NOXLATE

            //Show Legend
            var showLegend = (IUIWidget)appDef.CreateWidget("showLegend", widgets.FindWidget(KnownWidgetNames.InvokeScript)); //NOXLATE
            showLegend.Label = "Show Legend"; //NOXLATE
            showLegend.SetValue("Script", "showLegend()"); //NOXLATE

            //Show Selection Panel
            var showSelectionPanel = (IUIWidget)appDef.CreateWidget("showSelectionPanel", widgets.FindWidget(KnownWidgetNames.InvokeScript)); //NOXLATE
            showSelectionPanel.Label = "Show Selection Panel"; //NOXLATE
            showSelectionPanel.SetValue("Script", "showSelectionPanel()"); //NOXLATE

            //Coordinate Tracker
            var coordTracker = appDef.CreateWidget("statusCoordinates", widgets.FindWidget(KnownWidgetNames.CursorPosition)); //NOXLATE
            coordTracker.SetValue("Template", "X: {x} {units}, Y: {y} {units}"); //NOXLATE
            coordTracker.SetValue("Precision", "4"); //NOXLATE
            coordTracker.SetValue("EmptyText", "&amp;nbsp;"); //NOXLATE

            //Selection Info
            var selInfo = appDef.CreateWidget("statusSelection", widgets.FindWidget(KnownWidgetNames.SelectionInfo)); //NOXLATE
            selInfo.SetValue("EmptyText", "No selection"); //NOXLATE

            //View Size
            var viewSize = appDef.CreateWidget("statusViewSize", widgets.FindWidget(KnownWidgetNames.ViewSize)); //NOXLATE
            viewSize.SetValue("Template", "{w} x {h} ({units})"); //NOXLATE
            viewSize.SetValue("Precision", "2"); //NOXLATE

            widgetSet.AddWidget(zoomIn);
            widgetSet.AddWidget(zoomOut);
            widgetSet.AddWidget(prevView);
            widgetSet.AddWidget(nextView);
            widgetSet.AddWidget(buffer);
            widgetSet.AddWidget(measure);
            widgetSet.AddWidget(showOverview);
            widgetSet.AddWidget(showTaskPane);
            widgetSet.AddWidget(showLegend);
            widgetSet.AddWidget(showSelectionPanel);
            widgetSet.AddWidget(coordTracker);
            widgetSet.AddWidget(selInfo);
            widgetSet.AddWidget(viewSize);

            widgetSet.AddWidget(vZoomIn);
            widgetSet.AddWidget(vZoomOut);
            widgetSet.AddWidget(vPrevView);
            widgetSet.AddWidget(vNextView);

            //Now here's where things may diverge completely between templates
            //So let's try for something that is somewhat consistent

            //Init primary toolbar
            toolbar.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.Print));

            //2.2 specific stuff
            if (owner.SiteVersion >= new Version(2, 2))
            {
                toolbar.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.QuickPlot));
            }

            toolbar.AddItem(appDef.CreateSeparator());
            toolbar.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.RefreshMap));
            //2.4 requires maptips to be a toggle widget
            if (owner.SiteVersion >= VER_240)
            {
                toolbar.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.Maptip));
            }
            toolbar.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.SelectRadius));
            toolbar.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.SelectPolygon));
            toolbar.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.ClearSelection));

            toolbar.AddItem(appDef.CreateWidgetReference(buffer.Name));
            toolbar.AddItem(appDef.CreateWidgetReference(measure.Name));

            //2.2 specific stuff
            if (owner.SiteVersion >= new Version(2, 2))
            {
                toolbar.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.FeatureInfo));
                toolbar.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.Query));
                toolbar.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.Theme));
                toolbar.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.Redline));
            }

            toolbar.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.ViewOptions));
            toolbar.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.About));
            toolbar.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.Help));

            //Init secondary toolbar
            secToolbar.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.Select));
            secToolbar.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.Pan));
            secToolbar.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.Zoom));
            secToolbar.AddItem(appDef.CreateWidgetReference(zoomIn.Name));
            secToolbar.AddItem(appDef.CreateWidgetReference(zoomOut.Name));
            secToolbar.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.InitialMapView));
            secToolbar.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.ZoomToSelection));
            secToolbar.AddItem(appDef.CreateWidgetReference(prevView.Name));
            secToolbar.AddItem(appDef.CreateWidgetReference(nextView.Name));

            //Init vertical toolbar
            widgetSet.AddWidget(CreateVerticalWidget((IUIWidget)appDef.CreateWidget(KnownWidgetNames.Select, widgets.FindWidget(KnownWidgetNames.Select))));
            widgetSet.AddWidget(CreateVerticalWidget((IUIWidget)appDef.CreateWidget(KnownWidgetNames.Pan, widgets.FindWidget(KnownWidgetNames.Pan))));
            widgetSet.AddWidget(CreateVerticalWidget((IUIWidget)appDef.CreateWidget(KnownWidgetNames.Zoom, widgets.FindWidget(KnownWidgetNames.Zoom))));
            widgetSet.AddWidget(CreateVerticalWidget((IUIWidget)appDef.CreateWidget(KnownWidgetNames.InitialMapView, widgets.FindWidget(KnownWidgetNames.InitialMapView))));
            widgetSet.AddWidget(CreateVerticalWidget((IUIWidget)appDef.CreateWidget(KnownWidgetNames.ZoomToSelection, widgets.FindWidget(KnownWidgetNames.ZoomToSelection))));

            vertToolbar.AddItem(appDef.CreateWidgetReference("vert" + KnownWidgetNames.Select)); //NOXLATE
            vertToolbar.AddItem(appDef.CreateWidgetReference("vert" + KnownWidgetNames.Pan)); //NOXLATE
            vertToolbar.AddItem(appDef.CreateWidgetReference("vert" + KnownWidgetNames.Zoom)); //NOXLATE
            vertToolbar.AddItem(appDef.CreateWidgetReference(vZoomIn.Name));
            vertToolbar.AddItem(appDef.CreateWidgetReference(vZoomOut.Name));
            vertToolbar.AddItem(appDef.CreateWidgetReference("vert" + KnownWidgetNames.InitialMapView)); //NOXLATE
            vertToolbar.AddItem(appDef.CreateWidgetReference("vert" + KnownWidgetNames.ZoomToSelection)); //NOXLATE
            vertToolbar.AddItem(appDef.CreateWidgetReference(vPrevView.Name));
            vertToolbar.AddItem(appDef.CreateWidgetReference(vNextView.Name));

            //Main menu
            menu.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.MapMenu));

            //2.2 specific stuff
            if (owner.SiteVersion >= new Version(2, 2))
            {
                menu.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.BasemapSwitcher));
            }
            var viewMenu = appDef.CreateFlyout(Strings.ADF_Flyout_View);
            viewMenu.AddItem(appDef.CreateWidgetReference(showOverview.Name));
            viewMenu.AddItem(appDef.CreateWidgetReference(showTaskPane.Name));
            viewMenu.AddItem(appDef.CreateWidgetReference(showLegend.Name));
            viewMenu.AddItem(appDef.CreateWidgetReference(showSelectionPanel.Name));
            menu.AddItem(viewMenu);

            //status bar
            statusbar.AddItem(appDef.CreateWidgetReference(coordTracker.Name));
            statusbar.AddItem(appDef.CreateWidgetReference(selInfo.Name));
            statusbar.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.EditableScale));
            statusbar.AddItem(appDef.CreateWidgetReference(viewSize.Name));

            //Map Context Menu
            mapContextMenu.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.RefreshMap));
            mapContextMenu.AddItem(appDef.CreateSeparator());
            mapContextMenu.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.Pan));
            mapContextMenu.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.Zoom));
            mapContextMenu.AddItem(appDef.CreateSeparator());
            mapContextMenu.AddItem(appDef.CreateWidgetReference(zoomIn.Name));
            mapContextMenu.AddItem(appDef.CreateWidgetReference(zoomOut.Name));
            mapContextMenu.AddItem(appDef.CreateSeparator());
            var zoomMenu = appDef.CreateFlyout(Strings.ADF_Flyout_Zoom);

            mapContextMenu.AddItem(zoomMenu);
            mapContextMenu.AddItem(appDef.CreateSeparator());
            mapContextMenu.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.Select));
            mapContextMenu.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.ClearSelection));
            var selectMoreMenu = appDef.CreateFlyout(Strings.ADF_Flyout_SelectMore);

            mapContextMenu.AddItem(selectMoreMenu);
            mapContextMenu.AddItem(appDef.CreateSeparator());
            mapContextMenu.AddItem(appDef.CreateWidgetReference(buffer.Name));
            mapContextMenu.AddItem(appDef.CreateWidgetReference(measure.Name));

            if (owner.SiteVersion >= new Version(2, 2))
            {
                mapContextMenu.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.FeatureInfo));
                mapContextMenu.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.Query));
                mapContextMenu.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.Theme));
                mapContextMenu.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.Redline));
            }

            mapContextMenu.AddItem(appDef.CreateSeparator());
            mapContextMenu.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.ViewOptions));
            mapContextMenu.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.Help));
            mapContextMenu.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.About));

            //Tasks Context Menu
            taskPaneMenu.AddItem(appDef.CreateWidgetReference(measure.Name));
            taskPaneMenu.AddItem(appDef.CreateWidgetReference(buffer.Name));

            if (owner.SiteVersion >= new Version(2, 2))
            {
                taskPaneMenu.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.FeatureInfo));
                taskPaneMenu.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.Query));
                taskPaneMenu.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.Theme));
                taskPaneMenu.AddItem(appDef.CreateWidgetReference(KnownWidgetNames.Redline));
            }

            //Now add them all to the main widget set
            widgetSet.AddContainer(toolbar);
            widgetSet.AddContainer(secToolbar);
            widgetSet.AddContainer(vertToolbar);
            widgetSet.AddContainer(menu);
            widgetSet.AddContainer(statusbar);
            widgetSet.AddContainer(mapContextMenu);
            widgetSet.AddContainer(taskPaneMenu);

            //Set positioning
            toolbar.Position = "top"; //NOXLATE
            secToolbar.Position = "top"; //NOXLATE
            menu.Position = "top"; //NOXLATE
            statusbar.Position = "bottom"; //NOXLATE
            mapContextMenu.Position = "top"; //NOXLATE
            taskPaneMenu.Position = "top"; //NOXLATE
            vertToolbar.Position = "left"; //NOXLATE

            return appDef;
        }
 public static bool LoadFromFile(string fileName, out ApplicationDefinitionType obj) {
     System.Exception exception = null;
     return LoadFromFile(fileName, out obj, out exception);
 }
 /// <summary>
 /// Deserializes xml markup from file into an ApplicationDefinitionType object
 /// </summary>
 /// <param name="fileName">string xml file to load and deserialize</param>
 /// <param name="obj">Output ApplicationDefinitionType object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool LoadFromFile(string fileName, out ApplicationDefinitionType obj, out System.Exception exception) {
     exception = null;
     obj = default(ApplicationDefinitionType);
     try {
         obj = LoadFromFile(fileName);
         return true;
     }
     catch (System.Exception ex) {
         exception = ex;
         return false;
     }
 }
 public static bool Deserialize(string xml, out ApplicationDefinitionType obj) {
     System.Exception exception = null;
     return Deserialize(xml, out obj, out exception);
 }
 /// <summary>
 /// Deserializes workflow markup into an ApplicationDefinitionType object
 /// </summary>
 /// <param name="xml">string workflow markup to deserialize</param>
 /// <param name="obj">Output ApplicationDefinitionType object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool Deserialize(string xml, out ApplicationDefinitionType obj, out System.Exception exception) {
     exception = null;
     obj = default(ApplicationDefinitionType);
     try {
         obj = Deserialize(xml);
         return true;
     }
     catch (System.Exception ex) {
         exception = ex;
         return false;
     }
 }