[mapguide-commits] r6829 - in trunk/Tools/Maestro: Maestro.MapViewer OSGeo.MapGuide.MaestroAPI OSGeo.MapGuide.MaestroAPI/Mapping OSGeo.MapGuide.MaestroAPI/Services OSGeo.MapGuide.MaestroAPI.Http OSGeo.MapGuide.MaestroAPI.Local OSGeo.MapGuide.MaestroAPI.Native

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Sun Jul 1 06:54:36 PDT 2012


Author: jng
Date: 2012-07-01 06:54:36 -0700 (Sun, 01 Jul 2012)
New Revision: 6829

Modified:
   trunk/Tools/Maestro/Maestro.MapViewer/MapViewer.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Http/HttpServerConnection.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Local/LocalConnection.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Local/LocalRuntimeMap.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeConnection.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMap.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapLayer.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/MgServerConnectionBase.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Services/IMappingService.cs
Log:
This submission includes the following changes:
 - Remove obsoleted QueryMapFeatures APIs in IMappingService
 - Update the existing QueryMapFeatures API to take a RuntimeMap instead of a resource id to match updated rendering APIs
 - Update the local QueryMapFeatures implementation to map directly to the newly implemented QueryFeatures API from the recent mg-desktop release.

Modified: trunk/Tools/Maestro/Maestro.MapViewer/MapViewer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.MapViewer/MapViewer.cs	2012-07-01 11:13:41 UTC (rev 6828)
+++ trunk/Tools/Maestro/Maestro.MapViewer/MapViewer.cs	2012-07-01 13:54:36 UTC (rev 6829)
@@ -1726,7 +1726,9 @@
             }
             if (args.SelectionRenderingOptions != null)
             {
-                res.SelectionImage = Image.FromStream(_map.RenderDynamicOverlay(null, args.SelectionRenderingOptions.Format, args.SelectionRenderingOptions.Color, args.SelectionRenderingOptions.Behavior));
+                //HACK: HTTP provider is stateless, so passing the selection is not only redundant, but will probably break on large selections.
+                var sel = (_map.CurrentConnection.ProviderName.ToUpper().Equals("MAESTRO.HTTP")) ? null : _map.Selection;
+                res.SelectionImage = Image.FromStream(_map.RenderDynamicOverlay(sel, args.SelectionRenderingOptions.Format, args.SelectionRenderingOptions.Color, args.SelectionRenderingOptions.Behavior));
             }
 
             e.Result = res;
@@ -2034,7 +2036,7 @@
             var sw = new Stopwatch();
             sw.Start();
 #endif
-            _map.QueryMapFeatures(wkt, -1, true, "INTERSECTS", null);
+            _map.QueryMapFeatures(wkt, -1, true, "INTERSECTS", CreateQueryOptionsForSelection());
 #if TRACE
             sw.Stop();
             Trace.TraceInformation("Selection processing completed in {0}ms", sw.ElapsedMilliseconds);
@@ -2046,6 +2048,14 @@
                 handler(this, EventArgs.Empty);
         }
 
+        private QueryMapOptions CreateQueryOptionsForSelection()
+        {
+            return new QueryMapOptions()
+            {
+                LayerAttributeFilter = QueryMapFeaturesLayerAttributes.OnlySelectable | QueryMapFeaturesLayerAttributes.OnlyVisible
+            };
+        }
+
         protected override void OnResize(EventArgs e)
         {
             OnControlResized(this, e);

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMap.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMap.cs	2012-07-01 11:13:41 UTC (rev 6828)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMap.cs	2012-07-01 13:54:36 UTC (rev 6829)
@@ -1551,12 +1551,12 @@
                 format);
         }
 
