Exemplo n.º 1
0
 public static void QueryByAttribute(string qstring, mapObj map, bool zoomToResults)
 {
     Console.WriteLine("\nPerforming QueryByAttribute:");
     try
     {
         layerObj layer;
         rectObj  query_bounds = null;
         for (int i = 0; i < map.numlayers; i++)
         {
             layer = map.getLayer(i);
             if (layer.connection != null && IsLayerQueryable(layer))
             {
                 Console.WriteLine("Layer [" + i + "] name: " + layer.name);
                 BuildQuery(layer, qstring);
                 // zoom to the query results
                 using (resultCacheObj results = layer.getResults())
                 {
                     if (results != null && results.numresults > 0)
                     {
                         // calculating the extent of the results
                         if (query_bounds == null)
                         {
                             query_bounds = new rectObj(results.bounds.minx, results.bounds.miny,
                                                        results.bounds.maxx, results.bounds.maxy, 0);
                         }
                         else
                         {
                             if (results.bounds.minx < query_bounds.minx)
                             {
                                 query_bounds.minx = results.bounds.minx;
                             }
                             if (results.bounds.miny < query_bounds.miny)
                             {
                                 query_bounds.miny = results.bounds.miny;
                             }
                             if (results.bounds.maxx > query_bounds.maxx)
                             {
                                 query_bounds.maxx = results.bounds.maxx;
                             }
                             if (results.bounds.maxy > query_bounds.maxy)
                             {
                                 query_bounds.maxy = results.bounds.maxy;
                             }
                         }
                     }
                 }
             }
         }
         // setting the map extent to the result bounds
         if (query_bounds != null)
         {
             if (zoomToResults)
             {
                 map.setExtent(query_bounds.minx, query_bounds.miny, query_bounds.maxx, query_bounds.maxy);
                 map.scaleExtent(1.2, 0, 0);                     // increasing the visible area
                 Console.WriteLine("Current map scale: 1:" + (int)map.scaledenom);
             }
         }
         else
         {
             Console.WriteLine("The query returned 0 results ...");
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("QueryByAttribute: " + e.Message);
     }
 }
Exemplo n.º 2
0
    public static void QueryByAttribute(string qstring, mapObj map, bool zoomToResults)
    {
        Console.WriteLine("\nPerforming QueryByAttribute:");
        try
        {
        	layerObj layer;
            rectObj query_bounds = null;
            for (int i = 0; i < map.numlayers; i++)
            {
                layer = map.getLayer(i);
                if (layer.connection != null && IsLayerQueryable(layer))
                {
                    Console.WriteLine("Layer [" + i + "] name: " + layer.name);
                    BuildQuery(layer, qstring);
                    // zoom to the query results
                    using (resultCacheObj results = layer.getResults())
                    {
                        if (results != null && results.numresults > 0)
                        {
                            // calculating the extent of the results
                            if (query_bounds == null)
                                query_bounds = new rectObj(results.bounds.minx, results.bounds.miny,
                                    results.bounds.maxx, results.bounds.maxy,0);
                            else
                            {
                                if (results.bounds.minx < query_bounds.minx) query_bounds.minx = results.bounds.minx;
                                if (results.bounds.miny < query_bounds.miny) query_bounds.miny = results.bounds.miny;
                                if (results.bounds.maxx > query_bounds.maxx) query_bounds.maxx = results.bounds.maxx;
                                if (results.bounds.maxy > query_bounds.maxy) query_bounds.maxy = results.bounds.maxy;
                            }
                        }
                    }
                }
            }
            // setting the map extent to the result bounds
			if (query_bounds != null) 
			{
				if (zoomToResults) 
				{
					map.setExtent(query_bounds.minx, query_bounds.miny, query_bounds.maxx, query_bounds.maxy);
					map.scaleExtent(1.2, 0, 0); // increasing the visible area
					Console.WriteLine("Current map scale: 1:" + (int)map.scaledenom);
				}
			}
			else
				Console.WriteLine("The query returned 0 results ...");
        }
        catch (Exception e)
        {
        	Console.WriteLine("QueryByAttribute: " + e.Message);
        }
    }