[mapguide-commits] r6816 - in trunk/Tools/Maestro: OSGeo.MapGuide.MaestroAPI/Mapping OSGeo.MapGuide.MaestroAPI.Local

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Tue Jun 26 07:22:25 PDT 2012


Author: jng
Date: 2012-06-26 07:22:25 -0700 (Tue, 26 Jun 2012)
New Revision: 6816

Added:
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Local/LocalRuntimeMap.cs
Modified:
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Local/LocalConnection.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Local/OSGeo.MapGuide.MaestroAPI.Local.csproj
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMap.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapGroup.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapLayer.cs
Log:
#2048: First cut of RuntimeMap wrapper for mg-desktop. We can now view mg-desktop maps in the Live Map Editor.

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMap.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMap.cs	2012-06-26 11:58:17 UTC (rev 6815)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMap.cs	2012-06-26 14:22:25 UTC (rev 6816)
@@ -150,7 +150,7 @@
         /// </summary>
         public const double Z_ORDER_TOP = 100.0;
 
-        internal RuntimeMap(IServerConnection conn)
+        protected internal RuntimeMap(IServerConnection conn)
         {
             this.StrictSelection = true;
             _disableChangeTracking = true;
@@ -327,10 +327,10 @@
         /// Gets or sets the map extents.
         /// </summary>
         /// <value>The map extents.</value>
-        public IEnvelope MapExtent
+        public virtual IEnvelope MapExtent
         {
             get;
-            private set;
+            protected set;
         }
         
         /// <summary>
@@ -342,7 +342,7 @@
         /// Gets or sets the data extent.
         /// </summary>
         /// <value>The data extent.</value>
-        public IEnvelope DataExtent
+        public virtual IEnvelope DataExtent
         {
             get
             {
@@ -376,7 +376,7 @@
         /// Gets or sets the display dpi.
         /// </summary>
         /// <value>The display dpi.</value>
-        public int DisplayDpi
+        public virtual int DisplayDpi
         {
             get
             {
@@ -397,7 +397,7 @@
         /// Gets or sets the display height.
         /// </summary>
         /// <value>The display height.</value>
-        public int DisplayHeight
+        public virtual int DisplayHeight
         {
             get
             {
@@ -418,7 +418,7 @@
         /// Gets or sets the display width.
         /// </summary>
         /// <value>The display width.</value>
-        public int DisplayWidth
+        public virtual int DisplayWidth
         {
             get
             {
@@ -434,7 +434,7 @@
         /// Gets or sets the map definition resource id
         /// </summary>
         /// <value>The map definition resource id.</value>
-        public string MapDefinition
+        public virtual string MapDefinition
         {
             get;
             internal set;
@@ -444,7 +444,7 @@
         /// Gets or sets the object id.
         /// </summary>
         /// <value>The object id.</value>
-        public string ObjectId
+        public virtual string ObjectId
         {
             get;
             internal set;
@@ -454,7 +454,7 @@
         /// Gets or sets the session id.
         /// </summary>
         /// <value>The session id.</value>
-        public string SessionId
+        public virtual string SessionId
         {
             get;
             internal set;
@@ -469,7 +469,7 @@
         /// Gets or sets the view center.
         /// </summary>
         /// <value>The view center.</value>
-        public IPoint2D ViewCenter
+        public virtual IPoint2D ViewCenter
         {
             get
             {
@@ -490,7 +490,7 @@
         /// Gets or sets the view scale.
         /// </summary>
         /// <value>The view scale.</value>
-        public double ViewScale
+        public virtual double ViewScale
         {
             get
             {
@@ -526,7 +526,7 @@
         /// Gets or sets the coordinate system in WKT format
         /// </summary>
         /// <value>The coordinate system in WKT format.</value>
-        public string CoordinateSystem
+        public virtual string CoordinateSystem
         {
             get { return _mapSrs; }
             internal set { SetField(ref _mapSrs, value, "CoordinateSystem"); }
@@ -541,7 +541,7 @@
         /// Gets or sets the color of the background.
         /// </summary>
         /// <value>The color of the background.</value>
-        public System.Drawing.Color BackgroundColor
+        public virtual System.Drawing.Color BackgroundColor
         {
             get
             {
@@ -584,7 +584,7 @@
         /// Gets the meters per unit value.
         /// </summary>
         /// <value>The meters per unit.</value>
-        public double MetersPerUnit
+        public virtual double MetersPerUnit
         {
             get;
             internal set;
@@ -593,7 +593,7 @@
         /// <summary>
         /// Gets the watermark usage. Not applicable for version of MapGuide older than 2.3
         /// </summary>
-        public int WatermarkUsage
+        public virtual int WatermarkUsage
         {
             get;
             private set;
@@ -613,7 +613,7 @@
         /// Gets the layer refresh mode.
         /// </summary>
         /// <value>The layer refresh mode.</value>
-        public int LayerRefreshMode
+        public virtual int LayerRefreshMode
         {
             get;
             private set;
@@ -625,7 +625,7 @@
         /// Serializes this instance to the specified binary stream
         /// </summary>
         /// <param name="s"></param>
-        public void Serialize(MgBinarySerializer s)
+        public virtual void Serialize(MgBinarySerializer s)
         {
             if (s.SiteVersion >= SiteVersions.GetVersion(KnownSiteVersions.MapGuideOS1_2))
             {
@@ -777,7 +777,7 @@
         /// Initializes this instance from the specified binary stream
         /// </summary>
         /// <param name="d"></param>
-        public void Deserialize(MgBinaryDeserializer d)
+        public virtual void Deserialize(MgBinaryDeserializer d)
         {
             _disableChangeTracking = true;
 
@@ -945,7 +945,7 @@
         /// Gets the selection set
         /// </summary>
         /// <value>The selection.</value>
-        public MapSelection Selection
+        public virtual MapSelection Selection
         {
             get
             {

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapGroup.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapGroup.cs	2012-06-26 11:58:17 UTC (rev 6815)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapGroup.cs	2012-06-26 14:22:25 UTC (rev 6816)
@@ -49,7 +49,7 @@
         /// </summary>
         /// <param name="map">The map.</param>
         /// <param name="name">The name.</param>
-        internal RuntimeMapGroup(RuntimeMap map, string name) 
+        protected internal RuntimeMapGroup(RuntimeMap map, string name) 
             : this()
         {
             this.Parent = map;
@@ -63,7 +63,7 @@
         /// </summary>
         /// <param name="map">The map.</param>
         /// <param name="group">The group.</param>
-        internal RuntimeMapGroup(RuntimeMap map, IMapLayerGroup group)
+        protected internal RuntimeMapGroup(RuntimeMap map, IMapLayerGroup group)
             : this(map, group.Name)
         {
             _disableChangeTracking = true;
@@ -98,7 +98,7 @@
         /// <summary>
         /// Gets or sets whether this group is visible
         /// </summary>
-        public bool Visible
+        public virtual bool Visible
         {
             get
             {
@@ -115,7 +115,7 @@
         /// <summary>
         /// Gets or sets the name of the parent group
         /// </summary>
-        public string Group
+        public virtual string Group
         {
             get
             {
@@ -141,7 +141,7 @@
         /// <summary>
         /// Gets or sets the name of this group
         /// </summary>
-        public string Name
+        public virtual string Name
         {
             get
             {
@@ -158,7 +158,7 @@
         /// <summary>
         /// Gets or sets whether this group is visible in the legend
         /// </summary>
-        public bool ShowInLegend
+        public virtual bool ShowInLegend
         {
             get
             {
@@ -175,7 +175,7 @@
         /// <summary>
         /// Gets or sets the legend label
         /// </summary>
-        public string LegendLabel
+        public virtual string LegendLabel
         {
             get
             {
@@ -192,7 +192,7 @@
         /// <summary>
         /// Gets or sets whether this group is expanded in the legend
         /// </summary>
-        public bool ExpandInLegend
+        public virtual bool ExpandInLegend
         {
             get
             {
@@ -207,7 +207,7 @@
         /// <summary>
         /// Gets the group type
         /// </summary>
-        public int Type
+        public virtual int Type
         {
             get;
             internal set;
@@ -216,7 +216,7 @@
         /// <summary>
         /// Gets the unique identifier for this group
         /// </summary>
-        public string ObjectId
+        public virtual string ObjectId
         {
             get;
             private set;
@@ -226,7 +226,7 @@
         /// Serializes this instance
         /// </summary>
         /// <param name="s"></param>
-        public void Serialize(MgBinarySerializer s)
+        public virtual void Serialize(MgBinarySerializer s)
         {
             s.Write(this.Group);
             if (s.SiteVersion >= SiteVersions.GetVersion(KnownSiteVersions.MapGuideOS1_2))
@@ -246,7 +246,7 @@
         /// Initialize this instance using the specified binary stream
         /// </summary>
         /// <param name="d"></param>
-        public void Deserialize(MgBinaryDeserializer d)
+        public virtual void Deserialize(MgBinaryDeserializer d)
         {
             this.Group = d.ReadString();
             int objid = d.ReadClassId();

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapLayer.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapLayer.cs	2012-06-26 11:58:17 UTC (rev 6815)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapLayer.cs	2012-06-26 14:22:25 UTC (rev 6816)
@@ -167,7 +167,7 @@
             EnsureOrderedMinMaxScales();
         }
 
-        internal RuntimeMapLayer(RuntimeMap parent) 
+        protected internal RuntimeMapLayer(RuntimeMap parent) 
         {
             _scaleRanges = new double[] { 0.0, InfinityScale };
             _type = kDynamic;
@@ -182,7 +182,7 @@
         /// </summary>
         /// <param name="parent">The parent.</param>
         /// <param name="ldf">The LDF.</param>
-        internal RuntimeMapLayer(RuntimeMap parent, ILayerDefinition ldf)
+        protected internal RuntimeMapLayer(RuntimeMap parent, ILayerDefinition ldf)
             : this(parent)
         {
             _disableChangeTracking = true;
@@ -195,13 +195,13 @@
         /// </summary>
         /// <param name="parent">The parent.</param>
         /// <param name="source">The source.</param>
-        internal RuntimeMapLayer(RuntimeMap parent, IMapLayer source)
+        protected internal RuntimeMapLayer(RuntimeMap parent, IMapLayer source)
             : this(parent, source, (ILayerDefinition)parent.CurrentConnection.ResourceService.GetResource(source.ResourceId))
         {
             _disableChangeTracking = false;
         }
 
-        internal RuntimeMapLayer(RuntimeMap parent, IMapLayer source, ILayerDefinition ldf)
+        protected internal RuntimeMapLayer(RuntimeMap parent, IMapLayer source, ILayerDefinition ldf)
             : this(parent, (IBaseMapLayer)source, ldf)
         {
             _disableChangeTracking = true;
@@ -212,7 +212,7 @@
             _disableChangeTracking = false;
         }
 
-        internal RuntimeMapLayer(RuntimeMap parent, IBaseMapLayer source, ILayerDefinition ldf) 
+        protected internal RuntimeMapLayer(RuntimeMap parent, IBaseMapLayer source, ILayerDefinition ldf) 
             : this(parent, ldf)
         {
             Check.NotNull(source, "source");
@@ -282,7 +282,7 @@
         /// Gets or sets a value indicating whether this <see cref="RuntimeMapLayer"/> is visible.
         /// </summary>
         /// <value><c>true</c> if visible; otherwise, <c>false</c>.</value>
-        public bool Visible
+        public virtual bool Visible
         {
             get
             {
@@ -304,7 +304,7 @@
         /// Gets or sets the group.
         /// </summary>
         /// <value>The group.</value>
-        public string Group
+        public virtual string Group
         {
             get
             {
@@ -321,7 +321,7 @@
         /// Gets the layer definition ID.
         /// </summary>
         /// <value>The layer definition ID.</value>
-        public string LayerDefinitionID
+        public virtual string LayerDefinitionID
         {
             get;
             internal set;
@@ -333,7 +333,7 @@
         /// Gets or sets a value indicating whether this <see cref="RuntimeMapLayer"/> is selectable.
         /// </summary>
         /// <value><c>true</c> if selectable; otherwise, <c>false</c>.</value>
-        public bool Selectable
+        public virtual bool Selectable
         {
             get
             {
@@ -352,7 +352,7 @@
         /// Gets or sets the name.
         /// </summary>
         /// <value>The name.</value>
-        public string Name
+        public virtual string Name
         {
             get
             {
@@ -371,7 +371,7 @@
         /// Gets or sets a value indicating whether [show in legend].
         /// </summary>
         /// <value><c>true</c> if [show in legend]; otherwise, <c>false</c>.</value>
-        public bool ShowInLegend
+        public virtual bool ShowInLegend
         {
             get
             {
@@ -390,7 +390,7 @@
         /// Gets or sets the legend label.
         /// </summary>
         /// <value>The legend label.</value>
-        public string LegendLabel
+        public virtual string LegendLabel
         {
             get
             {
@@ -409,7 +409,7 @@
         /// Gets or sets a value indicating whether [expand in legend].
         /// </summary>
         /// <value><c>true</c> if [expand in legend]; otherwise, <c>false</c>.</value>
-        public bool ExpandInLegend
+        public virtual bool ExpandInLegend
         {
             get
             {
@@ -428,7 +428,7 @@
         /// Gets or sets the feature source ID.
         /// </summary>
         /// <value>The feature source ID.</value>
-        public string FeatureSourceID
+        public virtual string FeatureSourceID
         {
             get { return _featureSourceId; }
             internal set { _featureSourceId = value; }
@@ -440,7 +440,7 @@
         /// Gets the name of the qualified name of the feature class.
         /// </summary>
         /// <value>The name of the qualified name of the feature class.</value>
-        public string QualifiedClassName
+        public virtual string QualifiedClassName
         {
             get { return _qualifiedClassName; }
             internal set { _qualifiedClassName = value; }
@@ -462,7 +462,7 @@
         /// Gets the object id.
         /// </summary>
         /// <value>The object id.</value>
-        public string ObjectId
+        public virtual string ObjectId
         {
             get { return _objectId; }
             internal set { _objectId = value; }
@@ -474,7 +474,7 @@
         /// Gets the name of the geometry property.
         /// </summary>
         /// <value>The name of the geometry property.</value>
-        public string GeometryPropertyName
+        public virtual string GeometryPropertyName
         {
             get { return _geometryPropertyName; }
             private set { _geometryPropertyName = value; }
@@ -486,7 +486,7 @@
         /// Gets the filter.
         /// </summary>
         /// <value>The filter.</value>
-        public string Filter
+        public virtual string Filter
         {
             get { return _filter; }
             internal set { _filter = value; }
@@ -497,7 +497,7 @@
         /// <summary>
         /// Gets the type
         /// </summary>
-        public int Type
+        public virtual int Type
         {
             get { return _type; }
             internal set { _type = value; }
@@ -508,7 +508,7 @@
         /// <summary>
         /// Gets the display order
         /// </summary>
-        public double DisplayOrder
+        public virtual double DisplayOrder
         {
             get { return _displayOrder; }
             internal set { _displayOrder = value; }
@@ -519,7 +519,7 @@
         /// <summary>
         /// Gets whether this layer needs to be refreshed
         /// </summary>
-        public bool NeedsRefresh
+        public virtual bool NeedsRefresh
         {
             get { return _needsRefresh; }
             internal set { _needsRefresh = value; }
@@ -528,7 +528,7 @@
         /// <summary>
         /// Sets the refresh flag for this layer
         /// </summary>
-        public void ForceRefresh()
+        public virtual void ForceRefresh()
         {
             if (!this.IsVisibleAtScale(this.Parent.ViewScale))
                 return;
@@ -541,7 +541,7 @@
         /// <summary>
         /// Gets whether this layer has tooltips
         /// </summary>
-        public bool HasTooltips
+        public virtual bool HasTooltips
         {
             get { return _hasTooltips; }
             internal set { _hasTooltips = value; }
@@ -567,7 +567,7 @@
         /// Serializes this instance to a binary stream
         /// </summary>
         /// <param name="s"></param>
-        public void Serialize(MgBinarySerializer s)
+        public virtual void Serialize(MgBinarySerializer s)
         {
             s.Write(this.Group);
 
@@ -698,7 +698,7 @@
         /// Initializes this instance with the specified binary stream
         /// </summary>
         /// <param name="d"></param>
-        public void Deserialize(MgBinaryDeserializer d)
+        public virtual void Deserialize(MgBinaryDeserializer d)
         {
             this.Group = d.ReadString();
 

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Local/LocalConnection.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Local/LocalConnection.cs	2012-06-26 11:58:17 UTC (rev 6815)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Local/LocalConnection.cs	2012-06-26 14:22:25 UTC (rev 6816)
@@ -42,7 +42,7 @@
                                    IFeatureService,
                                    IResourceService,
                                    ITileService,
-                                   //IMappingService,
+                                   IMappingService,
                                    IDrawingService
     {
         public event EventHandler SessionIDChanged; //Not used
@@ -901,6 +901,7 @@
                 case ServiceType.Feature:
                 case ServiceType.Resource:
                 case ServiceType.Tile:
+                case ServiceType.Mapping:
                     return this;
             }
             throw new UnsupportedServiceTypeException(st);
@@ -1026,5 +1027,192 @@
                 throw exMgd;
             }
         }
+
+        protected override double InferMPU(string csWkt, double units)
+        {
+            return base.InferMPU(csWkt, units);
+        }
+
+        public override Mapping.RuntimeMap CreateMap(string runtimeMapResourceId, ObjectModels.MapDefinition.IMapDefinition mdf, double metersPerUnit)
+        {
+            var mdfId = new MgResourceIdentifier(mdf.ResourceID);
+            var implMap = new MgdMap(mdfId);
+            var map = new LocalRuntimeMap(this, implMap);
+            map.ResourceID = runtimeMapResourceId;
+            return map;
+        }
+
+        public override Mapping.RuntimeMapGroup CreateMapGroup(Mapping.RuntimeMap parent, ObjectModels.MapDefinition.IBaseMapGroup group)
+        {
+            var impl = parent as LocalRuntimeMap;
+            if (impl == null)
+                throw new ArgumentException("Instance is not a LocalRuntimeMap", "map"); //LOCALIZEME
+
+            var rtGroup = new MgLayerGroup(group.Name);
+            rtGroup.DisplayInLegend = group.ShowInLegend;
+            MgdMap.SetGroupExpandInLegend(rtGroup, group.ExpandInLegend);
+            //MgdMap.SetLayerGroupType(rtGroup, MgLayerGroupType.BaseMap);
+            rtGroup.LegendLabel = group.LegendLabel;
+            rtGroup.Visible = group.Visible;
+
+            return new LocalRuntimeMapGroup(impl, rtGroup);
+        }
+
+        public override Mapping.RuntimeMapGroup CreateMapGroup(Mapping.RuntimeMap parent, ObjectModels.MapDefinition.IMapLayerGroup group)
+        {
+            var impl = parent as LocalRuntimeMap;
+            if (impl == null)
+                throw new ArgumentException("Instance is not a LocalRuntimeMap", "map"); //LOCALIZEME
+
+            var rtGroup = new MgLayerGroup(group.Name);
+            rtGroup.DisplayInLegend = group.ShowInLegend;
+            MgdMap.SetGroupExpandInLegend(rtGroup, group.ExpandInLegend);
+            rtGroup.LegendLabel = group.LegendLabel;
+            rtGroup.Visible = group.Visible;
+
+            return new LocalRuntimeMapGroup(impl, rtGroup);
+        }
+
+        public override Mapping.RuntimeMapGroup CreateMapGroup(Mapping.RuntimeMap parent, string name)
+        {
+            var impl = parent as LocalRuntimeMap;
+            if (impl == null)
+                throw new ArgumentException("Instance is not a LocalRuntimeMap", "map"); //LOCALIZEME
+
+            var group = new MgLayerGroup(name);
+            return new LocalRuntimeMapGroup(impl, group);
+        }
+
+        public override Mapping.RuntimeMapLayer CreateMapLayer(Mapping.RuntimeMap parent, ObjectModels.LayerDefinition.ILayerDefinition ldf)
+        {
+            var impl = parent as LocalRuntimeMap;
+            if (impl == null)
+                throw new ArgumentException("Instance is not a LocalRuntimeMap", "map"); //LOCALIZEME
+
+            var ldfId = new MgResourceIdentifier(ldf.ResourceID);
+            var layer = new MgdLayer(ldfId, GetResourceService());
+            return new LocalRuntimeMapLayer(impl, layer);
+        }
+
+        public Stream RenderDynamicOverlay(Mapping.RuntimeMap map, Mapping.MapSelection selection, string format)
+        {
+            return RenderDynamicOverlay(map, selection, format, true);
+        }
+
+        private static MgdSelection Convert(Mapping.MapSelection sel)
+        {
+            if (sel == null)
+                return null;
+
+            MgdSelection impl = new MgdSelection();
+            var xml = sel.ToXml();
+            if (!string.IsNullOrEmpty(xml))
+                impl.FromXml(xml);
+            return impl;
+        }
+
+        public Stream RenderDynamicOverlay(Mapping.RuntimeMap map, Mapping.MapSelection selection, string format, bool keepSelection)
+        {
+            var impl = map as LocalRuntimeMap;
+            if (impl == null)
+                throw new ArgumentException("Instance is not a LocalRuntimeMap", "map"); //LOCALIZEME
+            var renderSvc = GetRenderingService();
+            GetByteReaderMethod fetch = () =>
+            {
+                var sel = Convert(selection);
+                return renderSvc.RenderDynamicOverlay(impl.GetWrappedInstance(), sel, format, keepSelection);
+            };
+            return new MgReadOnlyStream(fetch);
+        }
+
+        public Stream RenderDynamicOverlay(Mapping.RuntimeMap map, Mapping.MapSelection selection, string format, System.Drawing.Color selectionColor, int behaviour)
+        {
+            var impl = map as LocalRuntimeMap;
+            if (impl == null)
+                throw new ArgumentException("Instance is not a LocalRuntimeMap", "map"); //LOCALIZEME
+            var renderSvc = GetRenderingService();
+            GetByteReaderMethod fetch = () =>
+            {
+                var sel = Convert(selection);
+                var opts = new MgRenderingOptions(format, behaviour, new MgColor(selectionColor));
+                return renderSvc.RenderDynamicOverlay(impl.GetWrappedInstance(), sel, opts);
+            };
+            return new MgReadOnlyStream(fetch);
+        }
+
+        public Stream RenderRuntimeMap(string resourceId, double x, double y, double scale, int width, int height, int dpi)
+        {
+            throw new NotImplementedException(); //TODO: Not needed for Live Map Editor, but will have problems when viewer component is used standalone
+        }
+
+        public Stream RenderRuntimeMap(string resourceId, double x1, double y1, double x2, double y2, int width, int height, int dpi)
+        {
+            throw new NotImplementedException(); //TODO: Not needed for Live Map Editor, but will have problems when viewer component is used standalone
+        }
+
+        public Stream RenderRuntimeMap(string resourceId, double x, double y, double scale, int width, int height, int dpi, string format)
+        {
+            throw new NotImplementedException(); //TODO: Not needed for Live Map Editor, but will have problems when viewer component is used standalone
+        }
+
+        public Stream RenderRuntimeMap(string resourceId, double x1, double y1, double x2, double y2, int width, int height, int dpi, string format)
+        {
+            throw new NotImplementedException(); //TODO: Not needed for Live Map Editor, but will have problems when viewer component is used standalone
+        }
+
+        public Stream RenderRuntimeMap(string resourceId, double x, double y, double scale, int width, int height, int dpi, string format, bool clip)
+        {
+            throw new NotImplementedException(); //TODO: Not needed for Live Map Editor, but will have problems when viewer component is used standalone
+        }
+
+        public Stream RenderRuntimeMap(string resourceId, double x1, double y1, double x2, double y2, int width, int height, int dpi, string format, bool clip)
+        {
+            throw new NotImplementedException(); //TODO: Not needed for Live Map Editor, but will have problems when viewer component is used standalone
+        }
+
+        public Stream RenderMapLegend(Mapping.RuntimeMap map, int width, int height, System.Drawing.Color backgroundColor, string format)
+        {
+            var impl = map as LocalRuntimeMap;
+            if (impl == null)
+                throw new ArgumentException("Instance is not a LocalRuntimeMap", "map"); //LOCALIZEME
+            var renderSvc = GetRenderingService();
+            GetByteReaderMethod fetch = () =>
+            {
+                MgColor bgColor = new MgColor(backgroundColor);
+                return renderSvc.RenderMapLegend(impl.GetWrappedInstance(), width, height, bgColor, format);
+            };
+            return new MgReadOnlyStream(fetch);
+        }
+
+        public System.Drawing.Image GetLegendImage(double scale, string layerdefinition, int themeIndex, int type)
+        {
+            return GetLegendImage(scale, layerdefinition, themeIndex, type, 16, 16, "PNG");
+        }
+
+        public System.Drawing.Image GetLegendImage(double scale, string layerdefinition, int themeIndex, int type, int width, int height, string format)
+        {
+            var renderSvc = GetRenderingService();
+            GetByteReaderMethod fetch = () =>
+            {
+                MgResourceIdentifier resId = new MgResourceIdentifier(layerdefinition);
+                return renderSvc.GenerateLegendImage(resId, scale, width, height, format, type, themeIndex);
+            };
+            return new System.Drawing.Bitmap(new MgReadOnlyStream(fetch));
+        }
+
+        public string QueryMapFeatures(string runtimeMapName, string wkt, bool persist, QueryMapFeaturesLayerAttributes attributes, bool raw)
+        {
+            return string.Empty; //TODO: Not needed for Live Map Editor, but will have problems when viewer component is used standalone
+        }
+
+        public string QueryMapFeatures(string runtimeMapName, string wkt, bool persist)
+        {
+            return string.Empty; //TODO: Not needed for Live Map Editor, but will have problems when viewer component is used standalone
+        }
+
+        public string QueryMapFeatures(string runtimeMapName, int maxFeatures, string wkt, bool persist, string selectionVariant, QueryMapOptions extraOptions)
+        {
+            return string.Empty; //TODO: Not needed for Live Map Editor, but will have problems when viewer component is used standalone
+        }
     }
 }

Added: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Local/LocalRuntimeMap.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Local/LocalRuntimeMap.cs	                        (rev 0)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Local/LocalRuntimeMap.cs	2012-06-26 14:22:25 UTC (rev 6816)
@@ -0,0 +1,528 @@
+#region Disclaimer / License
+// Copyright (C) 2012, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at gmail.com
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// 
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+// 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+// 
+#endregion
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using OSGeo.MapGuide.MaestroAPI.Mapping;
+using System.Drawing;
+using OSGeo.MapGuide.ObjectModels;
+
+namespace OSGeo.MapGuide.MaestroAPI.Local
+{
+    internal class LocalRuntimeMap : RuntimeMap
+    {
+        private MgdMap _impl;
+
+        public LocalRuntimeMap(LocalConnection conn, MgdMap map) : base(conn)
+        { 
+            _impl = map;
+            InitializeLayersAndGroups();
+        }
+
+        private void InitializeLayersAndGroups()
+        {
+            this.Layers.Clear();
+            this.Groups.Clear();
+
+            var groups = _impl.GetLayerGroups();
+            var layers = _impl.GetLayers();
+
+            //Groups first
+            for (int i = 0; i < groups.GetCount(); i++)
+            {
+                this.Groups.Add(new LocalRuntimeMapGroup(this, groups.GetItem(i)));
+            }
+            
+            //Then layers
+            for (int i = 0; i < layers.GetCount(); i++)
+            {
+                this.Layers.Add(new LocalRuntimeMapLayer(this, layers.GetItem(i)));
+            }
+        }
+
+        public override System.Drawing.Color BackgroundColor
+        {
+            get
+            {
+                var bgColor = _impl.GetBackgroundColor();
+                if (bgColor.Length == 8 || bgColor.Length == 6)
+                {
+                    return ColorTranslator.FromHtml("#" + bgColor);
+                }
+                throw new InvalidOperationException("Unsure how to convert color: " + bgColor);
+            }
+            set
+            {
+                if (_disableChangeTracking) return; //Still initializing
+                throw new NotSupportedException();
+            }
+        }
+
+        public override string CoordinateSystem
+        {
+            get
+            {
+                return _impl.GetMapSRS();
+            }
+        }
+
+        public override ObjectModels.Common.IEnvelope DataExtent
+        {
+            get
+            {
+                var env = _impl.GetDataExtent();
+                var envLL = env.GetLowerLeftCoordinate();
+                var envUR = env.GetUpperRightCoordinate();
+
+                return ObjectFactory.CreateEnvelope(envLL.X, envLL.Y, envUR.X, envUR.Y);
+            }
+            set
+            {
+                if (_disableChangeTracking) return; //Still initializing
+                throw new NotSupportedException();
+            }
+        }
+
+        public override int DisplayDpi
+        {
+            get
+            {
+                return _impl.DisplayDpi;
+            }
+            set
+            {
+                _impl.DisplayDpi = value;
+            }
+        }
+
+        public override int DisplayHeight
+        {
+            get
+            {
+                return _impl.DisplayHeight;
+            }
+            set
+            {
+                _impl.SetDisplaySize(_impl.DisplayWidth, value);
+            }
+        }
+
+        public override int DisplayWidth
+        {
+            get
+            {
+                return _impl.DisplayWidth;
+            }
+            set
+            {
+                _impl.SetDisplaySize(value, _impl.DisplayHeight);
+            }
+        }
+
+        public override int LayerRefreshMode
+        {
+            get
+            {
+                return base.LayerRefreshMode;
+            }
+        }
+
+        public override string MapDefinition
+        {
+            get
+            {
+                return _impl.MapDefinition.ToString();
+            }
+        }
+
+        public override ObjectModels.Common.IEnvelope MapExtent
+        {
+            get
+            {
+                var env = _impl.GetMapExtent();
+                var envLL = env.GetLowerLeftCoordinate();
+                var envUR = env.GetUpperRightCoordinate();
+
+                return ObjectFactory.CreateEnvelope(envLL.X, envLL.Y, envUR.X, envUR.Y);
+            }
+            protected set
+            {
+                if (_disableChangeTracking) return; //Still initializing
+                throw new NotSupportedException();
+            }
+        }
+
+        public override double MetersPerUnit
+        {
+            get
+            {
+                return _impl.GetMetersPerUnit();
+            }
+        }
+
+        public override string ObjectId
+        {
+            get
+            {
+                return _impl.GetObjectId();
+            }
+        }
+
+        public override ObjectModels.Common.IPoint2D ViewCenter
+        {
+            get
+            {
+                var pt = _impl.ViewCenter;
+                var coord = pt.Coordinate;
+                return ObjectFactory.CreatePoint2D(coord.X, coord.Y);
+            }
+            set
+            {
+                if (value == null)
+                    throw new ArgumentNullException();
+
+                _impl.SetViewCenterXY(value.X, value.Y);
+            }
+        }
+
+        public override double ViewScale
+        {
+            get
+            {
+                return _impl.ViewScale;
+            }
+            set
+            {
+                _impl.SetViewScale(value);
+            }
+        }
+
+        public override int WatermarkUsage
+        {
+            get
+            {
+                return _impl.GetWatermarkUsage();
+            }
+        }
+
+        public override void Save()
+        {
+            //Synchronize the ordering of our layers and groups
+
+        }
+
+        public MgdMap GetWrappedInstance() { return _impl; }
+    }
+
+    internal class LocalRuntimeMapGroup : RuntimeMapGroup
+    {
+        private LocalRuntimeMap _parent;
+        private MgLayerGroup _impl;
+
+        public LocalRuntimeMapGroup(LocalRuntimeMap parent, MgLayerGroup group) : base(parent, "")
+        {
+            _parent = parent;
+            _impl = group;
+        }
+
+        public override bool ExpandInLegend
+        {
+            get
+            {
+                return _impl.ExpandInLegend;
+            }
+            set
+            {
+                MgdMap.SetGroupExpandInLegend(_impl, value);
+            }
+        }
+
+        public override string Group
+        {
+            get
+            {
+                var grp = _impl.Group;
+                if (grp != null)
+                    return grp.Name;
+                return null;
+            }
+            set
+            {
+                if (_disableChangeTracking) return; //Still initializing it seems
+                var impl = _parent.GetWrappedInstance();
+                var groups = impl.GetLayerGroups();
+                if (groups.IndexOf(value) >= 0)
+                {
+                    var grp = groups.GetItem(value);
+                    _impl.Group = grp;
+                }
+                else
+                {
+                    throw new ArgumentException("Group not found: " + value); //LOCALIZEME
+                }
+            }
+        }
+
+        public override string LegendLabel
+        {
+            get
+            {
+                return _impl.LegendLabel;
+            }
+            set
+            {
+                if (_disableChangeTracking) return; //Still initializing it seems
+                _impl.LegendLabel = value;
+            }
+        }
+
+        public override string Name
+        {
+            get
+            {
+                return _impl.Name;
+            }
+            set
+            {
+                if (_disableChangeTracking) return; //Still initializing it seems
+                throw new NotSupportedException();
+            }
+        }
+
+        public override string ObjectId
+        {
+            get
+            {
+                return _impl.GetObjectId();
+            }
+        }
+
+        public override bool ShowInLegend
+        {
+            get
+            {
+                return _impl.GetDisplayInLegend();
+            }
+            set
+            {
+                if (_disableChangeTracking) return; //Still initializing it seems
+                _impl.SetDisplayInLegend(value);
+            }
+        }
+
+        public override int Type
+        {
+            get
+            {
+                return _impl.LayerGroupType;
+            }
+        }
+
+        public override bool Visible
+        {
+            get
+            {
+                return _impl.Visible;
+            }
+            set
+            {
+                if (_disableChangeTracking) return; //Still initializing it seems
+                _impl.Visible = value;
+            }
+        }
+    }
+
+    internal class LocalRuntimeMapLayer : RuntimeMapLayer
+    {
+        private LocalRuntimeMap _parent;
+        private MgLayerBase _impl;
+
+        public LocalRuntimeMapLayer(LocalRuntimeMap parent, MgLayerBase layer) : base(parent)
+        {
+            _parent = parent;
+            _impl = layer;
+        }
+
+        public override bool ExpandInLegend
+        {
+            get
+            {
+                return _impl.ExpandInLegend;
+            }
+            set
+            {
+                if (_disableChangeTracking) return; //Still initializing it seems
+                MgdMap.SetLayerExpandInLegend(_impl, value);
+            }
+        }
+
+        public override string FeatureSourceID
+        {
+            get
+            {
+                return _impl.FeatureSourceId;
+            }
+        }
+
+        public override string Filter
+        {
+            get
+            {
+                return _impl.Filter;
+            }
+        }
+
+        public override string GeometryPropertyName
+        {
+            get
+            {
+                return _impl.GetFeatureGeometryName();
+            }
+        }
+
+        public override string Group
+        {
+            get
+            {
+                var grp = _impl.Group;
+                if (grp != null)
+                    return grp.Name;
+                return null;
+            }
+            set
+            {
+                if (_disableChangeTracking) return; //Still initializing it seems
+                var impl = _parent.GetWrappedInstance();
+                var groups = impl.GetLayerGroups();
+                if (groups.IndexOf(value) >= 0)
+                {
+                    var grp = groups.GetItem(value);
+                    _impl.Group = grp;
+                }
+                else
+                {
+                    throw new ArgumentException("Group not found: " + value); //LOCALIZEME
+                }
+            }
+        }
+
+        public override string LayerDefinitionID
+        {
+            get
+            {
+                return _impl.LayerDefinition.ToString();
+            }
+        }
+
+        public override string LegendLabel
+        {
+            get
+            {
+                return _impl.LegendLabel;
+            }
+            set
+            {
+                _impl.LegendLabel = value;
+            }
+        }
+
+        public override string Name
+        {
+            get
+            {
+                return _impl.Name;
+            }
+            set
+            {
+                if (_disableChangeTracking) return; //Still initializing
+                throw new NotSupportedException();
+            }
+        }
+
+        public override bool NeedsRefresh
+        {
+            get
+            {
+                return _impl.NeedsRefresh();
+            }
+        }
+
+        public override string ObjectId
+        {
+            get
+            {
+                return _impl.GetObjectId();
+            }
+        }
+
+        public override string QualifiedClassName
+        {
+            get
+            {
+                return _impl.GetClassName();
+            }
+        }
+
+        public override bool Selectable
+        {
+            get
+            {
+                return _impl.Selectable;
+            }
+            set
+            {
+                _impl.Selectable = value;
+            }
+        }
+
+        public override bool ShowInLegend
+        {
+            get
+            {
+                return _impl.DisplayInLegend;
+            }
+            set
+            {
+                _impl.DisplayInLegend = value;
+            }
+        }
+
+        public override int Type
+        {
+            get
+            {
+                return _impl.GetLayerType();
+            }
+        }
+
+        public override bool Visible
+        {
+            get
+            {
+                return _impl.Visible;
+            }
+            set
+            {
+                _impl.Visible = value;
+            }
+        }
+    }
+}

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Local/OSGeo.MapGuide.MaestroAPI.Local.csproj
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Local/OSGeo.MapGuide.MaestroAPI.Local.csproj	2012-06-26 11:58:17 UTC (rev 6815)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Local/OSGeo.MapGuide.MaestroAPI.Local.csproj	2012-06-26 14:22:25 UTC (rev 6816)
@@ -126,6 +126,7 @@
     </Compile>
     <Compile Include="LocalCapabilities.cs" />
     <Compile Include="LocalConnection.cs" />
+    <Compile Include="LocalRuntimeMap.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
   <ItemGroup>



More information about the mapguide-commits mailing list