-        public string QueryMapFeatures(string wkt, int maxFeatures, bool persist, string selectionVariant, QueryMapOptions extraOptions)
+        public virtual string QueryMapFeatures(string wkt, int maxFeatures, bool persist, string selectionVariant, QueryMapOptions extraOptions)
         {
             if (_mapSvc == null)
                 throw new NotSupportedException();
 
-            var ret = _mapSvc.QueryMapFeatures(this.Name, maxFeatures, wkt, true, selectionVariant, extraOptions);
+            var ret = _mapSvc.QueryMapFeatures(this, maxFeatures, wkt, true, selectionVariant, extraOptions);
 
             //Need to re-sync the selection as this will probably have been changed
             ReloadSelection();

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapLayer.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapLayer.cs	2012-07-01 11:13:41 UTC (rev 6828)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapLayer.cs	2012-07-01 13:54:36 UTC (rev 6829)
@@ -112,7 +112,7 @@
         /// </summary>
         public RuntimeMap Parent { get; private set; }
 
-        private void Initialize(ILayerDefinition ldf)
+        protected void Initialize(ILayerDefinition ldf)
         {
             Check.NotNull(ldf, "ldf");
             this.LayerDefinitionID = ldf.ResourceID;

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/MgServerConnectionBase.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/MgServerConnectionBase.cs	2012-07-01 11:13:41 UTC (rev 6828)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/MgServerConnectionBase.cs	2012-07-01 13:54:36 UTC (rev 6829)
@@ -171,32 +171,9 @@
 
         #region Rendering
 
-        /// <summary>
-        /// Selects features from a runtime map, returning a selection Xml.
-        /// </summary>
-        /// <param name="runtimeMapName">The map to query. NOT a resourceID, only the map name!</param>
-        /// <param name="wkt">The WKT of the geometry to query with (always uses intersection)</param>
-        /// <param name="persist">True if the selection should be saved in the runtime map, false otherwise.</param>
-        /// <returns>The selection Xml, or an empty string if there were no data.</returns>
-        public string QueryMapFeatures(string runtimeMapName, string wkt, bool persist)
-        {
-            return QueryMapFeatures(runtimeMapName, wkt, persist, QueryMapFeaturesLayerAttributes.Default, false);
-        }
+        public abstract string QueryMapFeatures(RuntimeMap rtMap, int maxFeatures, string wkt, bool persist, string selectionVariant, QueryMapOptions extraOptions);
 
         /// <summary>
-        /// Selects features from a runtime map, returning a selection Xml.
-        /// </summary>
-        /// <param name="runtimeMapName">The map to query. NOT a resourceID, only the map name!</param>
-        /// <param name="wkt">The WKT of the geometry to query with (always uses intersection)</param>
-        /// <param name="persist">True if the selection should be saved in the runtime map, false otherwise.</param>
-        /// <param name="attributes">The type of layer to include in the query</param>
-        /// <param name="raw">True if the result should contain the tooltip and link info</param>
-        /// <returns>The selection Xml, or an empty string if there were no data.</returns>
-        abstract public string QueryMapFeatures(string runtimeMapName, string wkt, bool persist, QueryMapFeaturesLayerAttributes attributes, bool raw);
-
-        public abstract string QueryMapFeatures(string runtimeMapName, int maxFeatures, string wkt, bool persist, string selectionVariant, QueryMapOptions extraOptions);
-
-        /// <summary>
         /// Renders a minature bitmap of the layers style
         /// </summary>
         /// <param name="scale">The scale for the bitmap to match</param>

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Services/IMappingService.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Services/IMappingService.cs	2012-07-01 11:13:41 UTC (rev 6828)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Services/IMappingService.cs	2012-07-01 13:54:36 UTC (rev 6829)
@@ -316,37 +316,15 @@
         System.Drawing.Image GetLegendImage(double scale, string layerdefinition, int themeIndex, int type, int width, int height, string format);
 
         /// <summary>
-        /// Selects features from a runtime map, returning a selection Xml.
-        /// </summary>
-        /// <param name="runtimeMapName">The map to query. NOT a resourceID, only the map name!</param>
-        /// <param name="wkt">The WKT of the geometry to query with (always uses intersection)</param>
-        /// <param name="persist">True if the selection should be saved in the runtime map, false otherwise.</param>
-        /// <param name="attributes">The type of layer to include in the query</param>
-        /// <param name="raw">True if the result should contain the tooltip and link info</param>
-        /// <returns>The selection Xml, or an empty string if there were no data.</returns>
-        [Obsolete("Use the version of QueryMapFeatures that isn't marked Obsolete")]
-        string QueryMapFeatures(string runtimeMapName, string wkt, bool persist, QueryMapFeaturesLayerAttributes attributes, bool raw);
-
-        /// <summary>
-        /// Selects features from a runtime map, returning a selection Xml.
-        /// </summary>
-        /// <param name="runtimeMapName">The map to query. NOT a resourceID, only the map name!</param>
-        /// <param name="wkt">The WKT of the geometry to query with (always uses intersection)</param>
-        /// <param name="persist">True if the selection should be saved in the runtime map, false otherwise.</param>
-        /// <returns>The selection Xml, or an empty string if there were no data.</returns>
-        [Obsolete("Use the version of QueryMapFeatures that isn't marked Obsolete")]
-        string QueryMapFeatures(string runtimeMapName, string wkt, bool persist);
-
-        /// <summary>
         /// Identifies features that meet the specified spatial selection criteria. These features can be persisted as selected features in a map. QueryMapFeatures returns an XML document describing the set of selected features. If a single feature is selected, the XML contains the tooltip, hyperlink, and properties of the feature.
         /// </summary>
-        /// <param name="runtimeMapName"></param>
+        /// <param name="map"></param>
         /// <param name="maxFeatures"></param>
         /// <param name="wkt"></param>
         /// <param name="persist"></param>
         /// <param name="selectionVariant"></param>
         /// <param name="extraOptions"></param>
         /// <returns></returns>
-        string QueryMapFeatures(string runtimeMapName, int maxFeatures, string wkt, bool persist, string selectionVariant, QueryMapOptions extraOptions);
+        string QueryMapFeatures(RuntimeMap map, int maxFeatures, string wkt, bool persist, string selectionVariant, QueryMapOptions extraOptions);
     }
 }

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Http/HttpServerConnection.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Http/HttpServerConnection.cs	2012-07-01 11:13:41 UTC (rev 6828)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Http/HttpServerConnection.cs	2012-07-01 13:54:36 UTC (rev 6829)
@@ -1800,8 +1800,9 @@
             }
         }
 
