[mapserver-commits] How to work Query Map(Zoom to Shape)
venkat
ven.tammineni at gmail.com
Fri Jun 27 01:28:30 EDT 2008
Dear All,
I am Venkat,I have one problem that is "how to work with Query Map".How
to get zoom to shape.I have done some code getting extents for shape and set
extents for shape(The complete Envelop of shape) with that i have done
some code that is set extents for shape
Ex :-
lyar = map.getLayerByName("Continents");
if (ddlContinents.SelectedIndex.ToString() == "0")
//dropdownbox filtering
{ map.setExtent(-25.36055756, -34.82200241, 63.49575806,
37.34041214); } //shape extents
But i have 3000 plues shapes .I can not write code for each and every
shape.code will be very big and complicated.
I got some sample code in Mapserver5.0.but is Console Application.I have
modified that application.I am getting error. "object not initialized"
Please anyone can help me how to use "Query Map" sample code.
Here is Sample code for Query Map :-
private static bool IsLayerQueryable(layerObj layer)
{
if (layer.type == MS_LAYER_TYPE.MS_LAYER_TILEINDEX)
return false;
if (layer.template != null && layer.template.Length > 0) return
true;
for (int i = 0; i < layer.numclasses; i++)
{
if (layer.getClass(i).template != null &&
layer.getClass(i).template.Length > 0)
return true;
}
return false;
}
public static void QueryByAttribute(string qstring, mapObj map, bool
zoomToResults)
{
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))
{
MessageBox.Show("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);
MessageBox.Show("Current map scale: 1:" +
(int)map.scaledenom);
}
}
catch (Exception e)
{
MessageBox.Show("QueryByAttribute: " + e.Message);
}
}
private static void BuildQuery(layerObj layer, string qstring)
{
if (layer != null && layer.map != null)
{
string qs = qstring;
string att = null;
MessageBox.Show("Query string: " + qs);
try
{
layer.queryByAttributes(layer.map, att, qs, 1);
}
catch (Exception e)
{
MessageBox.Show("BuildQuery: " + e.Message);
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
bool ZoomToResults = true;
QueryByAttribute("India",map, ZoomToResults);
map.querymap.status = mapscript.MS_ON;
map.querymap.color.setRGB(0, 0, 255);
map.querymap.style = (int)MS_QUERYMAP_STYLES.MS_HILITE;
}
Thanks And Regards,
Venkat.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapserver-commits/attachments/20080627/21f3aec2/attachment-0001.html
More information about the mapserver-commits
mailing list