[mapguide-commits] r6249 - in trunk/Tools/Maestro: OSGeo.MapGuide.MaestroAPI OSGeo.MapGuide.MaestroAPI/Services OSGeo.MapGuide.MaestroAPI.Http OSGeo.MapGuide.MaestroAPI.Native

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Thu Nov 24 09:32:43 EST 2011


Author: jng
Date: 2011-11-24 06:32:43 -0800 (Thu, 24 Nov 2011)
New Revision: 6249

Modified:
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Http/HttpServerConnection.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeConnection.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/MgServerConnectionBase.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Services/IMappingService.cs
Log:
Re-introduce QueryMapFeatures to IMappingService. The implementation is a direct copy/paste from Maestro 2.1

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/MgServerConnectionBase.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/MgServerConnectionBase.cs	2011-11-23 14:56:48 UTC (rev 6248)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/MgServerConnectionBase.cs	2011-11-24 14:32:43 UTC (rev 6249)
@@ -146,6 +146,29 @@
         #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);
+        }
+
+        /// <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);
+
+        /// <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	2011-11-23 14:56:48 UTC (rev 6248)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Services/IMappingService.cs	2011-11-24 14:32:43 UTC (rev 6249)
@@ -238,5 +238,25 @@
         /// <param name="type">The geometry type, 1 for point, 2 for line, 3 for area, 4 for composite</param>
         /// <returns>The minature bitmap</returns>
         System.Drawing.Image GetLegendImage(double scale, string layerdefinition, int themeIndex, int type);
+
+        /// <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>
+        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>
+        string QueryMapFeatures(string runtimeMapName, string wkt, bool persist);
     }
 }

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Http/HttpServerConnection.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Http/HttpServerConnection.cs	2011-11-23 14:56:48 UTC (rev 6248)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Http/HttpServerConnection.cs	2011-11-24 14:32:43 UTC (rev 6249)
@@ -1710,6 +1710,48 @@
             }
         }
 
+        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.Native/LocalNativeConnection.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeConnection.cs	2011-11-23 14:56:48 UTC (rev 6248)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeConnection.cs	2011-11-24 14:32:43 UTC (rev 6249)
@@ -1193,5 +1193,36 @@
             LogMethodCall("MgDrawingService::GetSectionResource", true, resourceID, resourceName);
             return res;
         }
+
+        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);
+
+            using (var ms = new MemoryStream())
+            {
+                using (var stream = Utility.MgStreamToNetStream(info, info.GetType().GetMethod("ToXml"), null))
+                {
+                    MaestroAPI.Utility.CopyStream(stream, ms);
+                    ms.Position = 0L;
+
+                    string xml = System.Text.Encoding.UTF8.GetString(ms.ToArray()).Trim();
+
+                    if (persist)
+                    {
+                        MgSelection sel = new MgSelection(map, xml);
+                        sel.Save(res, mapname);
+                    }
+
+                    return xml;
+                }
+            }
+        }
     }
 }



More information about the mapguide-commits mailing list