-        public override string QueryMapFeatures(string runtimeMapName, int maxFeatures, string wkt, bool persist, string selectionVariant, QueryMapOptions extraOptions)
+        public override string QueryMapFeatures(RuntimeMap map, int maxFeatures, string wkt, bool persist, string selectionVariant, QueryMapOptions extraOptions)
         {
+            string runtimeMapName = map.Name;
             //The request may execeed the url limit of the server, when large geometries
             System.IO.MemoryStream ms = new System.IO.MemoryStream();
             System.Net.WebRequest req = m_reqBuilder.QueryMapFeatures(runtimeMapName, maxFeatures, wkt, persist, selectionVariant, extraOptions, ms);
@@ -1818,48 +1819,6 @@
                 return sr.ReadToEnd();
         }
 
-        public override string QueryMapFeatures(string runtimeMapName, string wkt, bool persist, QueryMapFeaturesLayerAttributes attributes, bool raw)
-        {
-            //The request may execeed the url limit of the server, when large geometries
-            System.IO.MemoryStream ms = new System.IO.MemoryStream();
-            System.Net.WebRequest req = m_reqBuilder.QueryMapFeatures(runtimeMapName, persist, wkt, ms, attributes);
-            req.Timeout = 200 * 1000;
-            ms.Position = 0;
-
-            using (System.IO.Stream rs = req.GetRequestStream())
-            {
-                Utility.CopyStream(ms, rs);
-                rs.Flush();
-            }
-
-            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
-#if DEBUG
-            System.IO.MemoryStream xms = new System.IO.MemoryStream();
-            Utility.CopyStream(req.GetResponse().GetResponseStream(), xms);
-            xms.Position = 0;
-            string f = System.Text.Encoding.UTF8.GetString(xms.ToArray());
-            if (raw)
-                return f;
-            xms.Position = 0;
-            doc.Load(xms);
-
-#else
-			
-			if (raw)
-			{
-				System.IO.MemoryStream xms = new System.IO.MemoryStream();
-				Utility.CopyStream(req.GetResponse().GetResponseStream(), xms);
-				return System.Text.Encoding.UTF8.GetString(xms.ToArray());
-			}
-
-			doc.Load(req.GetResponse().GetResponseStream());
-#endif
-            if (doc.SelectSingleNode("FeatureInformation/FeatureSet") != null && doc["FeatureInformation"]["FeatureSet"].ChildNodes.Count > 0)
-                return "<FeatureSet>" + doc["FeatureInformation"]["FeatureSet"].InnerXml + "</FeatureSet>";
-            else
-                return "";
-        }
-
         public override string[] GetSchemas(string resourceId)
         {
             var req = m_reqBuilder.GetSchemas(resourceId);

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Local/LocalConnection.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Local/LocalConnection.cs	2012-07-01 11:13:41 UTC (rev 6828)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Local/LocalConnection.cs	2012-07-01 13:54:36 UTC (rev 6829)
@@ -629,7 +629,7 @@
 
         public override Version SiteVersion
         {
-            get { return new Version(2, 4, 0, 0); }
+            get { return typeof(MgdMap).Assembly.GetName().Version; }
         }
 
         public override string[] GetCustomPropertyNames()
@@ -1107,7 +1107,7 @@
 
             var ldfId = new MgResourceIdentifier(ldf.ResourceID);
             var layer = new MgdLayer(ldfId, GetResourceService());
-            return new LocalRuntimeMapLayer(impl, layer);
+            return new LocalRuntimeMapLayer(impl, layer, this);
         }
 
         public Stream RenderDynamicOverlay(Mapping.RuntimeMap map, Mapping.MapSelection selection, string format)
