Skip to content

Commit

Permalink
#109: Embed appdef json into mrl viewer template
Browse files Browse the repository at this point in the history
  • Loading branch information
jumpinjackie committed Oct 21, 2021
1 parent ad2dccf commit dd35fee
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 21 deletions.
13 changes: 4 additions & 9 deletions Maestro.Editors/Fusion/MapEditors/XYZEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,14 @@

#endregion Disclaimer / License

using Maestro.Editors.Generic;
using OSGeo.MapGuide.ObjectModels;
using OSGeo.MapGuide.ObjectModels.ApplicationDefinition;
using OSGeo.MapGuide.ObjectModels.TileSetDefinition;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OSGeo.MapGuide.ObjectModels.ApplicationDefinition;
using Maestro.Editors.Generic;
using OSGeo.MapGuide.ObjectModels;
using OSGeo.MapGuide.ObjectModels.TileSetDefinition;
using System.Xml;

namespace Maestro.Editors.Fusion.MapEditors
Expand Down
2 changes: 2 additions & 0 deletions Maestro.MapPublisher.Common/MapViewerModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class MapViewerModel

public ViewerOptionsBase ViewerOptions { get; set; }

public dynamic Meta { get; set; }

public bool HasExternalBaseLayer(ExternalBaseLayerType type)
=> ExternalBaseLayers.Any(ebl => ebl.Type == type);

Expand Down
33 changes: 22 additions & 11 deletions Maestro.MapPublisher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@
using OSGeo.MapGuide.ObjectModels.ApplicationDefinition;
using OSGeo.MapGuide.ObjectModels.Json;
using RazorEngine;
using RazorEngine.Configuration;
using RazorEngine.Templating;
using RazorEngine.Text;
using System;
using System.Dynamic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -128,7 +131,8 @@ static async Task<int> Run(object arg)
ViewerOptions = pubOpts.ViewerOptions,
LatLngBounds = new [] { bounds.MinX, bounds.MinY, bounds.MaxX, bounds.MaxY },
ExternalBaseLayers = pubOpts.ExternalBaseLayers,
OverlayLayers = pubOpts.OverlayLayers
OverlayLayers = pubOpts.OverlayLayers,
Meta = new ExpandoObject()
};

var agent = pubOpts.Title;
Expand Down Expand Up @@ -166,10 +170,13 @@ static async Task<int> Run(object arg)
case ViewerType.MapGuideReactLayout:
{
var appDef = Utility.CreateFlexibleLayout(pubOpts.Connection, ((MapGuideReactLayoutViewerOptions)pubOpts.ViewerOptions).TemplateName);
InitAppDef(appDef, pubOpts);
var json = AppDefJsonSerializer.Serialize(appDef);
InitAppDef(appDef, pubOpts, vm);
vm.Meta.AppDefJson = AppDefJsonSerializer.Serialize(appDef);
string template = File.ReadAllText("viewer_content/viewer_mrl.cshtml");
result = Engine.Razor.RunCompile(template, "templateKey", null, vm);
var config = new TemplateServiceConfiguration();
config.EncodedStringFactory = new RawStringFactory();
var service = RazorEngineService.Create(config);
result = service.RunCompile(template, "templateKey", null, vm);
}
break;
default:
Expand Down Expand Up @@ -239,7 +246,7 @@ static async Task<int> Run(object arg)
}
}

static void InitAppDef(IApplicationDefinition appDef, IStaticMapPublishingOptions pubOpts)
static void InitAppDef(IApplicationDefinition appDef, IStaticMapPublishingOptions pubOpts, MapViewerModel vm)
{
appDef.Title = pubOpts.Title;
//Clear groups
Expand All @@ -257,24 +264,28 @@ static void InitAppDef(IApplicationDefinition appDef, IStaticMapPublishingOption
var ble = mg.CreateCmsMapEntry(bl.Type.ToString(), false, bl.Name, bl.Type.ToString());
if (bl.Type == ExternalBaseLayerType.XYZ)
{
ble.SetValue("Foo", "Bar");
ble.SetXYZUrls(((XYZBaseLayer)bl).UrlTemplate);
}
else if (bl.Type == ExternalBaseLayerType.BingMaps)
{

var bs = (BingMapsBaseLayer)bl;
appDef.SetValue("BingMapsKey", bs.ApiKey);
}
mg.AddMap(ble);
}

//Add UTFGrid layer (if set)
if (pubOpts.UTFGridTileSet != null)
if (!string.IsNullOrEmpty(vm.UTFGridUrl))
{

var ug = mg.CreateUTFGridEntry(vm.UTFGridUrl);
mg.AddMap(ug);
}

//Add XYZ layer (if set)
if (pubOpts.ImageTileSet != null)
if (!string.IsNullOrEmpty(vm.XYZImageUrl))
{

var xyz = mg.CreateCmsMapEntry("XYZ", false, "XYZ tile set" /* TODO: Configurable layer name */, "XYZ");
xyz.SetXYZUrls(vm.XYZImageUrl);
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion Maestro.MapPublisher/viewer_content/viewer_mrl.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@
<script type="text/javascript">
var el = document.getElementById("map");
var viewer = new MapGuide.Application();
var appDef = @(Model.Meta.AppDefJson);
viewer.mount(el, {
layout: "@(((MapGuideReactLayoutViewerOptions)Model.ViewerOptions).TemplateName)",
mapguide: {
agentUri: "@(Model.MapAgent)"
}
},
resourceId: () => Promise.resolve(appDef)
});
</script>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,13 @@ public interface IMapGroup : IExtensibleElement, INotifyPropertyChanged
/// <returns></returns>
IMap CreateCmsMapEntry(string type, bool singleTile, string name, string olType);

/// <summary>
/// Creates a UTFGrid tileset entry
/// </summary>
/// <param name="tileSet"></param>
/// <returns></returns>
IMap CreateUTFGridEntry(string tileSet);

/// <summary>
/// Creates a generic map entry
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,20 @@ IMap IMapGroup.CreateGenericEntry()
return map;
}

IMap IMapGroup.CreateUTFGridEntry(string tileSet)
{
var el = AppDefDocument.Instance.CreateElement("UrlTemplate"); //NOXLATE
el.InnerText = tileSet;
return new MapType()
{
Extension = new CustomContentType()
{
Any = new XmlElement[] { el }
},
Type = "UTFGrid" //NOXLATE
};
}

IMap IMapGroup.CreateCmsMapEntry(string type, bool singleTile, string name, string olType)
{
var el = AppDefDocument.Instance.CreateElement("Options"); //NOXLATE
Expand Down

0 comments on commit dd35fee

Please sign in to comment.