You should calculate the bounds of the results by reading the bounds of the resultCacheObj and set the extent of the map accordingly.
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)
{
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 (zoomToResults)
map.setExtent(query_bounds.minx, query_bounds.miny,
query_bounds.maxx, query_bounds.maxy);
}
catch (Exception e)
{
Console.WriteLine("QueryByAttribute: " + e.Message);
}
}
private static void BuildQuery(layerObj layer, string qstring)
{
if (layer != null && layer.map != null)
{
layer.open();
string qs = "";
string att = "";
for (int i=0; i < layer.numitems; i++)
{
if (qs == "")
{
qs = "(";
att = layer.getItem(i);
}
else
{
qs += " OR ";
}
qs += "'[" + layer.getItem(i) + "]'='" + qstring + "'";
}
qs += ")";
layer.close();
Console.WriteLine("Query string: " + qs);
try
{
layer.queryByAttributes(layer.map, att, qs, 1);
}
catch (Exception e)
{
Console.WriteLine("BuildQuery: " + e.Message);
}
}
}
The complete example can be found here:
http://trac.osgeo.org/mapserver/browser/trunk/mapserver/mapscript/csharp/examples/drawquery.cs
and I've attached the resulting image of the sample by using / not
using the zoom option.
2007/6/2, lakku <[EMAIL PROTECTED]>:
iam working with mapscript c# i have hilited a query on the map. now i want to zoom the hilited query anybody plz tell me the code in c# -- View this message in context: http://www.nabble.com/zoom-hilited-query-in-c--tf3856419.html#a10925940 Sent from the Mapserver - User mailing list archive at Nabble.com.
<<attachment: Hun_zoom.png>>
<<attachment: Hun.png>>