@@ -1263,19 +1263,57 @@
             return new System.Drawing.Bitmap(new MgReadOnlyStream(fetch));
         }
 
-        public string QueryMapFeatures(string runtimeMapName, string wkt, bool persist, QueryMapFeaturesLayerAttributes attributes, bool raw)
+        public string QueryMapFeatures(RuntimeMap rtMap, 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
-        }
+            var impl = rtMap as LocalRuntimeMap;
+            if (impl == null)
+                throw new ArgumentException("Instance is not a LocalRuntimeMap", "map"); //LOCALIZEME
 
-        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
-        }
+            var rs = GetRenderingService();
+            var res = GetResourceService();
+            var map = impl.GetWrappedInstance();
 
-        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
+            MgWktReaderWriter r = new MgWktReaderWriter();
+            MgStringCollection layerNames = null;
+            string featureFilter = "";
+            int layerAttributeFilter = 0;
+            int op = MgFeatureSpatialOperations.Intersects;
+            if (selectionVariant == "TOUCHES")
+                op = MgFeatureSpatialOperations.Touches;
+            else if (selectionVariant == "INTERSECTS")
+                op = MgFeatureSpatialOperations.Intersects;
+            else if (selectionVariant == "WITHIN")
+                op = MgFeatureSpatialOperations.Within;
+            else if (selectionVariant == "ENVELOPEINTERSECTS")
+                op = MgFeatureSpatialOperations.EnvelopeIntersects;
+            else
+                throw new ArgumentException("Unknown or unsupported selection variant: " + selectionVariant);
+
+            if (extraOptions != null)
+            {
+                if (!string.IsNullOrEmpty(extraOptions.FeatureFilter))
+                    featureFilter = extraOptions.FeatureFilter;
+                if (extraOptions.LayerNames != null && extraOptions.LayerNames.Length > 0)
+                {
+                    layerNames = new MgStringCollection();
+                    foreach (var name in extraOptions.LayerNames)
+                        layerNames.Add(name);
+                }
+                layerAttributeFilter = (int)extraOptions.LayerAttributeFilter;
+            }
+
+            MgdFeatureInformation info = rs.QueryFeatures(map, layerNames, r.Read(wkt), op, featureFilter, maxFeatures, layerAttributeFilter);
+
+            string xml = "";
+            GetByteReaderMethod fetch = () => { return info.ToXml(); };
+            using (var sr = new StreamReader(new MgReadOnlyStream(fetch)))
+            {
+                xml = sr.ReadToEnd();
+            }
+            
+            impl.Selection.LoadXml(xml);
+
+            return xml;
         }
     }
 }

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Local/LocalRuntimeMap.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Local/LocalRuntimeMap.cs	2012-07-01 11:13:41 UTC (rev 6828)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Local/LocalRuntimeMap.cs	2012-07-01 13:54:36 UTC (rev 6829)
@@ -24,6 +24,8 @@
 using OSGeo.MapGuide.MaestroAPI.Mapping;
 using System.Drawing;
 using OSGeo.MapGuide.ObjectModels;
+using OSGeo.MapGuide.MaestroAPI.Services;
+using OSGeo.MapGuide.ObjectModels.LayerDefinition;
 
 namespace OSGeo.MapGuide.MaestroAPI.Local
 {
@@ -36,10 +38,12 @@
     internal class LocalRuntimeMap : RuntimeMap
     {
         private MgdMap _impl;
+        private LocalConnection _conn;
 
         public LocalRuntimeMap(LocalConnection conn, MgdMap map) : base(conn)
         { 
             _impl = map;
+            _conn = conn;
             InitializeLayersAndGroups();
             _disableChangeTracking = false;
         }
@@ -61,7 +65,7 @@
             //Then layers
             for (int i = 0; i < layers.GetCount(); i++)
             {
-                this.Layers.Add(new LocalRuntimeMapLayer(this, layers.GetItem(i)));
+                this.Layers.Add(new LocalRuntimeMapLayer(this, layers.GetItem(i), _conn));
             }
         }
 
@@ -433,10 +437,13 @@
         private LocalRuntimeMap _parent;
         private MgLayerBase _impl;
 
-        public LocalRuntimeMapLayer(LocalRuntimeMap parent, MgLayerBase layer) : base(parent)
+        internal LocalRuntimeMapLayer(LocalRuntimeMap parent, MgLayerBase layer, IResourceService resSvc) : base(parent)
         {
             _parent = parent;
             _impl = layer;
+            var ldfId = layer.GetLayerDefinition();
+            var ldf = (ILayerDefinition)resSvc.GetResource(ldfId.ToString());
+            Initialize(ldf);
             _disableChangeTracking = false;
         }
 
@@ -565,7 +572,7 @@
         {
             get
             {
-                return _impl.GetClassName();
+                return _impl.GetFeatureClassName();
             }
         }
 

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeConnection.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeConnection.cs	2012-07-01 11:13:41 UTC (rev 6828)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeConnection.cs	2012-07-01 13:54:36 UTC (rev 6829)
@@ -1334,8 +1334,9 @@
             return new MgReadOnlyStream(fetch);
         }
 
-        public override string QueryMapFeatures(string runtimeMapName, int maxFeatures, string wkt, bool persist, string selectionVariant, QueryMapOptions extraOptions)
+        public override string QueryMapFeatures(RuntimeMap rtMap, int maxFeatures, string wkt, bool persist, string selectionVariant, QueryMapOptions extraOptions)
         {
+            string runtimeMapName = rtMap.Name;
             MgRenderingService rs = this.Connection.CreateService(MgServiceType.RenderingService) as MgRenderingService;
             MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
             MgMap map = new MgMap();
@@ -1387,31 +1388,6 @@
             return xml;
         }
 
-        public override string QueryMapFeatures(string runtimeMapName, string wkt, bool persist, QueryMapFeaturesLayerAttributes attributes, bool raw)
-        {
-            MgRenderingService rs = this.Connection.CreateService(MgServiceType.RenderingService) as MgRenderingService;
-            MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
-            MgMap map = new MgMap();
-            string mapname = runtimeMapName.IndexOf(":") > 0 ? new ResourceIdentifier(runtimeMapName).Path : runtimeMapName;
-            map.Open(res, mapname);
-
-            MgWktReaderWriter r = new MgWktReaderWriter();
-            MgFeatureInformation info = rs.QueryFeatures(map, null, r.Read(wkt), (int)MgFeatureSpatialOperations.Intersects, "", -1, (int)attributes);
-
-            string xml = "";
-            GetByteReaderMethod fetch = () => { return info.ToXml(); };
-            using (var sr = new StreamReader(new MgReadOnlyStream(fetch)))
-            {
-                xml = sr.ReadToEnd();
-            }
-            MgSelection sel = new MgSelection(map, xml);
-            sel.Save(res, mapname);
-
-            LogMethodCall("QueryMapFeatures", true, runtimeMapName, wkt, persist, (int)attributes, raw);
-
-            return xml;
-        }
-
         internal void InsertFeatures(MgResourceIdentifier fsId, string className, MgPropertyCollection props)
         {
             try



More information about the mapguide-commits mailing list